[Libsysio-commit] HEAD: libsysio/drivers/native fs_native.c
Brought to you by:
lward
|
From: Lee W. <lw...@us...> - 2003-10-20 17:06:40
|
Update of /cvsroot/libsysio/libsysio/drivers/native
In directory sc8-pr-cvs1:/tmp/cvs-serv9788/native
Modified Files:
fs_native.c
Log Message:
From Ruth Klundt; If a file is opened twice the first close destroys the
file descriptor in the low-level driver. Further use by the second, then,
will get EBADF or, on close, aborts.
Why was the open ref count code ifdef'd out? I did it and can't for the
life of me recall why. Anyway, it's back now.
Index: fs_native.c
===================================================================
RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -w -b -B -p -r1.21 -r1.22
--- fs_native.c 17 Oct 2003 21:30:29 -0000 1.21
+++ fs_native.c 20 Oct 2003 16:44:36 -0000 1.22
@@ -191,9 +191,7 @@ struct native_inode {
struct file_identifier ni_fileid; /* ditto */
int ni_fd; /* host fildes */
int ni_oflags; /* flags, from open */
-#if 0
unsigned ni_nopens; /* soft ref count */
-#endif
off_t ni_fpos; /* current pos */
};
@@ -357,9 +355,7 @@ native_i_new(struct filesys *fs, struct
nino->ni_fileid.fid_len = sizeof(nino->ni_ident);
nino->ni_fd = -1;
nino->ni_oflags = 0;
-#if 0
nino->ni_nopens = 0;
-#endif
nino->ni_fpos = 0;
ino =
_sysio_i_new(fs,
@@ -1048,10 +1044,8 @@ native_inop_open(struct pnode *pno, int
* Remember this new open.
*/
nino = I2NI(pno->p_base->pb_ino);
-#if 0
nino->ni_nopens++;
assert(nino->ni_nopens);
-#endif
if (nino->ni_fd >= 0) {
if ((nino->ni_oflags & O_RDWR) ||
@@ -1082,15 +1076,21 @@ native_inop_close(struct inode *ino)
if (nino->ni_fd < 0)
abort();
-#if 0
- assert(nino->ni_nopens);
- if (--nino->ni_nopens)
- return 0;
-#endif
-
err = syscall(SYS_close, nino->ni_fd);
if (err)
return -errno;
+
+ assert(nino->ni_nopens);
+ if (--nino->ni_nopens) {
+ /*
+ * Hmmm. We really don't need anything else. However, some
+ * filesystems try to implement a sync-on-close semantic.
+ * As this appears now, that is lost. Might want to change
+ * it somehow in the future?
+ */
+ return 0;
+ }
+
nino->ni_fd = -1;
nino->ni_fpos = 0;
return 0;
|