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 {
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",
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" );
/* 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))
#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"
/* 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));
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);
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));
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;
}
}
-
+\r
+#ifdef min\r
+#undef min\r
+#endif
int min(int a,int b)
{
return a < b ? a : b;
#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. */
# 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
#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"
int main(int argc,char **argv)
-{
+{\r
+ int optind;
DOS_FS fs;
int rw,salvage_files,verify,c;
unsigned long free_clusters;
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 */
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);
#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 {
/* 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') */
#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)
{
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;
#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>*/
#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>
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;
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) {
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);
}
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
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
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
return -1;\r
}\r
if (trunc) {\r
+ exit(52);\r
if (!SetEndOfFile(fh)) {\r
errno = GetLastError();\r
CloseHandle(fh);\r
/* 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 */
/* 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