Fixes by tamlin. It really works now.
authorSteven Edwards <winehacker@gmail.com>
Fri, 29 Jul 2005 16:48:09 +0000 (16:48 +0000)
committerSteven Edwards <winehacker@gmail.com>
Fri, 29 Jul 2005 16:48:09 +0000 (16:48 +0000)
svn path=/trunk/; revision=16873

12 files changed:
rosapps/sysutils/dosfsck/boot.c
rosapps/sysutils/dosfsck/check.c
rosapps/sysutils/dosfsck/common.c
rosapps/sysutils/dosfsck/common.h
rosapps/sysutils/dosfsck/compiler.h
rosapps/sysutils/dosfsck/dosfsck.c
rosapps/sysutils/dosfsck/dosfsck.h
rosapps/sysutils/dosfsck/fat.c
rosapps/sysutils/dosfsck/file.c
rosapps/sysutils/dosfsck/io.c
rosapps/sysutils/dosfsck/lfn.c
rosapps/sysutils/dosfsck/mkdosfs.c

index 704b64d..f29231f 100644 (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))
index e8c13bb..a7c384a 100644 (file)
@@ -10,7 +10,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <limits.h>
-#include <time.h>
+#include <time.h>\r
+#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];\r
+    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;
-
-    if (offset)
-       fs_read(offset,sizeof(DIR_ENT),&de);
-    else {
+\r
+       char tmpBuffer[512]; // TMN:\r
+
+    if (offset) {
+//     fs_read(offset,sizeof(DIR_ENT),&de);\r
+       fs_read(offset,sizeof(tmpBuffer),&tmpBuffer); // TMN:\r
+       memcpy(&de, tmpBuffer, sizeof(DIR_ENT));      // TMN:
+    } else {
        memcpy(de.name,"           ",MSDOS_NAME);
        de.attr = ATTR_DIR;
        de.size = de.time = de.date = 0;
index dd5bc74..48a5f33 100644 (file)
@@ -78,7 +78,10 @@ void qfree(void **root)
     }
 }
 
-
+\r
+#ifdef min\r
+#undef min\r
+#endif
 int min(int a,int b)
 {
     return a < b ? a : b;
index a558e14..98a4685 100644 (file)
@@ -6,12 +6,14 @@
 
 #ifndef _COMMON_H
 #define _COMMON_H
-
-void die(char *msg,...) __attribute((noreturn));
+\r
+//void die(char *msg,...) __attribute((noreturn));
+__declspec(noreturn) void die(char *msg,...);\r
 
 /* 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,...);\r
 
 /* Like die, but appends an error message according to the state of errno. */
 
index d737821..2d3edfe 100644 (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
index b0ddad1..6735ea8 100644 (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)
-{
+{\r
+       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();
-
+\r
+#if 1\r
+       optind = 1;\r
+       verbose = 1;\r
+       list = 1;\r
+#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]);
-       }
+       }\r
+
     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\r
 
     printf( "dosfsck " VERSION ", " VERSION_DATE ", FAT32, LFN\n" );
     fs_open(argv[optind],rw);
index 8f3940e..f3ab006 100644 (file)
@@ -63,6 +63,8 @@ typedef __int64 ll_t;
 
 #define VFAT_LN_ATTR (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME)
 
+#include <pshpack1.h>\r
+\r
 /* ++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));
+};
+\r
+#include <poppack.h>\r
 
 struct info_sector {
     __u32      magic;          /* Magic for info sector ('RRaA') */
index 91928d4..921d9f7 100644 (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"
-
+\r
+#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;\r
+       // TMN: Must round up to disk-sector boundary. For now, assume 512-byte disk.\r
+       if (eff_size % 512) {\r
+               eff_size += 512 - (eff_size % 512);\r
+       }
     first = alloc(eff_size);
     fs_read(fs->fat_start,eff_size,first);
     use = first;
index 1da9d87..9d6b4ff 100644 (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>*/
index c751217..6f1299e 100644 (file)
 #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>\r
+#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);\r
 #define write  WIN32write
 static loff_t WIN32llseek(int fd, loff_t offset, int whence);\r
+#ifdef llseek\r
+#undef llseek\r
+#endif\r
 #define llseek WIN32llseek\r
 
 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;\r
+#if 1 // TMN:\r
+       const size_t readsize_aligned = size + (512 - (size % 512));        // TMN:\r
+       const loff_t seekpos_aligned = pos - (pos % 512);                   // TMN:\r
+       const size_t seek_delta = (size_t)(pos - seekpos_aligned);          // TMN:\r
+       const size_t readsize = (pos - seekpos_aligned) + readsize_aligned; // TMN: \r
+       char* tmpBuf = malloc(readsize);                                    // TMN:
+    if (llseek(fd,seekpos_aligned,0) != seekpos_aligned) pdie("Seek to %lld",pos);\r
+    if ((got = read(fd,tmpBuf,readsize_aligned)) < 0) pdie("Read %d bytes at %lld",size,pos);\r
+       assert(got >= size);\r
+       got = size;\r
+       assert(seek_delta + size < readsize);\r
+       memcpy(data, tmpBuf+seek_delta, size);\r
+       free(tmpBuf);\r
+#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);\r
+#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) {\r
        case O_RDONLY:\r
                desiredAccess = GENERIC_READ;\r
-               shareMode = FILE_SHARE_READ;\r
+//             shareMode = FILE_SHARE_READ;\r
+               shareMode = FILE_SHARE_READ|FILE_SHARE_WRITE; // TMN:\r
                break;\r
        case O_WRONLY:\r
+               exit(42);\r
                desiredAccess = GENERIC_WRITE;\r
                shareMode = 0;\r
                break;\r
        case O_RDWR:\r
+               exit(43);\r
                desiredAccess = GENERIC_READ|GENERIC_WRITE;\r
                shareMode = 0;\r
                break;\r
        case O_NONE:\r
+               exit(44);\r
                desiredAccess = 0;\r
                shareMode = FILE_SHARE_READ|FILE_SHARE_WRITE;\r
        }\r
        if (oflag & O_APPEND) {\r
+               exit(45);\r
                desiredAccess |= FILE_APPEND_DATA|SYNCHRONIZE;\r
                shareMode = FILE_SHARE_READ|FILE_SHARE_WRITE;\r
        }\r
@@ -249,22 +272,27 @@ static int WIN32open(const char *path, int oflag, ...)
                creationDisposition = OPEN_EXISTING;\r
                break;\r
        case O_CREAT:\r
+               exit(46);\r
                creationDisposition = OPEN_ALWAYS;\r
                break;\r
        case O_CREAT|O_EXCL:\r
        case O_CREAT|O_TRUNC|O_EXCL:\r
+               exit(47);\r
                creationDisposition = CREATE_NEW;\r
                break;\r
        case O_TRUNC:\r
        case O_TRUNC|O_EXCL:\r
+               exit(48);\r
                creationDisposition = TRUNCATE_EXISTING;\r
                break;\r
        case O_CREAT|O_TRUNC:\r
+               exit(49);\r
                creationDisposition = OPEN_ALWAYS;\r
                trunc = TRUE;\r
                break;\r
         }\r
        if (oflag & O_CREAT) {\r
+               exit(50);\r
                va_start(ap, oflag);\r
                pmode = va_arg(ap, int);\r
                va_end(ap);\r
@@ -272,6 +300,7 @@ static int WIN32open(const char *path, int oflag, ...)
                        flagsAttributes |= FILE_ATTRIBUTE_READONLY;\r
        }\r
        if (oflag & O_TEMPORARY) {\r
+               exit(51);\r
                flagsAttributes |= FILE_FLAG_DELETE_ON_CLOSE;\r
                desiredAccess |= DELETE;\r
        }\r
@@ -289,6 +318,7 @@ static int WIN32open(const char *path, int oflag, ...)
                return -1;\r
        }\r
        if (trunc) {\r
+               exit(52);\r
                if (!SetEndOfFile(fh)) {\r
                        errno = GetLastError();\r
                        CloseHandle(fh);\r
index 9b2cfc3..0c5c92c 100644 (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 );\r
+static char *cnv_unicode( const unsigned char *uni, int maxlen, int use_q );\r
+\r
+/* Convert name part in 'lfn' from unicode to ASCII */\r
+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 */
index 9c6e0ed..a74dcca 100644 (file)
@@ -50,7 +50,9 @@
 
 /* Include the header files */
 
-#include "../version.h"
+//#include "../version.h"\r
+#define VERSION      "test"\r
+#define VERSION_DATE __DATE__
 \r
 #ifdef _WIN32\r
 #define _WIN32_WINNT   0x0400\r