Fixes by tamlin. It really works now.

svn path=/trunk/; revision=16873
This commit is contained in:
Steven Edwards 2005-07-29 16:48:09 +00:00
parent 6aa9f0c2da
commit 7917a7f21d
12 changed files with 118 additions and 55 deletions

View file

@ -81,15 +81,15 @@ static void dump_boot(DOS_FS *fs,struct boot_sector *b,unsigned lss)
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);
(__u64)fs->fat_start,
(__u64)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);
(__u64)fs->root_start,
(__u64)fs->root_start/lss);
printf("%10d root directory entries\n",fs->root_entries);
}
else {
@ -97,10 +97,10 @@ static void dump_boot(DOS_FS *fs,struct boot_sector *b,unsigned lss)
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);
(__u64)fs->data_start,
(__u64)fs->data_start/lss);
printf("%10lu data clusters (%llu bytes)\n",fs->clusters,
(unsigned long long)fs->clusters*fs->cluster_size);
(__u64)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",
@ -242,15 +242,15 @@ static void read_fsinfo(DOS_FS *fs, struct boot_sector *b,int lss)
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),
(__u64)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),
(__u64)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),
(__u64)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" );
@ -348,9 +348,9 @@ 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;
if (fs->clusters > ((unsigned long long)fs->fat_size*8/fs->fat_bits)-2)
if (fs->clusters > ((__u64)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,((__u64)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))

View file

@ -10,7 +10,8 @@
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <time.h>
#include <time.h>
#include <windows.h>
#include "common.h"
#include "dosfsck.h"
@ -105,7 +106,7 @@ loff_t alloc_rootdir_entry(DOS_FS *fs, DIR_ENT *de, const char *pattern)
/* 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) )
for( i = 0; i < (int)fs->cluster_size; i += sizeof(DIR_ENT) )
fs_write( offset+i, sizeof(d2), &d2 );
}
memset(de,0,sizeof(DIR_ENT));
@ -140,22 +141,22 @@ loff_t alloc_rootdir_entry(DOS_FS *fs, DIR_ENT *de, const char *pattern)
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)
while (next_free < (int)fs->root_entries)
if (IS_FREE(root[next_free].name) &&
root[next_free].attr != VFAT_LN_ATTR)
break;
else next_free++;
if (next_free == fs->root_entries)
if (next_free == (int)fs->root_entries)
die("Root directory is full.");
offset = fs->root_start+next_free*sizeof(DIR_ENT);
memset(de,0,sizeof(DIR_ENT));
while (1) {
sprintf(de->name,pattern,curr_num);
for (scan = 0; scan < fs->root_entries; scan++)
for (scan = 0; scan < (int)fs->root_entries; scan++)
if (scan != next_free &&
!strncmp(root[scan].name,de->name,MSDOS_NAME))
break;
if (scan == fs->root_entries) break;
if (scan == (int)fs->root_entries) break;
if (++curr_num >= 10000) die("Unable to create unique name");
}
free(root);
@ -167,11 +168,12 @@ loff_t alloc_rootdir_entry(DOS_FS *fs, DIR_ENT *de, const char *pattern)
static char *path_name(DOS_FILE *file)
{
static char path[PATH_MAX*2];
// static char path[PATH_MAX*2];
static char path[MAX_PATH*2];
if (!file) *path = 0;
else {
if (strlen(path_name(file->parent)) > PATH_MAX)
if (strlen(path_name(file->parent)) > MAX_PATH)
die("Path name too long.");
if (strcmp(path,"/") != 0) strcat(path,"/");
strcpy(strrchr(path,0),file->lfn?file->lfn:file_name(file->dir_ent.name));
@ -747,10 +749,14 @@ static void add_file(DOS_FS *fs,DOS_FILE ***chain,DOS_FILE *parent,
DOS_FILE *new;
DIR_ENT de;
FD_TYPE type;
char tmpBuffer[512]; // TMN:
if (offset)
fs_read(offset,sizeof(DIR_ENT),&de);
else {
if (offset) {
// fs_read(offset,sizeof(DIR_ENT),&de);
fs_read(offset,sizeof(tmpBuffer),&tmpBuffer); // TMN:
memcpy(&de, tmpBuffer, sizeof(DIR_ENT)); // TMN:
} else {
memcpy(de.name," ",MSDOS_NAME);
de.attr = ATTR_DIR;
de.size = de.time = de.date = 0;

View file

@ -78,7 +78,10 @@ void qfree(void **root)
}
}
#ifdef min
#undef min
#endif
int min(int a,int b)
{
return a < b ? a : b;

View file

@ -6,12 +6,14 @@
#ifndef _COMMON_H
#define _COMMON_H
void die(char *msg,...) __attribute((noreturn));
//void die(char *msg,...) __attribute((noreturn));
__declspec(noreturn) void die(char *msg,...);
/* Displays a prinf-style message and terminates the program. */
void pdie(char *msg,...) __attribute((noreturn));
//void pdie(char *msg,...) __attribute((noreturn));
__declspec(noreturn) void pdie(char *msg,...);
/* Like die, but appends an error message according to the state of errno. */

View file

@ -26,7 +26,7 @@ extern void __chk_io_ptr(void __iomem *);
# define __iomem
# define __chk_user_ptr(x) (void)0
# define __chk_io_ptr(x) (void)0
# define __builtin_warning(x, y...) (1)
//# define __builtin_warning(x, y...) (1)
# define __acquires(x)
# define __releases(x)
# define __acquire(x) (void)0

View file

@ -12,8 +12,8 @@
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
//#include <unistd.h>
//#include <getopt.h>
#include "common.h"
#include "dosfsck.h"
@ -81,7 +81,8 @@ static void check_atari( void )
int main(int argc,char **argv)
{
{
int optind;
DOS_FS fs;
int rw,salvage_files,verify,c;
unsigned long free_clusters;
@ -89,7 +90,12 @@ int main(int argc,char **argv)
rw = salvage_files = verify = 0;
interactive = 1;
check_atari();
#if 1
optind = 1;
verbose = 1;
list = 1;
#else
while ((c = getopt(argc,argv,"Aad:flnrtu:vVwy")) != EOF)
switch (c) {
case 'A': /* toggle Atari format */
@ -136,12 +142,14 @@ int main(int argc,char **argv)
break;
default:
usage(argv[0]);
}
}
if ((test || write_immed) && !rw) {
fprintf(stderr,"-t and -w require -a or -r\n");
exit(2);
}
if (optind != argc-1) usage(argv[0]);
#endif
printf( "dosfsck " VERSION ", " VERSION_DATE ", FAT32, LFN\n" );
fs_open(argv[optind],rw);

View file

@ -63,6 +63,8 @@ typedef __int64 ll_t;
#define VFAT_LN_ATTR (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME)
#include <pshpack1.h>
/* ++roman: Use own definition of boot sector structure -- the kernel headers'
* name for it is msdos_boot_sector in 2.0 and fat_boot_sector in 2.1 ... */
struct boot_sector {
@ -93,7 +95,9 @@ struct boot_sector {
/* fill up to 512 bytes */
__u8 junk[448];
} __attribute__ ((packed));
};
#include <poppack.h>
struct info_sector {
__u32 magic; /* Magic for info sector ('RRaA') */

View file

@ -9,14 +9,15 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
//#include <unistd.h>
#include "common.h"
#include "dosfsck.h"
#include "io.h"
#include "check.h"
#include "fat.h"
#pragma warning(disable: 4018)
static void get_fat(FAT_ENTRY *entry,void *fat,unsigned long cluster,DOS_FS *fs)
{
@ -54,7 +55,11 @@ void read_fat(DOS_FS *fs)
void *first,*second,*use;
int first_ok,second_ok;
eff_size = ((fs->clusters+2)*fs->fat_bits+7)/8;
eff_size = ((fs->clusters+2)*fs->fat_bits+7)/8;
// TMN: Must round up to disk-sector boundary. For now, assume 512-byte disk.
if (eff_size % 512) {
eff_size += 512 - (eff_size % 512);
}
first = alloc(eff_size);
fs_read(fs->fat_start,eff_size,first);
use = first;

View file

@ -10,7 +10,7 @@
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
//#include <unistd.h>
#define _LINUX_STAT_H /* hack to avoid inclusion of <linux/stat.h> */
#define _LINUX_STRING_H_ /* hack to avoid inclusion of <linux/string.h>*/

View file

@ -14,11 +14,12 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
//#include <unistd.h>
#include <sys/stat.h>
//#include <sys/ioctl.h>
#include <errno.h>
#include <fcntl.h>
#include <fcntl.h>
#include <assert.h>
//#include <linux/fd.h>
@ -62,6 +63,9 @@ static int WIN32read(int fd, void *buf, unsigned int len);
static int WIN32write(int fd, void *buf, unsigned int len);
#define write WIN32write
static loff_t WIN32llseek(int fd, loff_t offset, int whence);
#ifdef llseek
#undef llseek
#endif
#define llseek WIN32llseek
static int is_device = 0;
@ -96,10 +100,24 @@ void fs_open(char *path,int rw)
void fs_read(loff_t pos,int size,void *data)
{
CHANGE *walk;
int got;
int got;
#if 1 // TMN:
const size_t readsize_aligned = size + (512 - (size % 512)); // TMN:
const loff_t seekpos_aligned = pos - (pos % 512); // TMN:
const size_t seek_delta = (size_t)(pos - seekpos_aligned); // TMN:
const size_t readsize = (pos - seekpos_aligned) + readsize_aligned; // TMN:
char* tmpBuf = malloc(readsize); // TMN:
if (llseek(fd,seekpos_aligned,0) != seekpos_aligned) pdie("Seek to %lld",pos);
if ((got = read(fd,tmpBuf,readsize_aligned)) < 0) pdie("Read %d bytes at %lld",size,pos);
assert(got >= size);
got = size;
assert(seek_delta + size < readsize);
memcpy(data, tmpBuf+seek_delta, size);
free(tmpBuf);
#else // TMN:
if (llseek(fd,pos,0) != pos) pdie("Seek to %lld",pos);
if ((got = read(fd,data,size)) < 0) pdie("Read %d bytes at %lld",size,pos);
if ((got = read(fd,data,size)) < 0) pdie("Read %d bytes at %lld",size,pos);
#endif // TMN:
if (got != size) die("Got %d bytes instead of %d at %lld",got,size,pos);
for (walk = changes; walk; walk = walk->next) {
if (walk->pos < pos+size && walk->pos+walk->size > pos) {
@ -158,13 +176,13 @@ static void fs_flush(void)
changes = changes->next;
if (llseek(fd,this->pos,0) != this->pos)
fprintf(stderr,"Seek to %lld failed: %s\n Did not write %d bytes.\n",
(long long)this->pos,strerror(errno),this->size);
(__int64)this->pos,strerror(errno),this->size);
else if ((size = write(fd,this->data,this->size)) < 0)
fprintf(stderr,"Writing %d bytes at %lld failed: %s\n",this->size,
(long long)this->pos,strerror(errno));
(__int64)this->pos,strerror(errno));
else if (size != this->size)
fprintf(stderr,"Wrote %d bytes instead of %d bytes at %lld."
"\n",size,this->size,(long long)this->pos);
"\n",size,this->size,(__int64)this->pos);
free(this->data);
free(this);
}
@ -223,21 +241,26 @@ static int WIN32open(const char *path, int oflag, ...)
switch (oflag & O_ACCMODE) {
case O_RDONLY:
desiredAccess = GENERIC_READ;
shareMode = FILE_SHARE_READ;
// shareMode = FILE_SHARE_READ;
shareMode = FILE_SHARE_READ|FILE_SHARE_WRITE; // TMN:
break;
case O_WRONLY:
exit(42);
desiredAccess = GENERIC_WRITE;
shareMode = 0;
break;
case O_RDWR:
exit(43);
desiredAccess = GENERIC_READ|GENERIC_WRITE;
shareMode = 0;
break;
case O_NONE:
exit(44);
desiredAccess = 0;
shareMode = FILE_SHARE_READ|FILE_SHARE_WRITE;
}
if (oflag & O_APPEND) {
exit(45);
desiredAccess |= FILE_APPEND_DATA|SYNCHRONIZE;
shareMode = FILE_SHARE_READ|FILE_SHARE_WRITE;
}
@ -249,22 +272,27 @@ static int WIN32open(const char *path, int oflag, ...)
creationDisposition = OPEN_EXISTING;
break;
case O_CREAT:
exit(46);
creationDisposition = OPEN_ALWAYS;
break;
case O_CREAT|O_EXCL:
case O_CREAT|O_TRUNC|O_EXCL:
exit(47);
creationDisposition = CREATE_NEW;
break;
case O_TRUNC:
case O_TRUNC|O_EXCL:
exit(48);
creationDisposition = TRUNCATE_EXISTING;
break;
case O_CREAT|O_TRUNC:
exit(49);
creationDisposition = OPEN_ALWAYS;
trunc = TRUE;
break;
}
if (oflag & O_CREAT) {
exit(50);
va_start(ap, oflag);
pmode = va_arg(ap, int);
va_end(ap);
@ -272,6 +300,7 @@ static int WIN32open(const char *path, int oflag, ...)
flagsAttributes |= FILE_ATTRIBUTE_READONLY;
}
if (oflag & O_TEMPORARY) {
exit(51);
flagsAttributes |= FILE_FLAG_DELETE_ON_CLOSE;
desiredAccess |= DELETE;
}
@ -289,6 +318,7 @@ static int WIN32open(const char *path, int oflag, ...)
return -1;
}
if (trunc) {
exit(52);
if (!SetEndOfFile(fh)) {
errno = GetLastError();
CloseHandle(fh);

View file

@ -54,13 +54,16 @@ static unsigned char fat_uni2esc[64] = {
/* for maxlen param */
#define UNTIL_0 INT_MAX
/* Convert name part in 'lfn' from unicode to ASCII */
#define CNV_THIS_PART(lfn) \
({ \
char __part_uni[CHARS_PER_LFN*2]; \
copy_lfn_part( __part_uni, lfn ); \
cnv_unicode( __part_uni, CHARS_PER_LFN, 0 ); \
})
static void copy_lfn_part( char *dst, LFN_ENT *lfn );
static char *cnv_unicode( const unsigned char *uni, int maxlen, int use_q );
/* Convert name part in 'lfn' from unicode to ASCII */
static __inline char* CNV_THIS_PART(LFN_ENT *lfn)
{ \
char __part_uni[CHARS_PER_LFN*2];
copy_lfn_part( __part_uni, lfn );
cnv_unicode( __part_uni, CHARS_PER_LFN, 0 );
}
/* Convert name parts collected so far (from previous slots) from unicode to
* ASCII */

View file

@ -50,7 +50,9 @@
/* Include the header files */
#include "../version.h"
//#include "../version.h"
#define VERSION "test"
#define VERSION_DATE __DATE__
#ifdef _WIN32
#define _WIN32_WINNT 0x0400