[Libsysio-commit] HEAD: libsysio/drivers/native fs_native.c
Brought to you by:
lward
From: Lee W. <lw...@us...> - 2004-04-16 20:38:42
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30430/drivers/native Modified Files: fs_native.c Log Message: New operation for the drivers to implement -- take note! The drivers now need to implement inop_pos which takes an inode and a _SYSIO_OFF_T and should return the resulting position as though it were lseek(FD2INO(fd), off, SEEK_SET). As usual a negative return value is the negated errno. Lseek is altered to use this. Changes in fs_native.c to utilize pread/pwrite whenever positioning is required instead of an lseek/io-op pair of calls. This addresses a race to yod. Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.34 retrieving revision 1.35 diff -u -w -b -B -p -r1.34 -r1.35 --- fs_native.c 14 Apr 2004 17:25:43 -0000 1.34 +++ fs_native.c 16 Apr 2004 20:38:34 -0000 1.35 @@ -247,6 +247,7 @@ static int native_inop_unlink(struct pno static int native_inop_rename(struct pnode *old, struct pnode *new); static int native_inop_read(struct inode *ino, struct ioctx *ioctx); static int native_inop_write(struct inode *ino, struct ioctx *ioctx); +static _SYSIO_OFF_T native_inop_pos(struct inode *ino, _SYSIO_OFF_T off); static int native_inop_iodone(struct ioctx *ioctx); static int native_inop_fcntl(struct inode *ino, int cmd, va_list ap); static int native_inop_sync(struct inode *ino); @@ -278,6 +279,7 @@ static struct inode_ops native_i_ops = { native_inop_rename, native_inop_read, native_inop_write, + native_inop_pos, native_inop_iodone, native_inop_fcntl, native_inop_sync, @@ -1293,24 +1295,47 @@ out: static ssize_t dopio(void *buf, size_t count, _SYSIO_OFF_T off, struct native_io *nio) { +#ifdef _LARGEFILE64_SOURCE +#define _NATIVE_SYSCALL_PREAD SYS_pread64 +#define _NATIVE_SYSCALL_PWRITE SYS_pwrite64 +#else +#define _NATIVE_SYSCALL_PREAD SYS_pread +#define _NATIVE_SYSCALL_PWRITE SYS_pwrite +#endif + ssize_t cc; + + if (!(off == nio->nio_nino->ni_fpos || nio->nio_nino->ni_seekok)) + return -ESPIPE; + if (!nio->nio_nino->ni_seekok) { + if (off != nio->nio_nino->ni_fpos) { /* - * Avoid the reposition call if we're already at the right place. - * Allows us to access pipes and fifos. + * They've done a p{read,write} or somesuch. Can't + * seek on this descriptor so we err out now. */ - if (off != nio->nio_nino->ni_fpos) { - int err; - - err = native_pos(nio->nio_nino->ni_fd, &off, SEEK_SET); - if (err) - return err; - nio->nio_nino->ni_fpos = off; + errno = ESPIPE; + return -1; } - - return syscall(nio->nio_op == 'r' ? SYS_read : SYS_write, + cc = + syscall(nio->nio_op == 'r' ? SYS_read : SYS_write, nio->nio_nino->ni_fd, buf, count); + if (cc > 0) + nio->nio_nino->ni_fpos += cc; + } else + cc = + syscall((nio->nio_op == 'r' + ? _NATIVE_SYSCALL_PREAD + : _NATIVE_SYSCALL_PWRITE), + nio->nio_nino->ni_fd, + buf, + count, + off); + + return cc; +#undef _NATIVE_SYSCALL_PREAD +#undef _NATIVE_SYSCALL_PWRITE } static ssize_t @@ -1515,6 +1540,16 @@ native_inop_write(struct inode *ino __IS return doio('w', ioctx); } +static _SYSIO_OFF_T +native_inop_pos(struct inode *ino, _SYSIO_OFF_T off) +{ + struct native_inode *nino = I2NI(ino); + int err; + + err = native_pos(nino->ni_fd, &off, SEEK_SET); + return err < 0 ? err : off; +} + static int native_inop_iodone(struct ioctx *ioctxp __IS_UNUSED) { |