Пример #1
0
static int write_file(Stream_t *Stream, char *buf, mt_off_t iwhere, size_t len)
{
	DeclareThis(File_t);
	mt_off_t pos;
	int ret;
	size_t requestedLen;
	Stream_t *Disk = This->Fs->Next;
	off_t where = truncBytes32(iwhere);
	int err;

	requestedLen = len;
	err = This->map(This, where, &len, MT_WRITE, &pos);
	if( err <= 0)
		return err;
	if(batchmode)
		ret = force_write(Disk, buf, pos, len);
	else
		ret = WRITES(Disk, buf, pos, len);
	if(ret > requestedLen)
		ret = requestedLen;
	if (ret > 0 && where + ret > This->FileSize )
		This->FileSize = where + ret;
	recalcPreallocSize(This);
	return ret;
}
Пример #2
0
static int write_file(struct Stream_t *Stream, char *buf, off_t iwhere, size_t len)
{
	DeclareThis(struct File_t);

	off_t pos;

	struct Stream_t *Disk = This->Fs->Next;
	off_t where = truncBytes32(iwhere);

	const size_t requestedLen = len;

	int err = This->map(This, where, &len, MT_WRITE, &pos);

	if (err <= 0)
		return err;

	int ret = WRITES(Disk, buf, pos, len);

	if(ret > (signed int) requestedLen)
		ret = requestedLen;

	if (ret > 0 && where + ret > (off_t) This->FileSize)
		This->FileSize = where + ret;

	recalcPreallocSize(This);

	return ret;
}
Пример #3
0
_X_NORETURN
static void
catchsig(int sig)
{
#ifdef SYSV
    if (sig > 0) signal (sig, die);	/* re-establish signal handler */
#endif
    /*
     * fileno() might not be reentrant, avoid it if possible, and use
     * stderr instead of stdout
     */
#ifdef STDERR_FILENO
    if (verbose && xauth_modified) WRITES(STDERR_FILENO, "\r\n");
#else
    if (verbose && xauth_modified) WRITES(fileno(stderr), "\r\n");
#endif
    die (sig);
    /* NOTREACHED */
}
Пример #4
0
/* ARGSUSED */
void
CleanupChild(int n)
{
    int olderrno = errno;
    pid_t child;

#ifdef DEBUG
    WRITES("got a child signal\n");
#endif

    while ( (child = waitpid((pid_t)-1, NULL, WNOHANG)) > 0 ) {
#ifdef DEBUG
	char msgbuf[64];

	snprintf(msgbuf, sizeof(msgbuf), " child %d exited\n", child);
	WRITES(msgbuf);
#endif
    }

    errno = olderrno;
}
Пример #5
0
/* ARGSUSED */
void
GiveUp(int n)
{
    int olderrno = errno;
#ifdef DEBUG
    WRITES("got a TERM signal\n");
#endif

    dispatchException |= DE_TERMINATE;
    isItTimeToYield = TRUE;
    errno = olderrno;
}
Пример #6
0
/* ARGSUSED */
void
AutoResetServer(int n)
{
    int olderrno = errno;

#ifdef DEBUG
    WRITES("got a reset signal\n");
#endif

    dispatchException |= DE_RESET;
    isItTimeToYield = TRUE;

    errno = olderrno;
}
Пример #7
0
/* ARGSUSED */
void
ServerCacheFlush(int n)
{
    int olderrno = errno;

#ifdef DEBUG
    WRITES("got a flush signal\n");
#endif

    dispatchException |= DE_FLUSH;
    isItTimeToYield = TRUE;

    errno = olderrno;
}
Пример #8
0
/* ARGSUSED */
void
ServerReconfig(int n)
{
    int olderrno = errno;

#ifdef DEBUG
    WRITES("got a re-config signal\n");
#endif

    dispatchException |= DE_RECONFIG;
    isItTimeToYield = TRUE;

    errno = olderrno;
}
Пример #9
0
void mcat(int argc, char **argv, int type)
{
    struct device *dev;
    struct device out_dev;
    char *drive, name[EXPAND_BUF];
    char errmsg[200];
    Stream_t *Stream;
    char buf[BUF_SIZE];

    mt_off_t address = 0;

    char mode = O_RDONLY;
    int optindex = 1;
    size_t len;

    noPrivileges = 1;

    if (argc < 2) {
        usage();
    }

    if (argv[1][0] == '-') {
        if (argv[1][1] != 'w') {
            usage();
        }
        mode = O_WRONLY;
        optindex++;
    }

    if (argc - optindex < 1)
        usage();


    if (skip_drive(argv[optindex]) == argv[optindex])
        usage();

    drive = get_drive(argv[optindex], NULL);

    /* check out a drive whose letter and parameters match */
    sprintf(errmsg, "Drive '%s:' not supported", drive);
    Stream = NULL;
    for (dev=devices; dev->name; dev++) {
        FREE(&Stream);
        if (strcmp(dev->drive, drive) != 0)
            continue;
        out_dev = *dev;
        expand(dev->name,name);
#ifdef USING_NEW_VOLD
        strcpy(name, getVoldName(dev, name));
#endif

        Stream = 0;
#ifdef USE_XDF
        Stream = XdfOpen(&out_dev, name, mode, errmsg, 0);
        if(Stream)
            out_dev.use_2m = 0x7f;

#endif

#ifdef USE_FLOPPYD
        if(!Stream)
            Stream = FloppydOpen(&out_dev, dev, name,
                                 mode, errmsg, 0, 1);
#endif


        if (!Stream)
            Stream = SimpleFileOpen(&out_dev, dev, name, mode,
                                    errmsg, 0, 1, 0);

        if( !Stream)
            continue;
        break;
    }

    /* print error msg if needed */
    if ( dev->drive == 0 ) {
        FREE(&Stream);
        fprintf(stderr,"%s\n",errmsg);
        exit(1);
    }

    if (mode == O_WRONLY) {
        while ((len = fread(buf, 1, BUF_SIZE, stdin))
                == BUF_SIZE) {
            WRITES(Stream, buf, address, BUF_SIZE);
            address += BUF_SIZE;
        }
        if (len)
            WRITES(Stream, buf, address, len);
    } else {
        while ((len = READS(Stream, buf, address, BUF_SIZE))
                == BUF_SIZE) {
            fwrite(buf, 1, BUF_SIZE, stdout);
            address += BUF_SIZE;
        }
        if (len)
            fwrite(buf, 1, len, stdout);
    }

    FREE(&Stream);
    exit(0);
}
Пример #10
0
int write_pass_through(struct Stream_t *Stream, char *buf, off_t start, size_t len)
{
	return WRITES(Stream->Next, buf, start, len);
}
Пример #11
0
int 
auth_finalize(void)
{
    char temp_name[1024];	/* large filename size */

    if (xauth_modified) {
	if (dieing) {
	    if (verbose) {
		/*
		 * called from a signal handler -- printf is *not* reentrant; also
		 * fileno() might not be reentrant, avoid it if possible, and use
		 * stderr instead of stdout
		 */
#ifdef STDERR_FILENO
		WRITES(STDERR_FILENO, "\nAborting changes to authority file ");
		WRITES(STDERR_FILENO, xauth_filename);
		WRITES(STDERR_FILENO, "\n");
#else
		WRITES(fileno(stderr), "\nAborting changes to authority file ");
		WRITES(fileno(stderr), xauth_filename);
		WRITES(fileno(stderr), "\n");
#endif
	    }
	} else if (!xauth_allowed) {
	    fprintf (stderr, 
		     "%s:  %s not writable, changes ignored\n",
		     ProgramName, xauth_filename);
	} else {
	    if (verbose) {
		printf ("%s authority file %s\n", 
			ignore_locks ? "Ignoring locks and writing" :
			"Writing", xauth_filename);
	    }
	    temp_name[0] = '\0';
	    if (write_auth_file (temp_name) == -1) {
		fprintf (stderr,
			 "%s:  unable to write authority file %s\n",
			 ProgramName, temp_name);
	    } else {
		(void) unlink (xauth_filename);
#if defined(WIN32) || defined(__UNIXOS2__)|| defined(__CYGWIN__)
		if (rename(temp_name, xauth_filename) == -1)
#else
		if (link (temp_name, xauth_filename) == -1)
#endif
		{
		    fprintf (stderr,
		     "%s:  unable to link authority file %s, use %s\n",
			     ProgramName, xauth_filename, temp_name);
		} else {
		    (void) unlink (temp_name);
		}
	    }
	}
    }

    if (xauth_locked) {
	XauUnlockAuth (xauth_filename);
    }
    (void) umask (original_umask);
    return 0;
}
Пример #12
0
void mcat(int argc, char **argv, int type)
{
	struct device *dev;
	struct device out_dev;
	char drive, name[EXPAND_BUF];
        char errmsg[200];
        Stream_t *Stream;
	char buf[BUF_SIZE];

	mt_off_t address = 0;

	char mode = O_RDONLY;
	int optindex = 1;
	size_t len;

	noPrivileges = 1;

	if (argc < 2) {
		usage();
	}

	if (argv[1][0] == '-') {
		if (argv[1][1] != 'w') {
			usage();
		}
		mode = O_WRONLY;
		optindex++;
	}

	if (argc - optindex < 1)
		usage();


	if (!argv[optindex][0] || argv[optindex][1] != ':' 
	    || argv[optindex][2]) {
		usage();
	}

        drive = toupper(argv[optindex][0]);

        /* check out a drive whose letter and parameters match */       
        sprintf(errmsg, "Drive '%c:' not supported", drive);    
        Stream = NULL;
        for (dev=devices; dev->name; dev++) {
                FREE(&Stream);
                if (dev->drive != drive)
                        continue;
                out_dev = *dev;
                expand(dev->name,name);
#ifdef USING_NEW_VOLD
                strcpy(name, getVoldName(dev, name));
#endif

                Stream = 0;
#ifdef USE_XDF
                Stream = XdfOpen(&out_dev, name, mode, errmsg, 0);
				if(Stream)
                        out_dev.use_2m = 0x7f;

#endif

#ifdef USE_FLOPPYD
                if(!Stream)
                        Stream = FloppydOpen(&out_dev, dev, name, 
					     mode, errmsg, 0, 1);
#endif


                if (!Stream)
                        Stream = SimpleFileOpen(&out_dev, dev, name, mode,
						errmsg, 0, 1, 0);

                if( !Stream)
                        continue;
                break;
        }

        /* print error msg if needed */ 
        if ( dev->drive == 0 ){
                FREE(&Stream);
                fprintf(stderr,"%s\n",errmsg);
                exit(1);
        }


	if (mode == O_WRONLY) {
		mt_size_t size=0;
		size = out_dev.sectors * out_dev.heads * out_dev.tracks;
		size *= 512;
		while ((len = fread(buf, 1,
				    bufLen(BUF_SIZE, size, address),
				    stdin)) > 0) {			
			int r = WRITES(Stream, buf, address, len);
			fprintf(stderr, "Wrote to %d\n", (int) address);
			if(r < 0)
				break;
			address += len;
		}
	} else {
		while ((len = READS(Stream, buf, address, BUF_SIZE)) > 0) {
			fwrite(buf, 1, len, stdout);
			address += len;
		}
	}

	FREE(&Stream);
	exit(0);
}