/* * Mount DOS filesystem */ static int dos_mount(DOS_FS *fs, struct open_file *fd) { int err; struct devdesc *dd = fd->f_devdata; u_char *buf; bzero(fs, sizeof(DOS_FS)); fs->fd = fd; if ((err = !(buf = malloc(secbyt(1))) ? errno : 0) || (err = ioget(fs->fd, 0, 0, buf, secbyt(1))) || (err = parsebs(fs, (DOS_BS *)buf))) { if (buf != NULL) free(buf); (void)dosunmount(fs); return(err); } free(buf); if (fat.buf == NULL || fat.unit != dd->d_unit) dos_read_fat(fs, fd); 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; }
/* * Mount DOS filesystem */ static int dos_mount(DOS_FS *fs, struct open_file *fd) { int err; uchar_t *buf; bzero(fs, sizeof (DOS_FS)); fs->fd = fd; if ((buf = malloc(secbyt(1))) == NULL) return (errno); if ((err = ioget(fs->fd, 0, buf, secbyt(1))) || (err = parsebs(fs, (DOS_BS *)buf))) { free(buf); return (err); } free(buf); if ((fs->fatbuf = malloc(FATBLKSZ)) == NULL) return (errno); err = dos_read_fatblk(fs, fd, 0); if (err != 0) { free(fs->fatbuf); return (err); } 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; }
static void dos_read_fat(DOS_FS *fs, struct open_file *fd) { struct devdesc *dd = fd->f_devdata; if (fat.buf != NULL) { /* can we reuse old buffer? */ if (fat.size != fs->spf) { free(fat.buf); /* no, free old buffer */ fat.buf = NULL; } } if (fat.buf == NULL) fat.buf = malloc(secbyt(fs->spf)); if (fat.buf != NULL) { if (ioget(fd, fs->lsnfat, 0, fat.buf, secbyt(fs->spf)) == 0) { fat.size = fs->spf; fat.unit = dd->d_unit; return; } } if (fat.buf != NULL) /* got IO error */ free(fat.buf); fat.buf = NULL; fat.unit = -1; /* impossible unit */ fat.size = 0; }
static int dos_read_fatblk(DOS_FS *fs, struct open_file *fd, uint_t blknum) { 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 = ((uint_t)(-1)); return (err); } } if (io_size < FATBLKSZ) memset(fs->fatbuf + io_size, 0, FATBLKSZ - io_size); fs->fatbuf_blknum = blknum; return (0); }
/* * Mount DOS filesystem */ static int dos_mount(DOS_FS *fs, struct open_file *fd) { int err; bzero(fs, sizeof(DOS_FS)); fs->fd = fd; if ((err = !(fs->buf = malloc(SECSIZ)) ? errno : 0) || (err = ioget(fs->fd, 0, fs->buf, 1)) || (err = parsebs(fs, (DOS_BS *)fs->buf))) { (void)dosunmount(fs); return(err); } 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; }