From: <ges...@us...> - 2011-07-21 21:05:46
|
Revision: 5752 http://ipcop.svn.sourceforge.net/ipcop/?rev=5752&view=rev Author: gespinasse Date: 2011-07-21 21:05:37 +0000 (Thu, 21 Jul 2011) Log Message: ----------- Upgrade dosfstools from 3.0.9 to 3.0.11 Use an upstream repository snapshot that fix the more than 150 warnings Unfortunately, there is some code re-indentation, so patch is not that small. Compile with -fno-strict-aliasing to fix the aliasing warnings So only 6 warnings remain, better than the 180 before Modified Paths: -------------- ipcop/trunk/config/rootfiles/common/dosfstools ipcop/trunk/lfs/dosfstools Added Paths: ----------- ipcop/trunk/src/patches/dosfstools-3.0.11_2011-06-07.patch Modified: ipcop/trunk/config/rootfiles/common/dosfstools =================================================================== --- ipcop/trunk/config/rootfiles/common/dosfstools 2011-07-21 05:21:46 UTC (rev 5751) +++ ipcop/trunk/config/rootfiles/common/dosfstools 2011-07-21 21:05:37 UTC (rev 5752) @@ -7,6 +7,7 @@ #sbin/mkfs.vfat #usr/share/doc/dosfstools #usr/share/doc/dosfstools/ANNOUNCE.mkdosfs +#usr/share/doc/dosfstools/ChangeLog #usr/share/doc/dosfstools/ChangeLog.dosfsck #usr/share/doc/dosfstools/ChangeLog.dosfstools-2.x #usr/share/doc/dosfstools/ChangeLog.mkdosfs Modified: ipcop/trunk/lfs/dosfstools =================================================================== --- ipcop/trunk/lfs/dosfstools 2011-07-21 05:21:46 UTC (rev 5751) +++ ipcop/trunk/lfs/dosfstools 2011-07-21 21:05:37 UTC (rev 5752) @@ -33,7 +33,7 @@ include Config PKG_NAME = dosfstools -VER = 3.0.9 +VER = 3.0.11 HOST_ARCH = all OTHER_SRC = yes @@ -43,6 +43,8 @@ DIR_APP = $(DIR_SRC)/$(THISAPP) TARGET = $(DIR_INFO)/$(STAGE_ORDER)_$(STAGE)/$(THISAPP) +CFLAGS += -fno-strict-aliasing + ############################################################################### # Top-level Rules ############################################################################### @@ -51,7 +53,7 @@ $(DL_FILE) = $(DL_FROM)/$(DL_FILE) -$(DL_FILE)_MD5 = 7f159ec44d3b9c502904bab0236050e4 +$(DL_FILE)_MD5 = 8d2211d5bd813164e20740e7c852aa06 install : $(TARGET) @@ -81,6 +83,8 @@ $(TARGET) : $(firstword $(MAKEFILE_LIST)) $(patsubst %,$(DIR_DL)/%,$(objects)) @$(PREBUILD) @rm -rf $(DIR_APP) && cd $(DIR_SRC) && tar jxf $(DIR_DL)/$(DL_FILE) + # from upstream, so removed on 3.0.12 + cd $(DIR_APP) && patch -Np1 -i $(DIR_PATCHES)/$(THISAPP)_2011-06-07.patch cd $(DIR_APP) && make cd $(DIR_APP) && make PREFIX=usr SBINDIR=sbin install Added: ipcop/trunk/src/patches/dosfstools-3.0.11_2011-06-07.patch =================================================================== --- ipcop/trunk/src/patches/dosfstools-3.0.11_2011-06-07.patch (rev 0) +++ ipcop/trunk/src/patches/dosfstools-3.0.11_2011-06-07.patch 2011-07-21 21:05:37 UTC (rev 5752) @@ -0,0 +1,7742 @@ +git clone git://git.debian-maintainers.org/git/daniel/dosfstools.git +cd dosfstools +git checkout -b upstream origin/upstream +git diff upstream/3.0.11.. > <path>/src/patches/dosfstools-3.0.11_<last-update>.patch + +diff --git a/bin/Nindent b/bin/Nindent +new file mode 100755 +index 0000000..cf8ecfd +--- /dev/null ++++ b/bin/Nindent +@@ -0,0 +1,18 @@ ++#!/bin/sh ++PARAM="-npro -kr -i4 -ts8 -sob -l80 -ss -ncs -cp1" ++RES=`indent --version` ++V1=`echo $RES | cut -d' ' -f3 | cut -d'.' -f1` ++V2=`echo $RES | cut -d' ' -f3 | cut -d'.' -f2` ++V3=`echo $RES | cut -d' ' -f3 | cut -d'.' -f3` ++if [ $V1 -gt 2 ]; then ++ PARAM="$PARAM -il0" ++elif [ $V1 -eq 2 ]; then ++ if [ $V2 -gt 2 ]; then ++ PARAM="$PARAM -il0"; ++ elif [ $V2 -eq 2 ]; then ++ if [ $V3 -ge 10 ]; then ++ PARAM="$PARAM -il0" ++ fi ++ fi ++fi ++exec indent $PARAM "$@" +diff --git a/src/boot.c b/src/boot.c +index 8848efe..bbaee04 100644 +--- a/src/boot.c ++++ b/src/boot.c +@@ -35,7 +35,6 @@ + #include "io.h" + #include "boot.h" + +- + #define ROUND_TO_MULTIPLE(n,m) ((n) && (m) ? (n)+(m)-1-((n)-1)%(m) : 0) + /* don't divide by zero */ + +@@ -47,17 +46,17 @@ static struct { + __u8 media; + char *descr; + } mediabytes[] = { +- { 0xf0, "5.25\" or 3.5\" HD floppy" }, +- { 0xf8, "hard disk" }, +- { 0xf9, "3,5\" 720k floppy 2s/80tr/9sec or " +- "5.25\" 1.2M floppy 2s/80tr/15sec" }, +- { 0xfa, "5.25\" 320k floppy 1s/80tr/8sec" }, +- { 0xfb, "3.5\" 640k floppy 2s/80tr/8sec" }, +- { 0xfc, "5.25\" 180k floppy 1s/40tr/9sec" }, +- { 0xfd, "5.25\" 360k floppy 2s/40tr/9sec" }, +- { 0xfe, "5.25\" 160k floppy 1s/40tr/8sec" }, +- { 0xff, "5.25\" 320k floppy 2s/40tr/8sec" }, +-}; ++ { ++ 0xf0, "5.25\" or 3.5\" HD floppy"}, { ++ 0xf8, "hard disk"}, { ++ 0xf9, "3,5\" 720k floppy 2s/80tr/9sec or " ++ "5.25\" 1.2M floppy 2s/80tr/15sec"}, { ++ 0xfa, "5.25\" 320k floppy 1s/80tr/8sec"}, { ++ 0xfb, "3.5\" 640k floppy 2s/80tr/8sec"}, { ++ 0xfc, "5.25\" 180k floppy 1s/40tr/9sec"}, { ++ 0xfd, "5.25\" 360k floppy 2s/40tr/9sec"}, { ++ 0xfe, "5.25\" 160k floppy 1s/40tr/8sec"}, { ++0xff, "5.25\" 320k floppy 2s/40tr/8sec"},}; + + #if defined __alpha || defined __arm || defined __arm__ || defined __ia64__ || defined __x86_64__ \ + || defined __ppc64__ || defined __bfin__ || defined __MICROBLAZE__ +@@ -72,87 +71,84 @@ static struct { + #define GET_UNALIGNED_W(f) CF_LE_W( *(unsigned short *)&f ) + #endif + +- +-static char *get_media_descr( unsigned char media ) ++static char *get_media_descr(unsigned char media) + { + int i; + +- for( i = 0; i < sizeof(mediabytes)/sizeof(*mediabytes); ++i ) { ++ for (i = 0; i < sizeof(mediabytes) / sizeof(*mediabytes); ++i) { + if (mediabytes[i].media == media) +- return( mediabytes[i].descr ); ++ return (mediabytes[i].descr); + } +- return( "undefined" ); ++ return ("undefined"); + } + +-static void dump_boot(DOS_FS *fs,struct boot_sector *b,unsigned lss) ++static void dump_boot(DOS_FS * fs, struct boot_sector *b, unsigned lss) + { + unsigned short sectors; + + printf("Boot sector contents:\n"); + if (!atari_format) { + char id[9]; +- strncpy(id,b->system_id,8); ++ strncpy(id, (const char *)b->system_id, 8); + id[8] = 0; +- printf("System ID \"%s\"\n",id); +- } +- else { ++ printf("System ID \"%s\"\n", id); ++ } else { + /* On Atari, a 24 bit serial number is stored at offset 8 of the boot + * sector */ + printf("Serial number 0x%x\n", +- b->system_id[5] | (b->system_id[6]<<8) | (b->system_id[7]<<16)); ++ b->system_id[5] | (b-> ++ system_id[6] << 8) | (b->system_id[7] << 16)); + } +- printf("Media byte 0x%02x (%s)\n",b->media,get_media_descr(b->media)); +- printf("%10d bytes per logical sector\n",GET_UNALIGNED_W(b->sector_size)); +- printf("%10d bytes per cluster\n",fs->cluster_size); +- printf("%10d reserved sector%s\n",CF_LE_W(b->reserved), ++ printf("Media byte 0x%02x (%s)\n", b->media, get_media_descr(b->media)); ++ printf("%10d bytes per logical sector\n", GET_UNALIGNED_W(b->sector_size)); ++ printf("%10d bytes per cluster\n", fs->cluster_size); ++ printf("%10d reserved sector%s\n", CF_LE_W(b->reserved), + CF_LE_W(b->reserved) == 1 ? "" : "s"); + printf("First FAT starts at byte %llu (sector %llu)\n", + (unsigned long long)fs->fat_start, +- (unsigned long long)fs->fat_start/lss); +- printf("%10d FATs, %d bit entries\n",b->fats,fs->fat_bits); +- printf("%10d bytes per FAT (= %u sectors)\n",fs->fat_size, +- fs->fat_size/lss); ++ (unsigned long long)fs->fat_start / lss); ++ printf("%10d FATs, %d bit entries\n", b->fats, fs->fat_bits); ++ printf("%10d bytes per FAT (= %u sectors)\n", fs->fat_size, ++ fs->fat_size / lss); + if (!fs->root_cluster) { + printf("Root directory starts at byte %llu (sector %llu)\n", + (unsigned long long)fs->root_start, +- (unsigned long long)fs->root_start/lss); +- printf("%10d root directory entries\n",fs->root_entries); +- } +- else { +- printf( "Root directory start at cluster %lu (arbitrary size)\n", +- fs->root_cluster); ++ (unsigned long long)fs->root_start / lss); ++ printf("%10d root directory entries\n", fs->root_entries); ++ } else { ++ printf("Root directory start at cluster %lu (arbitrary size)\n", ++ fs->root_cluster); + } + printf("Data area starts at byte %llu (sector %llu)\n", + (unsigned long long)fs->data_start, +- (unsigned long long)fs->data_start/lss); +- printf("%10lu data clusters (%llu bytes)\n",fs->clusters, +- (unsigned long long)fs->clusters*fs->cluster_size); +- printf("%u sectors/track, %u heads\n",CF_LE_W(b->secs_track), ++ (unsigned long long)fs->data_start / lss); ++ printf("%10lu data clusters (%llu bytes)\n", fs->clusters, ++ (unsigned long long)fs->clusters * fs->cluster_size); ++ printf("%u sectors/track, %u heads\n", CF_LE_W(b->secs_track), + CF_LE_W(b->heads)); +- printf("%10u hidden sectors\n", +- atari_format ? ++ printf("%10u hidden sectors\n", atari_format ? + /* On Atari, the hidden field is only 16 bit wide and unused */ + (((unsigned char *)&b->hidden)[0] | +- ((unsigned char *)&b->hidden)[1] << 8) : +- CF_LE_L(b->hidden)); +- sectors = GET_UNALIGNED_W( b->sectors ); ++ ((unsigned char *)&b->hidden)[1] << 8) : CF_LE_L(b->hidden)); ++ sectors = GET_UNALIGNED_W(b->sectors); + printf("%10u sectors total\n", sectors ? sectors : CF_LE_L(b->total_sect)); + } + +-static void check_backup_boot(DOS_FS *fs, struct boot_sector *b, int lss) ++static void check_backup_boot(DOS_FS * fs, struct boot_sector *b, int lss) + { + struct boot_sector b2; + + if (!fs->backupboot_start) { +- printf( "There is no backup boot sector.\n" ); ++ printf("There is no backup boot sector.\n"); + if (CF_LE_W(b->reserved) < 3) { +- printf( "And there is no space for creating one!\n" ); ++ printf("And there is no space for creating one!\n"); + return; + } + if (interactive) +- printf( "1) Create one\n2) Do without a backup\n" ); +- else printf( " Auto-creating backup boot block.\n" ); +- if (!interactive || get_key("12","?") == '1') { ++ printf("1) Create one\n2) Do without a backup\n"); ++ else ++ printf(" Auto-creating backup boot block.\n"); ++ if (!interactive || get_key("12", "?") == '1') { + int bbs; + /* The usual place for the backup boot sector is sector 6. Choose + * that or the last reserved sector. */ +@@ -161,55 +157,56 @@ static void check_backup_boot(DOS_FS *fs, struct boot_sector *b, int lss) + else { + bbs = CF_LE_W(b->reserved) - 1; + if (bbs == CF_LE_W(b->info_sector)) +- --bbs; /* this is never 0, as we checked reserved >= 3! */ ++ --bbs; /* this is never 0, as we checked reserved >= 3! */ + } +- fs->backupboot_start = bbs*lss; ++ fs->backupboot_start = bbs * lss; + b->backup_boot = CT_LE_W(bbs); +- fs_write(fs->backupboot_start,sizeof(*b),b); +- fs_write((loff_t)offsetof(struct boot_sector,backup_boot), +- sizeof(b->backup_boot),&b->backup_boot); +- printf( "Created backup of boot sector in sector %d\n", bbs ); ++ fs_write(fs->backupboot_start, sizeof(*b), b); ++ fs_write((loff_t) offsetof(struct boot_sector, backup_boot), ++ sizeof(b->backup_boot), &b->backup_boot); ++ printf("Created backup of boot sector in sector %d\n", bbs); ++ return; ++ } else + return; +- } +- else return; + } + +- fs_read(fs->backupboot_start,sizeof(b2),&b2); +- if (memcmp(b,&b2,sizeof(b2)) != 0) { ++ fs_read(fs->backupboot_start, sizeof(b2), &b2); ++ if (memcmp(b, &b2, sizeof(b2)) != 0) { + /* there are any differences */ + __u8 *p, *q; + int i, pos, first = 1; + char buf[20]; + +- printf( "There are differences between boot sector and its backup.\n" ); +- printf( "Differences: (offset:original/backup)\n " ); ++ printf("There are differences between boot sector and its backup.\n"); ++ printf("Differences: (offset:original/backup)\n "); + pos = 2; +- for( p = (__u8 *)b, q = (__u8 *)&b2, i = 0; i < sizeof(b2); +- ++p, ++q, ++i ) { ++ for (p = (__u8 *) b, q = (__u8 *) & b2, i = 0; i < sizeof(b2); ++ ++p, ++q, ++i) { + if (*p != *q) { +- sprintf( buf, "%s%u:%02x/%02x", first ? "" : ", ", +- (unsigned)(p-(__u8 *)b), *p, *q ); +- if (pos + strlen(buf) > 78) printf( "\n " ), pos = 2; +- printf( "%s", buf ); ++ sprintf(buf, "%s%u:%02x/%02x", first ? "" : ", ", ++ (unsigned)(p - (__u8 *) b), *p, *q); ++ if (pos + strlen(buf) > 78) ++ printf("\n "), pos = 2; ++ printf("%s", buf); + pos += strlen(buf); + first = 0; + } + } +- printf( "\n" ); ++ printf("\n"); + + if (interactive) +- printf( "1) Copy original to backup\n" +- "2) Copy backup to original\n" +- "3) No action\n" ); +- else printf( " Not automatically fixing this.\n" ); +- switch (interactive ? get_key("123","?") : '3') { +- case '1': +- fs_write(fs->backupboot_start,sizeof(*b),b); ++ printf("1) Copy original to backup\n" ++ "2) Copy backup to original\n" "3) No action\n"); ++ else ++ printf(" Not automatically fixing this.\n"); ++ switch (interactive ? get_key("123", "?") : '3') { ++ case '1': ++ fs_write(fs->backupboot_start, sizeof(*b), b); + break; +- case '2': +- fs_write(0,sizeof(b2),&b2); ++ case '2': ++ fs_write(0, sizeof(b2), &b2); + break; +- default: ++ default: + break; + } + } +@@ -224,75 +221,76 @@ static void init_fsinfo(struct info_sector *i) + i->boot_sign = CT_LE_W(0xaa55); + } + +-static void read_fsinfo(DOS_FS *fs, struct boot_sector *b,int lss) ++static void read_fsinfo(DOS_FS * fs, struct boot_sector *b, int lss) + { + struct info_sector i; + + if (!b->info_sector) { +- printf( "No FSINFO sector\n" ); ++ printf("No FSINFO sector\n"); + if (interactive) +- printf( "1) Create one\n2) Do without FSINFO\n" ); +- else printf( " Not automatically creating it.\n" ); +- if (interactive && get_key("12","?") == '1') { ++ printf("1) Create one\n2) Do without FSINFO\n"); ++ else ++ printf(" Not automatically creating it.\n"); ++ if (interactive && get_key("12", "?") == '1') { + /* search for a free reserved sector (not boot sector and not + * backup boot sector) */ + __u32 s; +- for( s = 1; s < CF_LE_W(b->reserved); ++s ) +- if (s != CF_LE_W(b->backup_boot)) break; ++ for (s = 1; s < CF_LE_W(b->reserved); ++s) ++ if (s != CF_LE_W(b->backup_boot)) ++ break; + if (s > 0 && s < CF_LE_W(b->reserved)) { + init_fsinfo(&i); +- fs_write((loff_t)s*lss,sizeof(i),&i); ++ fs_write((loff_t) s * lss, sizeof(i), &i); + b->info_sector = CT_LE_W(s); +- fs_write((loff_t)offsetof(struct boot_sector,info_sector), +- sizeof(b->info_sector),&b->info_sector); ++ fs_write((loff_t) offsetof(struct boot_sector, info_sector), ++ sizeof(b->info_sector), &b->info_sector); + if (fs->backupboot_start) +- fs_write(fs->backupboot_start+ +- offsetof(struct boot_sector,info_sector), +- sizeof(b->info_sector),&b->info_sector); +- } +- else { +- printf( "No free reserved sector found -- " +- "no space for FSINFO sector!\n" ); ++ fs_write(fs->backupboot_start + ++ offsetof(struct boot_sector, info_sector), ++ sizeof(b->info_sector), &b->info_sector); ++ } else { ++ printf("No free reserved sector found -- " ++ "no space for FSINFO sector!\n"); + return; + } +- } +- else return; ++ } else ++ return; + } + +- fs->fsinfo_start = CF_LE_W(b->info_sector)*lss; +- fs_read(fs->fsinfo_start,sizeof(i),&i); ++ fs->fsinfo_start = CF_LE_W(b->info_sector) * lss; ++ fs_read(fs->fsinfo_start, sizeof(i), &i); + + if (i.magic != CT_LE_L(0x41615252) || +- i.signature != CT_LE_L(0x61417272) || +- i.boot_sign != CT_LE_W(0xaa55)) { +- printf( "FSINFO sector has bad magic number(s):\n" ); ++ i.signature != CT_LE_L(0x61417272) || i.boot_sign != CT_LE_W(0xaa55)) { ++ printf("FSINFO sector has bad magic number(s):\n"); + if (i.magic != CT_LE_L(0x41615252)) +- printf( " Offset %llu: 0x%08x != expected 0x%08x\n", +- (unsigned long long)offsetof(struct info_sector,magic), +- CF_LE_L(i.magic),0x41615252); ++ printf(" Offset %llu: 0x%08x != expected 0x%08x\n", ++ (unsigned long long)offsetof(struct info_sector, magic), ++ CF_LE_L(i.magic), 0x41615252); + if (i.signature != CT_LE_L(0x61417272)) +- printf( " Offset %llu: 0x%08x != expected 0x%08x\n", +- (unsigned long long)offsetof(struct info_sector,signature), +- CF_LE_L(i.signature),0x61417272); ++ printf(" Offset %llu: 0x%08x != expected 0x%08x\n", ++ (unsigned long long)offsetof(struct info_sector, signature), ++ CF_LE_L(i.signature), 0x61417272); + if (i.boot_sign != CT_LE_W(0xaa55)) +- printf( " Offset %llu: 0x%04x != expected 0x%04x\n", +- (unsigned long long)offsetof(struct info_sector,boot_sign), +- CF_LE_W(i.boot_sign),0xaa55); ++ printf(" Offset %llu: 0x%04x != expected 0x%04x\n", ++ (unsigned long long)offsetof(struct info_sector, boot_sign), ++ CF_LE_W(i.boot_sign), 0xaa55); + if (interactive) +- printf( "1) Correct\n2) Don't correct (FSINFO invalid then)\n" ); +- else printf( " Auto-correcting it.\n" ); +- if (!interactive || get_key("12","?") == '1') { ++ printf("1) Correct\n2) Don't correct (FSINFO invalid then)\n"); ++ else ++ printf(" Auto-correcting it.\n"); ++ if (!interactive || get_key("12", "?") == '1') { + init_fsinfo(&i); +- fs_write(fs->fsinfo_start,sizeof(i),&i); +- } +- else fs->fsinfo_start = 0; ++ fs_write(fs->fsinfo_start, sizeof(i), &i); ++ } else ++ fs->fsinfo_start = 0; + } + + if (fs->fsinfo_start) + fs->free_clusters = CF_LE_L(i.free_clusters); + } + +-void read_boot(DOS_FS *fs) ++void read_boot(DOS_FS * fs) + { + struct boot_sector b; + unsigned total_sectors; +@@ -300,41 +298,45 @@ void read_boot(DOS_FS *fs) + unsigned fat_length; + loff_t data_size; + +- fs_read(0,sizeof(b),&b); ++ fs_read(0, sizeof(b), &b); + logical_sector_size = GET_UNALIGNED_W(b.sector_size); +- if (!logical_sector_size) die("Logical sector size is zero."); ++ if (!logical_sector_size) ++ die("Logical sector size is zero."); + + /* This was moved up because it's the first thing that will fail */ + /* if the platform needs special handling of unaligned multibyte accesses */ + /* but such handling isn't being provided. See GET_UNALIGNED_W() above. */ +- if (logical_sector_size & (SECTOR_SIZE-1)) ++ if (logical_sector_size & (SECTOR_SIZE - 1)) + die("Logical sector size (%d bytes) is not a multiple of the physical " +- "sector size.",logical_sector_size); ++ "sector size.", logical_sector_size); + +- fs->cluster_size = b.cluster_size*logical_sector_size; +- if (!fs->cluster_size) die("Cluster size is zero."); ++ fs->cluster_size = b.cluster_size * logical_sector_size; ++ if (!fs->cluster_size) ++ die("Cluster size is zero."); + if (b.fats != 2 && b.fats != 1) +- die("Currently, only 1 or 2 FATs are supported, not %d.\n",b.fats); ++ die("Currently, only 1 or 2 FATs are supported, not %d.\n", b.fats); + fs->nfats = b.fats; + sectors = GET_UNALIGNED_W(b.sectors); + total_sectors = sectors ? sectors : CF_LE_L(b.total_sect); +- if (verbose) printf("Checking we can access the last sector of the filesystem\n"); ++ if (verbose) ++ printf("Checking we can access the last sector of the filesystem\n"); + /* Can't access last odd sector anyway, so round down */ +- fs_test((loff_t)((total_sectors & ~1)-1)*(loff_t)logical_sector_size, ++ fs_test((loff_t) ((total_sectors & ~1) - 1) * (loff_t) logical_sector_size, + logical_sector_size); + fat_length = CF_LE_W(b.fat_length) ? +- CF_LE_W(b.fat_length) : CF_LE_L(b.fat32_length); +- fs->fat_start = (loff_t)CF_LE_W(b.reserved)*logical_sector_size; +- fs->root_start = ((loff_t)CF_LE_W(b.reserved)+b.fats*fat_length)* +- logical_sector_size; ++ CF_LE_W(b.fat_length) : CF_LE_L(b.fat32_length); ++ fs->fat_start = (loff_t) CF_LE_W(b.reserved) * logical_sector_size; ++ fs->root_start = ((loff_t) CF_LE_W(b.reserved) + b.fats * fat_length) * ++ logical_sector_size; + fs->root_entries = GET_UNALIGNED_W(b.dir_entries); +- fs->data_start = fs->root_start+ROUND_TO_MULTIPLE(fs->root_entries << +- MSDOS_DIR_BITS,logical_sector_size); +- data_size = (loff_t)total_sectors*logical_sector_size-fs->data_start; +- fs->clusters = data_size/fs->cluster_size; +- fs->root_cluster = 0; /* indicates standard, pre-FAT32 root dir */ +- fs->fsinfo_start = 0; /* no FSINFO structure */ +- fs->free_clusters = -1; /* unknown */ ++ fs->data_start = fs->root_start + ROUND_TO_MULTIPLE(fs->root_entries << ++ MSDOS_DIR_BITS, ++ logical_sector_size); ++ data_size = (loff_t) total_sectors *logical_sector_size - fs->data_start; ++ fs->clusters = data_size / fs->cluster_size; ++ fs->root_cluster = 0; /* indicates standard, pre-FAT32 root dir */ ++ fs->fsinfo_start = 0; /* no FSINFO structure */ ++ fs->free_clusters = -1; /* unknown */ + if (!b.fat_length && b.fat32_length) { + fs->fat_bits = 32; + fs->root_cluster = CF_LE_L(b.root_cluster); +@@ -344,42 +346,39 @@ void read_boot(DOS_FS *fs) + * (root_entries != 0), we handle the root dir the old way. Give a + * warning, but convertig to a root dir in a cluster chain seems + * to complex for now... */ +- printf( "Warning: FAT32 root dir not in cluster chain! " +- "Compatibility mode...\n" ); ++ printf("Warning: FAT32 root dir not in cluster chain! " ++ "Compatibility mode...\n"); + else if (!fs->root_cluster && !fs->root_entries) + die("No root directory!"); + else if (fs->root_cluster && fs->root_entries) +- printf( "Warning: FAT32 root dir is in a cluster chain, but " +- "a separate root dir\n" +- " area is defined. Cannot fix this easily.\n" ); ++ printf("Warning: FAT32 root dir is in a cluster chain, but " ++ "a separate root dir\n" ++ " area is defined. Cannot fix this easily.\n"); + if (fs->clusters < FAT16_THRESHOLD) +- printf("Warning: Filesystem is FAT32 according to fat_length " +- "and fat32_length fields,\n" +- " but has only %lu clusters, less than the required " +- "minimum of %d.\n" +- " This may lead to problems on some systems.\n", +- fs->clusters, FAT16_THRESHOLD); +- +- fs->backupboot_start = CF_LE_W(b.backup_boot)*logical_sector_size; +- check_backup_boot(fs,&b,logical_sector_size); +- +- read_fsinfo(fs,&b,logical_sector_size); +- } +- else if (!atari_format) { ++ printf("Warning: Filesystem is FAT32 according to fat_length " ++ "and fat32_length fields,\n" ++ " but has only %lu clusters, less than the required " ++ "minimum of %d.\n" ++ " This may lead to problems on some systems.\n", ++ fs->clusters, FAT16_THRESHOLD); ++ ++ fs->backupboot_start = CF_LE_W(b.backup_boot) * logical_sector_size; ++ check_backup_boot(fs, &b, logical_sector_size); ++ ++ read_fsinfo(fs, &b, logical_sector_size); ++ } else if (!atari_format) { + /* On real MS-DOS, a 16 bit FAT is used whenever there would be too + * much clusers otherwise. */ + fs->fat_bits = (fs->clusters >= FAT12_THRESHOLD) ? 16 : 12; + if (fs->clusters >= FAT16_THRESHOLD) +- die("Too many clusters (%lu) for FAT16 filesystem.", +- fs->clusters); +- } +- else { ++ die("Too many clusters (%lu) for FAT16 filesystem.", fs->clusters); ++ } else { + /* On Atari, things are more difficult: GEMDOS always uses 12bit FATs + * on floppies, and always 16 bit on harddisks. */ +- fs->fat_bits = 16; /* assume 16 bit FAT for now */ ++ fs->fat_bits = 16; /* assume 16 bit FAT for now */ + /* If more clusters than fat entries in 16-bit fat, we assume + * it's a real MSDOS FS with 12-bit fat. */ +- if (fs->clusters+2 > fat_length*logical_sector_size*8/16 || ++ if (fs->clusters + 2 > fat_length * logical_sector_size * 8 / 16 || + /* if it's a floppy disk --> 12bit fat */ + device_no == 2 || + /* if it's a ramdisk or loopback device and has one of the usual +@@ -391,68 +390,72 @@ void read_boot(DOS_FS *fs) + } + /* On FAT32, the high 4 bits of a FAT entry are reserved */ + fs->eff_fat_bits = (fs->fat_bits == 32) ? 28 : fs->fat_bits; +- fs->fat_size = fat_length*logical_sector_size; ++ fs->fat_size = fat_length * logical_sector_size; + +- fs->label = calloc(12, sizeof (__u8)); ++ fs->label = calloc(12, sizeof(__u8)); + if (fs->fat_bits == 12 || fs->fat_bits == 16) { +- struct boot_sector_16 *b16 = (struct boot_sector_16 *)&b; +- if (b16->extended_sig == 0x29) +- memmove(fs->label, b16->label, 11); +- else +- fs->label = NULL; ++ struct boot_sector_16 *b16 = (struct boot_sector_16 *)&b; ++ if (b16->extended_sig == 0x29) ++ memmove(fs->label, b16->label, 11); ++ else ++ fs->label = NULL; + } else if (fs->fat_bits == 32) { +- if (b.extended_sig == 0x29) +- memmove(fs->label, &b.label, 11); +- else +- fs->label = NULL; ++ if (b.extended_sig == 0x29) ++ memmove(fs->label, &b.label, 11); ++ else ++ fs->label = NULL; + } + +- if (fs->clusters > ((unsigned long long)fs->fat_size*8/fs->fat_bits)-2) ++ if (fs->clusters > ++ ((unsigned long long)fs->fat_size * 8 / fs->fat_bits) - 2) + die("File system has %d clusters but only space for %d FAT entries.", +- fs->clusters,((unsigned long long)fs->fat_size*8/fs->fat_bits)-2); ++ fs->clusters, ++ ((unsigned long long)fs->fat_size * 8 / fs->fat_bits) - 2); + if (!fs->root_entries && !fs->root_cluster) + die("Root directory has zero size."); +- if (fs->root_entries & (MSDOS_DPS-1)) ++ if (fs->root_entries & (MSDOS_DPS - 1)) + die("Root directory (%d entries) doesn't span an integral number of " +- "sectors.",fs->root_entries); +- if (logical_sector_size & (SECTOR_SIZE-1)) ++ "sectors.", fs->root_entries); ++ if (logical_sector_size & (SECTOR_SIZE - 1)) + die("Logical sector size (%d bytes) is not a multiple of the physical " +- "sector size.",logical_sector_size); +-#if 0 /* linux kernel doesn't check that either */ ++ "sector size.", logical_sector_size); ++#if 0 /* linux kernel doesn't check that either */ + /* ++roman: On Atari, these two fields are often left uninitialized */ + if (!atari_format && (!b.secs_track || !b.heads)) + die("Invalid disk format in boot sector."); + #endif +- if (verbose) dump_boot(fs,&b,logical_sector_size); ++ if (verbose) ++ dump_boot(fs, &b, logical_sector_size); + } + +-static void write_boot_label(DOS_FS *fs, char *label) ++static void write_boot_label(DOS_FS * fs, char *label) + { + struct boot_sector b; + struct boot_sector_16 *b16 = (struct boot_sector_16 *)&b; + + fs_read(0, sizeof(b), &b); + if (fs->fat_bits == 12 || fs->fat_bits == 16) { +- if (b16->extended_sig != 0x29) { +- b16->extended_sig = 0x29; +- b16->serial = 0; +- memmove(b16->fs_type, fs->fat_bits == 12 ?"FAT12 ":"FAT16 ", 8); +- } +- memmove(b16->label, label, 11); ++ if (b16->extended_sig != 0x29) { ++ b16->extended_sig = 0x29; ++ b16->serial = 0; ++ memmove(b16->fs_type, fs->fat_bits == 12 ? "FAT12 " : "FAT16 ", ++ 8); ++ } ++ memmove(b16->label, label, 11); + } else if (fs->fat_bits == 32) { +- if (b.extended_sig != 0x29) { +- b.extended_sig = 0x29; +- b.serial = 0; +- memmove(b.fs_type, "FAT32 ", 8); +- } +- memmove(b.label, label, 11); ++ if (b.extended_sig != 0x29) { ++ b.extended_sig = 0x29; ++ b.serial = 0; ++ memmove(b.fs_type, "FAT32 ", 8); ++ } ++ memmove(b.label, label, 11); + } + fs_write(0, sizeof(b), &b); + if (fs->fat_bits == 32 && fs->backupboot_start) +- fs_write(fs->backupboot_start, sizeof(b), &b); ++ fs_write(fs->backupboot_start, sizeof(b), &b); + } + +-static loff_t find_volume_de(DOS_FS *fs, DIR_ENT *de) ++static loff_t find_volume_de(DOS_FS * fs, DIR_ENT * de) + { + unsigned long cluster; + loff_t offset; +@@ -482,7 +485,7 @@ static loff_t find_volume_de(DOS_FS *fs, DIR_ENT *de) + return 0; + } + +-static void write_volume_label(DOS_FS *fs, char *label) ++static void write_volume_label(DOS_FS * fs, char *label) + { + time_t now = time(NULL); + struct tm *mtime = localtime(&now); +@@ -498,17 +501,17 @@ static void write_volume_label(DOS_FS *fs, char *label) + (mtime->tm_min << 5) + + (mtime->tm_hour << 11))); + de.date = CT_LE_W((unsigned short)(mtime->tm_mday + +- ((mtime->tm_mon+1) << 5) + +- ((mtime->tm_year-80) << 9))); ++ ((mtime->tm_mon + 1) << 5) + ++ ((mtime->tm_year - 80) << 9))); + fs_write(offset, sizeof(DIR_ENT), &de); + } + +-void write_label(DOS_FS *fs, char *label) ++void write_label(DOS_FS * fs, char *label) + { + int l = strlen(label); + + while (l < 11) +- label[l++] = ' '; ++ label[l++] = ' '; + + write_boot_label(fs, label); + write_volume_label(fs, label); +diff --git a/src/boot.h b/src/boot.h +index eedf2b0..c9edfa3 100644 +--- a/src/boot.h ++++ b/src/boot.h +@@ -19,12 +19,11 @@ + can be found in /usr/share/common-licenses/GPL-3 file. + */ + +- + #ifndef _BOOT_H + #define _BOOT_H + +-void read_boot(DOS_FS *fs); +-void write_label(DOS_FS *fs, char *label); ++void read_boot(DOS_FS * fs); ++void write_label(DOS_FS * fs, char *label); + + /* Reads the boot sector from the currently open device and initializes *FS */ + +diff --git a/src/check.c b/src/check.c +index d6c54c1..3f175b0 100644 +--- a/src/check.c ++++ b/src/check.c +@@ -23,7 +23,6 @@ + /* FAT32, VFAT, Atari format support, and various fixes additions May 1998 + * by Roman Hodek <Rom...@in...> */ + +- + #include <stdio.h> + #include <stdlib.h> + #include <string.h> +@@ -38,7 +37,6 @@ + #include "lfn.h" + #include "check.h" + +- + static DOS_FILE *root; + + /* get start field of a dir entry */ +@@ -76,8 +74,7 @@ static DOS_FILE *root; + } \ + } while(0) + +- +-loff_t alloc_rootdir_entry(DOS_FS *fs, DIR_ENT *de, const char *pattern) ++loff_t alloc_rootdir_entry(DOS_FS * fs, DIR_ENT * de, const char *pattern) + { + static int curr_num = 0; + loff_t offset; +@@ -89,9 +86,9 @@ loff_t alloc_rootdir_entry(DOS_FS *fs, DIR_ENT *de, const char *pattern) + loff_t offset2; + + clu_num = fs->root_cluster; +- offset = cluster_start(fs,clu_num); ++ offset = cluster_start(fs, clu_num); + while (clu_num > 0 && clu_num != -1) { +- fs_read(offset,sizeof(DIR_ENT),&d2); ++ fs_read(offset, sizeof(DIR_ENT), &d2); + if (IS_FREE(d2.name) && d2.attr != VFAT_LN_ATTR) { + got = 1; + break; +@@ -100,9 +97,9 @@ loff_t alloc_rootdir_entry(DOS_FS *fs, DIR_ENT *de, const char *pattern) + offset += sizeof(DIR_ENT); + if ((i % fs->cluster_size) == 0) { + prev = clu_num; +- if ((clu_num = next_cluster(fs,clu_num)) == 0 || clu_num == -1) ++ if ((clu_num = next_cluster(fs, clu_num)) == 0 || clu_num == -1) + break; +- offset = cluster_start(fs,clu_num); ++ offset = cluster_start(fs, clu_num); + } + } + if (!got) { +@@ -110,77 +107,83 @@ loff_t alloc_rootdir_entry(DOS_FS *fs, DIR_ENT *de, const char *pattern) + * after previous one */ + if (!prev) + die("Root directory has no cluster allocated!"); +- for (clu_num = prev+1; clu_num != prev; clu_num++) { +- FAT_ENTRY entry; ++ for (clu_num = prev + 1; clu_num != prev; clu_num++) { ++ FAT_ENTRY entry; + +- if (clu_num >= fs->clusters+2) clu_num = 2; +- get_fat(&entry, fs->fat, clu_num, fs); ++ if (clu_num >= fs->clusters + 2) ++ clu_num = 2; ++ get_fat(&entry, fs->fat, clu_num, fs); + if (!entry.value) + break; + } + if (clu_num == prev) + die("Root directory full and no free cluster"); +- set_fat(fs,prev,clu_num); +- set_fat(fs,clu_num,-1); ++ set_fat(fs, prev, clu_num); ++ set_fat(fs, clu_num, -1); + set_owner(fs, clu_num, get_owner(fs, fs->root_cluster)); + /* clear new cluster */ +- memset( &d2, 0, sizeof(d2) ); +- offset = cluster_start(fs,clu_num); +- for( i = 0; i < fs->cluster_size; i += sizeof(DIR_ENT) ) +- fs_write( offset+i, sizeof(d2), &d2 ); ++ memset(&d2, 0, sizeof(d2)); ++ offset = cluster_start(fs, clu_num); ++ for (i = 0; i < fs->cluster_size; i += sizeof(DIR_ENT)) ++ fs_write(offset + i, sizeof(d2), &d2); + } +- memset(de,0,sizeof(DIR_ENT)); ++ memset(de, 0, sizeof(DIR_ENT)); + while (1) { + char expanded[12]; + sprintf(expanded, pattern, curr_num); +- memcpy(de->name+4, expanded, 4); +- memcpy(de->ext, expanded+4, 3); ++ memcpy(de->name + 4, expanded, 4); ++ memcpy(de->ext, expanded + 4, 3); + clu_num = fs->root_cluster; + i = 0; +- offset2 = cluster_start(fs,clu_num); ++ offset2 = cluster_start(fs, clu_num); + while (clu_num > 0 && clu_num != -1) { +- fs_read(offset2,sizeof(DIR_ENT),&d2); ++ fs_read(offset2, sizeof(DIR_ENT), &d2); + if (offset2 != offset && +- !strncmp(d2.name,de->name,MSDOS_NAME)) ++ !strncmp((const char *)d2.name, (const char *)de->name, ++ MSDOS_NAME)) + break; + i += sizeof(DIR_ENT); + offset2 += sizeof(DIR_ENT); + if ((i % fs->cluster_size) == 0) { +- if ((clu_num = next_cluster(fs,clu_num)) == 0 || ++ if ((clu_num = next_cluster(fs, clu_num)) == 0 || + clu_num == -1) + break; +- offset2 = cluster_start(fs,clu_num); ++ offset2 = cluster_start(fs, clu_num); + } + } + if (clu_num == 0 || clu_num == -1) + break; +- if (++curr_num >= 10000) die("Unable to create unique name"); ++ if (++curr_num >= 10000) ++ die("Unable to create unique name"); + } +- } +- else { ++ } else { + DIR_ENT *root; + int next_free = 0, scan; + +- root = alloc(fs->root_entries*sizeof(DIR_ENT)); +- fs_read(fs->root_start,fs->root_entries*sizeof(DIR_ENT),root); ++ root = alloc(fs->root_entries * sizeof(DIR_ENT)); ++ fs_read(fs->root_start, fs->root_entries * sizeof(DIR_ENT), root); + + while (next_free < fs->root_entries) + if (IS_FREE(root[next_free].name) && + root[next_free].attr != VFAT_LN_ATTR) + break; +- else next_free++; ++ else ++ next_free++; + if (next_free == fs->root_entries) + die("Root directory is full."); +- offset = fs->root_start+next_free*sizeof(DIR_ENT); +- memset(de,0,sizeof(DIR_ENT)); ++ offset = fs->root_start + next_free * sizeof(DIR_ENT); ++ memset(de, 0, sizeof(DIR_ENT)); + while (1) { +- sprintf(de->name,pattern,curr_num); ++ sprintf((char *)de->name, pattern, curr_num); + for (scan = 0; scan < fs->root_entries; scan++) + if (scan != next_free && +- !strncmp(root[scan].name,de->name,MSDOS_NAME)) ++ !strncmp((const char *)root[scan].name, ++ (const char *)de->name, MSDOS_NAME)) + break; +- if (scan == fs->root_entries) break; +- if (++curr_num >= 10000) die("Unable to create unique name"); ++ if (scan == fs->root_entries) ++ break; ++ if (++curr_num >= 10000) ++ die("Unable to create unique name"); + } + free(root); + } +@@ -188,7 +191,6 @@ loff_t alloc_rootdir_entry(DOS_FS *fs, DIR_ENT *de, const char *pattern) + return offset; + } + +- + /** + * Construct a full path (starting with '/') for the specified dentry, + * relative to the partition. All components are "long" names where possible. +@@ -197,63 +199,64 @@ loff_t alloc_rootdir_entry(DOS_FS *fs, DIR_ENT *de, const char *pattern) + * + * return Pointer to static string containing file's full path + */ +-static char *path_name(DOS_FILE *file) ++static char *path_name(DOS_FILE * file) + { +- static char path[PATH_MAX*2]; ++ static char path[PATH_MAX * 2]; + +- if (!file) *path = 0; /* Reached the root directory */ ++ if (!file) ++ *path = 0; /* Reached the root directory */ + else { + if (strlen(path_name(file->parent)) > PATH_MAX) + die("Path name too long."); +- if (strcmp(path,"/") != 0) strcat(path,"/"); +- +- /* Append the long name to the path, +- * or the short name if there isn't a long one +- */ +- strcpy(strrchr(path,0),file->lfn?file->lfn:file_name(file->dir_ent.name)); ++ if (strcmp(path, "/") != 0) ++ strcat(path, "/"); ++ ++ /* Append the long name to the path, ++ * or the short name if there isn't a long one ++ */ ++ strcpy(strrchr(path, 0), ++ file->lfn ? file->lfn : file_name(file->dir_ent.name)); + } + return path; + } + +- +-static int day_n[] = { 0,31,59,90,120,151,181,212,243,273,304,334,0,0,0,0 }; ++static int day_n[] = ++ { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 0, 0, 0, 0 }; + /* JanFebMarApr May Jun Jul Aug Sep Oct Nov Dec */ + +- + /* Convert a MS-DOS time/date pair to a UNIX date (seconds since 1 1 70). */ + +-time_t date_dos2unix(unsigned short time,unsigned short date) ++time_t date_dos2unix(unsigned short time, unsigned short date) + { +- int month,year; ++ int month, year; + time_t secs; + +- month = ((date >> 5) & 15)-1; ++ month = ((date >> 5) & 15) - 1; + year = date >> 9; +- secs = (time & 31)*2+60*((time >> 5) & 63)+(time >> 11)*3600+86400* +- ((date & 31)-1+day_n[month]+(year/4)+year*365-((year & 3) == 0 && +- month < 2 ? 1 : 0)+3653); +- /* days since 1.1.70 plus 80's leap day */ ++ secs = ++ (time & 31) * 2 + 60 * ((time >> 5) & 63) + (time >> 11) * 3600 + ++ 86400 * ((date & 31) - 1 + day_n[month] + (year / 4) + year * 365 - ++ ((year & 3) == 0 && month < 2 ? 1 : 0) + 3653); ++ /* days since 1.1.70 plus 80's leap day */ + return secs; + } + +- +-static char *file_stat(DOS_FILE *file) ++static char *file_stat(DOS_FILE * file) + { + static char temp[100]; + struct tm *tm; + char tmp[100]; + time_t date; + +- date = date_dos2unix(CF_LE_W(file->dir_ent.time),CF_LE_W(file-> +- dir_ent.date)); ++ date = ++ date_dos2unix(CF_LE_W(file->dir_ent.time), CF_LE_W(file->dir_ent.date)); + tm = localtime(&date); +- strftime(tmp,99,"%H:%M:%S %b %d %Y",tm); +- sprintf(temp," Size %u bytes, date %s",CF_LE_L(file->dir_ent.size),tmp); ++ strftime(tmp, 99, "%H:%M:%S %b %d %Y", tm); ++ sprintf(temp, " Size %u bytes, date %s", CF_LE_L(file->dir_ent.size), tmp); + return temp; + } + +- +-static int bad_name(DOS_FILE *file) ++static int bad_name(DOS_FILE * file) + { + int i, spc, suspicious = 0; + char *bad_chars = atari_format ? "*?\\/:" : "*?<>|\"\\/:"; +@@ -261,23 +264,31 @@ static int bad_name(DOS_FILE *file) + + /* Do not complain about (and auto-correct) the extended attribute files + * of OS/2. */ +- if (strncmp(name,"EA DATA SF",11) == 0 || +- strncmp(name,"WP ROOT SF",11) == 0) return 0; ++ if (strncmp((const char *)name, "EA DATA SF", 11) == 0 || ++ strncmp((const char *)name, "WP ROOT SF", 11) == 0) ++ return 0; + + /* don't complain about the dummy 11 bytes used by patched Linux + kernels */ +- if (file->dir_ent.lcase & FAT_NO_83NAME) return 0; ++ if (file->dir_ent.lcase & FAT_NO_83NAME) ++ return 0; + + for (i = 0; i < 8; i++) { +- if (name[i] < ' ' || name[i] == 0x7f) return 1; +- if (name[i] > 0x7f) ++suspicious; +- if (strchr(bad_chars,name[i])) return 1; ++ if (name[i] < ' ' || name[i] == 0x7f) ++ return 1; ++ if (name[i] > 0x7f) ++ ++suspicious; ++ if (strchr(bad_chars, name[i])) ++ return 1; + } + + for (i = 8; i < 11; i++) { +- if (name[i] < ' ' || name[i] == 0x7f) return 1; +- if (name[i] > 0x7f) ++suspicious; +- if (strchr(bad_chars,name[i])) return 1; ++ if (name[i] < ' ' || name[i] == 0x7f) ++ return 1; ++ if (name[i] > 0x7f) ++ ++suspicious; ++ if (strchr(bad_chars, name[i])) ++ return 1; + } + + spc = 0; +@@ -313,260 +324,288 @@ static int bad_name(DOS_FILE *file) + + static void lfn_remove(loff_t from, loff_t to) + { +- int i; + DIR_ENT empty; + + /* New dir entry is zeroed except first byte, which is set to 0xe5. + * This is to avoid that some FAT-reading OSes (not Linux! ;) stop reading + * a directory at the first zero entry... + */ +- memset( &empty, 0, sizeof(empty) ); ++ memset(&empty, 0, sizeof(empty)); + empty.name[0] = DELETED_FLAG; + +- for( ; from < to; from += sizeof(empty) ) { +- fs_write( from, sizeof(DIR_ENT), &empty ); ++ for (; from < to; from += sizeof(empty)) { ++ fs_write(from, sizeof(DIR_ENT), &empty); + } + } + +-static void drop_file(DOS_FS *fs,DOS_FILE *file) ++static void drop_file(DOS_FS * fs, DOS_FILE * file) + { + unsigned long cluster; + +- MODIFY(file,name[0],DELETED_FLAG); +- if (file->lfn) lfn_remove(file->lfn_offset, file->offset); +- for (cluster = FSTART(file,fs); cluster > 0 && cluster < +- fs->clusters+2; cluster = next_cluster(fs,cluster)) +- set_owner(fs,cluster,NULL); ++ MODIFY(file, name[0], DELETED_FLAG); ++ if (file->lfn) ++ lfn_remove(file->lfn_offset, file->offset); ++ for (cluster = FSTART(file, fs); cluster > 0 && cluster < ++ fs->clusters + 2; cluster = next_cluster(fs, cluster)) ++ set_owner(fs, cluster, NULL); + --n_files; + } + +- +-static void truncate_file(DOS_FS *fs,DOS_FILE *file,unsigned long clusters) ++static void truncate_file(DOS_FS * fs, DOS_FILE * file, unsigned long clusters) + { + int deleting; +- unsigned long walk,next,prev; ++ unsigned long walk, next, prev; + +- walk = FSTART(file,fs); ++ walk = FSTART(file, fs); + prev = 0; +- if ((deleting = !clusters)) MODIFY_START(file,0,fs); ++ if ((deleting = !clusters)) ++ MODIFY_START(file, 0, fs); + while (walk > 0 && walk != -1) { +- next = next_cluster(fs,walk); +- if (deleting) set_fat(fs,walk,0); +- else if ((deleting = !--clusters)) set_fat(fs,walk,-1); ++ next = next_cluster(fs, walk); ++ if (deleting) ++ set_fat(fs, walk, 0); ++ else if ((deleting = !--clusters)) ++ set_fat(fs, walk, -1); + prev = walk; + walk = next; + } + } + +- +-static void auto_rename(DOS_FILE *file) ++static void auto_rename(DOS_FILE * file) + { +- DOS_FILE *first,*walk; ++ DOS_FILE *first, *walk; + unsigned long int number; + +- if (!file->offset) return; /* cannot rename FAT32 root dir */ ++ if (!file->offset) ++ return; /* cannot rename FAT32 root dir */ + first = file->parent ? file->parent->first : root; + number = 0; + while (1) { + char num[8]; +- sprintf(num, "%07d", number); ++ sprintf(num, "%07lu", number); + memcpy(file->dir_ent.name, "FSCK", 4); +- memcpy(file->dir_ent.name+4, num, 4); +- memcpy(file->dir_ent.ext, num+4, 3); ++ memcpy(file->dir_ent.name + 4, num, 4); ++ memcpy(file->dir_ent.ext, num + 4, 3); + for (walk = first; walk; walk = walk->next) +- if (walk != file && !strncmp(walk->dir_ent.name,file->dir_ent. +- name,MSDOS_NAME)) break; ++ if (walk != file ++ && !strncmp((const char *)walk->dir_ent.name, ++ (const char *)file->dir_ent.name, MSDOS_NAME)) ++ break; + if (!walk) { +- fs_write(file->offset,MSDOS_NAME,file->dir_ent.name); +- if (file->lfn) lfn_fix_checksum(file->lfn_offset, file->offset, file->dir_ent.name); ++ fs_write(file->offset, MSDOS_NAME, file->dir_ent.name); ++ if (file->lfn) ++ lfn_fix_checksum(file->lfn_offset, file->offset, ++ (const char *)file->dir_ent.name); + return; + } + number++; + if (number > 9999999) { +- die("Too many files need repair."); ++ die("Too many files need repair."); + } + } + die("Can't generate a unique name."); + } + +- +-static void rename_file(DOS_FILE *file) ++static void rename_file(DOS_FILE * file) + { + unsigned char name[46]; +- unsigned char *walk,*here; ++ unsigned char *walk, *here; + + if (!file->offset) { +- printf( "Cannot rename FAT32 root dir\n" ); +- return; /* cannot rename FAT32 root dir */ ++ printf("Cannot rename FAT32 root dir\n"); ++ return; /* cannot rename FAT32 root dir */ + } + while (1) { + printf("New name: "); + fflush(stdout); +- if (fgets(name,45,stdin)) { +- if ((here = strchr(name,'\n'))) *here = 0; +- for (walk = strrchr(name,0); walk >= name && (*walk == ' ' || +- *walk == '\t'); walk--); ++ if (fgets((char *)name, 45, stdin)) { ++ if ((here = (unsigned char *)strchr((const char *)name, '\n'))) ++ *here = 0; ++ for (walk = (unsigned char *)strrchr((const char *)name, 0); ++ walk >= name && (*walk == ' ' || *walk == '\t'); walk--) ; + walk[1] = 0; +- for (walk = name; *walk == ' ' || *walk == '\t'; walk++); +- if (file_cvt(walk,file->dir_ent.name)) { +- fs_write(file->offset,MSDOS_NAME,file->dir_ent.name); +- if (file->lfn) lfn_fix_checksum(file->lfn_offset, file->offset, file->dir_ent.name); ++ for (walk = name; *walk == ' ' || *walk == '\t'; walk++) ; ++ if (file_cvt(walk, file->dir_ent.name)) { ++ fs_write(file->offset, MSDOS_NAME, file->dir_ent.name); ++ if (file->lfn) ++ lfn_fix_checksum(file->lfn_offset, file->offset, ++ (const char *)file->dir_ent.name); + return; + } + } + } + } + +- +-static int handle_dot(DOS_FS *fs,DOS_FILE *file,int dots) ++static int handle_dot(DOS_FS * fs, DOS_FILE * file, int dots) + { + char *name; + +- name = strncmp(file->dir_ent.name,MSDOS_DOT,MSDOS_NAME) ? ".." : "."; ++ name = ++ strncmp((const char *)file->dir_ent.name, MSDOS_DOT, ++ MSDOS_NAME) ? ".." : "."; + if (!(file->dir_ent.attr & ATTR_DIR)) { +- printf("%s\n Is a non-directory.\n",path_name(file)); ++ printf("%s\n Is a non-directory.\n", path_name(file)); + if (interactive) + printf("1) Drop it\n2) Auto-rename\n3) Rename\n" +- "4) Convert to directory\n"); +- else printf(" Auto-renaming it.\n"); +- switch (interactive ? get_key("1234","?") : '2') { +- case '1': +- drop_file(fs,file); +- return 1; +- case '2': +- auto_rename(file); +- printf(" Renamed to %s\n",file_name(file->dir_ent.name)); +- return 0; +- case '3': +- rename_file(file); +- return 0; +- case '4': +- MODIFY(file,size,CT_LE_L(0)); +- MODIFY(file,attr,file->dir_ent.attr | ATTR_DIR); +- break; ++ "4) Convert to directory\n"); ++ else ++ printf(" Auto-renaming it.\n"); ++ switch (interactive ? get_key("1234", "?") : '2') { ++ case '1': ++ drop_file(fs, file); ++ return 1; ++ case '2': ++ auto_rename(file); ++ printf(" Renamed to %s\n", file_name(file->dir_ent.name)); ++ return 0; ++ case '3': ++ rename_file(file); ++ return 0; ++ case '4': ++ MODIFY(file, size, CT_LE_L(0)); ++ MODIFY(file, attr, file->dir_ent.attr | ATTR_DIR); ++ break; + } + } + if (!dots) { +- printf("Root contains directory \"%s\". Dropping it.\n",name); +- drop_file(fs,file); ++ printf("Root contains directory \"%s\". Dropping it.\n", name); ++ drop_file(fs, file); + return 1; + } + return 0; + } + +- +-static int check_file(DOS_FS *fs,DOS_FILE *file) ++static int check_file(DOS_FS * fs, DOS_FILE * file) + { + DOS_FILE *owner; + int restart; +- unsigned long expect,curr,this,clusters,prev,walk,clusters2; ++ unsigned long expect, curr, this, clusters, prev, walk, clusters2; + + if (file->dir_ent.attr & ATTR_DIR) { + if (CF_LE_L(file->dir_ent.size)) { + printf("%s\n Directory has non-zero size. Fixing it.\n", +- path_name(file)); +- MODIFY(file,size,CT_LE_L(0)); ++ path_name(file)); ++ MODIFY(file, size, CT_LE_L(0)); + } +- if (file->parent && !strncmp(file->dir_ent.name,MSDOS_DOT,MSDOS_NAME)) { +- expect = FSTART(file->parent,fs); +- if (FSTART(file,fs) != expect) { ++ if (file->parent ++ && !strncmp((const char *)file->dir_ent.name, MSDOS_DOT, ++ MSDOS_NAME)) { ++ expect = FSTART(file->parent, fs); ++ if (FSTART(file, fs) != expect) { + printf("%s\n Start (%ld) does not point to parent (%ld)\n", +- path_name(file),FSTART(file,fs),expect); +- MODIFY_START(file,expect,fs); ++ path_name(file), FSTART(file, fs), expect); ++ MODIFY_START(file, expect, fs); + } + return 0; + } +- if (file->parent && !strncmp(file->dir_ent.name,MSDOS_DOTDOT, +- MSDOS_NAME)) { +- expect = file->parent->parent ? FSTART(file->parent->parent,fs):0; ++ if (file->parent ++ && !strncmp((const char *)file->dir_ent.name, MSDOS_DOTDOT, ++ MSDOS_NAME)) { ++ expect = ++ file->parent->parent ? FSTART(file->parent->parent, fs) : 0; + if (fs->root_cluster && expect == fs->root_cluster) + expect = 0; +- if (FSTART(file,fs) != expect) { ++ if (FSTART(file, fs) != expect) { + printf("%s\n Start (%lu) does not point to .. (%lu)\n", +- path_name(file),FSTART(file,fs),expect); +- MODIFY_START(file,expect,fs); ++ path_name(file), FSTART(file, fs), expect); ++ MODIFY_START(file, expect, fs); + } + return 0; + } +- if (FSTART(file,fs)==0){ +- printf ("%s\n Start does point to root directory. Deleting dir. \n", +- path_name(file)); +- MODIFY(file,name[0],DELETED_FLAG); +- return 0; ++ if (FSTART(file, fs) == 0) { ++ printf("%s\n Start does point to root directory. Deleting dir. \n", ++ path_name(file)); ++ MODIFY(file, name[0], DELETED_FLAG); ++ return 0; + } + } +- if (FSTART(file,fs) >= fs->clusters+2) { +- printf("%s\n Start cluster beyond limit (%lu > %lu). Truncating file.\n", +- path_name(file),FSTART(file,fs),fs->clusters+1); ++ if (FSTART(file, fs) >= fs->clusters + 2) { ++ printf ++ ("%s\n Start cluster beyond limit (%lu > %lu). Truncating file.\n", ++ path_name(file), FSTART(file, fs), fs->clusters + 1); + if (!file->offset) +- die( "Bad FAT32 root directory! (bad start cluster)\n" ); +- MODIFY_START(file,0,fs); ++ die("Bad FAT32 root directory! (bad start cluster)\n"); ++ MODIFY_START(file, 0, fs); + } + clusters = prev = 0; +- for (curr = FSTART(file,fs) ? FSTART(file,fs) : +- -1; curr != -1; curr = next_cluster(fs,curr)) { +- FAT_ENTRY curEntry; +- get_fat(&curEntry, fs->fat, curr, fs); ++ for (curr = FSTART(file, fs) ? FSTART(file, fs) : ++ -1; curr != -1; curr = next_cluster(fs, curr)) { ++ FAT_ENTRY curEntry; ++ get_fat(&curEntry, fs->fat, curr, fs); + +- if (!curEntry.value || bad_cluster(fs,curr)) { ++ if (!curEntry.value || bad_cluster(fs, curr)) { + printf("%s\n Contains a %s cluster (%lu). Assuming EOF.\n", +- path_name(file), curEntry.value ? "bad" : "free",curr); +- if (prev) set_fat(fs,prev,-1); ++ path_name(file), curEntry.value ? "bad" : "free", curr); ++ if (prev) ++ set_fat(fs, prev, -1); + else if (!file->offset) +- die( "FAT32 root dir starts with a bad cluster!" ); +- else MODIFY_START(file,0,fs); ++ die("FAT32 root dir starts with a bad cluster!"); ++ else ++ MODIFY_START(file, 0, fs); + break; + } + if (!(file->dir_ent.attr & ATTR_DIR) && CF_LE_L(file->dir_ent.size) <= +- (unsigned long long)clusters*fs->cluster_size) { +- printf("%s\n File size is %u bytes, cluster chain length is > %llu " +- "bytes.\n Truncating file to %u bytes.\n",path_name(file), +- CF_LE_L(file->dir_ent.size),(unsigned long long)clusters*fs->cluster_size, +- CF_LE_L(file->dir_ent.size)); +- truncate_file(fs,file,clusters); ++ (unsigned long long)clusters * fs->cluster_size) { ++ printf ++ ("%s\n File size is %u bytes, cluster chain length is > %llu " ++ "bytes.\n Truncating file to %u bytes.\n", path_name(file), ++ CF_LE_L(file->dir_ent.size), ++ (unsigned long long)clusters * fs->cluster_size, ++ CF_LE_L(file->dir_ent.size)); ++ truncate_file(fs, file, clusters); + break; + } +- if ((owner = get_owner(fs,curr))) { ++ if ((owner = get_owner(fs, curr))) { + int do_trunc = 0; +- printf("%s and\n",path_name(owner)); +- printf("%s\n share clusters.\n",path_name(file)); ++ printf("%s and\n", path_name(owner)); ++ printf("%s\n share clusters.\n", path_name(file)); + clusters2 = 0; +- for (walk = FSTART(owner,fs); walk > 0 && walk != -1; walk = +- next_cluster(fs,walk)) +- if (walk == curr) break; +- else clusters2++; ++ for (walk = FSTART(owner, fs); walk > 0 && walk != -1; walk = ++ next_cluster(fs, walk)) ++ if (walk == curr) ++ break; ++ else ++ clusters2++; + restart = file->dir_ent.attr & ATTR_DIR; + if (!owner->offset) { +- printf( " Truncating second to %llu bytes because first " +- "is FAT32 root dir.\n", (unsigned long long)clusters2*fs->cluster_size ); ++ printf(" Truncating second to %llu bytes because first " ++ "is FAT32 root dir.\n", ++ (unsigned long long)clusters2 * fs->cluster_size); + do_trunc = 2; +- } +- else if (!file->offset) { +- printf( " Truncating first to %llu bytes because second " +- "is FAT32 root dir.\n", (unsigned long long)clusters*fs->cluster_size ); ++ } else if (!file->offset) { ++ printf(" Truncating first to %llu bytes because second " ++ "is FAT32 root dir.\n", ++ (unsigned long long)clusters * fs->cluster_size); + do_trunc = 1; +- } +- else if (interactive) ++ } else if (interactive) + printf("1) Truncate first to %llu bytes%s\n" +- "2) Truncate second to %llu bytes\n",(unsigned long long)clusters*fs->cluster_size, +- restart ? " and restart" : "",(unsigned long long)clusters2*fs->cluster_size); +- else printf(" Truncating second to %llu bytes.\n",(unsigned long long)clusters2* +- fs->cluster_size); +- if (do_trunc != 2 && +- (do_trunc == 1 || +- (interactive && get_key("12","?") == '1'))) { ++ "2) Truncate second to %llu bytes\n", ++ (unsigned long long)clusters * fs->cluster_size, ++ restart ? " and restart" : "", ++ (unsigned long long)clusters2 * fs->cluster_size); ++ else ++ printf(" Truncating second to %llu bytes.\n", ++ (unsigned long long)clusters2 * fs->cluster_size); ++ if (do_trunc != 2 ++ && (do_trunc == 1 ++ || (interactive && get_key("12", "?") == '1'))) { + prev = 0; + clusters = 0; +- for (this = FSTART(owner,fs); this > 0 && this != -1; this = +- next_cluster(fs,this)) { ++ for (this = FSTART(owner, fs); this > 0 && this != -1; this = ++ next_cluster(fs, this)) { + if (this == curr) { +- if (prev) set_fat(fs,prev,-1); +- else MODIFY_START(owner,0,fs); +- MODIFY(owner,size,CT_LE_L((unsigned long long)clusters*fs->cluster_size)); +- if (restart) return 1; ++ if (prev) ++ set_fat(fs, prev, -1); ++ else ++ MODIFY_START(owner, 0, fs); ++ MODIFY(owner, size, ++ CT_LE_L((unsigned long long)clusters * ++ fs->cluster_size)); ++ if (restart) ++ return 1; + while (this > 0 && this != -1) { +- set_owner(fs,this,NULL); +- this = next_cluster(fs,this); ++ set_owner(fs, this, NULL); ++ this = next_cluster(fs, this); + } + this = curr; + break; +@@ -576,59 +615,68 @@ static int check_file(DOS_FS *fs,DOS_FILE *file) + } + if (this != curr) + die("Internal error: didn't find cluster %d in chain" +- " starting at %d",curr,FSTART(owner,fs)); +- } +- else { +- if (prev) set_fat(fs,prev,-1); +- else MODIFY_START(file,0,fs); ++ " starting at %d", curr, FSTART(owner, fs)); ++ } else { ++ if (prev) ++ set_fat(fs, prev, -1); ++ else ++ MODIFY_START(file, 0, fs); + break; + } + } +- set_owner(fs,curr,file); ++ set_owner(fs, curr, file); + clusters++; + prev = curr; + } + if (!(file->dir_ent.attr & ATTR_DIR) && CF_LE_L(file->dir_ent.size) > +- (unsigned long long)clusters*fs->cluster_size) { +- printf("%s\n File size is %u bytes, cluster chain length is %llu bytes." +- "\n Truncating file to %lu bytes.\n",path_name(file),CF_LE_L(file-> +- dir_ent.size),(unsigned long long)clusters*fs->cluster_size,(unsigned long long)clusters*fs->cluster_size); +- MODIFY(file,size,CT_LE_L((unsigned long long)clusters*fs->cluster_size)); ++ (unsigned long long)clusters * fs->cluster_size) { ++ printf ++ ("%s\n File size is %u bytes, cluster chain length is %llu bytes." ++ "\n Truncating file to %llu bytes.\n", path_name(file), ++ CF_LE_L(file->dir_ent.size), ++ (unsigned long long)clusters * fs->cluster_size, ++ (unsigned long long)clusters * fs->cluster_size); ++ MODIFY(file, size, ++ CT_LE_L((unsigned long long)clusters * fs->cluster_size)); + } + return 0; + } + +- +-static int check_files(DOS_FS *fs,DOS_FILE *start) ++static int check_files(DOS_FS * fs, DOS_FILE * start) + { + while (start) { +- if (check_file(fs,start)) return 1; ++ if (check_file(fs, start)) ++ return 1; + start = start->next; + } + return 0; + } + +- +-static int check_dir(DOS_FS *fs,DOS_FILE **root,int dots) ++static int check_dir(DOS_FS * fs, DOS_FILE ** root, int dots) + { +- DOS_FILE *parent,**walk,**scan; +- int dot,dotdot,skip,redo; +- int good,bad; ++ DOS_FILE *parent, **walk, **scan; ++ int dot, dotdot, skip, redo; ++ int good, bad; + +- if (!*root) return 0; ++ if (!*root) ++ return 0; + parent = (*root)->parent; + good = bad = 0; + for (walk = root; *walk; walk = &(*walk)->next) +- if (bad_name(*walk)) bad++; +- else good++; +- if (*root && parent && good+bad > 4 && bad > good/2) { ++ if (bad_name(*walk)) ++ bad++; ++ else ++ good++; ++ if (*root && parent && good + bad > 4 && bad > good / 2) { + printf("%s\n Has a large number of bad entries. (%d/%d)\n", +- path_name(parent),bad,good+bad); +- if (!dots) printf( " Not dropping root directory.\n" ); +- else if (!interactive) printf(" Not dropping it in auto-mode.\n"); +- else if (get_key("yn","Drop directory ? (y/n)") == 'y') { +- truncate_file(fs,parent,0); +- MODIFY(parent,name[0],DELETED_FLAG); ++ path_name(parent), bad, good + bad); ++ if (!dots) ++ printf(" Not dropping root directory.\n"); ++ else if (!interactive) ++ printf(" Not dropping it in auto-mode.\n"); ++ else if (get_key("yn", "Drop directory ? (y/n)") == 'y') { ++ truncate_file(fs, parent, 0); ++ MODIFY(parent, name[0], DELETED_FLAG); + /* buglet: deleted directory stays in the list. */ + return 1; + } +@@ -636,39 +684,44 @@ static int check_dir(DOS_FS *fs,DOS_FILE **root,int dots) + dot = dotdot = redo = 0; + walk = root; + while (*walk) { +- if (!strncmp((*walk)->dir_ent.name,MSDOS_DOT,MSDOS_NAME) || +- !strncmp((*walk)->dir_ent.name,MSDOS_DOTDOT,MSDOS_NAME)) { +- if (handle_dot(fs,*walk,dots)) { ++ if (!strncmp ++ ((const char *)((*walk)->dir_ent.name), MSDOS_DOT, MSDOS_NAME) ++ || !strncmp((const char *)((*walk)->dir_ent.name), MSDOS_DOTDOT, ++ MSDOS_NAME)) { ++ if (handle_dot(fs, *walk, dots)) { + *walk = (*walk)->next; + continue; + } +- if (!strncmp((*walk)->dir_ent.name,MSDOS_DOT,MSDOS_NAME)) dot++; +- else dotdot++; ++ if (!strncmp ++ ((const char *)((*walk)->dir_ent.name), MSDOS_DOT, MSDOS_NAME)) ++ dot++; ++ else ++ dotdot++; + } +- if (!((*walk)->dir_ent.attr & ATTR_VOLUME) && +- bad_name(*walk)) { ++ if (!((*walk)->dir_ent.attr & ATTR_VOLUME) && bad_name(*walk)) { + puts(path_name(*walk)); +- printf(" Bad short file name (%s).\n", file_name((*walk)->dir_ent.name)); ++ printf(" Bad short file name (%s).\n", ++ file_name((*walk)->dir_ent.name)); + if (interactive) + printf("1) Drop file\n2) Rename file\n3) Auto-rename\n" +- "4) Keep it\n"); +- else printf(" Auto-renaming it.\n"); +- switch (interactive ? get_key("1234","?") : '3') { +- case '1': +- drop_file(fs,*walk); +- walk = &(*walk)->next; +- continue; +- case '2': +- rename_file(*walk); +- redo = 1; +- break; +- case '3': +- auto_rename(*walk); +- printf(" Renamed to %s\n",file_name((*walk)->dir_ent. +- name)); +- break; +- case '4': +- break; ++ "4) Keep it\n"); ++ else ++ printf(" Auto-renaming it.\n"); ++ switch (interactive ? get_key("1234", "?") : '3') { ++ case '1': ++ drop_file(fs, *walk); ++ walk = &(*walk)->next; ++ continue; ++ case '2': ++ rename_file(*walk); ++ redo = 1; ++ break; ++ case '3': ++ auto_rename(*wal... [truncated message content] |