diff --git a/reactos/lib/fslib/vfatlib/check/boot.c b/reactos/lib/fslib/vfatlib/check/boot.c index 9a12eef8ddd..4f60c182230 100644 --- a/reactos/lib/fslib/vfatlib/check/boot.c +++ b/reactos/lib/fslib/vfatlib/check/boot.c @@ -119,10 +119,10 @@ static void check_backup_boot(DOS_FS *fs, struct boot_sector *b, int lss) VfatPrint( "And there is no space for creating one!\n" ); return; } - if (interactive) + if (FsCheckFlags & FSCHECK_INTERACTIVE) VfatPrint( "1) Create one\n2) Do without a backup\n" ); else VfatPrint( " Auto-creating backup boot block.\n" ); - if (!interactive || get_key("12","?") == '1') { + if (!(FsCheckFlags & FSCHECK_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. */ @@ -167,12 +167,12 @@ static void check_backup_boot(DOS_FS *fs, struct boot_sector *b, int lss) } VfatPrint( "\n" ); - if (interactive) + if (FsCheckFlags & FSCHECK_INTERACTIVE) VfatPrint( "1) Copy original to backup\n" "2) Copy backup to original\n" "3) No action\n" ); else VfatPrint( " Not automatically fixing this.\n" ); - switch (interactive ? get_key("123","?") : '3') { + switch ((FsCheckFlags & FSCHECK_INTERACTIVE) ? get_key("123","?") : '3') { case '1': fs_write(fs->backupboot_start,sizeof(*b),b); break; @@ -200,10 +200,10 @@ static void read_fsinfo(DOS_FS *fs, struct boot_sector *b,int lss) if (!b->info_sector) { VfatPrint( "No FSINFO sector\n" ); - if (interactive) + if (FsCheckFlags & FSCHECK_INTERACTIVE) VfatPrint( "1) Create one\n2) Do without FSINFO\n" ); else VfatPrint( " Not automatically creating it.\n" ); - if (interactive && get_key("12","?") == '1') { + if ((FsCheckFlags & FSCHECK_INTERACTIVE) && get_key("12","?") == '1') { /* search for a free reserved sector (not boot sector and not * backup boot sector) */ __u32 s; @@ -248,10 +248,10 @@ static void read_fsinfo(DOS_FS *fs, struct boot_sector *b,int lss) VfatPrint( " Offset %llu: 0x%04x != expected 0x%04x\n", (__u64)offsetof(struct info_sector,boot_sign), CF_LE_W(i.boot_sign),0xaa55); - if (interactive) + if (FsCheckFlags & FSCHECK_INTERACTIVE) VfatPrint( "1) Correct\n2) Don't correct (FSINFO invalid then)\n" ); else VfatPrint( " Auto-correcting it.\n" ); - if (!interactive || get_key("12","?") == '1') { + if (!(FsCheckFlags & FSCHECK_INTERACTIVE) || get_key("12","?") == '1') { init_fsinfo(&i); fs_write(fs->fsinfo_start,sizeof(i),&i); } @@ -280,7 +280,7 @@ void read_boot(DOS_FS *fs) fs->nfats = b.fats; sectors = GET_UNALIGNED_W(b.sectors); total_sectors = sectors ? sectors : CF_LE_L(b.total_sect); - if (verbose) VfatPrint("Checking we can access the last sector of the filesystem\n"); + if (FsCheckFlags & FSCHECK_VERBOSE) VfatPrint("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, logical_sector_size); @@ -358,7 +358,7 @@ void read_boot(DOS_FS *fs) /* ++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."); - if (verbose) dump_boot(fs,&b,logical_sector_size); + if (FsCheckFlags & FSCHECK_VERBOSE) dump_boot(fs,&b,logical_sector_size); } /* Local Variables: */ diff --git a/reactos/lib/fslib/vfatlib/check/check.c b/reactos/lib/fslib/vfatlib/check/check.c index 7b3ddcd61ed..bc7ca7946ed 100644 --- a/reactos/lib/fslib/vfatlib/check/check.c +++ b/reactos/lib/fslib/vfatlib/check/check.c @@ -267,7 +267,7 @@ static int bad_name(unsigned char *name) /* Only complain about too much suspicious chars in interactive mode, * never correct them automatically. The chars are all basically ok, so we * shouldn't auto-correct such names. */ - if (interactive && suspicious > 6) + if ((FsCheckFlags & FSCHECK_INTERACTIVE) && suspicious > 6) return 1; return 0; } @@ -365,11 +365,11 @@ static int handle_dot(DOS_FS *fs,DOS_FILE *file,int dots) name = strncmp((char*)file->dir_ent.name,MSDOS_DOT,MSDOS_NAME) ? ".." : "."; if (!(file->dir_ent.attr & ATTR_DIR)) { VfatPrint("%s\n Is a non-directory.\n",path_name(file)); - if (interactive) + if (FsCheckFlags & FSCHECK_INTERACTIVE) VfatPrint("1) Drop it\n2) Auto-rename\n3) Rename\n" "4) Convert to directory\n"); else VfatPrint(" Auto-renaming it.\n"); - switch (interactive ? get_key("1234","?") : '2') { + switch ((FsCheckFlags & FSCHECK_INTERACTIVE) ? get_key("1234","?") : '2') { case '1': drop_file(fs,file); return 1; @@ -483,7 +483,7 @@ static int check_file(DOS_FS *fs,DOS_FILE *file) "is FAT32 root dir.\n", clusters*fs->cluster_size ); do_trunc = 1; } - else if (interactive) + else if (FsCheckFlags & FSCHECK_INTERACTIVE) VfatPrint("1) Truncate first to %lu bytes%s\n" "2) Truncate second to %lu bytes\n",clusters*fs->cluster_size, restart ? " and restart" : "",clusters2*fs->cluster_size); @@ -491,7 +491,7 @@ static int check_file(DOS_FS *fs,DOS_FILE *file) fs->cluster_size); if (do_trunc != 2 && (do_trunc == 1 || - (interactive && get_key("12","?") == '1'))) { + ((FsCheckFlags & FSCHECK_INTERACTIVE) && get_key("12","?") == '1'))) { prev = 0; clusters = 0; for (this = FSTART(owner,fs); this > 0 && this != -1; this = @@ -561,7 +561,7 @@ static int check_dir(DOS_FS *fs,DOS_FILE **root,int dots) VfatPrint("%s\n Has a large number of bad entries. (%d/%d)\n", path_name(parent),bad,good+bad); if (!dots) VfatPrint( " Not dropping root directory.\n" ); - else if (!interactive) VfatPrint(" Not dropping it in auto-mode.\n"); + else if (!(FsCheckFlags & FSCHECK_INTERACTIVE)) VfatPrint(" 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); @@ -584,11 +584,11 @@ static int check_dir(DOS_FS *fs,DOS_FILE **root,int dots) if (!((*walk)->dir_ent.attr & ATTR_VOLUME) && bad_name((*walk)->dir_ent.name)) { VfatPrint("%s\n Bad file name.\n",path_name(*walk)); - if (interactive) + if (FsCheckFlags & FSCHECK_INTERACTIVE) VfatPrint("1) Drop file\n2) Rename file\n3) Auto-rename\n" "4) Keep it\n"); else VfatPrint(" Auto-renaming it.\n"); - switch (interactive ? get_key("1234","?") : '3') { + switch ((FsCheckFlags & FSCHECK_INTERACTIVE) ? get_key("1234","?") : '3') { case '1': drop_file(fs,*walk); walk = &(*walk)->next; @@ -616,12 +616,12 @@ static int check_dir(DOS_FS *fs,DOS_FILE **root,int dots) VfatPrint("%s\n Duplicate directory entry.\n First %s\n", path_name(*walk),file_stat(*walk)); VfatPrint(" Second %s\n",file_stat(*scan)); - if (interactive) + if (FsCheckFlags & FSCHECK_INTERACTIVE) VfatPrint("1) Drop first\n2) Drop second\n3) Rename first\n" "4) Rename second\n5) Auto-rename first\n" "6) Auto-rename second\n"); else VfatPrint(" Auto-renaming second.\n"); - switch (interactive ? get_key("123456","?") : '6') { + switch ((FsCheckFlags & FSCHECK_INTERACTIVE) ? get_key("123456","?") : '6') { case '1': drop_file(fs,*walk); *walk = (*walk)->next; @@ -789,7 +789,7 @@ static void add_file(DOS_FS *fs,DOS_FILE ***chain,DOS_FILE *parent, if (type == fdt_undelete) undelete(fs,new); **chain = new; *chain = &new->next; - if (list) { + if (FsCheckFlags & FSCHECK_LIST_FILES) { VfatPrint("Checking file %s",path_name(new)); if (new->lfn) VfatPrint(" (%s)", file_name(new->dir_ent.name) ); @@ -799,7 +799,7 @@ static void add_file(DOS_FS *fs,DOS_FILE ***chain,DOS_FILE *parent, strncmp((char*)de.name,MSDOS_DOT,MSDOS_NAME) != 0 && strncmp((char*)de.name,MSDOS_DOTDOT,MSDOS_NAME) != 0) ++n_files; - test_file(fs,new,test); + test_file(fs,new,FsCheckFlags & FSCHECK_TEST_READ); } diff --git a/reactos/lib/fslib/vfatlib/check/dosfsck.h b/reactos/lib/fslib/vfatlib/check/dosfsck.h index eb9360eeaab..0134996c75b 100644 --- a/reactos/lib/fslib/vfatlib/check/dosfsck.h +++ b/reactos/lib/fslib/vfatlib/check/dosfsck.h @@ -29,13 +29,6 @@ typedef __int64 ll_t; #endif -#define _LINUX_STAT_H /* hack to avoid inclusion of */ -#define _LINUX_STRING_H_ /* hack to avoid inclusion of */ -#define _LINUX_FS_H /* hack to avoid inclusion of */ - -//#include -//# include "types.h" - #ifdef _M_IX86 #include "byteorder.h" #endif @@ -165,7 +158,13 @@ typedef struct { #define offsetof(t,e) ((int)&(((t *)0)->e)) #endif -extern int interactive,list,verbose,test,write_immed; +#define FSCHECK_INTERACTIVE 0x01 +#define FSCHECK_LIST_FILES 0x02 +#define FSCHECK_TEST_READ 0x04 +#define FSCHECK_VERBOSE 0x08 +#define FSCHECK_IMMEDIATE_WRITE 0x10 + +extern ULONG FsCheckFlags; extern int atari_format; extern unsigned n_files; extern void *mem_queue; diff --git a/reactos/lib/fslib/vfatlib/check/fat.c b/reactos/lib/fslib/vfatlib/check/fat.c index 34a8461d867..ba7ee9bd65b 100644 --- a/reactos/lib/fslib/vfatlib/check/fat.c +++ b/reactos/lib/fslib/vfatlib/check/fat.c @@ -79,7 +79,7 @@ void read_fat(DOS_FS *fs) fs_write(fs->fat_start,eff_size,use = second); } if (first_ok && second_ok) { - if (interactive) { + if (FsCheckFlags & FSCHECK_INTERACTIVE) { VfatPrint("FATs differ but appear to be intact. Use which FAT ?\n" "1) Use first FAT\n2) Use second FAT\n"); if (get_key("12","?") == '1') @@ -199,7 +199,7 @@ void fix_bad(DOS_FS *fs) { unsigned long i; - if (verbose) + if (FsCheckFlags & FSCHECK_VERBOSE) VfatPrint("Checking for bad clusters.\n"); for (i = 2; i < fs->clusters+2; i++) if (!get_owner(fs,i) && !FAT_IS_BAD(fs,fs->fat[i].value)) @@ -215,7 +215,7 @@ void reclaim_free(DOS_FS *fs) int reclaimed; unsigned long i; - if (verbose) + if (FsCheckFlags & FSCHECK_VERBOSE) VfatPrint("Checking for unused clusters.\n"); reclaimed = 0; for (i = 2; i < fs->clusters+2; i++) @@ -261,7 +261,7 @@ void reclaim_file(DOS_FS *fs) int reclaimed,files,changed; unsigned long i,next,walk; - if (verbose) + if (FsCheckFlags & FSCHECK_VERBOSE) VfatPrint("Reclaiming unconnected clusters.\n"); for (i = 2; i < fs->clusters+2; i++) fs->fat[i].prev = 0; for (i = 2; i < fs->clusters+2; i++) { @@ -324,25 +324,25 @@ unsigned long update_free(DOS_FS *fs) if (!fs->fsinfo_start) return free; - if (verbose) + if (FsCheckFlags & FSCHECK_VERBOSE) VfatPrint("Checking free cluster summary.\n"); if (fs->free_clusters >= 0) { if (free != fs->free_clusters) { VfatPrint( "Free cluster summary wrong (%ld vs. really %ld)\n", fs->free_clusters,free); - if (interactive) + if (FsCheckFlags & FSCHECK_INTERACTIVE) VfatPrint( "1) Correct\n2) Don't correct\n" ); else VfatPrint( " Auto-correcting.\n" ); - if (!interactive || get_key("12","?") == '1') + if (!(FsCheckFlags & FSCHECK_INTERACTIVE) || get_key("12","?") == '1') do_set = 1; } } else { VfatPrint( "Free cluster summary uninitialized (should be %ld)\n", free ); - if (interactive) + if (FsCheckFlags & FSCHECK_INTERACTIVE) VfatPrint( "1) Set it\n2) Leave it uninitialized\n" ); else VfatPrint( " Auto-setting.\n" ); - if (!interactive || get_key("12","?") == '1') + if (!(FsCheckFlags & FSCHECK_INTERACTIVE) || get_key("12","?") == '1') do_set = 1; } diff --git a/reactos/lib/fslib/vfatlib/check/io.c b/reactos/lib/fslib/vfatlib/check/io.c index 623a843121c..b266cad069d 100644 --- a/reactos/lib/fslib/vfatlib/check/io.c +++ b/reactos/lib/fslib/vfatlib/check/io.c @@ -139,7 +139,7 @@ void fs_write(loff_t pos,int size,void *data) int did; #if 1 //SAE - if (write_immed) { + if (FsCheckFlags & FSCHECK_IMMEDIATE_WRITE) { void *scratch; const size_t readsize_aligned = (size % 512) ? (size + (512 - (size % 512))) : size; const loff_t seekpos_aligned = pos - (pos % 512); @@ -204,10 +204,10 @@ void fs_write(loff_t pos,int size,void *data) static void fs_flush(void) { CHANGE *this; - int old_write_immed = write_immed; + int old_write_immed = (FsCheckFlags & FSCHECK_IMMEDIATE_WRITE); /* Disable writes to the list now */ - write_immed = 1; + FsCheckFlags |= FSCHECK_IMMEDIATE_WRITE; while (changes) { this = changes; @@ -220,7 +220,7 @@ static void fs_flush(void) } /* Restore values */ - write_immed = old_write_immed; + if (!old_write_immed) FsCheckFlags ^= FSCHECK_IMMEDIATE_WRITE; } diff --git a/reactos/lib/fslib/vfatlib/check/lfn.c b/reactos/lib/fslib/vfatlib/check/lfn.c index 01fb697d184..0aad9ae3055 100644 --- a/reactos/lib/fslib/vfatlib/check/lfn.c +++ b/reactos/lib/fslib/vfatlib/check/lfn.c @@ -173,13 +173,13 @@ void lfn_add_slot( DIR_ENT *de, loff_t dir_offset ) vffree( part2 ); can_clear = 1; } - if (interactive) { + if (FsCheckFlags & FSCHECK_INTERACTIVE) { VfatPrint( "1: Delete previous LFN\n2: Leave it as it is.\n" ); if (can_clear) VfatPrint( "3: Clear start bit and concatenate LFNs\n" ); } else VfatPrint( " Not auto-correcting this.\n" ); - if (interactive) { + if (FsCheckFlags & FSCHECK_INTERACTIVE) { switch( get_key( can_clear ? "123" : "12", "?" )) { case '1': clear_lfn_slots( 0, lfn_parts-1 ); @@ -210,12 +210,12 @@ void lfn_add_slot( DIR_ENT *de, loff_t dir_offset ) VfatPrint( "Long filename fragment \"%s\" found outside a LFN " "sequence.\n (Maybe the start bit is missing on the " "last fragment)\n", part ); - if (interactive) { + if (FsCheckFlags & FSCHECK_INTERACTIVE) { VfatPrint( "1: Delete fragment\n2: Leave it as it is.\n" "3: Set start bit\n" ); } else VfatPrint( " Not auto-correcting this.\n" ); - if (interactive) { + if (FsCheckFlags & FSCHECK_INTERACTIVE) { switch( get_key( "123", "?" )) { case '1': if (!lfn_offsets) @@ -259,13 +259,13 @@ void lfn_add_slot( DIR_ENT *de, loff_t dir_offset ) vffree( part2 ); can_fix = 1; } - if (interactive) { + if (FsCheckFlags & FSCHECK_INTERACTIVE) { VfatPrint( "1: Delete LFN\n2: Leave it as it is (and ignore LFN so far)\n" ); if (can_fix) VfatPrint( "3: Correct sequence number\n" ); } else VfatPrint( " Not auto-correcting this.\n" ); - if (interactive) { + if (FsCheckFlags & FSCHECK_INTERACTIVE) { switch( get_key( can_fix ? "123" : "12", "?" )) { case '1': lfn_offsets[lfn_parts++] = dir_offset; @@ -291,12 +291,12 @@ void lfn_add_slot( DIR_ENT *de, loff_t dir_offset ) VfatPrint( "Checksum in long filename part wrong " "(%02x vs. expected %02x).\n", lfn->alias_checksum, lfn_checksum ); - if (interactive) { + if (FsCheckFlags & FSCHECK_INTERACTIVE) { VfatPrint( "1: Delete LFN\n2: Leave it as it is.\n" "3: Correct checksum\n" ); } else VfatPrint( " Not auto-correcting this.\n" ); - if (interactive) { + if (FsCheckFlags & FSCHECK_INTERACTIVE) { switch( get_key( "123", "?" )) { case '1': lfn_offsets[lfn_parts++] = dir_offset; @@ -326,10 +326,10 @@ void lfn_add_slot( DIR_ENT *de, loff_t dir_offset ) if (lfn->reserved != 0) { VfatPrint( "Reserved field in VFAT long filename slot is not 0 " "(but 0x%02x).\n", lfn->reserved ); - if (interactive) + if (FsCheckFlags & FSCHECK_INTERACTIVE) VfatPrint( "1: Fix.\n2: Leave it.\n" ); else VfatPrint( "Auto-setting to 0.\n" ); - if (!interactive || get_key("12","?") == '1') { + if (!(FsCheckFlags & FSCHECK_INTERACTIVE) || get_key("12","?") == '1') { lfn->reserved = 0; fs_write( dir_offset+offsetof(LFN_ENT,reserved), sizeof(lfn->reserved), &lfn->reserved ); @@ -338,10 +338,10 @@ void lfn_add_slot( DIR_ENT *de, loff_t dir_offset ) if (lfn->start != CT_LE_W(0)) { VfatPrint( "Start cluster field in VFAT long filename slot is not 0 " "(but 0x%04x).\n", lfn->start ); - if (interactive) + if (FsCheckFlags & FSCHECK_INTERACTIVE) VfatPrint( "1: Fix.\n2: Leave it.\n" ); else VfatPrint( "Auto-setting to 0.\n" ); - if (!interactive || get_key("12","?") == '1') { + if (!(FsCheckFlags & FSCHECK_INTERACTIVE) || get_key("12","?") == '1') { lfn->start = CT_LE_W(0); fs_write( dir_offset+offsetof(LFN_ENT,start), sizeof(lfn->start),&lfn->start ); @@ -382,13 +382,13 @@ char *lfn_get( DIR_ENT *de ) " (Start may have been overwritten by %s)\n", long_name, short_name ); vffree( long_name ); - if (interactive) { + if (FsCheckFlags & FSCHECK_INTERACTIVE) { VfatPrint( "1: Delete LFN\n2: Leave it as it is.\n" "3: Fix numbering (truncates long name and attaches " "it to short name %s)\n", short_name ); } else VfatPrint( " Not auto-correcting this.\n" ); - if (interactive) { + if (FsCheckFlags & FSCHECK_INTERACTIVE) { switch( get_key( "123", "?" )) { case '1': clear_lfn_slots( 0, lfn_parts-1 ); @@ -422,13 +422,13 @@ char *lfn_get( DIR_ENT *de ) " (Short name %s may have changed without updating the long name)\n", long_name, short_name ); vffree( long_name ); - if (interactive) { + if (FsCheckFlags & FSCHECK_INTERACTIVE) { VfatPrint( "1: Delete LFN\n2: Leave it as it is.\n" "3: Fix checksum (attaches to short name %s)\n", short_name ); } else VfatPrint( " Not auto-correcting this.\n" ); - if (interactive) { + if (FsCheckFlags & FSCHECK_INTERACTIVE) { switch( get_key( "123", "?" )) { case '1': clear_lfn_slots( 0, lfn_parts-1 ); @@ -461,10 +461,10 @@ void lfn_check_orphaned(void) long_name = CNV_PARTS_SO_FAR(); VfatPrint("Orphaned long file name part \"%s\"\n", long_name); - if (interactive) + if (FsCheckFlags & FSCHECK_INTERACTIVE) VfatPrint( "1: Delete.\n2: Leave it.\n" ); else VfatPrint( " Auto-deleting.\n" ); - if (!interactive || get_key("12","?") == '1') { + if (!(FsCheckFlags & FSCHECK_INTERACTIVE) || get_key("12","?") == '1') { clear_lfn_slots(0, lfn_parts - 1); } lfn_reset();