[Libsysio-commit] HEAD: libsysio/drivers/native fs_native.c
Brought to you by:
lward
From: Sonja T. <so...@us...> - 2004-07-21 21:22:32
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv514/drivers/native Modified Files: fs_native.c Log Message: Fixing bugs to do with device files. Now, you cant open devices that do not have an associated driver. Also, you can now do an fstat() on a device Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.40 retrieving revision 1.41 diff -u -w -b -B -p -r1.40 -r1.41 --- fs_native.c 16 Jul 2004 20:10:07 -0000 1.40 +++ fs_native.c 21 Jul 2004 21:22:23 -0000 1.41 @@ -210,6 +210,7 @@ struct native_inode { int ni_oflags; /* flags, from open */ unsigned ni_nopens; /* soft ref count */ _SYSIO_OFF_T ni_fpos; /* current pos */ + struct __native_stat *ni_stat; /* cached copy of the stat */ }; /* @@ -328,15 +329,14 @@ static struct mount *native_internal_mou * stat -- by path. */ static int -native_stat(const char *path, struct intnl_stat *buf) +native_stat(const char *path, struct intnl_stat *buf, struct __native_stat *stbuf) { int err; - struct __native_stat stbuf; - err = syscall(__SYS_STAT, path, &stbuf); + err = syscall(__SYS_STAT, path, stbuf); if (err) err = -errno; - COPY_STAT(&stbuf, buf); + COPY_STAT(stbuf, buf); return err; } @@ -345,15 +345,14 @@ native_stat(const char *path, struct int * stat -- by fildes */ static int -native_fstat(int fd, struct intnl_stat *buf) +native_fstat(int fd, struct intnl_stat *buf, struct __native_stat *stbuf) { int err; - struct __native_stat stbuf; - err = syscall(__SYS_FSTAT, fd, &stbuf); + err = syscall(__SYS_FSTAT, fd, stbuf); if (err) err = -errno; - COPY_STAT(&stbuf, buf); + COPY_STAT(stbuf, buf); return err; } @@ -382,6 +381,7 @@ native_i_new(struct filesys *fs, struct nino->ni_oflags = 0; nino->ni_nopens = 0; nino->ni_fpos = 0; + nino->ni_stat = NULL; ino = _sysio_i_new(fs, &nino->ni_fileid, @@ -390,7 +390,7 @@ native_i_new(struct filesys *fs, struct #else buf->st_mode, /* all of the bits! */ #endif - 0, + buf->st_rdev, 0, &native_i_ops, nino); @@ -429,6 +429,8 @@ create_internal_namespace() static struct qstr noname = { NULL, 0, 0 }; struct filesys *fs; struct intnl_stat stbuf; + struct __native_stat *ni_stat; + if (native_internal_mount) { /* @@ -437,6 +439,8 @@ create_internal_namespace() abort(); } + ni_stat = (struct __native_stat *)malloc(sizeof(struct __native_stat)); + /* * We maintain an artificial, internal, name space in order to * have access to fully qualified path names in the various routines. @@ -454,7 +458,7 @@ create_internal_namespace() /* * Get root i-node. */ - err = native_stat("/", &stbuf); + err = native_stat("/", &stbuf, ni_stat); if (err) goto error; rootino = native_i_new(fs, &stbuf); @@ -462,6 +466,7 @@ create_internal_namespace() err = -ENOMEM; goto error; } + I2NI(rootino)->ni_stat = ni_stat; /* * Generate base path-node for root. @@ -593,11 +598,14 @@ native_iget(struct filesys *fs, struct intnl_stat stbuf; struct native_inode_identifier ident; struct file_identifier fileid; + struct __native_stat *ni_stat; + + ni_stat = (struct __native_stat *)malloc(sizeof(struct __native_stat)); /* * Get file status. */ - err = native_stat(path, &stbuf); + err = native_stat(path, &stbuf, ni_stat); if (err) { *inop = NULL; return err; @@ -653,6 +661,7 @@ native_iget(struct filesys *fs, out: if (!err) *inop = ino; + I2NI(ino)->ni_stat = ni_stat; return err; } @@ -714,19 +723,31 @@ native_inop_getattr(struct pnode *pno, s { char *path; int err; + struct __native_stat *ni_stat; path = NULL; + ni_stat = (struct __native_stat *)malloc(sizeof(struct __native_stat)); if (!ino || I2NI(ino)->ni_fd < 0) { + if (pno) path = _sysio_pb_path(pno->p_base, '/'); + else if (ino) { + COPY_STAT(I2NI(ino)->ni_stat, stbuf); + return 0; + } if (!path) return -ENOMEM; + /* if no pno, copy stat and return success */ } err = path - ? native_stat(path, stbuf) - : native_fstat(I2NI(ino)->ni_fd, stbuf); + ? native_stat(path, stbuf, ni_stat) + : native_fstat(I2NI(ino)->ni_fd, stbuf, ni_stat); if (path) free(path); + + /* Cache a copy of the stat */ + I2NI(ino)->ni_stat = ni_stat; + return err; } @@ -739,6 +760,7 @@ native_inop_setattr(struct pnode *pno, char *path; int fd; struct intnl_stat st; + struct __native_stat *ni_stat; int err; path = NULL; @@ -754,10 +776,14 @@ native_inop_setattr(struct pnode *pno, /* * Get current status for undo. */ + ni_stat = (struct __native_stat *)malloc(sizeof(struct __native_stat)); err = fd < 0 - ? native_stat(path, &st) - : native_fstat(fd, &st); + ? native_stat(path, &st, ni_stat) + : native_fstat(fd, &st, ni_stat); + if (ino) + I2NI(ino)->ni_stat = ni_stat; + if (err) goto out; @@ -1711,6 +1737,10 @@ native_inop_gone(struct inode *ino) if (nino->ni_fd >= 0) (void )syscall(SYS_close, nino->ni_fd); + + if (nino->ni_stat) + free(nino->ni_stat); + free(ino->i_private); } |