From 0466e5cbb24fc0b1145922fb55a38f520ba651d5 Mon Sep 17 00:00:00 2001 From: Steven Edwards Date: Thu, 4 Aug 2005 21:42:32 +0000 Subject: [PATCH] took a stab at write support and turned it on. Removed getopt as its not needed. svn path=/trunk/; revision=17049 --- rosapps/sysutils/dosfsck/Makefile | 2 +- rosapps/sysutils/dosfsck/getopt.c | 63 ------------------------------- rosapps/sysutils/dosfsck/io.c | 44 ++++++++++++++------- 3 files changed, 32 insertions(+), 77 deletions(-) delete mode 100644 rosapps/sysutils/dosfsck/getopt.c diff --git a/rosapps/sysutils/dosfsck/Makefile b/rosapps/sysutils/dosfsck/Makefile index c32f532fc92..0ea3d54eeca 100644 --- a/rosapps/sysutils/dosfsck/Makefile +++ b/rosapps/sysutils/dosfsck/Makefile @@ -1,5 +1,5 @@ CC=mingw32-gcc -OBJECTS = getopt.o boot.o check.o common.o dosfsck.o fat.o file.o io.o lfn.o +OBJECTS = boot.o check.o common.o dosfsck.o fat.o file.o io.o lfn.o all: dosfsck.exe diff --git a/rosapps/sysutils/dosfsck/getopt.c b/rosapps/sysutils/dosfsck/getopt.c deleted file mode 100644 index 0a37f95d320..00000000000 --- a/rosapps/sysutils/dosfsck/getopt.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * $Id$ - * This is an unpublished work copyright (c) 1998 HELIOS Software GmbH - * 30827 Garbsen, Germany - */ - - -#include -#include -#ifdef HAS_UNISTD -# include -#endif - -char *optarg; -int optind = 1; -int opterr = 1; -int optopt; -static int subopt; -static int suboptind = 1; - -int getopt(int argc, char *const argv[], const char * optstring) -{ - char *curopt; - char *p; - int cursubopt; - - if (suboptind == optind-1 && argv[suboptind][subopt] != '\0') { - curopt = (char *)argv[suboptind]; - } else { - curopt = (char *)argv[optind]; - if (curopt == NULL || curopt[0] != '-' || strcmp(curopt, "-") == 0) - return -1; - suboptind = optind; - subopt = 1; - optind++; - if (strcmp(curopt, "--") == 0) - return -1; - } - cursubopt = subopt++; - if ((p = strchr(optstring, curopt[cursubopt])) == NULL) { - optopt = curopt[cursubopt]; - if (opterr) - fprintf(stderr, "%s: illegal option -- %c\n", argv[0], optopt); - return '?'; - } - if (p[1] == ':') { - if (curopt[cursubopt+1] != '\0') { - optarg = curopt+cursubopt+1; - suboptind++; - return p[0]; - } - if (argv[optind] == NULL) { - optopt = p[0]; - if (opterr) - fprintf(stderr, "%s: option requires an argument -- %c\n", argv[0], optopt); - if (*optstring == ':') - return ':'; - return '?'; - } - optarg = argv[optind++]; - } - return p[0]; -} diff --git a/rosapps/sysutils/dosfsck/io.c b/rosapps/sysutils/dosfsck/io.c index e4e231f793c..32aee9f3218 100644 --- a/rosapps/sysutils/dosfsck/io.c +++ b/rosapps/sysutils/dosfsck/io.c @@ -164,7 +164,35 @@ void fs_write(loff_t pos,int size,void *data) { CHANGE *new; int did; - + +#if 1 //SAE + void *scratch; + const size_t readsize_aligned = (size % 512) ? (size + (512 - (size % 512))) : size; + const loff_t seekpos_aligned = pos - (pos % 512); + const size_t seek_delta = (size_t)(pos - seekpos_aligned); + const size_t readsize = (size_t)(pos - seekpos_aligned) + readsize_aligned; + scratch = alloc(readsize_aligned); + + if (write_immed) { + did_change = 1; + if (llseek(fd,seekpos_aligned,0) != seekpos_aligned) pdie("Seek to %lld",pos); + if ((did = write(fd,data,readsize_aligned)) == (int)readsize_aligned) + { + free(scratch); + return; + } + if (did < 0) pdie("Write %d bytes at %lld",size,pos); + die("Wrote %d bytes instead of %d at %lld",did,size,pos); + } + new = alloc(sizeof(CHANGE)); + new->pos = pos; + memcpy(new->data = alloc(new->size = size),data,size); + new->next = NULL; + if (last) last->next = new; + else changes = new; + last = new; + +#else //SAE if (write_immed) { did_change = 1; if (llseek(fd,pos,0) != pos) pdie("Seek to %lld",pos); @@ -178,7 +206,8 @@ void fs_write(loff_t pos,int size,void *data) new->next = NULL; if (last) last->next = new; else changes = new; - last = new; + last = new; +#endif //SAE } @@ -261,22 +290,18 @@ static int WIN32open(const char *path, int oflag, ...) 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; } @@ -288,27 +313,22 @@ 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); @@ -316,7 +336,6 @@ 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; } @@ -334,7 +353,6 @@ static int WIN32open(const char *path, int oflag, ...) return -1; } if (trunc) { - exit(52); if (!SetEndOfFile(fh)) { errno = GetLastError(); CloseHandle(fh); -- 2.17.1