mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 18:35:41 +00:00
took a stab at write support and turned it on. Removed getopt as its not needed.
svn path=/trunk/; revision=17049
This commit is contained in:
parent
b3af499b55
commit
0466e5cbb2
3 changed files with 32 additions and 77 deletions
|
@ -1,5 +1,5 @@
|
||||||
CC=mingw32-gcc
|
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
|
all: dosfsck.exe
|
||||||
|
|
||||||
|
|
|
@ -1,63 +0,0 @@
|
||||||
/*
|
|
||||||
* $Id$
|
|
||||||
* This is an unpublished work copyright (c) 1998 HELIOS Software GmbH
|
|
||||||
* 30827 Garbsen, Germany
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#ifdef HAS_UNISTD
|
|
||||||
# include <unistd.h>
|
|
||||||
#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];
|
|
||||||
}
|
|
|
@ -165,6 +165,34 @@ void fs_write(loff_t pos,int size,void *data)
|
||||||
CHANGE *new;
|
CHANGE *new;
|
||||||
int did;
|
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) {
|
if (write_immed) {
|
||||||
did_change = 1;
|
did_change = 1;
|
||||||
if (llseek(fd,pos,0) != pos) pdie("Seek to %lld",pos);
|
if (llseek(fd,pos,0) != pos) pdie("Seek to %lld",pos);
|
||||||
|
@ -179,6 +207,7 @@ void fs_write(loff_t pos,int size,void *data)
|
||||||
if (last) last->next = new;
|
if (last) last->next = new;
|
||||||
else changes = 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:
|
shareMode = FILE_SHARE_READ|FILE_SHARE_WRITE; // TMN:
|
||||||
break;
|
break;
|
||||||
case O_WRONLY:
|
case O_WRONLY:
|
||||||
exit(42);
|
|
||||||
desiredAccess = GENERIC_WRITE;
|
desiredAccess = GENERIC_WRITE;
|
||||||
shareMode = 0;
|
shareMode = 0;
|
||||||
break;
|
break;
|
||||||
case O_RDWR:
|
case O_RDWR:
|
||||||
exit(43);
|
|
||||||
desiredAccess = GENERIC_READ|GENERIC_WRITE;
|
desiredAccess = GENERIC_READ|GENERIC_WRITE;
|
||||||
shareMode = 0;
|
shareMode = 0;
|
||||||
break;
|
break;
|
||||||
case O_NONE:
|
case O_NONE:
|
||||||
exit(44);
|
|
||||||
desiredAccess = 0;
|
desiredAccess = 0;
|
||||||
shareMode = FILE_SHARE_READ|FILE_SHARE_WRITE;
|
shareMode = FILE_SHARE_READ|FILE_SHARE_WRITE;
|
||||||
}
|
}
|
||||||
if (oflag & O_APPEND) {
|
if (oflag & O_APPEND) {
|
||||||
exit(45);
|
|
||||||
desiredAccess |= FILE_APPEND_DATA|SYNCHRONIZE;
|
desiredAccess |= FILE_APPEND_DATA|SYNCHRONIZE;
|
||||||
shareMode = FILE_SHARE_READ|FILE_SHARE_WRITE;
|
shareMode = FILE_SHARE_READ|FILE_SHARE_WRITE;
|
||||||
}
|
}
|
||||||
|
@ -288,27 +313,22 @@ static int WIN32open(const char *path, int oflag, ...)
|
||||||
creationDisposition = OPEN_EXISTING;
|
creationDisposition = OPEN_EXISTING;
|
||||||
break;
|
break;
|
||||||
case O_CREAT:
|
case O_CREAT:
|
||||||
exit(46);
|
|
||||||
creationDisposition = OPEN_ALWAYS;
|
creationDisposition = OPEN_ALWAYS;
|
||||||
break;
|
break;
|
||||||
case O_CREAT|O_EXCL:
|
case O_CREAT|O_EXCL:
|
||||||
case O_CREAT|O_TRUNC|O_EXCL:
|
case O_CREAT|O_TRUNC|O_EXCL:
|
||||||
exit(47);
|
|
||||||
creationDisposition = CREATE_NEW;
|
creationDisposition = CREATE_NEW;
|
||||||
break;
|
break;
|
||||||
case O_TRUNC:
|
case O_TRUNC:
|
||||||
case O_TRUNC|O_EXCL:
|
case O_TRUNC|O_EXCL:
|
||||||
exit(48);
|
|
||||||
creationDisposition = TRUNCATE_EXISTING;
|
creationDisposition = TRUNCATE_EXISTING;
|
||||||
break;
|
break;
|
||||||
case O_CREAT|O_TRUNC:
|
case O_CREAT|O_TRUNC:
|
||||||
exit(49);
|
|
||||||
creationDisposition = OPEN_ALWAYS;
|
creationDisposition = OPEN_ALWAYS;
|
||||||
trunc = TRUE;
|
trunc = TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (oflag & O_CREAT) {
|
if (oflag & O_CREAT) {
|
||||||
exit(50);
|
|
||||||
va_start(ap, oflag);
|
va_start(ap, oflag);
|
||||||
pmode = va_arg(ap, int);
|
pmode = va_arg(ap, int);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
@ -316,7 +336,6 @@ static int WIN32open(const char *path, int oflag, ...)
|
||||||
flagsAttributes |= FILE_ATTRIBUTE_READONLY;
|
flagsAttributes |= FILE_ATTRIBUTE_READONLY;
|
||||||
}
|
}
|
||||||
if (oflag & O_TEMPORARY) {
|
if (oflag & O_TEMPORARY) {
|
||||||
exit(51);
|
|
||||||
flagsAttributes |= FILE_FLAG_DELETE_ON_CLOSE;
|
flagsAttributes |= FILE_FLAG_DELETE_ON_CLOSE;
|
||||||
desiredAccess |= DELETE;
|
desiredAccess |= DELETE;
|
||||||
}
|
}
|
||||||
|
@ -334,7 +353,6 @@ static int WIN32open(const char *path, int oflag, ...)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (trunc) {
|
if (trunc) {
|
||||||
exit(52);
|
|
||||||
if (!SetEndOfFile(fh)) {
|
if (!SetEndOfFile(fh)) {
|
||||||
errno = GetLastError();
|
errno = GetLastError();
|
||||||
CloseHandle(fh);
|
CloseHandle(fh);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue