1998-08-20 08:19:55 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1996, 1998 Robert Nordier
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS
|
|
|
|
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
|
|
|
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
|
|
|
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
|
|
|
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2001-09-30 22:28:01 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1998-08-20 08:19:55 +00:00
|
|
|
/*
|
|
|
|
* Readonly filesystem for Microsoft FAT12/FAT16/FAT32 filesystems,
|
|
|
|
* also supports VFAT.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
#include "stand.h"
|
|
|
|
|
|
|
|
#include "dosfs.h"
|
|
|
|
|
|
|
|
|
1998-10-06 19:23:57 +00:00
|
|
|
static int dos_open(const char *path, struct open_file *fd);
|
1998-08-20 08:19:55 +00:00
|
|
|
static int dos_close(struct open_file *fd);
|
|
|
|
static int dos_read(struct open_file *fd, void *buf, size_t size, size_t *resid);
|
|
|
|
static off_t dos_seek(struct open_file *fd, off_t offset, int whence);
|
|
|
|
static int dos_stat(struct open_file *fd, struct stat *sb);
|
2010-01-09 22:33:34 +00:00
|
|
|
static int dos_readdir(struct open_file *fd, struct dirent *d);
|
1998-08-20 08:19:55 +00:00
|
|
|
|
1998-08-27 10:45:20 +00:00
|
|
|
struct fs_ops dosfs_fsops = {
|
2000-04-29 20:47:10 +00:00
|
|
|
"dosfs",
|
|
|
|
dos_open,
|
|
|
|
dos_close,
|
|
|
|
dos_read,
|
|
|
|
null_write,
|
|
|
|
dos_seek,
|
|
|
|
dos_stat,
|
2010-01-09 22:33:34 +00:00
|
|
|
dos_readdir
|
1998-08-20 08:19:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define SECSIZ 512 /* sector size */
|
|
|
|
#define SSHIFT 9 /* SECSIZ shift */
|
|
|
|
#define DEPSEC 16 /* directory entries per sector */
|
|
|
|
#define DSHIFT 4 /* DEPSEC shift */
|
|
|
|
#define LOCLUS 2 /* lowest cluster number */
|
2017-04-06 20:12:39 +00:00
|
|
|
#define FATBLKSZ 0x20000 /* size of block in the FAT cache buffer */
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
/* DOS "BIOS Parameter Block" */
|
|
|
|
typedef struct {
|
|
|
|
u_char secsiz[2]; /* sector size */
|
|
|
|
u_char spc; /* sectors per cluster */
|
|
|
|
u_char ressec[2]; /* reserved sectors */
|
|
|
|
u_char fats; /* FATs */
|
|
|
|
u_char dirents[2]; /* root directory entries */
|
|
|
|
u_char secs[2]; /* total sectors */
|
|
|
|
u_char media; /* media descriptor */
|
|
|
|
u_char spf[2]; /* sectors per FAT */
|
|
|
|
u_char spt[2]; /* sectors per track */
|
|
|
|
u_char heads[2]; /* drive heads */
|
|
|
|
u_char hidsec[4]; /* hidden sectors */
|
|
|
|
u_char lsecs[4]; /* huge sectors */
|
|
|
|
u_char lspf[4]; /* huge sectors per FAT */
|
|
|
|
u_char xflg[2]; /* flags */
|
|
|
|
u_char vers[2]; /* filesystem version */
|
|
|
|
u_char rdcl[4]; /* root directory start cluster */
|
|
|
|
u_char infs[2]; /* filesystem info sector */
|
|
|
|
u_char bkbs[2]; /* backup boot sector */
|
|
|
|
} DOS_BPB;
|
|
|
|
|
|
|
|
/* Initial portion of DOS boot sector */
|
|
|
|
typedef struct {
|
|
|
|
u_char jmp[3]; /* usually 80x86 'jmp' opcode */
|
|
|
|
u_char oem[8]; /* OEM name and version */
|
|
|
|
DOS_BPB bpb; /* BPB */
|
|
|
|
} DOS_BS;
|
|
|
|
|
|
|
|
/* Supply missing "." and ".." root directory entries */
|
|
|
|
static const char *const dotstr[2] = {".", ".."};
|
|
|
|
static DOS_DE dot[2] = {
|
|
|
|
{". ", " ", FA_DIR, {0, 0, {0, 0}, {0, 0}, {0, 0}, {0, 0}},
|
|
|
|
{0, 0}, {0x21, 0}, {0, 0}, {0, 0, 0, 0}},
|
|
|
|
{".. ", " ", FA_DIR, {0, 0, {0, 0}, {0, 0}, {0, 0}, {0, 0}},
|
|
|
|
{0, 0}, {0x21, 0}, {0, 0}, {0, 0, 0, 0}}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* The usual conversion macros to avoid multiplication and division */
|
|
|
|
#define bytsec(n) ((n) >> SSHIFT)
|
|
|
|
#define secbyt(s) ((s) << SSHIFT)
|
|
|
|
#define entsec(e) ((e) >> DSHIFT)
|
|
|
|
#define bytblk(fs, n) ((n) >> (fs)->bshift)
|
|
|
|
#define blkbyt(fs, b) ((b) << (fs)->bshift)
|
|
|
|
#define secblk(fs, s) ((s) >> ((fs)->bshift - SSHIFT))
|
|
|
|
#define blksec(fs, b) ((b) << ((fs)->bshift - SSHIFT))
|
|
|
|
|
|
|
|
/* Convert cluster number to offset within filesystem */
|
|
|
|
#define blkoff(fs, b) (secbyt((fs)->lsndta) + blkbyt(fs, (b) - LOCLUS))
|
|
|
|
|
|
|
|
/* Convert cluster number to logical sector number */
|
|
|
|
#define blklsn(fs, b) ((fs)->lsndta + blksec(fs, (b) - LOCLUS))
|
|
|
|
|
|
|
|
/* Convert cluster number to offset within FAT */
|
|
|
|
#define fatoff(sz, c) ((sz) == 12 ? (c) + ((c) >> 1) : \
|
|
|
|
(sz) == 16 ? (c) << 1 : \
|
|
|
|
(c) << 2)
|
|
|
|
|
|
|
|
/* Does cluster number reference a valid data cluster? */
|
|
|
|
#define okclus(fs, c) ((c) >= LOCLUS && (c) <= (fs)->xclus)
|
|
|
|
|
|
|
|
/* Get start cluster from directory entry */
|
|
|
|
#define stclus(sz, de) ((sz) != 32 ? cv2((de)->clus) : \
|
|
|
|
((u_int)cv2((de)->dex.h_clus) << 16) | \
|
|
|
|
cv2((de)->clus))
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
|
1998-08-20 08:19:55 +00:00
|
|
|
static int parsebs(DOS_FS *, DOS_BS *);
|
|
|
|
static int namede(DOS_FS *, const char *, DOS_DE **);
|
|
|
|
static int lookup(DOS_FS *, u_int, const char *, DOS_DE **);
|
|
|
|
static void cp_xdnm(u_char *, DOS_XDE *);
|
|
|
|
static void cp_sfn(u_char *, DOS_DE *);
|
1998-08-27 10:45:20 +00:00
|
|
|
static off_t fsize(DOS_FS *, DOS_DE *);
|
|
|
|
static int fatcnt(DOS_FS *, u_int);
|
1998-08-20 08:19:55 +00:00
|
|
|
static int fatget(DOS_FS *, u_int *);
|
|
|
|
static int fatend(u_int, u_int);
|
2017-04-06 20:12:39 +00:00
|
|
|
static int ioread(DOS_FS *, u_int, void *, size_t);
|
|
|
|
static int ioget(struct open_file *, daddr_t, void *, size_t);
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
|
2017-04-06 20:12:39 +00:00
|
|
|
static int
|
|
|
|
dos_read_fatblk(DOS_FS *fs, struct open_file *fd, u_int blknum)
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
{
|
2017-04-06 20:12:39 +00:00
|
|
|
int err;
|
|
|
|
size_t io_size;
|
|
|
|
daddr_t offset_in_fat, max_offset_in_fat;
|
|
|
|
|
|
|
|
offset_in_fat = ((daddr_t)blknum) * FATBLKSZ;
|
|
|
|
max_offset_in_fat = secbyt(fs->spf);
|
|
|
|
io_size = FATBLKSZ;
|
|
|
|
if (offset_in_fat > max_offset_in_fat)
|
|
|
|
offset_in_fat = max_offset_in_fat;
|
|
|
|
if (offset_in_fat + io_size > max_offset_in_fat)
|
|
|
|
io_size = ((size_t)(max_offset_in_fat - offset_in_fat));
|
|
|
|
|
|
|
|
if (io_size != 0) {
|
|
|
|
err = ioget(fd, fs->lsnfat + bytsec(offset_in_fat),
|
|
|
|
fs->fatbuf, io_size);
|
|
|
|
if (err != 0) {
|
|
|
|
fs->fatbuf_blknum = ((u_int)(-1));
|
|
|
|
return (err);
|
|
|
|
}
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
}
|
2017-04-06 20:12:39 +00:00
|
|
|
if (io_size < FATBLKSZ)
|
|
|
|
memset(fs->fatbuf + io_size, 0, FATBLKSZ - io_size);
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
|
2017-04-06 20:12:39 +00:00
|
|
|
fs->fatbuf_blknum = blknum;
|
|
|
|
return (0);
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
}
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Mount DOS filesystem
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
dos_mount(DOS_FS *fs, struct open_file *fd)
|
|
|
|
{
|
|
|
|
int err;
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
u_char *buf;
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
bzero(fs, sizeof(DOS_FS));
|
|
|
|
fs->fd = fd;
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
|
2017-04-06 20:12:39 +00:00
|
|
|
if ((buf = malloc(secbyt(1))) == NULL)
|
|
|
|
return (errno);
|
|
|
|
if ((err = ioget(fs->fd, 0, buf, secbyt(1))) ||
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
(err = parsebs(fs, (DOS_BS *)buf))) {
|
2017-04-06 20:12:39 +00:00
|
|
|
free(buf);
|
2016-12-01 19:19:20 +00:00
|
|
|
return (err);
|
1998-08-20 08:19:55 +00:00
|
|
|
}
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
free(buf);
|
|
|
|
|
2017-04-06 20:12:39 +00:00
|
|
|
if ((fs->fatbuf = malloc(FATBLKSZ)) == NULL)
|
|
|
|
return (errno);
|
|
|
|
err = dos_read_fatblk(fs, fd, 0);
|
|
|
|
if (err != 0) {
|
|
|
|
free(fs->fatbuf);
|
|
|
|
return (err);
|
|
|
|
}
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
|
2013-12-19 05:23:10 +00:00
|
|
|
fs->root = dot[0];
|
|
|
|
fs->root.name[0] = ' ';
|
|
|
|
if (fs->fatsz == 32) {
|
|
|
|
fs->root.clus[0] = fs->rdcl & 0xff;
|
|
|
|
fs->root.clus[1] = (fs->rdcl >> 8) & 0xff;
|
|
|
|
fs->root.dex.h_clus[0] = (fs->rdcl >> 16) & 0xff;
|
|
|
|
fs->root.dex.h_clus[1] = (fs->rdcl >> 24) & 0xff;
|
|
|
|
}
|
2016-12-01 19:19:20 +00:00
|
|
|
return (0);
|
1998-08-20 08:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unmount mounted filesystem
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
dos_unmount(DOS_FS *fs)
|
|
|
|
{
|
|
|
|
if (fs->links)
|
2016-12-01 19:19:20 +00:00
|
|
|
return (EBUSY);
|
2017-04-06 20:12:39 +00:00
|
|
|
free(fs->fatbuf);
|
1998-08-27 10:45:20 +00:00
|
|
|
free(fs);
|
2016-12-01 19:19:20 +00:00
|
|
|
return (0);
|
1998-08-20 08:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open DOS file
|
|
|
|
*/
|
|
|
|
static int
|
1998-10-06 19:23:57 +00:00
|
|
|
dos_open(const char *path, struct open_file *fd)
|
1998-08-20 08:19:55 +00:00
|
|
|
{
|
|
|
|
DOS_DE *de;
|
|
|
|
DOS_FILE *f;
|
|
|
|
DOS_FS *fs;
|
|
|
|
u_int size, clus;
|
2017-04-06 20:12:39 +00:00
|
|
|
int err;
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
/* Allocate mount structure, associate with open */
|
2017-04-06 20:12:39 +00:00
|
|
|
if ((fs = malloc(sizeof(DOS_FS))) == NULL)
|
|
|
|
return (errno);
|
|
|
|
if ((err = dos_mount(fs, fd))) {
|
|
|
|
free(fs);
|
|
|
|
return (err);
|
|
|
|
}
|
1998-08-20 08:19:55 +00:00
|
|
|
|
2017-04-06 20:12:39 +00:00
|
|
|
if ((err = namede(fs, path, &de))) {
|
|
|
|
dos_unmount(fs);
|
|
|
|
return (err);
|
|
|
|
}
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
clus = stclus(fs->fatsz, de);
|
|
|
|
size = cv4(de->size);
|
1998-08-27 10:45:20 +00:00
|
|
|
|
|
|
|
if ((!(de->attr & FA_DIR) && (!clus != !size)) ||
|
|
|
|
((de->attr & FA_DIR) && size) ||
|
|
|
|
(clus && !okclus(fs, clus))) {
|
2017-04-06 20:12:39 +00:00
|
|
|
dos_unmount(fs);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
if ((f = malloc(sizeof(DOS_FILE))) == NULL) {
|
|
|
|
err = errno;
|
|
|
|
dos_unmount(fs);
|
|
|
|
return (err);
|
1998-08-20 08:19:55 +00:00
|
|
|
}
|
|
|
|
bzero(f, sizeof(DOS_FILE));
|
|
|
|
f->fs = fs;
|
|
|
|
fs->links++;
|
|
|
|
f->de = *de;
|
|
|
|
fd->f_fsdata = (void *)f;
|
2017-04-06 20:12:39 +00:00
|
|
|
return (0);
|
1998-08-20 08:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read from file
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
dos_read(struct open_file *fd, void *buf, size_t nbyte, size_t *resid)
|
|
|
|
{
|
1998-08-27 10:45:20 +00:00
|
|
|
off_t size;
|
1998-08-20 08:19:55 +00:00
|
|
|
u_int nb, off, clus, c, cnt, n;
|
|
|
|
DOS_FILE *f = (DOS_FILE *)fd->f_fsdata;
|
|
|
|
int err = 0;
|
|
|
|
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
/*
|
|
|
|
* as ioget() can be called *a lot*, use twiddle here.
|
|
|
|
* also 4 seems to be good value not to slow loading down too much:
|
|
|
|
* with 270MB file (~540k ioget() calls, twiddle can easily waste 4-5sec.
|
|
|
|
*/
|
|
|
|
twiddle(4);
|
1998-08-20 08:19:55 +00:00
|
|
|
nb = (u_int)nbyte;
|
1998-08-27 10:45:20 +00:00
|
|
|
if ((size = fsize(f->fs, &f->de)) == -1)
|
2016-12-01 19:19:20 +00:00
|
|
|
return (EINVAL);
|
1998-08-27 10:45:20 +00:00
|
|
|
if (nb > (n = size - f->offset))
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
nb = n;
|
1998-08-20 08:19:55 +00:00
|
|
|
off = f->offset;
|
|
|
|
if ((clus = stclus(f->fs->fatsz, &f->de)))
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
off &= f->fs->bsize - 1;
|
1998-08-20 08:19:55 +00:00
|
|
|
c = f->c;
|
|
|
|
cnt = nb;
|
|
|
|
while (cnt) {
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
n = 0;
|
|
|
|
if (!c) {
|
|
|
|
if ((c = clus))
|
|
|
|
n = bytblk(f->fs, f->offset);
|
|
|
|
} else if (!off)
|
|
|
|
n++;
|
|
|
|
while (n--) {
|
|
|
|
if ((err = fatget(f->fs, &c)))
|
1998-08-20 08:19:55 +00:00
|
|
|
goto out;
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
if (!okclus(f->fs, c)) {
|
1998-08-20 08:19:55 +00:00
|
|
|
err = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
}
|
|
|
|
if (!clus || (n = f->fs->bsize - off) > cnt)
|
|
|
|
n = cnt;
|
|
|
|
if ((err = ioread(f->fs, (c ? blkoff(f->fs, c) :
|
|
|
|
secbyt(f->fs->lsndir)) + off, buf, n)))
|
1998-08-20 08:19:55 +00:00
|
|
|
goto out;
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
f->offset += n;
|
|
|
|
f->c = c;
|
|
|
|
off = 0;
|
|
|
|
buf = (char *)buf + n;
|
|
|
|
cnt -= n;
|
1998-08-20 08:19:55 +00:00
|
|
|
}
|
|
|
|
out:
|
|
|
|
if (resid)
|
1998-08-27 10:45:20 +00:00
|
|
|
*resid = nbyte - nb + cnt;
|
2016-12-01 19:19:20 +00:00
|
|
|
return (err);
|
1998-08-20 08:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reposition within file
|
|
|
|
*/
|
|
|
|
static off_t
|
|
|
|
dos_seek(struct open_file *fd, off_t offset, int whence)
|
|
|
|
{
|
|
|
|
off_t off;
|
|
|
|
u_int size;
|
|
|
|
DOS_FILE *f = (DOS_FILE *)fd->f_fsdata;
|
|
|
|
|
|
|
|
size = cv4(f->de.size);
|
|
|
|
switch (whence) {
|
|
|
|
case SEEK_SET:
|
|
|
|
off = 0;
|
|
|
|
break;
|
|
|
|
case SEEK_CUR:
|
|
|
|
off = f->offset;
|
|
|
|
break;
|
|
|
|
case SEEK_END:
|
|
|
|
off = size;
|
|
|
|
break;
|
|
|
|
default:
|
2004-01-21 20:12:23 +00:00
|
|
|
errno = EINVAL;
|
2016-12-01 19:19:20 +00:00
|
|
|
return (-1);
|
1998-08-20 08:19:55 +00:00
|
|
|
}
|
|
|
|
off += offset;
|
2004-01-21 20:12:23 +00:00
|
|
|
if (off < 0 || off > size) {
|
|
|
|
errno = EINVAL;
|
2016-12-01 19:19:20 +00:00
|
|
|
return (-1);
|
2004-01-21 20:12:23 +00:00
|
|
|
}
|
1998-08-20 08:19:55 +00:00
|
|
|
f->offset = (u_int)off;
|
|
|
|
f->c = 0;
|
2016-12-01 19:19:20 +00:00
|
|
|
return (off);
|
1998-08-20 08:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Close open file
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
dos_close(struct open_file *fd)
|
|
|
|
{
|
|
|
|
DOS_FILE *f = (DOS_FILE *)fd->f_fsdata;
|
|
|
|
DOS_FS *fs = f->fs;
|
|
|
|
|
|
|
|
f->fs->links--;
|
1998-08-27 10:45:20 +00:00
|
|
|
free(f);
|
1998-08-20 08:19:55 +00:00
|
|
|
dos_unmount(fs);
|
2016-12-01 19:19:20 +00:00
|
|
|
return (0);
|
1998-08-20 08:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return some stat information on a file.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
dos_stat(struct open_file *fd, struct stat *sb)
|
|
|
|
{
|
|
|
|
DOS_FILE *f = (DOS_FILE *)fd->f_fsdata;
|
|
|
|
|
|
|
|
/* only important stuff */
|
1998-08-27 10:45:20 +00:00
|
|
|
sb->st_mode = f->de.attr & FA_DIR ? S_IFDIR | 0555 : S_IFREG | 0444;
|
1998-08-20 08:19:55 +00:00
|
|
|
sb->st_nlink = 1;
|
|
|
|
sb->st_uid = 0;
|
|
|
|
sb->st_gid = 0;
|
1998-08-27 10:45:20 +00:00
|
|
|
if ((sb->st_size = fsize(f->fs, &f->de)) == -1)
|
2016-12-01 19:19:20 +00:00
|
|
|
return (EINVAL);
|
1998-08-20 08:19:55 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
static int
|
|
|
|
dos_checksum(char *name, char *ext)
|
|
|
|
{
|
|
|
|
int x, i;
|
|
|
|
char buf[11];
|
|
|
|
|
|
|
|
bcopy(name, buf, 8);
|
|
|
|
bcopy(ext, buf+8, 3);
|
|
|
|
x = 0;
|
|
|
|
for (i = 0; i < 11; i++) {
|
|
|
|
x = ((x & 1) << 7) | (x >> 1);
|
|
|
|
x += buf[i];
|
|
|
|
x &= 0xff;
|
|
|
|
}
|
|
|
|
return (x);
|
|
|
|
}
|
|
|
|
|
2010-01-09 22:33:34 +00:00
|
|
|
static int
|
|
|
|
dos_readdir(struct open_file *fd, struct dirent *d)
|
|
|
|
{
|
2011-05-03 07:43:47 +00:00
|
|
|
/* DOS_FILE *f = (DOS_FILE *)fd->f_fsdata; */
|
2010-01-09 22:33:34 +00:00
|
|
|
u_char fn[261];
|
|
|
|
DOS_DIR dd;
|
|
|
|
size_t res;
|
2016-08-26 14:58:57 +00:00
|
|
|
u_int chk, x, xdn;
|
2010-01-09 22:33:34 +00:00
|
|
|
int err;
|
|
|
|
|
|
|
|
x = chk = 0;
|
|
|
|
while (1) {
|
|
|
|
xdn = x;
|
|
|
|
x = 0;
|
|
|
|
err = dos_read(fd, &dd, sizeof(dd), &res);
|
|
|
|
if (err)
|
|
|
|
return (err);
|
|
|
|
if (res == sizeof(dd))
|
|
|
|
return (ENOENT);
|
|
|
|
if (dd.de.name[0] == 0)
|
|
|
|
return (ENOENT);
|
|
|
|
|
|
|
|
/* Skip deleted entries */
|
|
|
|
if (dd.de.name[0] == 0xe5)
|
|
|
|
continue;
|
|
|
|
|
2013-12-18 04:44:38 +00:00
|
|
|
/* Check if directory entry is volume label */
|
|
|
|
if (dd.de.attr & FA_LABEL) {
|
|
|
|
/*
|
|
|
|
* If volume label set, check if the current entry is
|
|
|
|
* extended entry (FA_XDE) for long file names.
|
|
|
|
*/
|
|
|
|
if ((dd.de.attr & FA_MASK) == FA_XDE) {
|
|
|
|
/*
|
|
|
|
* Read through all following extended entries
|
|
|
|
* to get the long file name. 0x40 marks the
|
|
|
|
* last entry containing part of long file name.
|
|
|
|
*/
|
|
|
|
if (dd.xde.seq & 0x40)
|
|
|
|
chk = dd.xde.chk;
|
|
|
|
else if (dd.xde.seq != xdn - 1 || dd.xde.chk != chk)
|
|
|
|
continue;
|
|
|
|
x = dd.xde.seq & ~0x40;
|
|
|
|
if (x < 1 || x > 20) {
|
|
|
|
x = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
cp_xdnm(fn, &dd.xde);
|
|
|
|
} else {
|
|
|
|
/* skip only volume label entries */
|
2010-01-09 22:33:34 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (xdn == 1) {
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
x = dos_checksum(dd.de.name, dd.de.ext);
|
2010-01-09 22:33:34 +00:00
|
|
|
if (x == chk)
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
cp_sfn(fn, &dd.de);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-03 07:43:47 +00:00
|
|
|
d->d_fileno = (dd.de.clus[1] << 8) + dd.de.clus[0];
|
2010-01-09 22:33:34 +00:00
|
|
|
d->d_reclen = sizeof(*d);
|
|
|
|
d->d_type = (dd.de.attr & FA_DIR) ? DT_DIR : DT_REG;
|
|
|
|
memcpy(d->d_name, fn, sizeof(d->d_name));
|
2016-12-01 19:19:20 +00:00
|
|
|
return (0);
|
2010-01-09 22:33:34 +00:00
|
|
|
}
|
|
|
|
|
1998-08-20 08:19:55 +00:00
|
|
|
/*
|
|
|
|
* Parse DOS boot sector
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
parsebs(DOS_FS *fs, DOS_BS *bs)
|
|
|
|
{
|
|
|
|
u_int sc;
|
|
|
|
|
|
|
|
if ((bs->jmp[0] != 0x69 &&
|
|
|
|
bs->jmp[0] != 0xe9 &&
|
|
|
|
(bs->jmp[0] != 0xeb || bs->jmp[2] != 0x90)) ||
|
|
|
|
bs->bpb.media < 0xf0)
|
2016-12-01 19:19:20 +00:00
|
|
|
return (EINVAL);
|
1998-08-20 08:19:55 +00:00
|
|
|
if (cv2(bs->bpb.secsiz) != SECSIZ)
|
2016-12-01 19:19:20 +00:00
|
|
|
return (EINVAL);
|
1998-08-20 08:19:55 +00:00
|
|
|
if (!(fs->spc = bs->bpb.spc) || fs->spc & (fs->spc - 1))
|
2016-12-01 19:19:20 +00:00
|
|
|
return (EINVAL);
|
1998-08-20 08:19:55 +00:00
|
|
|
fs->bsize = secbyt(fs->spc);
|
|
|
|
fs->bshift = ffs(fs->bsize) - 1;
|
|
|
|
if ((fs->spf = cv2(bs->bpb.spf))) {
|
|
|
|
if (bs->bpb.fats != 2)
|
2016-12-01 19:19:20 +00:00
|
|
|
return (EINVAL);
|
1998-08-20 08:19:55 +00:00
|
|
|
if (!(fs->dirents = cv2(bs->bpb.dirents)))
|
2016-12-01 19:19:20 +00:00
|
|
|
return (EINVAL);
|
1998-08-20 08:19:55 +00:00
|
|
|
} else {
|
|
|
|
if (!(fs->spf = cv4(bs->bpb.lspf)))
|
2016-12-01 19:19:20 +00:00
|
|
|
return (EINVAL);
|
1998-08-20 08:19:55 +00:00
|
|
|
if (!bs->bpb.fats || bs->bpb.fats > 16)
|
2016-12-01 19:19:20 +00:00
|
|
|
return (EINVAL);
|
1998-08-20 08:19:55 +00:00
|
|
|
if ((fs->rdcl = cv4(bs->bpb.rdcl)) < LOCLUS)
|
2016-12-01 19:19:20 +00:00
|
|
|
return (EINVAL);
|
1998-08-20 08:19:55 +00:00
|
|
|
}
|
|
|
|
if (!(fs->lsnfat = cv2(bs->bpb.ressec)))
|
2016-12-01 19:19:20 +00:00
|
|
|
return (EINVAL);
|
1998-08-20 08:19:55 +00:00
|
|
|
fs->lsndir = fs->lsnfat + fs->spf * bs->bpb.fats;
|
|
|
|
fs->lsndta = fs->lsndir + entsec(fs->dirents);
|
|
|
|
if (!(sc = cv2(bs->bpb.secs)) && !(sc = cv4(bs->bpb.lsecs)))
|
2016-12-01 19:19:20 +00:00
|
|
|
return (EINVAL);
|
1998-08-20 08:19:55 +00:00
|
|
|
if (fs->lsndta > sc)
|
2016-12-01 19:19:20 +00:00
|
|
|
return (EINVAL);
|
1998-08-20 08:19:55 +00:00
|
|
|
if ((fs->xclus = secblk(fs, sc - fs->lsndta) + 1) < LOCLUS)
|
2016-12-01 19:19:20 +00:00
|
|
|
return (EINVAL);
|
1998-08-20 08:19:55 +00:00
|
|
|
fs->fatsz = fs->dirents ? fs->xclus < 0xff6 ? 12 : 16 : 32;
|
|
|
|
sc = (secbyt(fs->spf) << 1) / (fs->fatsz >> 2) - 1;
|
|
|
|
if (fs->xclus > sc)
|
|
|
|
fs->xclus = sc;
|
2016-12-01 19:19:20 +00:00
|
|
|
return (0);
|
1998-08-20 08:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return directory entry from path
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
namede(DOS_FS *fs, const char *path, DOS_DE **dep)
|
|
|
|
{
|
|
|
|
char name[256];
|
|
|
|
DOS_DE *de;
|
|
|
|
char *s;
|
|
|
|
size_t n;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = 0;
|
2013-12-19 05:23:10 +00:00
|
|
|
de = &fs->root;
|
1998-08-20 08:19:55 +00:00
|
|
|
while (*path) {
|
2013-12-19 05:23:10 +00:00
|
|
|
while (*path == '/')
|
|
|
|
path++;
|
|
|
|
if (*path == '\0')
|
|
|
|
break;
|
1998-08-20 08:19:55 +00:00
|
|
|
if (!(s = strchr(path, '/')))
|
|
|
|
s = strchr(path, 0);
|
|
|
|
if ((n = s - path) > 255)
|
2016-12-01 19:19:20 +00:00
|
|
|
return (ENAMETOOLONG);
|
1998-08-20 08:19:55 +00:00
|
|
|
memcpy(name, path, n);
|
|
|
|
name[n] = 0;
|
|
|
|
path = s;
|
|
|
|
if (!(de->attr & FA_DIR))
|
2016-12-01 19:19:20 +00:00
|
|
|
return (ENOTDIR);
|
1998-08-20 08:19:55 +00:00
|
|
|
if ((err = lookup(fs, stclus(fs->fatsz, de), name, &de)))
|
2016-12-01 19:19:20 +00:00
|
|
|
return (err);
|
1998-08-20 08:19:55 +00:00
|
|
|
}
|
|
|
|
*dep = de;
|
2016-12-01 19:19:20 +00:00
|
|
|
return (0);
|
1998-08-20 08:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lookup path segment
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
lookup(DOS_FS *fs, u_int clus, const char *name, DOS_DE **dep)
|
|
|
|
{
|
|
|
|
static DOS_DIR dir[DEPSEC];
|
|
|
|
u_char lfn[261];
|
|
|
|
u_char sfn[13];
|
|
|
|
u_int nsec, lsec, xdn, chk, sec, ent, x;
|
2016-08-26 14:58:57 +00:00
|
|
|
int err, ok;
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
if (!clus)
|
|
|
|
for (ent = 0; ent < 2; ent++)
|
|
|
|
if (!strcasecmp(name, dotstr[ent])) {
|
|
|
|
*dep = dot + ent;
|
2016-12-01 19:19:20 +00:00
|
|
|
return (0);
|
1998-08-20 08:19:55 +00:00
|
|
|
}
|
|
|
|
if (!clus && fs->fatsz == 32)
|
|
|
|
clus = fs->rdcl;
|
|
|
|
nsec = !clus ? entsec(fs->dirents) : fs->spc;
|
|
|
|
lsec = 0;
|
|
|
|
xdn = chk = 0;
|
|
|
|
for (;;) {
|
|
|
|
if (!clus && !lsec)
|
|
|
|
lsec = fs->lsndir;
|
|
|
|
else if (okclus(fs, clus))
|
|
|
|
lsec = blklsn(fs, clus);
|
|
|
|
else
|
2016-12-01 19:19:20 +00:00
|
|
|
return (EINVAL);
|
1998-08-20 08:19:55 +00:00
|
|
|
for (sec = 0; sec < nsec; sec++) {
|
2016-12-30 19:06:29 +00:00
|
|
|
if ((err = ioget(fs->fd, lsec + sec, dir, secbyt(1))))
|
2016-12-01 19:19:20 +00:00
|
|
|
return (err);
|
1998-08-20 08:19:55 +00:00
|
|
|
for (ent = 0; ent < DEPSEC; ent++) {
|
|
|
|
if (!*dir[ent].de.name)
|
2016-12-01 19:19:20 +00:00
|
|
|
return (ENOENT);
|
1999-04-25 22:29:30 +00:00
|
|
|
if (*dir[ent].de.name != 0xe5) {
|
1998-08-20 08:19:55 +00:00
|
|
|
if ((dir[ent].de.attr & FA_MASK) == FA_XDE) {
|
|
|
|
x = dir[ent].xde.seq;
|
|
|
|
if (x & 0x40 || (x + 1 == xdn &&
|
|
|
|
dir[ent].xde.chk == chk)) {
|
|
|
|
if (x & 0x40) {
|
|
|
|
chk = dir[ent].xde.chk;
|
|
|
|
x &= ~0x40;
|
|
|
|
}
|
|
|
|
if (x >= 1 && x <= 20) {
|
|
|
|
cp_xdnm(lfn, &dir[ent].xde);
|
|
|
|
xdn = x;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (!(dir[ent].de.attr & FA_LABEL)) {
|
|
|
|
if ((ok = xdn == 1)) {
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
x = dos_checksum(dir[ent].de.name, dir[ent].de.ext);
|
1998-08-20 08:19:55 +00:00
|
|
|
ok = chk == x &&
|
|
|
|
!strcasecmp(name, (const char *)lfn);
|
|
|
|
}
|
|
|
|
if (!ok) {
|
|
|
|
cp_sfn(sfn, &dir[ent].de);
|
|
|
|
ok = !strcasecmp(name, (const char *)sfn);
|
|
|
|
}
|
|
|
|
if (ok) {
|
|
|
|
*dep = &dir[ent].de;
|
2016-12-01 19:19:20 +00:00
|
|
|
return (0);
|
1998-08-20 08:19:55 +00:00
|
|
|
}
|
|
|
|
}
|
1999-04-25 22:29:30 +00:00
|
|
|
}
|
1998-08-20 08:19:55 +00:00
|
|
|
xdn = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!clus)
|
|
|
|
break;
|
|
|
|
if ((err = fatget(fs, &clus)))
|
2016-12-01 19:19:20 +00:00
|
|
|
return (err);
|
1998-08-20 08:19:55 +00:00
|
|
|
if (fatend(fs->fatsz, clus))
|
|
|
|
break;
|
|
|
|
}
|
2016-12-01 19:19:20 +00:00
|
|
|
return (ENOENT);
|
1998-08-20 08:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy name from extended directory entry
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
cp_xdnm(u_char *lfn, DOS_XDE *xde)
|
|
|
|
{
|
|
|
|
static struct {
|
|
|
|
u_int off;
|
|
|
|
u_int dim;
|
|
|
|
} ix[3] = {
|
|
|
|
{offsetof(DOS_XDE, name1), sizeof(xde->name1) / 2},
|
|
|
|
{offsetof(DOS_XDE, name2), sizeof(xde->name2) / 2},
|
|
|
|
{offsetof(DOS_XDE, name3), sizeof(xde->name3) / 2}
|
|
|
|
};
|
|
|
|
u_char *p;
|
|
|
|
u_int n, x, c;
|
|
|
|
|
|
|
|
lfn += 13 * ((xde->seq & ~0x40) - 1);
|
|
|
|
for (n = 0; n < 3; n++)
|
|
|
|
for (p = (u_char *)xde + ix[n].off, x = ix[n].dim; x;
|
|
|
|
p += 2, x--) {
|
|
|
|
if ((c = cv2(p)) && (c < 32 || c > 127))
|
|
|
|
c = '?';
|
|
|
|
if (!(*lfn++ = c))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (xde->seq & 0x40)
|
|
|
|
*lfn = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy short filename
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
cp_sfn(u_char *sfn, DOS_DE *de)
|
|
|
|
{
|
|
|
|
u_char *p;
|
|
|
|
int j, i;
|
|
|
|
|
|
|
|
p = sfn;
|
|
|
|
if (*de->name != ' ') {
|
|
|
|
for (j = 7; de->name[j] == ' '; j--);
|
|
|
|
for (i = 0; i <= j; i++)
|
|
|
|
*p++ = de->name[i];
|
|
|
|
if (*de->ext != ' ') {
|
|
|
|
*p++ = '.';
|
|
|
|
for (j = 2; de->ext[j] == ' '; j--);
|
|
|
|
for (i = 0; i <= j; i++)
|
|
|
|
*p++ = de->ext[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*p = 0;
|
|
|
|
if (*sfn == 5)
|
|
|
|
*sfn = 0xe5;
|
|
|
|
}
|
|
|
|
|
1998-08-27 10:45:20 +00:00
|
|
|
/*
|
|
|
|
* Return size of file in bytes
|
|
|
|
*/
|
|
|
|
static off_t
|
|
|
|
fsize(DOS_FS *fs, DOS_DE *de)
|
|
|
|
{
|
|
|
|
u_long size;
|
|
|
|
u_int c;
|
|
|
|
int n;
|
|
|
|
|
1999-04-25 22:29:30 +00:00
|
|
|
if (!(size = cv4(de->size)) && de->attr & FA_DIR) {
|
1998-08-27 10:45:20 +00:00
|
|
|
if (!(c = cv2(de->clus)))
|
|
|
|
size = fs->dirents * sizeof(DOS_DE);
|
|
|
|
else {
|
|
|
|
if ((n = fatcnt(fs, c)) == -1)
|
2016-12-01 19:19:20 +00:00
|
|
|
return (n);
|
1998-08-27 10:45:20 +00:00
|
|
|
size = blkbyt(fs, n);
|
|
|
|
}
|
1999-04-25 22:29:30 +00:00
|
|
|
}
|
2016-12-01 19:19:20 +00:00
|
|
|
return (size);
|
1998-08-27 10:45:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Count number of clusters in chain
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
fatcnt(DOS_FS *fs, u_int c)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
|
|
|
|
for (n = 0; okclus(fs, c); n++)
|
|
|
|
if (fatget(fs, &c))
|
2016-12-01 19:19:20 +00:00
|
|
|
return (-1);
|
|
|
|
return (fatend(fs->fatsz, c) ? n : -1);
|
1998-08-27 10:45:20 +00:00
|
|
|
}
|
|
|
|
|
1998-08-20 08:19:55 +00:00
|
|
|
/*
|
2017-04-06 20:12:39 +00:00
|
|
|
* Get next cluster in cluster chain. Use in core fat cache unless
|
|
|
|
* the number of current 128K block in FAT has changed.
|
1998-08-20 08:19:55 +00:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
fatget(DOS_FS *fs, u_int *c)
|
|
|
|
{
|
2017-04-06 20:12:39 +00:00
|
|
|
u_int val_in, val_out, offset, blknum, nbyte;
|
|
|
|
const u_char *p_entry;
|
|
|
|
int err;
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
|
2017-04-06 20:12:39 +00:00
|
|
|
/* check input value to prevent overflow in fatoff() */
|
|
|
|
val_in = *c;
|
|
|
|
if (val_in & 0xf0000000)
|
|
|
|
return (EINVAL);
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
|
2017-04-06 20:12:39 +00:00
|
|
|
/* ensure that current 128K FAT block is cached */
|
|
|
|
offset = fatoff(fs->fatsz, val_in);
|
|
|
|
nbyte = fs->fatsz != 32 ? 2 : 4;
|
|
|
|
if (offset + nbyte > secbyt(fs->spf))
|
|
|
|
return (EINVAL);
|
|
|
|
blknum = offset / FATBLKSZ;
|
|
|
|
offset %= FATBLKSZ;
|
|
|
|
if (offset + nbyte > FATBLKSZ)
|
|
|
|
return (EINVAL);
|
|
|
|
if (blknum != fs->fatbuf_blknum) {
|
|
|
|
err = dos_read_fatblk(fs, fs->fd, blknum);
|
|
|
|
if (err != 0)
|
|
|
|
return (err);
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
}
|
2017-04-06 20:12:39 +00:00
|
|
|
p_entry = fs->fatbuf + offset;
|
1998-08-20 08:19:55 +00:00
|
|
|
|
2017-04-06 20:12:39 +00:00
|
|
|
/* extract cluster number from FAT entry */
|
|
|
|
switch (fs->fatsz) {
|
|
|
|
case 32:
|
|
|
|
val_out = cv4(p_entry);
|
|
|
|
val_out &= 0x0fffffff;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
val_out = cv2(p_entry);
|
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
val_out = cv2(p_entry);
|
|
|
|
if (val_in & 1)
|
|
|
|
val_out >>= 4;
|
|
|
|
else
|
|
|
|
val_out &= 0xfff;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
*c = val_out;
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
return (0);
|
1998-08-20 08:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is cluster an end-of-chain marker?
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
fatend(u_int sz, u_int c)
|
|
|
|
{
|
2016-12-01 19:19:20 +00:00
|
|
|
return (c > (sz == 12 ? 0xff7U : sz == 16 ? 0xfff7U : 0xffffff7));
|
1998-08-20 08:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Offset-based I/O primitive
|
|
|
|
*/
|
|
|
|
static int
|
2017-04-06 20:12:39 +00:00
|
|
|
ioread(DOS_FS *fs, u_int offset, void *buf, size_t nbyte)
|
1998-08-20 08:19:55 +00:00
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
u_int off, n;
|
|
|
|
int err;
|
2016-12-30 19:06:29 +00:00
|
|
|
u_char local_buf[SECSIZ];
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
s = buf;
|
|
|
|
if ((off = offset & (SECSIZ - 1))) {
|
|
|
|
offset -= off;
|
|
|
|
if ((n = SECSIZ - off) > nbyte)
|
|
|
|
n = nbyte;
|
2016-12-30 19:06:29 +00:00
|
|
|
if ((err = ioget(fs->fd, bytsec(offset), local_buf, sizeof(local_buf))))
|
2016-12-01 19:19:20 +00:00
|
|
|
return (err);
|
2016-12-30 19:06:29 +00:00
|
|
|
memcpy(s, local_buf + off, n);
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
offset += SECSIZ;
|
1998-08-20 08:19:55 +00:00
|
|
|
s += n;
|
|
|
|
nbyte -= n;
|
|
|
|
}
|
|
|
|
n = nbyte & (SECSIZ - 1);
|
|
|
|
if (nbyte -= n) {
|
2016-12-30 19:06:29 +00:00
|
|
|
if ((err = ioget(fs->fd, bytsec(offset), s, nbyte)))
|
2016-12-01 19:19:20 +00:00
|
|
|
return (err);
|
1998-08-20 08:19:55 +00:00
|
|
|
offset += nbyte;
|
|
|
|
s += nbyte;
|
|
|
|
}
|
|
|
|
if (n) {
|
2016-12-30 19:06:29 +00:00
|
|
|
if ((err = ioget(fs->fd, bytsec(offset), local_buf, sizeof(local_buf))))
|
2016-12-01 19:19:20 +00:00
|
|
|
return (err);
|
2016-12-30 19:06:29 +00:00
|
|
|
memcpy(s, local_buf, n);
|
1998-08-20 08:19:55 +00:00
|
|
|
}
|
2016-12-01 19:19:20 +00:00
|
|
|
return (0);
|
1998-08-20 08:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sector-based I/O primitive
|
|
|
|
*/
|
|
|
|
static int
|
2017-04-06 20:12:39 +00:00
|
|
|
ioget(struct open_file *fd, daddr_t lsec, void *buf, size_t size)
|
1998-08-20 08:19:55 +00:00
|
|
|
{
|
2017-04-06 20:12:39 +00:00
|
|
|
size_t rsize;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
/* Make sure we get full read or error. */
|
|
|
|
rsize = 0;
|
|
|
|
rv = (fd->f_dev->dv_strategy)(fd->f_devdata, F_READ, lsec,
|
|
|
|
size, buf, &rsize);
|
|
|
|
if ((rv == 0) && (size != rsize))
|
|
|
|
rv = EIO;
|
|
|
|
return (rv);
|
1998-08-20 08:19:55 +00:00
|
|
|
}
|