1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-02 08:42:48 +00:00

Rename fields to match better the msdosfs headers. This work is still

incomplete as some info doesn't really belong to the structs where it is
defined.

Submitted by:	Pedro F. Giffuni <giffunip tutopia com>
Reviewed by:	bde
MFC after:	2 weeks
This commit is contained in:
Konstantin Belousov 2010-02-14 12:31:28 +00:00
parent b41cd53957
commit 75fb535394
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=203874
5 changed files with 106 additions and 106 deletions

View File

@ -62,22 +62,22 @@ readboot(int dosfs, struct bootblock *boot)
boot->ValidFat = -1;
/* decode bios parameter block */
boot->BytesPerSec = block[11] + (block[12] << 8);
boot->SecPerClust = block[13];
boot->ResSectors = block[14] + (block[15] << 8);
boot->FATs = block[16];
boot->RootDirEnts = block[17] + (block[18] << 8);
boot->Sectors = block[19] + (block[20] << 8);
boot->Media = block[21];
boot->FATsmall = block[22] + (block[23] << 8);
boot->bpbBytesPerSec = block[11] + (block[12] << 8);
boot->bpbSecPerClust = block[13];
boot->bpbResSectors = block[14] + (block[15] << 8);
boot->bpbFATs = block[16];
boot->bpbRootDirEnts = block[17] + (block[18] << 8);
boot->bpbSectors = block[19] + (block[20] << 8);
boot->bpbMedia = block[21];
boot->bpbFATsmall = block[22] + (block[23] << 8);
boot->SecPerTrack = block[24] + (block[25] << 8);
boot->Heads = block[26] + (block[27] << 8);
boot->HiddenSecs = block[28] + (block[29] << 8) + (block[30] << 16) + (block[31] << 24);
boot->HugeSectors = block[32] + (block[33] << 8) + (block[34] << 16) + (block[35] << 24);
boot->bpbHeads = block[26] + (block[27] << 8);
boot->bpbHiddenSecs = block[28] + (block[29] << 8) + (block[30] << 16) + (block[31] << 24);
boot->bpbHugeSectors = block[32] + (block[33] << 8) + (block[34] << 16) + (block[35] << 24);
boot->FATsecs = boot->FATsmall;
boot->FATsecs = boot->bpbFATsmall;
if (!boot->RootDirEnts)
if (!boot->bpbRootDirEnts)
boot->flags |= FAT32;
if (boot->flags & FAT32) {
boot->FATsecs = block[36] + (block[37] << 8)
@ -92,13 +92,13 @@ readboot(int dosfs, struct bootblock *boot)
block[43], block[42]);
return FSFATAL;
}
boot->RootCl = block[44] + (block[45] << 8)
boot->bpbRootClust = block[44] + (block[45] << 8)
+ (block[46] << 16) + (block[47] << 24);
boot->FSInfo = block[48] + (block[49] << 8);
boot->Backup = block[50] + (block[51] << 8);
boot->bpbFSInfo = block[48] + (block[49] << 8);
boot->bpbBackup = block[50] + (block[51] << 8);
if (lseek(dosfs, boot->FSInfo * boot->BytesPerSec, SEEK_SET)
!= boot->FSInfo * boot->BytesPerSec
if (lseek(dosfs, boot->bpbFSInfo * boot->bpbBytesPerSec, SEEK_SET)
!= boot->bpbFSInfo * boot->bpbBytesPerSec
|| read(dosfs, fsinfo, sizeof fsinfo)
!= sizeof fsinfo) {
perror("could not read fsinfo block");
@ -124,18 +124,18 @@ readboot(int dosfs, struct bootblock *boot)
fsinfo[0x3fc] = fsinfo[0x3fd] = 0;
fsinfo[0x3fe] = 0x55;
fsinfo[0x3ff] = 0xaa;
if (lseek(dosfs, boot->FSInfo * boot->BytesPerSec, SEEK_SET)
!= boot->FSInfo * boot->BytesPerSec
if (lseek(dosfs, boot->bpbFSInfo * boot->bpbBytesPerSec, SEEK_SET)
!= boot->bpbFSInfo * boot->bpbBytesPerSec
|| write(dosfs, fsinfo, sizeof fsinfo)
!= sizeof fsinfo) {
perror("Unable to write FSInfo");
perror("Unable to write bpbFSInfo");
return FSFATAL;
}
ret = FSBOOTMOD;
} else
boot->FSInfo = 0;
boot->bpbFSInfo = 0;
}
if (boot->FSInfo) {
if (boot->bpbFSInfo) {
boot->FSFree = fsinfo[0x1e8] + (fsinfo[0x1e9] << 8)
+ (fsinfo[0x1ea] << 16)
+ (fsinfo[0x1eb] << 24);
@ -144,8 +144,8 @@ readboot(int dosfs, struct bootblock *boot)
+ (fsinfo[0x1ef] << 24);
}
if (lseek(dosfs, boot->Backup * boot->BytesPerSec, SEEK_SET)
!= boot->Backup * boot->BytesPerSec
if (lseek(dosfs, boot->bpbBackup * boot->bpbBytesPerSec, SEEK_SET)
!= boot->bpbBackup * boot->bpbBytesPerSec
|| read(dosfs, backup, sizeof backup) != sizeof backup) {
perror("could not read backup bootblock");
return FSFATAL;
@ -162,36 +162,36 @@ readboot(int dosfs, struct bootblock *boot)
* print out useful information and continue.
*/
pfatal("backup (block %d) mismatch with primary bootblock:\n",
boot->Backup);
boot->bpbBackup);
for (i = 11; i < 11 + 90; i++) {
if (block[i] != backup[i])
pfatal("\ti=%d\tprimary 0x%02x\tbackup 0x%02x\n",
i, block[i], backup[i]);
}
}
/* Check backup FSInfo? XXX */
/* Check backup bpbFSInfo? XXX */
}
boot->ClusterOffset = (boot->RootDirEnts * 32 + boot->BytesPerSec - 1)
/ boot->BytesPerSec
+ boot->ResSectors
+ boot->FATs * boot->FATsecs
- CLUST_FIRST * boot->SecPerClust;
boot->ClusterOffset = (boot->bpbRootDirEnts * 32 + boot->bpbBytesPerSec - 1)
/ boot->bpbBytesPerSec
+ boot->bpbResSectors
+ boot->bpbFATs * boot->FATsecs
- CLUST_FIRST * boot->bpbSecPerClust;
if (boot->BytesPerSec % DOSBOOTBLOCKSIZE != 0) {
pfatal("Invalid sector size: %u", boot->BytesPerSec);
if (boot->bpbBytesPerSec % DOSBOOTBLOCKSIZE != 0) {
pfatal("Invalid sector size: %u", boot->bpbBytesPerSec);
return FSFATAL;
}
if (boot->SecPerClust == 0) {
pfatal("Invalid cluster size: %u", boot->SecPerClust);
if (boot->bpbSecPerClust == 0) {
pfatal("Invalid cluster size: %u", boot->bpbSecPerClust);
return FSFATAL;
}
if (boot->Sectors) {
boot->HugeSectors = 0;
boot->NumSectors = boot->Sectors;
if (boot->bpbSectors) {
boot->bpbHugeSectors = 0;
boot->NumSectors = boot->bpbSectors;
} else
boot->NumSectors = boot->HugeSectors;
boot->NumClusters = (boot->NumSectors - boot->ClusterOffset) / boot->SecPerClust;
boot->NumSectors = boot->bpbHugeSectors;
boot->NumClusters = (boot->NumSectors - boot->ClusterOffset) / boot->bpbSecPerClust;
if (boot->flags&FAT32)
boot->ClustMask = CLUST32_MASK;
@ -207,13 +207,13 @@ readboot(int dosfs, struct bootblock *boot)
switch (boot->ClustMask) {
case CLUST32_MASK:
boot->NumFatEntries = (boot->FATsecs * boot->BytesPerSec) / 4;
boot->NumFatEntries = (boot->FATsecs * boot->bpbBytesPerSec) / 4;
break;
case CLUST16_MASK:
boot->NumFatEntries = (boot->FATsecs * boot->BytesPerSec) / 2;
boot->NumFatEntries = (boot->FATsecs * boot->bpbBytesPerSec) / 2;
break;
default:
boot->NumFatEntries = (boot->FATsecs * boot->BytesPerSec * 2) / 3;
boot->NumFatEntries = (boot->FATsecs * boot->bpbBytesPerSec * 2) / 3;
break;
}
@ -222,7 +222,7 @@ readboot(int dosfs, struct bootblock *boot)
boot->NumClusters, boot->FATsecs);
return FSFATAL;
}
boot->ClusterSize = boot->BytesPerSec * boot->SecPerClust;
boot->ClusterSize = boot->bpbBytesPerSec * boot->bpbSecPerClust;
boot->NumFiles = 1;
boot->NumFree = 0;
@ -235,8 +235,8 @@ writefsinfo(int dosfs, struct bootblock *boot)
{
u_char fsinfo[2 * DOSBOOTBLOCKSIZE];
if (lseek(dosfs, boot->FSInfo * boot->BytesPerSec, SEEK_SET)
!= boot->FSInfo * boot->BytesPerSec
if (lseek(dosfs, boot->bpbFSInfo * boot->bpbBytesPerSec, SEEK_SET)
!= boot->bpbFSInfo * boot->bpbBytesPerSec
|| read(dosfs, fsinfo, sizeof fsinfo) != sizeof fsinfo) {
perror("could not read fsinfo block");
return FSFATAL;
@ -249,11 +249,11 @@ writefsinfo(int dosfs, struct bootblock *boot)
fsinfo[0x1ed] = (u_char)(boot->FSNext >> 8);
fsinfo[0x1ee] = (u_char)(boot->FSNext >> 16);
fsinfo[0x1ef] = (u_char)(boot->FSNext >> 24);
if (lseek(dosfs, boot->FSInfo * boot->BytesPerSec, SEEK_SET)
!= boot->FSInfo * boot->BytesPerSec
if (lseek(dosfs, boot->bpbFSInfo * boot->bpbBytesPerSec, SEEK_SET)
!= boot->bpbFSInfo * boot->bpbBytesPerSec
|| write(dosfs, fsinfo, sizeof fsinfo)
!= sizeof fsinfo) {
perror("Unable to write FSInfo");
perror("Unable to write bpbFSInfo");
return FSFATAL;
}
/*

View File

@ -98,7 +98,7 @@ checkfilesys(const char *fname)
}
if (boot.ValidFat < 0)
for (i = 1; i < (int)boot.FATs; i++) {
for (i = 1; i < (int)boot.bpbFATs; i++) {
struct fatEntry *currentFat;
mod |= readfat(dosfs, &boot, i, &currentFat);

View File

@ -219,8 +219,8 @@ resetDosDirSection(struct bootblock *boot, struct fatEntry *fat)
cl_t cl;
int ret = FSOK;
b1 = boot->RootDirEnts * 32;
b2 = boot->SecPerClust * boot->BytesPerSec;
b1 = boot->bpbRootDirEnts * 32;
b2 = boot->bpbSecPerClust * boot->bpbBytesPerSec;
if ((buffer = malloc( b1 > b2 ? b1 : b2)) == NULL) {
perror("No space for directory buffer");
@ -242,15 +242,15 @@ resetDosDirSection(struct bootblock *boot, struct fatEntry *fat)
memset(rootDir, 0, sizeof *rootDir);
if (boot->flags & FAT32) {
if (boot->RootCl < CLUST_FIRST || boot->RootCl >= boot->NumClusters) {
if (boot->bpbRootClust < CLUST_FIRST || boot->bpbRootClust >= boot->NumClusters) {
pfatal("Root directory starts with cluster out of range(%u)",
boot->RootCl);
boot->bpbRootClust);
return FSFATAL;
}
cl = fat[boot->RootCl].next;
cl = fat[boot->bpbRootClust].next;
if (cl < CLUST_FIRST
|| (cl >= CLUST_RSRVD && cl< CLUST_EOFS)
|| fat[boot->RootCl].head != boot->RootCl) {
|| fat[boot->bpbRootClust].head != boot->bpbRootClust) {
if (cl == CLUST_FREE)
pwarn("Root directory starts with free cluster\n");
else if (cl >= CLUST_RSRVD)
@ -261,14 +261,14 @@ resetDosDirSection(struct bootblock *boot, struct fatEntry *fat)
return FSFATAL;
}
if (ask(1, "Fix")) {
fat[boot->RootCl].next = CLUST_FREE;
fat[boot->bpbRootClust].next = CLUST_FREE;
ret = FSFATMOD;
} else
ret = FSFATAL;
}
fat[boot->RootCl].flags |= FAT_USED;
rootDir->head = boot->RootCl;
fat[boot->bpbRootClust].flags |= FAT_USED;
rootDir->head = boot->bpbRootClust;
}
return ret;
@ -313,7 +313,7 @@ delete(int f, struct bootblock *boot, struct fatEntry *fat, cl_t startcl,
{
u_char *s, *e;
off_t off;
int clsz = boot->SecPerClust * boot->BytesPerSec;
int clsz = boot->bpbSecPerClust * boot->bpbBytesPerSec;
s = delbuf + startoff;
e = delbuf + clsz;
@ -323,8 +323,8 @@ delete(int f, struct bootblock *boot, struct fatEntry *fat, cl_t startcl,
break;
e = delbuf + endoff;
}
off = startcl * boot->SecPerClust + boot->ClusterOffset;
off *= boot->BytesPerSec;
off = startcl * boot->bpbSecPerClust + boot->ClusterOffset;
off *= boot->bpbBytesPerSec;
if (lseek(f, off, SEEK_SET) != off
|| read(f, delbuf, clsz) != clsz) {
perror("Unable to read directory");
@ -461,14 +461,14 @@ readDosDirSection(int f, struct bootblock *boot, struct fatEntry *fat,
vallfn = invlfn = empty = NULL;
do {
if (!(boot->flags & FAT32) && !dir->parent) {
last = boot->RootDirEnts * 32;
off = boot->ResSectors + boot->FATs * boot->FATsecs;
last = boot->bpbRootDirEnts * 32;
off = boot->bpbResSectors + boot->bpbFATs * boot->FATsecs;
} else {
last = boot->SecPerClust * boot->BytesPerSec;
off = cl * boot->SecPerClust + boot->ClusterOffset;
last = boot->bpbSecPerClust * boot->bpbBytesPerSec;
off = cl * boot->bpbSecPerClust + boot->ClusterOffset;
}
off *= boot->BytesPerSec;
off *= boot->bpbBytesPerSec;
if (lseek(f, off, SEEK_SET) != off
|| read(f, buffer, last) != last) {
perror("Unable to read directory");
@ -957,7 +957,7 @@ reconnect(int dosfs, struct bootblock *boot, struct fatEntry *fat, cl_t head)
return FSERROR;
}
lfoff = lfcl * boot->ClusterSize
+ boot->ClusterOffset * boot->BytesPerSec;
+ boot->ClusterOffset * boot->bpbBytesPerSec;
if (lseek(dosfs, lfoff, SEEK_SET) != lfoff
|| (size_t)read(dosfs, lfbuf, boot->ClusterSize) != boot->ClusterSize) {
perror("could not read LOST.DIR");

View File

@ -39,31 +39,31 @@ typedef u_int32_t cl_t; /* type holding a cluster number */
* FAT boot block.
*/
struct bootblock {
u_int BytesPerSec; /* bytes per sector */
u_int SecPerClust; /* sectors per cluster */
u_int ResSectors; /* number of reserved sectors */
u_int FATs; /* number of FATs */
u_int RootDirEnts; /* number of root directory entries */
u_int Media; /* media descriptor */
u_int FATsmall; /* number of sectors per FAT */
u_int bpbBytesPerSec; /* bytes per sector */
u_int bpbSecPerClust; /* sectors per cluster */
u_int bpbResSectors; /* number of reserved sectors */
u_int bpbFATs; /* number of bpbFATs */
u_int bpbRootDirEnts; /* number of root directory entries */
u_int32_t bpbSectors; /* total number of sectors */
u_int bpbMedia; /* media descriptor */
u_int bpbFATsmall; /* number of sectors per FAT */
u_int SecPerTrack; /* sectors per track */
u_int Heads; /* number of heads */
u_int32_t HiddenSecs; /* # of hidden sectors */
u_int32_t Sectors; /* total number of sectors */
#define FAT32 1 /* this is a FAT32 file system */
/*
* Maybe, we should separate out
* various parts of FAT32? XXX
*/
u_int32_t HugeSectors; /* # of sectors if bpbSectors == 0 */
u_int FSInfo; /* FSInfo sector */
u_int Backup; /* Backup of Bootblocks */
cl_t RootCl; /* Start of Root Directory */
u_int bpbHeads; /* number of heads */
u_int32_t bpbHiddenSecs; /* # of hidden sectors */
u_int32_t bpbHugeSectors; /* # of sectors if bpbbpbSectors == 0 */
cl_t bpbRootClust; /* Start of Root Directory */
u_int bpbFSInfo; /* FSInfo sector */
u_int bpbBackup; /* Backup of Bootblocks */
cl_t FSFree; /* Number of free clusters acc. FSInfo */
cl_t FSNext; /* Next free cluster acc. FSInfo */
/* and some more calculated values */
u_int flags; /* some flags: */
#define FAT32 1 /* this is a FAT32 file system */
/*
* Maybe, we should separate out
* various parts of FAT32? XXX
*/
int ValidFat; /* valid fat if FAT32 non-mirrored */
cl_t ClustMask; /* mask for entries in FAT */
cl_t NumClusters; /* # of entries in a FAT */

View File

@ -73,10 +73,10 @@ checkdirty(int fs, struct bootblock *boot)
if (boot->ClustMask != CLUST16_MASK && boot->ClustMask != CLUST32_MASK)
return 0;
off = boot->ResSectors;
off *= boot->BytesPerSec;
off = boot->bpbResSectors;
off *= boot->bpbBytesPerSec;
buffer = malloc(boot->BytesPerSec);
buffer = malloc(boot->bpbBytesPerSec);
if (buffer == NULL) {
perror("No space for FAT");
return 1;
@ -87,7 +87,7 @@ checkdirty(int fs, struct bootblock *boot)
goto err;
}
if (read(fs, buffer, boot->BytesPerSec) != boot->BytesPerSec) {
if (read(fs, buffer, boot->bpbBytesPerSec) != boot->bpbBytesPerSec) {
perror("Unable to read FAT");
goto err;
}
@ -96,7 +96,7 @@ checkdirty(int fs, struct bootblock *boot)
* If we don't understand the FAT, then the file system must be
* assumed to be unclean.
*/
if (buffer[0] != boot->Media || buffer[1] != 0xff)
if (buffer[0] != boot->bpbMedia || buffer[1] != 0xff)
goto err;
if (boot->ClustMask == CLUST16_MASK) {
if ((buffer[2] & 0xf8) != 0xf8 || (buffer[3] & 0x3f) != 0x3f)
@ -163,22 +163,22 @@ _readfat(int fs, struct bootblock *boot, u_int no, u_char **buffer)
{
off_t off;
*buffer = malloc(boot->FATsecs * boot->BytesPerSec);
*buffer = malloc(boot->FATsecs * boot->bpbBytesPerSec);
if (*buffer == NULL) {
perror("No space for FAT");
return 0;
}
off = boot->ResSectors + no * boot->FATsecs;
off *= boot->BytesPerSec;
off = boot->bpbResSectors + no * boot->FATsecs;
off *= boot->bpbBytesPerSec;
if (lseek(fs, off, SEEK_SET) != off) {
perror("Unable to read FAT");
goto err;
}
if ((size_t)read(fs, *buffer, boot->FATsecs * boot->BytesPerSec)
!= boot->FATsecs * boot->BytesPerSec) {
if ((size_t)read(fs, *buffer, boot->FATsecs * boot->bpbBytesPerSec)
!= boot->FATsecs * boot->bpbBytesPerSec) {
perror("Unable to read FAT");
goto err;
}
@ -215,7 +215,7 @@ readfat(int fs, struct bootblock *boot, u_int no, struct fatEntry **fp)
}
(void)memset(fat, 0, len);
if (buffer[0] != boot->Media
if (buffer[0] != boot->bpbMedia
|| buffer[1] != 0xff || buffer[2] != 0xff
|| (boot->ClustMask == CLUST16_MASK && buffer[3] != 0xff)
|| (boot->ClustMask == CLUST32_MASK
@ -229,7 +229,7 @@ readfat(int fs, struct bootblock *boot, u_int no, struct fatEntry **fp)
* file system is dirty if it doesn't reboot cleanly.
* Check this special condition before errorring out.
*/
if (buffer[0] == boot->Media && buffer[1] == 0xff
if (buffer[0] == boot->bpbMedia && buffer[1] == 0xff
&& buffer[2] == 0xff
&& ((boot->ClustMask == CLUST16_MASK && buffer[3] == 0x7f)
|| (boot->ClustMask == CLUST32_MASK
@ -546,7 +546,7 @@ writefat(int fs, struct bootblock *boot, struct fatEntry *fat, int correct_fat)
off_t off;
int ret = FSOK;
buffer = malloc(fatsz = boot->FATsecs * boot->BytesPerSec);
buffer = malloc(fatsz = boot->FATsecs * boot->bpbBytesPerSec);
if (buffer == NULL) {
perror("No space for FAT");
return FSFATAL;
@ -555,7 +555,7 @@ writefat(int fs, struct bootblock *boot, struct fatEntry *fat, int correct_fat)
boot->NumFree = 0;
p = buffer;
if (correct_fat) {
*p++ = (u_char)boot->Media;
*p++ = (u_char)boot->bpbMedia;
*p++ = 0xff;
*p++ = 0xff;
switch (boot->ClustMask) {
@ -628,9 +628,9 @@ writefat(int fs, struct bootblock *boot, struct fatEntry *fat, int correct_fat)
break;
}
}
for (i = 0; i < boot->FATs; i++) {
off = boot->ResSectors + i * boot->FATsecs;
off *= boot->BytesPerSec;
for (i = 0; i < boot->bpbFATs; i++) {
off = boot->bpbResSectors + i * boot->FATsecs;
off *= boot->bpbBytesPerSec;
if (lseek(fs, off, SEEK_SET) != off
|| (size_t)write(fs, buffer, fatsz) != fatsz) {
perror("Unable to write FAT");
@ -672,7 +672,7 @@ checklost(int dosfs, struct bootblock *boot, struct fatEntry *fat)
}
finishlf();
if (boot->FSInfo) {
if (boot->bpbFSInfo) {
ret = 0;
if (boot->FSFree != boot->NumFree) {
pwarn("Free space in FSInfo block (%d) not correct (%d)\n",