2004-11-20 Ralf Corsepius <ralf.corsepiu@rtems.org>

PR 720/filesystem:
	* libfs/src/dosfs/dosfs.h, libfs/src/dosfs/fat.c,
	libfs/src/dosfs/fat.h, libfs/src/dosfs/msdos_format.c:
	Adaptations to msdos_format.
	(From Thomas Doerfler <Thomas.Doerfler@imd-systems.de>).

	* libfs/src/dosfs/dosfs.h, libfs/src/dosfs/fat.c,
	libfs/src/dosfs/fat.h, libfs/src/dosfs/msdos_format.c:
	Adaptations to RTEMS-4.7.
This commit is contained in:
Ralf Corsepius
2004-11-20 03:11:41 +00:00
parent b34665f8e8
commit c36f885aa7
5 changed files with 298 additions and 112 deletions

View File

@@ -1,3 +1,15 @@
2004-11-20 Ralf Corsepius <ralf.corsepiu@rtems.org>
PR 720/filesystem:
* libfs/src/dosfs/dosfs.h, libfs/src/dosfs/fat.c,
libfs/src/dosfs/fat.h, libfs/src/dosfs/msdos_format.c:
Adaptations to msdos_format.
(From Thomas Doerfler <Thomas.Doerfler@imd-systems.de>).
* libfs/src/dosfs/dosfs.h, libfs/src/dosfs/fat.c,
libfs/src/dosfs/fat.h, libfs/src/dosfs/msdos_format.c:
Adaptations to RTEMS-4.7.
2004-11-20 Ralf Corsepius <ralf.corsepiu@rtems.org> 2004-11-20 Ralf Corsepius <ralf.corsepiu@rtems.org>
PR 720/filesystem: PR 720/filesystem:

View File

@@ -12,6 +12,7 @@
* *
* @(#) $Id$ * @(#) $Id$
*/ */
#ifndef __DOSFS_DOSFS_H__ #ifndef __DOSFS_DOSFS_H__
#define __DOSFS_DOSFS_H__ #define __DOSFS_DOSFS_H__
@@ -24,6 +25,53 @@ extern "C" {
extern rtems_filesystem_operations_table msdos_ops; extern rtems_filesystem_operations_table msdos_ops;
#define MSDOS_FMT_FATANY 0
#define MSDOS_FMT_FAT12 1
#define MSDOS_FMT_FAT16 2
#define MSDOS_FMT_FAT32 3
/*
* data to be filled out for formatter: parameters for format call
* any parameter set to 0 or NULL will be automatically detected/computed
*/
typedef struct {
const char *OEMName; /* OEM Name string or NULL */
const char *VolLabel; /* Volume Label string or NULL */
uint32_t sectors_per_cluster; /* request value: sectors per cluster */
uint32_t fat_num; /* request value: number of FATs on disk */
uint32_t files_per_root_dir; /* request value: file entries in root */
uint8_t fattype; /* request value: MSDOS_FMT_FAT12/16/32 */
uint8_t media; /* media code. default: 0xF8 */
boolean quick_format; /* TRUE: do not clear out data sectors */
uint32_t cluster_align; /* requested value: cluster alignment */
/* make sector number of first sector */
/* of first cluster divisible by this */
/* value. This can optimize clusters */
/* to be located at start of track */
/* or start of flash block */
} msdos_format_request_param_t;
/*=========================================================================*\
| Function: |
\*-------------------------------------------------------------------------*/
int msdos_format
(
/*-------------------------------------------------------------------------*\
| Purpose: |
| format device with msdos filesystem |
+---------------------------------------------------------------------------+
| Input Parameters: |
\*-------------------------------------------------------------------------*/
const char *devname, /* device name */
const msdos_format_request_param_t *rqdata /* requested fmt parameters */
/* set to NULL for automatic */
/* determination */
);
/*-------------------------------------------------------------------------*\
| Return Value: |
| 0, if success, -1 and errno if failed |
\*=========================================================================*/
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -247,10 +247,10 @@ fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry)
} }
close(fd); close(fd);
vol->bps = FAT_BR_BYTES_PER_SECTOR(boot_rec); vol->bps = FAT_GET_BR_BYTES_PER_SECTOR(boot_rec);
if ( (vol->bps != 512) && if ( (vol->bps != 512) &&
(vol->bps != 1024) && (vol->bps != 1024) &&
(vol->bps != 2048) && (vol->bps != 2048) &&
(vol->bps != 4096)) (vol->bps != 4096))
{ {
@@ -263,7 +263,7 @@ fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry)
for (vol->sec_log2 = 0, i = vol->bps; (i & 1) == 0; for (vol->sec_log2 = 0, i = vol->bps; (i & 1) == 0;
i >>= 1, vol->sec_log2++); i >>= 1, vol->sec_log2++);
vol->spc = FAT_BR_SECTORS_PER_CLUSTER(boot_rec); vol->spc = FAT_GET_BR_SECTORS_PER_CLUSTER(boot_rec);
/* /*
* "sectors per cluster" of zero is invalid * "sectors per cluster" of zero is invalid
* (and would hang the following loop) * (and would hang the following loop)
@@ -289,33 +289,33 @@ fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry)
for (vol->bpc_log2 = 0, i = vol->bpc; (i & 1) == 0; for (vol->bpc_log2 = 0, i = vol->bpc; (i & 1) == 0;
i >>= 1, vol->bpc_log2++); i >>= 1, vol->bpc_log2++);
vol->fats = FAT_BR_FAT_NUM(boot_rec); vol->fats = FAT_GET_BR_FAT_NUM(boot_rec);
vol->fat_loc = FAT_BR_RESERVED_SECTORS_NUM(boot_rec); vol->fat_loc = FAT_GET_BR_RESERVED_SECTORS_NUM(boot_rec);
vol->rdir_entrs = FAT_BR_FILES_PER_ROOT_DIR(boot_rec);
vol->rdir_entrs = FAT_GET_BR_FILES_PER_ROOT_DIR(boot_rec);
/* calculate the count of sectors occupied by the root directory */ /* calculate the count of sectors occupied by the root directory */
vol->rdir_secs = ((vol->rdir_entrs * FAT_DIRENTRY_SIZE) + (vol->bps - 1)) / vol->rdir_secs = ((vol->rdir_entrs * FAT_DIRENTRY_SIZE) + (vol->bps - 1)) /
vol->bps; vol->bps;
vol->rdir_size = vol->rdir_secs << vol->sec_log2; vol->rdir_size = vol->rdir_secs << vol->sec_log2;
if ( (FAT_BR_SECTORS_PER_FAT(boot_rec)) != 0) if ( (FAT_GET_BR_SECTORS_PER_FAT(boot_rec)) != 0)
vol->fat_length = FAT_BR_SECTORS_PER_FAT(boot_rec); vol->fat_length = FAT_GET_BR_SECTORS_PER_FAT(boot_rec);
else else
vol->fat_length = FAT_BR_SECTORS_PER_FAT32(boot_rec); vol->fat_length = FAT_GET_BR_SECTORS_PER_FAT32(boot_rec);
vol->data_fsec = vol->fat_loc + vol->fats * vol->fat_length + vol->data_fsec = vol->fat_loc + vol->fats * vol->fat_length +
vol->rdir_secs; vol->rdir_secs;
/* for FAT12/16 root dir starts at(sector) */ /* for FAT12/16 root dir starts at(sector) */
vol->rdir_loc = vol->fat_loc + vol->fats * vol->fat_length; vol->rdir_loc = vol->fat_loc + vol->fats * vol->fat_length;
if ( (FAT_BR_TOTAL_SECTORS_NUM16(boot_rec)) != 0) if ( (FAT_GET_BR_TOTAL_SECTORS_NUM16(boot_rec)) != 0)
vol->tot_secs = FAT_BR_TOTAL_SECTORS_NUM16(boot_rec); vol->tot_secs = FAT_GET_BR_TOTAL_SECTORS_NUM16(boot_rec);
else else
vol->tot_secs = FAT_BR_TOTAL_SECTORS_NUM32(boot_rec); vol->tot_secs = FAT_GET_BR_TOTAL_SECTORS_NUM32(boot_rec);
data_secs = vol->tot_secs - vol->data_fsec; data_secs = vol->tot_secs - vol->data_fsec;
vol->data_cls = data_secs / vol->spc; vol->data_cls = data_secs / vol->spc;
@@ -345,15 +345,15 @@ fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry)
if (vol->type == FAT_FAT32) if (vol->type == FAT_FAT32)
{ {
vol->rdir_cl = FAT_BR_FAT32_ROOT_CLUSTER(boot_rec); vol->rdir_cl = FAT_GET_BR_FAT32_ROOT_CLUSTER(boot_rec);
vol->mirror = FAT_BR_EXT_FLAGS(boot_rec) & FAT_BR_EXT_FLAGS_MIRROR; vol->mirror = FAT_GET_BR_EXT_FLAGS(boot_rec) & FAT_BR_EXT_FLAGS_MIRROR;
if (vol->mirror) if (vol->mirror)
vol->afat = FAT_BR_EXT_FLAGS(boot_rec) & FAT_BR_EXT_FLAGS_FAT_NUM; vol->afat = FAT_GET_BR_EXT_FLAGS(boot_rec) & FAT_BR_EXT_FLAGS_FAT_NUM;
else else
vol->afat = 0; vol->afat = 0;
vol->info_sec = FAT_BR_FAT32_FS_INFO_SECTOR(boot_rec); vol->info_sec = FAT_GET_BR_FAT32_FS_INFO_SECTOR(boot_rec);
if( vol->info_sec == 0 ) if( vol->info_sec == 0 )
{ {
rtems_disk_release(vol->dd); rtems_disk_release(vol->dd);
@@ -367,9 +367,9 @@ fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry)
{ {
rtems_disk_release(vol->dd); rtems_disk_release(vol->dd);
return -1; return -1;
} }
if (FAT_FSINFO_LEAD_SIGNATURE(fs_info_sector) != if (FAT_GET_FSINFO_LEAD_SIGNATURE(fs_info_sector) !=
FAT_FSINFO_LEAD_SIGNATURE_VALUE) FAT_FSINFO_LEAD_SIGNATURE_VALUE)
{ {
rtems_disk_release(vol->dd); rtems_disk_release(vol->dd);
@@ -383,11 +383,11 @@ fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry)
{ {
rtems_disk_release(vol->dd); rtems_disk_release(vol->dd);
return -1; return -1;
} }
vol->free_cls = FAT_FSINFO_FREE_CLUSTER_COUNT(fs_info_sector); vol->free_cls = FAT_GET_FSINFO_FREE_CLUSTER_COUNT(fs_info_sector);
vol->next_cl = FAT_FSINFO_NEXT_FREE_CLUSTER(fs_info_sector); vol->next_cl = FAT_GET_FSINFO_NEXT_FREE_CLUSTER(fs_info_sector);
rc = fat_fat32_update_fsinfo_sector(mt_entry, 0xFFFFFFFF, rc = fat_fat32_update_fsinfo_sector(mt_entry, 0xFFFFFFFF,
0xFFFFFFFF); 0xFFFFFFFF);
if ( rc != RC_OK ) if ( rc != RC_OK )
{ {

View File

@@ -51,11 +51,11 @@ extern "C" {
*/ */
#if (CPU_BIG_ENDIAN == TRUE) #if (CPU_BIG_ENDIAN == TRUE)
# define CF_LE_W(v) CPU_swap_u16((uint16_t )v) # define CF_LE_W(v) CPU_swap_u16((uint16_t)(v))
# define CF_LE_L(v) CPU_swap_u32((uint32_t )v) # define CF_LE_L(v) CPU_swap_u32((uint32_t)(v))
# define CT_LE_W(v) CPU_swap_u16((uint16_t )v) # define CT_LE_W(v) CPU_swap_u16((uint16_t)(v))
# define CT_LE_L(v) CPU_swap_u32((uint32_t )v) # define CT_LE_L(v) CPU_swap_u32((uint32_t)(v))
#else #else
# define CF_LE_W(v) (v) # define CF_LE_W(v) (v)
# define CF_LE_L(v) (v) # define CF_LE_L(v) (v)
# define CT_LE_W(v) (v) # define CT_LE_W(v) (v)
@@ -101,55 +101,180 @@ extern "C" {
#define FAT_FAT32_MASK (uint32_t )0x0FFFFFFF #define FAT_FAT32_MASK (uint32_t )0x0FFFFFFF
#define FAT_MAX_BPB_SIZE 90 #define FAT_MAX_BPB_SIZE 90
#define FAT_TOTAL_MBR_SIZE 512
/* size of useful information in FSInfo sector */ /* size of useful information in FSInfo sector */
#define FAT_USEFUL_INFO_SIZE 12 #define FAT_USEFUL_INFO_SIZE 12
#define FAT_VAL8(x, ofs) (uint8_t )(*((uint8_t *)(x) + (ofs))) #define FAT_GET_ADDR(x, ofs) ((uint8_t *)(x) + (ofs))
#define FAT_VAL16(x, ofs) \ #define FAT_GET_VAL8(x, ofs) (uint8_t)(*((uint8_t *)(x) + (ofs)))
(uint16_t )( (*((uint8_t *)(x) + (ofs))) | \
((*((uint8_t *)(x) + (ofs) + 1)) << 8) )
#define FAT_VAL32(x, ofs) \ #define FAT_GET_VAL16(x, ofs) \
(uint32_t )( (uint32_t )(*((uint8_t *)(x) + (ofs))) | \ (uint16_t)( (*((uint8_t *)(x) + (ofs))) | \
((uint32_t )(*((uint8_t *)(x) + (ofs) + 1)) << 8) | \ ((*((uint8_t *)(x) + (ofs) + 1)) << 8) )
((uint32_t )(*((uint8_t *)(x) + (ofs) + 2)) << 16) | \
((uint32_t )(*((uint8_t *)(x) + (ofs) + 3)) << 24) ) #define FAT_GET_VAL32(x, ofs) \
(uint32_t)( (uint32_t)(*((uint8_t *)(x) + (ofs))) | \
((uint32_t)(*((uint8_t *)(x) + (ofs) + 1)) << 8) | \
((uint32_t)(*((uint8_t *)(x) + (ofs) + 2)) << 16) | \
((uint32_t)(*((uint8_t *)(x) + (ofs) + 3)) << 24) )
#define FAT_SET_VAL8(x, ofs,val) \
(*((uint8_t *)(x)+(ofs))=(uint8_t)(val))
#define FAT_SET_VAL16(x, ofs,val) do { \
FAT_SET_VAL8((x),(ofs),(val)); \
FAT_SET_VAL8((x),(ofs)+1,(val)>>8);\
} while (0)
#define FAT_SET_VAL32(x, ofs,val) do { \
FAT_SET_VAL16((x),(ofs),(val)); \
FAT_SET_VAL16((x),(ofs)+2,(val)>>16);\
} while (0)
/* macros to access boot sector fields */ /* macros to access boot sector fields */
#define FAT_BR_BYTES_PER_SECTOR(x) FAT_VAL16(x, 11) #define FAT_GET_BR_JMPBOOT(x) FAT_GET_VAL8( x, 0)
#define FAT_BR_SECTORS_PER_CLUSTER(x) FAT_VAL8(x, 13) #define FAT_SET_BR_JMPBOOT(x,val) FAT_SET_VAL8( x, 0,val)
#define FAT_BR_RESERVED_SECTORS_NUM(x) FAT_VAL16(x, 14)
#define FAT_BR_FAT_NUM(x) FAT_VAL8(x, 16) #define FAT_GET_ADDR_BR_OEMNAME(x) FAT_GET_ADDR( x, 3)
#define FAT_BR_FILES_PER_ROOT_DIR(x) FAT_VAL16(x, 17) #define FAT_BR_OEMNAME_SIZE (8)
#define FAT_BR_TOTAL_SECTORS_NUM16(x) FAT_VAL16(x, 19)
#define FAT_BR_MEDIA(x) FAT_VAL8(x, 21) #define FAT_GET_BR_BYTES_PER_SECTOR(x) FAT_GET_VAL16(x, 11)
#define FAT_BR_SECTORS_PER_FAT(x) FAT_VAL16(x, 22) #define FAT_SET_BR_BYTES_PER_SECTOR(x,val) FAT_SET_VAL16(x, 11,val)
#define FAT_BR_TOTAL_SECTORS_NUM32(x) FAT_VAL32(x, 32)
#define FAT_BR_SECTORS_PER_FAT32(x) FAT_VAL32(x, 36) #define FAT_GET_BR_SECTORS_PER_CLUSTER(x) FAT_GET_VAL8( x, 13)
#define FAT_BR_EXT_FLAGS(x) FAT_VAL16(x, 40) #define FAT_SET_BR_SECTORS_PER_CLUSTER(x,val)FAT_SET_VAL8( x, 13,val)
#define FAT_BR_FAT32_ROOT_CLUSTER(x) FAT_VAL32(x, 44)
#define FAT_BR_FAT32_FS_INFO_SECTOR(x) FAT_VAL16(x, 48) #define FAT_GET_BR_RESERVED_SECTORS_NUM(x) FAT_GET_VAL16(x, 14)
#define FAT_FSINFO_LEAD_SIGNATURE(x) FAT_VAL32(x, 0) #define FAT_SET_BR_RESERVED_SECTORS_NUM(x,val) FAT_SET_VAL16(x, 14,val)
/*
* I read FSInfo sector from offset 484 to access the information, so offsets #define FAT_GET_BR_FAT_NUM(x) FAT_GET_VAL8( x, 16)
#define FAT_SET_BR_FAT_NUM(x,val) FAT_SET_VAL8( x, 16,val)
#define FAT_GET_BR_FILES_PER_ROOT_DIR(x) FAT_GET_VAL16(x, 17)
#define FAT_SET_BR_FILES_PER_ROOT_DIR(x,val) FAT_SET_VAL16(x, 17,val)
#define FAT_GET_BR_TOTAL_SECTORS_NUM16(x) FAT_GET_VAL16(x, 19)
#define FAT_SET_BR_TOTAL_SECTORS_NUM16(x,val)FAT_SET_VAL16(x, 19,val)
#define FAT_GET_BR_MEDIA(x) FAT_GET_VAL8( x, 21)
#define FAT_SET_BR_MEDIA(x,val) FAT_SET_VAL8( x, 21,val)
#define FAT_GET_BR_SECTORS_PER_FAT(x) FAT_GET_VAL16(x, 22)
#define FAT_SET_BR_SECTORS_PER_FAT(x,val) FAT_SET_VAL16(x, 22,val)
#define FAT_GET_BR_SECTORS_PER_TRACK(x) FAT_GET_VAL16(x, 24)
#define FAT_SET_BR_SECTORS_PER_TRACK(x,val) FAT_SET_VAL16(x, 24,val)
#define FAT_GET_BR_NUMBER_OF_HEADS(x) FAT_GET_VAL16(x, 26)
#define FAT_SET_BR_NUMBER_OF_HEADS(x,val) FAT_SET_VAL16(x, 26,val)
#define FAT_GET_BR_HIDDEN_SECTORS(x) FAT_GET_VAL32(x, 28)
#define FAT_SET_BR_HIDDEN_SECTORS(x,val) FAT_SET_VAL32(x, 28,val)
#define FAT_GET_BR_TOTAL_SECTORS_NUM32(x) FAT_GET_VAL32(x, 32)
#define FAT_SET_BR_TOTAL_SECTORS_NUM32(x,val) FAT_SET_VAL32(x, 32,val)
/* --- start of FAT12/16 specific fields */
#define FAT_GET_BR_DRVNUM(x) FAT_GET_VAL8( x, 36)
#define FAT_SET_BR_DRVNUM(x,val) FAT_SET_VAL8( x, 36,val)
#define FAT_GET_BR_RSVD1(x) FAT_GET_VAL8( x, 37)
#define FAT_SET_BR_RSVD1(x,val) FAT_SET_VAL8( x, 37,val)
#define FAT_GET_BR_BOOTSIG(x) FAT_GET_VAL8( x, 38)
#define FAT_SET_BR_BOOTSIG(x,val) FAT_SET_VAL8( x, 38,val)
#define FAT_BR_BOOTSIG_VAL (0x29)
#define FAT_GET_BR_VOLID(x) FAT_GET_VAL32(x, 39)
#define FAT_SET_BR_VOLID(x,val) FAT_SET_VAL32(x, 39,val)
#define FAT_GET_ADDR_BR_VOLLAB(x) FAT_GET_ADDR (x, 43)
#define FAT_BR_VOLLAB_SIZE (11)
#define FAT_GET_ADDR_BR_FILSYSTYPE(x) FAT_GET_ADDR (x, 54)
#define FAT_BR_FILSYSTYPE_SIZE (8)
/* --- end of FAT12/16 specific fields */
/* --- start of FAT32 specific fields */
#define FAT_GET_BR_SECTORS_PER_FAT32(x) FAT_GET_VAL32(x, 36)
#define FAT_SET_BR_SECTORS_PER_FAT32(x,val) FAT_SET_VAL32(x, 36,val)
#define FAT_GET_BR_EXT_FLAGS(x) FAT_GET_VAL16(x, 40)
#define FAT_SET_BR_EXT_FLAGS(x,val) FAT_SET_VAL16(x, 40,val)
#define FAT_GET_BR_FSVER(x) FAT_GET_VAL16(x, 42)
#define FAT_SET_BR_FSVER(x,val) FAT_SET_VAL16(x, 42,val)
#define FAT_GET_BR_FAT32_ROOT_CLUSTER(x) FAT_GET_VAL32(x, 44)
#define FAT_SET_BR_FAT32_ROOT_CLUSTER(x,val) FAT_SET_VAL32(x, 44,val)
#define FAT_GET_BR_FAT32_FS_INFO_SECTOR(x) FAT_GET_VAL16(x, 48)
#define FAT_SET_BR_FAT32_FS_INFO_SECTOR(x,val) FAT_SET_VAL16(x, 48,val)
#define FAT_GET_BR_FAT32_BK_BOOT_SECTOR(x) FAT_GET_VAL16(x, 50)
#define FAT_SET_BR_FAT32_BK_BOOT_SECTOR(x,val) FAT_SET_VAL16(x, 50,val)
#define FAT_GET_ADDR_BR_FAT32_RESERVED(x) FAT_GET_ADDR (x, 52)
#define FAT_BR_FAT32_RESERVED_SIZE (12)
#define FAT_GET_BR_FAT32_DRVNUM(x) FAT_GET_VAL8( x, 64)
#define FAT_SET_BR_FAT32_DRVNUM(x,val) FAT_SET_VAL8( x, 64,val)
#define FAT_GET_BR_FAT32_RSVD1(x) FAT_GET_VAL8( x, 65)
#define FAT_SET_BR_FAT32_RSVD1(x,val) FAT_SET_VAL8( x, 65,val)
#define FAT_GET_BR_FAT32_BOOTSIG(x) FAT_GET_VAL8( x, 66)
#define FAT_SET_BR_FAT32_BOOTSIG(x,val) FAT_SET_VAL8( x, 66,val)
#define FAT_BR_FAT32_BOOTSIG_VAL (0x29)
#define FAT_GET_BR_FAT32_VOLID(x) FAT_GET_VAL32(x, 67)
#define FAT_SET_BR_FAT32_VOLID(x,val) FAT_SET_VAL32(x, 67,val)
#define FAT_GET_ADDR_BR_FAT32_VOLLAB(x) FAT_GET_ADDR (x, 71)
#define FAT_BR_FAT32_VOLLAB_SIZE (11)
#define FAT_GET_ADDR_BR_FAT32_FILSYSTYPE(x) FAT_GET_ADDR (x, 82)
#define FAT_BR_FAT32_FILSYSTYPE_SIZE (8)
/* --- end of FAT32 specific fields */
#define FAT_GET_BR_SIGNATURE(x) FAT_GET_VAL16(x,510)
#define FAT_SET_BR_SIGNATURE(x,val) FAT_SET_VAL16(x,510,val)
#define FAT_BR_SIGNATURE_VAL (0xAA55)
/*
* FAT32 FSINFO description
*/
#define FAT_GET_FSINFO_LEAD_SIGNATURE(x) FAT_GET_VAL32(x, 0)
#define FAT_SET_FSINFO_LEAD_SIGNATURE(x,val) FAT_SET_VAL32(x, 0,val)
#define FAT_FSINFO_LEAD_SIGNATURE_VALUE (0x41615252)
#define FAT_GET_FSINFO_STRUC_SIGNATURE(x) FAT_GET_VAL32(x,484)
#define FAT_SET_FSINFO_STRUC_SIGNATURE(x,val) FAT_SET_VAL32(x,484,val)
#define FAT_FSINFO_STRUC_SIGNATURE_VALUE (0x61417272)
#define FAT_GET_FSINFO_TRAIL_SIGNATURE(x) FAT_GET_VAL32(x,508)
#define FAT_SET_FSINFO_TRAIL_SIGNATURE(x,val) FAT_SET_VAL32(x,508,val)
#define FAT_FSINFO_TRAIL_SIGNATURE_VALUE (0x000055AA)
/*
* I read FSInfo sector from offset 484 to access the information, so offsets
* of these fields a relative * of these fields a relative
*/ */
#define FAT_FSINFO_FREE_CLUSTER_COUNT(x) FAT_VAL32(x, 4) #define FAT_GET_FSINFO_FREE_CLUSTER_COUNT(x) FAT_GET_VAL32(x, 4)
#define FAT_FSINFO_NEXT_FREE_CLUSTER(x) FAT_VAL32(x, 8) #define FAT_SET_FSINFO_FREE_CLUSTER_COUNT(x,val) FAT_SET_VAL32(x, 4,val)
#define FAT_GET_FSINFO_NEXT_FREE_CLUSTER(x) FAT_GET_VAL32(x, 8)
#define FAT_SET_FSINFO_NEXT_FREE_CLUSTER(x,val) FAT_SET_VAL32(x, 8,val)
#define FAT_FSINFO_FREE_CLUSTER_COUNT_OFFSET 488 #define FAT_FSI_INFO 484
#define FAT_FSINFO_STRUCT_OFFSET 488
#define FAT_FSINFO_FREE_CLUSTER_COUNT_OFFSET (FAT_FSINFO_STRUCT_OFFSET+0)
#define FAT_FSINFO_NEXT_FREE_CLUSTER_OFFSET 492 #define FAT_FSINFO_NEXT_FREE_CLUSTER_OFFSET (FAT_FSINFO_STRUCT_OFFSET+4)
#define FAT_RSRVD_CLN 0x02 #define FAT_RSRVD_CLN 0x02
#define FAT_FSINFO_LEAD_SIGNATURE_VALUE 0x41615252
#define FAT_FSI_LEADSIG_SIZE 0x04 #define FAT_FSI_LEADSIG_SIZE 0x04
#define FAT_FSI_INFO 484 #define FAT_TOTAL_FSINFO_SIZE 512
#define MS_BYTES_PER_CLUSTER_LIMIT 0x8000 /* 32K */ #define MS_BYTES_PER_CLUSTER_LIMIT 0x8000 /* 32K */
@@ -157,6 +282,7 @@ extern "C" {
#define FAT_BR_EXT_FLAGS_FAT_NUM 0x000F #define FAT_BR_EXT_FLAGS_FAT_NUM 0x000F
#define FAT_BR_MEDIA_FIXED 0xf8
#define FAT_DIRENTRY_SIZE 32 #define FAT_DIRENTRY_SIZE 32

View File

@@ -42,27 +42,27 @@
#include "dosfs.h" #include "dosfs.h"
typedef struct { typedef struct {
unsigned32 bytes_per_sector; uint32_t bytes_per_sector;
unsigned32 totl_sector_cnt; uint32_t totl_sector_cnt;
unsigned32 rsvd_sector_cnt; uint32_t rsvd_sector_cnt;
unsigned32 sectors_per_cluster; uint32_t sectors_per_cluster;
unsigned32 sectors_per_fat; uint32_t sectors_per_fat;
unsigned32 fat_start_sec; uint32_t fat_start_sec;
unsigned32 files_per_root_dir; uint32_t files_per_root_dir;
unsigned32 root_dir_sectors; uint32_t root_dir_sectors;
unsigned32 root_dir_start_sec; uint32_t root_dir_start_sec;
unsigned32 root_dir_fmt_sec_cnt; uint32_t root_dir_fmt_sec_cnt;
unsigned32 mbr_copy_sec; /* location of copy of mbr or 0 */ uint32_t mbr_copy_sec; /* location of copy of mbr or 0 */
unsigned32 fsinfo_sec; /* location of fsinfo sector or 0 */ uint32_t fsinfo_sec; /* location of fsinfo sector or 0 */
unsigned8 fat_num; uint8_t fat_num;
unsigned8 media_code; uint8_t media_code;
unsigned8 fattype; uint8_t fattype;
char OEMName[FAT_BR_OEMNAME_SIZE+1]; char OEMName[FAT_BR_OEMNAME_SIZE+1];
char VolLabel[FAT_BR_VOLLAB_SIZE+1]; char VolLabel[FAT_BR_VOLLAB_SIZE+1];
boolean VolLabel_present; boolean VolLabel_present;
unsigned32 vol_id; uint32_t vol_id;
} msdos_format_param_t; } msdos_format_param_t;
/*=========================================================================*\ /*=========================================================================*\
@@ -77,8 +77,8 @@ static int msdos_format_write_sec
| Input Parameters: | | Input Parameters: |
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
int fd, /* file descriptor index */ int fd, /* file descriptor index */
unsigned32 start_sector, /* sector number to write to */ uint32_t start_sector, /* sector number to write to */
unsigned32 sector_size, /* size of sector */ uint32_t sector_size, /* size of sector */
const char *buffer /* buffer with write data */ const char *buffer /* buffer with write data */
) )
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
@@ -112,9 +112,9 @@ static int msdos_format_fill_sectors
| Input Parameters: | | Input Parameters: |
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
int fd, /* file descriptor index */ int fd, /* file descriptor index */
unsigned32 start_sector, /* sector number to fill to */ uint32_t start_sector, /* sector number to fill to */
unsigned32 sector_cnt, /* number of sectors to fill to */ uint32_t sector_cnt, /* number of sectors to fill to */
unsigned32 sector_size, /* size of sector */ uint32_t sector_size, /* size of sector */
const char fill_byte /* byte to fill into sectors */ const char fill_byte /* byte to fill into sectors */
) )
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
@@ -169,7 +169,7 @@ static int msdos_format_gen_volid
+---------------------------------------------------------------------------+ +---------------------------------------------------------------------------+
| Input Parameters: | | Input Parameters: |
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
unsigned32 *volid_ptr /* volume ID return pointer */ uint32_t *volid_ptr /* volume ID return pointer */
) )
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
| Return Value: | | Return Value: |
@@ -203,13 +203,13 @@ static int msdos_format_eval_sectors_per_cluster
+---------------------------------------------------------------------------+ +---------------------------------------------------------------------------+
| Input Parameters: | | Input Parameters: |
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
int fattype, /* type code of FAT (FAT_FAT12 ...) */ int fattype, /* type code of FAT (FAT_FAT12 ...) */
unsigned32 bytes_per_sector, /* byte count per sector (512) */ uint32_t bytes_per_sector, /* byte count per sector (512) */
unsigned32 fatdata_sec_cnt, /* sectors available for FAT and data */ uint32_t fatdata_sec_cnt, /* sectors available for FAT and data */
unsigned8 fat_num, /* number of fat copies */ uint8_t fat_num, /* number of fat copies */
unsigned32 sectors_per_cluster, /* sectors per cluster (requested) */ uint32_t sectors_per_cluster, /* sectors per cluster (requested) */
unsigned32 *sectors_per_cluster_adj, /* ret: sec per cluster (granted) */ uint32_t *sectors_per_cluster_adj, /* ret: sec per cluster (granted) */
unsigned32 *sectors_per_fat_ptr /* ret: sectors needed for one FAT */ uint32_t *sectors_per_fat_ptr /* ret: sectors needed for one FAT */
) )
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
| Return Value: | | Return Value: |
@@ -219,10 +219,10 @@ static int msdos_format_eval_sectors_per_cluster
boolean finished = FALSE; boolean finished = FALSE;
int ret_val = 0; int ret_val = 0;
unsigned32 fatdata_cluster_cnt; uint32_t fatdata_cluster_cnt;
unsigned32 fat_capacity; uint32_t fat_capacity;
unsigned32 sectors_per_fat; uint32_t sectors_per_fat;
unsigned32 data_cluster_cnt; uint32_t data_cluster_cnt;
/* /*
* ensure, that maximum cluster size (32KByte) is not exceeded * ensure, that maximum cluster size (32KByte) is not exceeded
*/ */
@@ -308,9 +308,9 @@ static int msdos_format_determine_fmt_params
\*=========================================================================*/ \*=========================================================================*/
{ {
int ret_val = 0; int ret_val = 0;
unsigned32 fatdata_sect_cnt; uint32_t fatdata_sect_cnt;
unsigned32 onebit; uint32_t onebit;
unsigned32 sectors_per_cluster_adj; uint32_t sectors_per_cluster_adj;
memset(fmt_params,0,sizeof(*fmt_params)); memset(fmt_params,0,sizeof(*fmt_params));
/* /*
@@ -396,13 +396,13 @@ static int msdos_format_determine_fmt_params
* are a compromise concerning capacity and efficency * are a compromise concerning capacity and efficency
*/ */
if (fmt_params->totl_sector_cnt if (fmt_params->totl_sector_cnt
< ((unsigned32)FAT_FAT12_MAX_CLN)*8) { < ((uint32_t)FAT_FAT12_MAX_CLN)*8) {
fmt_params->fattype = FAT_FAT12; fmt_params->fattype = FAT_FAT12;
/* start trying with small clusters */ /* start trying with small clusters */
fmt_params->sectors_per_cluster = 2; fmt_params->sectors_per_cluster = 2;
} }
else if (fmt_params->totl_sector_cnt else if (fmt_params->totl_sector_cnt
< ((unsigned32)FAT_FAT16_MAX_CLN)*32) { < ((uint32_t)FAT_FAT16_MAX_CLN)*32) {
fmt_params->fattype = FAT_FAT16; fmt_params->fattype = FAT_FAT16;
/* start trying with small clusters */ /* start trying with small clusters */
fmt_params->sectors_per_cluster = 2; fmt_params->sectors_per_cluster = 2;
@@ -638,8 +638,8 @@ static int msdos_format_gen_mbr
| 0, if success, -1 and errno if failed | | 0, if success, -1 and errno if failed |
\*=========================================================================*/ \*=========================================================================*/
{ {
unsigned32 total_sectors_num16 = 0; uint32_t total_sectors_num16 = 0;
unsigned32 total_sectors_num32 = 0; uint32_t total_sectors_num32 = 0;
/* store total sector count in either 16 or 32 bit field in mbr */ /* store total sector count in either 16 or 32 bit field in mbr */
if (fmt_params->totl_sector_cnt < 0x10000) { if (fmt_params->totl_sector_cnt < 0x10000) {