minix/lib/nbsd_libc/sys-minix/pwrite.c
Thomas Veerman 490e0de548 Import librefuse and libpuffs
Import libpuffs and our port of libpuffs. The port was done as part of
GSoC 2011 FUSE project, done by Evgeniy Ivanov. The librefuse import
did not require any porting efforts. Libpuffs has been modified to
understand our VFS-FS protocol and translate between that and PUFFS. As
an example that it works, fuse-ntfs-3g from pkgsrc can be compiled and
used to mount ntfs partitions:
mount -t ntfs-3g <device> <mountpoint>

FUSE only works with the asynchronous version of VFS. See <docs/UPDATING> on
how to run AVFS.

This patch further includes some changes to mount(1) and mount(2) so it's
possible to use file systems provided by pkgsrc (note: manual modifications
to /etc/system.conf are still needed. There has been made an exception for
fuse-ntfs-3g, so it already as an entry).
2011-11-14 11:53:05 +00:00

55 lines
973 B
C

#include <sys/cdefs.h>
#include "namespace.h"
#include <lib.h>
#include <unistd.h>
#ifdef __weak_alias
__weak_alias(pwrite, _pwrite)
#endif
#include <minix/u64.h>
ssize_t pwrite64(int fd, const void *buffer, size_t nbytes, u64_t where)
{
u64_t here;
ssize_t w;
if (lseek64(fd, make64(0,0), SEEK_CUR, &here) < 0) return(-1);
if (lseek64(fd, where, SEEK_SET, NULL) < 0) return(-1);
if ((w = write(fd, buffer, nbytes)) < 0) {
int e = errno;
lseek64(fd, here, SEEK_SET, NULL);
errno = e;
return(-1);
}
if (lseek64(fd, here, SEEK_SET, NULL) < 0) return(-1);
return(w);
}
ssize_t pwrite(int fd, const void *buffer, size_t nbytes, off_t where)
{
off_t here;
ssize_t w;
if((here = lseek(fd, 0, SEEK_CUR)) < 0)
return -1;
if(lseek(fd, where, SEEK_SET) < 0)
return -1;
if((w=write(fd, buffer, nbytes)) < 0) {
int e = errno;
lseek(fd, here, SEEK_SET);
errno = e;
return -1;
}
if(lseek(fd, here, SEEK_SET) < 0)
return -1;
return w;
}