PERFORCE change 122840 for review
Brian Chu
chub at FreeBSD.org
Wed Jul 4 06:53:15 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=122840
Change 122840 by chub at chub-msdosfs on 2007/07/04 06:52:31
Removing geom/label's copy of msdosfs data structures.
Affected files ...
.. //depot/projects/soc2007/chub-msdosfs2/sys/fs/msdosfs/bootsect.h#2 edit
.. //depot/projects/soc2007/chub-msdosfs2/sys/fs/msdosfs/direntry.h#2 edit
.. //depot/projects/soc2007/chub-msdosfs2/sys/geom/label/g_label_msdosfs.c#2 edit
.. //depot/projects/soc2007/chub-msdosfs2/sys/geom/label/g_label_msdosfs.h#2 delete
Differences ...
==== //depot/projects/soc2007/chub-msdosfs2/sys/fs/msdosfs/bootsect.h#2 (text+ko) ====
@@ -73,21 +73,3 @@
struct bootsector50 bs50;
struct bootsector710 bs710;
};
-
-#if 0
-/*
- * Shorthand for fields in the bpb.
- */
-#define bsBytesPerSec bsBPB.bpbBytesPerSec
-#define bsSectPerClust bsBPB.bpbSectPerClust
-#define bsResSectors bsBPB.bpbResSectors
-#define bsFATS bsBPB.bpbFATS
-#define bsRootDirEnts bsBPB.bpbRootDirEnts
-#define bsSectors bsBPB.bpbSectors
-#define bsMedia bsBPB.bpbMedia
-#define bsFATsecs bsBPB.bpbFATsecs
-#define bsSectPerTrack bsBPB.bpbSectPerTrack
-#define bsHeads bsBPB.bpbHeads
-#define bsHiddenSecs bsBPB.bpbHiddenSecs
-#define bsHugeSectors bsBPB.bpbHugeSectors
-#endif
==== //depot/projects/soc2007/chub-msdosfs2/sys/fs/msdosfs/direntry.h#2 (text+ko) ====
@@ -88,7 +88,7 @@
#define WIN_CNT 0x3f
u_int8_t wePart1[10];
u_int8_t weAttributes;
-#define ATTR_WIN95 0x0f
+#define ATTR_WIN95 0x0f /* Long directory entryies */
u_int8_t weReserved1;
u_int8_t weChksum;
u_int8_t wePart2[12];
==== //depot/projects/soc2007/chub-msdosfs2/sys/geom/label/g_label_msdosfs.c#2 (text+ko) ====
@@ -1,6 +1,7 @@
/*-
* Copyright (c) 2004 Pawel Jakub Dawidek <pjd at FreeBSD.org>
* Copyright (c) 2006 Tobias Reifenberger
+ * Copyright (c) 2007 Brian Chu <chub at FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -33,20 +34,34 @@
#include <sys/kernel.h>
#include <sys/malloc.h>
+#include <fs/msdosfs/bootsect.h>
+#include <fs/msdosfs/bpb.h>
+#include <fs/msdosfs/direntry.h>
+
#include <geom/geom.h>
#include <geom/label/g_label.h>
-#include <geom/label/g_label_msdosfs.h>
#define G_LABEL_MSDOSFS_DIR "msdosfs"
#define LABEL_NO_NAME "NO NAME "
+/*
+ * Conversion macros for little endian encoded unsigned integers
+ * in byte streams to the local unsigned integer format.
+ */
+#include <sys/types.h>
+#define UINT16BYTES(p) ((uint32_t)((p)[0] + (256*(p)[1])))
+#define UINT32BYTES(p) ((uint32_t)((p)[0] + (256*(p)[1]) + \
+ (65536*(p)[2]) + (16777216*(p)[3])))
+
static void
g_label_msdosfs_taste(struct g_consumer *cp, char *label, size_t size)
{
struct g_provider *pp;
- FAT_BSBPB *pfat_bsbpb;
- FAT32_BSBPB *pfat32_bsbpb;
- FAT_DES *pfat_entry;
+ union bootsector *bsp;
+ struct byte_bpb50 *pfat_bpb50;
+ struct byte_bpb710 *pfat_bpb710;
+ struct extboot *pfat_extboot;
+ struct direntry* pfat_entry;
uint8_t *sector0, *sector;
uint32_t i;
@@ -74,10 +89,17 @@
if (sector0 == NULL)
return;
+ /* Set the bootsector/boot parameter block to a struct. */
+ bsp = (union bootsector *)sector0;
+ pfat_bpb50 = (struct byte_bpb50 *) bsp->bs50.bsBPB;
+ pfat_bpb710 = (struct byte_bpb710 *) bsp->bs710.bsBPB;
+
/* Check for the FAT boot sector signature. */
- if (sector0[510] != 0x55 || sector0[511] != 0xaa) {
- G_LABEL_DEBUG(1, "MSDOSFS: %s: no FAT signature found.",
- pp->name);
+ if (bsp->bs50.bsBootSectSig0 != BOOTSIG0 ||
+ bsp->bs50.bsBootSectSig1 != BOOTSIG1) {
+ G_LABEL_DEBUG(1,
+ "MSDOSFS: %s: no FAT signature found.",
+ pp->name);
goto error;
}
@@ -85,42 +107,56 @@
/*
* Test if this is really a FAT volume and determine the FAT type.
*/
+ if (UINT16BYTES(pfat_bpb50->bpbFATsecs) != 0) {
+ /* The extended boot record is one place for FAT12/FAT16
+ * and another for FAT32.
+ */
- pfat_bsbpb = (FAT_BSBPB *)sector0;
- pfat32_bsbpb = (FAT32_BSBPB *)sector0;
+ pfat_extboot = (struct extboot *) bsp->bs50.bsExt;
- if (UINT16BYTES(pfat_bsbpb->BPB_FATSz16) != 0) {
/*
- * If the BPB_FATSz16 field is not zero and the string "FAT" is
- * at the right place, this should be a FAT12 or FAT16 volume.
+ * If the BPB_FATSz16/bpbFATsecs field is not zero and
+ * the string "FAT" is at the right place, this should
+ * be a FAT12 or FAT16 volume.
*/
- if (strncmp(pfat_bsbpb->BS_FilSysType, "FAT", 3) != 0) {
+
+ if (strncmp(pfat_extboot->exFileSysType, "FAT", 3) != 0) {
G_LABEL_DEBUG(1,
"MSDOSFS: %s: FAT12/16 volume not valid.",
pp->name);
goto error;
}
- G_LABEL_DEBUG(1, "MSDOSFS: %s: FAT12/FAT16 volume detected.",
- pp->name);
+ G_LABEL_DEBUG(1,
+ "MSDOSFS: %s: FAT12/FAT16 volume detected.",
+ pp->name);
/* A volume with no name should have "NO NAME " as label. */
- if (strncmp(pfat_bsbpb->BS_VolLab, LABEL_NO_NAME,
- sizeof(pfat_bsbpb->BS_VolLab)) == 0) {
+ if (strncmp(pfat_extboot->exVolumeLabel, LABEL_NO_NAME,
+ sizeof(pfat_extboot->exVolumeLabel)) == 0) {
G_LABEL_DEBUG(1,
"MSDOSFS: %s: FAT12/16 volume has no name.",
pp->name);
goto error;
}
- strlcpy(label, pfat_bsbpb->BS_VolLab,
- MIN(size, sizeof(pfat_bsbpb->BS_VolLab) + 1));
- } else if (UINT32BYTES(pfat32_bsbpb->BPB_FATSz32) != 0) {
+ strlcpy(label, pfat_extboot->exVolumeLabel,
+ MIN(size, sizeof(pfat_extboot->exVolumeLabel) + 1));
+ }
+ else if (UINT32BYTES(pfat_bpb710->bpbBigFATsecs) != 0) {
uint32_t fat_FirstDataSector, fat_BytesPerSector, offset;
+ /* The extended boot record is one place for FAT12/FAT16
+ * and another for FAT32.
+ */
+
+ pfat_extboot = (struct extboot *) bsp->bs710.bsExt;
+
/*
- * If the BPB_FATSz32 field is not zero and the string "FAT" is
- * at the right place, this should be a FAT32 volume.
+ * If the BPB_FATSz32/bpbBigFATsecs field is not zero
+ * and the string "FAT" is at the right place, this
+ * should be a FAT32 volume.
*/
- if (strncmp(pfat32_bsbpb->BS_FilSysType, "FAT", 3) != 0) {
+
+ if (strncmp(pfat_extboot->exFileSysType, "FAT", 3) != 0) {
G_LABEL_DEBUG(1, "MSDOSFS: %s: FAT32 volume not valid.",
pp->name);
goto error;
@@ -131,10 +167,10 @@
/*
* If the volume label is not "NO NAME " we're done.
*/
- if (strncmp(pfat32_bsbpb->BS_VolLab, LABEL_NO_NAME,
- sizeof(pfat32_bsbpb->BS_VolLab)) != 0) {
- strlcpy(label, pfat32_bsbpb->BS_VolLab,
- MIN(size, sizeof(pfat32_bsbpb->BS_VolLab) + 1));
+ if (strncmp(pfat_extboot->exVolumeLabel, LABEL_NO_NAME,
+ sizeof(pfat_extboot->exVolumeLabel)) == 0) {
+ strlcpy(label, pfat_extboot->exVolumeLabel,
+ MIN(size, sizeof(pfat_extboot->exVolumeLabel) + 1));
goto endofchecks;
}
@@ -144,10 +180,10 @@
* the root directory.
*/
fat_FirstDataSector =
- UINT16BYTES(pfat32_bsbpb->BPB_RsvdSecCnt) +
- (pfat32_bsbpb->BPB_NumFATs *
- UINT32BYTES(pfat32_bsbpb->BPB_FATSz32));
- fat_BytesPerSector = UINT16BYTES(pfat32_bsbpb->BPB_BytsPerSec);
+ UINT16BYTES(pfat_bpb710->bpbResSectors) +
+ (pfat_bpb710->bpbFATs *
+ UINT32BYTES(pfat_bpb710->bpbBigFATsecs));
+ fat_BytesPerSector = UINT16BYTES(pfat_bpb710->bpbBytesPerSec);
G_LABEL_DEBUG(2,
"MSDOSFS: FAT_FirstDataSector=0x%x, FAT_BytesPerSector=%d",
@@ -160,10 +196,10 @@
if (sector == NULL)
goto error;
- pfat_entry = (FAT_DES *)sector;
+ pfat_entry = (struct direntry *)sector;
do {
/* No more entries available. */
- if (pfat_entry->DIR_Name[0] == 0) {
+ if (pfat_entry->deName[0] == 0) {
G_LABEL_DEBUG(1, "MSDOSFS: %s: "
"FAT32 volume has no name.",
pp->name);
@@ -171,10 +207,9 @@
}
/* Skip empty or long name entries. */
- if (pfat_entry->DIR_Name[0] == 0xe5 ||
- (pfat_entry->DIR_Attr &
- FAT_DES_ATTR_LONG_NAME) ==
- FAT_DES_ATTR_LONG_NAME) {
+ if (pfat_entry->deName[0] == 0xe5 ||
+ (pfat_entry->deAttributes &
+ ATTR_WIN95) == ATTR_WIN95) {
continue;
}
@@ -182,11 +217,11 @@
* The name of the entry is the volume label if
* ATTR_VOLUME_ID is set.
*/
- if (pfat_entry->DIR_Attr &
- FAT_DES_ATTR_VOLUME_ID) {
- strlcpy(label, pfat_entry->DIR_Name,
+ if (pfat_entry->deAttributes &
+ ATTR_DIRECTORY) {
+ strlcpy(label, pfat_entry->deName,
MIN(size,
- sizeof(pfat_bsbpb->BS_VolLab) + 1));
+ sizeof(pfat_extboot->exVolumeLabel) + 1));
goto endofchecks;
}
} while((uint8_t *)(++pfat_entry) <
More information about the p4-projects
mailing list