On 1998-12-11 Andreas Buschmann <[EMAIL PROTECTED]> wrote:
 > while writing a prototype filesystem using userfs and c (I started with
 > the contrib/arcfs as the only working C example), I noticed that the
 > open flags are not accessible in userfs.
 >...
 > In the kernel, the open flags are available in f->f_flags as part of the
 > file structure.

I think I ran into the same problem you are talking about.
However, I needed to know if open was opening RDONLY, RDWR, or
WRONLY and used file::f_mode, not f_flags, as you suggest.  I
don't see how open-flags relate to limiting the number of open
files.

Here are some patches against userfs-0.9.4.2.  Just take the
ones dealing with upp_open_s::mode.

Here is a decription of the patches:

        - Pass a mode to open.  This allows open to know if it
          is opening RDONLY, RDWR, WRONLY.

        - Seperate unlink from rmdir.  This is important when
          you don't want, or aren't able, to have your userfs
          client figure out if the arg to unlink is a dir or
          file.

        - Fix userfs_read to not use generic_file_read but to
          call do_userfs_read directly.  This allows
          do_userfs_read to pass the correct cred_tok so the
          client knows what is going on.  (NO_PAGE_CACHE)

        - Fix userfs_write so that O_APPEND files are handled
          correctly.

Maybe someone wants to clean them up and add portions to the
current source.

-- bart

- - - - - - - - - - - - - - - - tear off - - - - - - - - - - - - - - - -
Index: kernel/linux/userfs_types.ty
===================================================================
RCS file: /x/lomew/cvsroot/userfs/kernel/linux/userfs_types.ty,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -r1.1.1.1 -r1.3
--- userfs_types.ty     1998/05/08 23:23:53     1.1.1.1
+++ userfs_types.ty     1998/05/09 00:20:00     1.3
@@ -137,6 +137,7 @@
 {
        up_handle dir;
        up_name name;
+       int isdir;
 } upp_unlink_s;
 
 /* up_readlink */
@@ -248,6 +249,7 @@
 {
        up_cred cred;
        up_handle file;
+       mode_t mode;
 } upp_open_s;
 typedef struct
 {
Index: kernel/src/Makefile
===================================================================
RCS file: /x/lomew/cvsroot/userfs/kernel/src/Makefile,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- Makefile    1998/05/08 23:23:53     1.1.1.1
+++ Makefile    1998/05/08 23:44:12     1.2
@@ -10,6 +10,7 @@
 CC=$(KERNCC)
 
 DEFINES= -DMODULE #-DMODVERSIONS 
+DEFINES+=-DNO_PAGE_CACHE
 CFLAGS=-I.. -O2 -fomit-frame-pointer $(DEFINES) -D__KERNEL__ -Wall
 XCFLAGS=
 INCL=../linux
Index: kernel/src/file.c
===================================================================
RCS file: /x/lomew/cvsroot/userfs/kernel/src/file.c,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -r1.1.1.1 -r1.3
--- file.c      1998/05/08 23:23:53     1.1.1.1
+++ file.c      1998/05/17 07:29:55     1.3
@@ -101,7 +101,7 @@
 static int userfs_read(struct inode *inode, struct file *fl,
                       char *buf, int size)
 {
-#ifdef PRE_1_3_51
+#if defined(PRE_1_3_51) || defined(NO_PAGE_CACHE)
        off_t off;
        
        off = do_userfs_read(inode, U_FILE(fl).cred_tok,
@@ -145,6 +145,9 @@
        snd.file = U_INO(inode).handle;
        snd.ctok = U_FILE(fl).cred_tok;
 
+       if (fl->f_flags & O_APPEND)
+               fl->f_pos = inode->i_size;
+
        while(size > 0)
        {
                sz = MIN(max_size, size);
@@ -156,10 +159,7 @@
 
                userfs_genpkt(inode->i_sb, &pre, up_write);
 
-               if (fl->f_flags & O_APPEND)
-                       snd.off = inode->i_size;
-               else
-                       snd.off = fl->f_pos;
+               snd.off = fl->f_pos;
                snd.data.elems = mbuf;
                snd.data.nelem = sz;
                
@@ -424,6 +424,7 @@
 
        userfs_setcred(&snd.cred);
        snd.file = U_INO(ino).handle;
+       snd.mode = file->f_mode;
 
        if ((ret = userfs_doop(ino->i_sb, &pre, &repl,
                                upp_open_s, &snd, upp_open_r, &rcv)) != 0)
Index: kernel/src/inode.c
===================================================================
RCS file: /x/lomew/cvsroot/userfs/kernel/src/inode.c,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -r1.1.1.1 -r1.3
--- inode.c     1998/05/08 23:23:53     1.1.1.1
+++ inode.c     1998/05/09 00:20:01     1.3
@@ -250,6 +250,9 @@
 
 static int userfs_readpage(struct inode *inode, struct page *page)
 {
+#ifdef NO_PAGE_CACHE
+       return -ENOSYS;
+#else
        unsigned long address;
        off_t off;
        
@@ -283,6 +286,7 @@
        wake_up(&page->wait);
        free_page(address);
        return 0;
+#endif /* NO_PAGE_CACHE */
 }
 #endif
 
@@ -427,7 +431,7 @@
        return ret;
 }
 
-static int userfs_unlink(struct inode *dir, const char *name, int nlen)
+static int do_userfs_unlink(struct inode *dir, const char *name, int nlen, int isdir)
 {
        up_preamble pre;
        upp_unlink_s snd;
@@ -442,6 +446,7 @@
        snd.dir = U_INO(dir).handle;
        snd.name.nelem = nlen;
        snd.name.elems = (char *)name;
+       snd.isdir = isdir;
 
        if ((ret = userfs_doop(dir->i_sb, &pre, &rcv, upp_unlink_s, &snd, void, NULL)) 
!= 0)
                printk("userfs_unlink: userfs_doop failed %d\n", ret);
@@ -452,6 +457,16 @@
        return ret;
 }
 
+static int userfs_unlink(struct inode *dir, const char *name, int nlen)
+{
+       return do_userfs_unlink(dir, name, nlen, 0);
+}
+
+static int userfs_rmdir(struct inode *dir, const char *name, int nlen)
+{
+       return do_userfs_unlink(dir, name, nlen, 1);
+}
+
 int userfs_link(struct inode * oldinode, struct inode * dir, const char * name, int 
len)
 {
        int ret;
@@ -646,7 +661,7 @@
        userfs_unlink,          /* unlink */
        userfs_symlink,         /* symlink */
        userfs_mkdir,           /* mkdir */
-       userfs_unlink,          /* rmdir */
+       userfs_rmdir,           /* rmdir */
        userfs_mknod,           /* mknod */
        userfs_rename,          /* rename */
        userfs_readlink,        /* readlink */
Index: lib/DirInode.cc
===================================================================
RCS file: /x/lomew/cvsroot/userfs/lib/DirInode.cc,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- DirInode.cc 1998/05/08 23:23:54     1.1.1.1
+++ DirInode.cc 1998/05/08 23:44:13     1.2
@@ -304,7 +304,7 @@
                ents[i].file.handle = de->ino->gethandle();
                DB(printf("Multireaddir:%d '%s',nlen=%d,ino=%d,off=%d\n",
                          i, (const char *)de->name,
-                         len, ents[i].file.handle, off));
+                         len, ents[i].file.handle, ents[i].off));
                res.nelem = i+1;
        }
        res.nelem = i;
Index: lib/Makefile
===================================================================
RCS file: /x/lomew/cvsroot/userfs/lib/Makefile,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- Makefile    1998/05/08 23:23:54     1.1.1.1
+++ Makefile    1998/05/09 00:19:16     1.2
@@ -25,7 +25,7 @@
 
 userfs_types.o: userfs_types.cc userfs_types.h
 
-userfs_types.h: $(TYPEFILE) $(GENHDR)
+userfs_types.h: $(TYPEFILE) $(GENHDR) coder.h
        $(GENHDR) $(CPPFLAGS) -C $< > $@ || rm -f $@
 
 #userfs_types.cc: $(TYPEFILE) $(GENCODE)
Index: lib/ThreadComm.cc
===================================================================
RCS file: /x/lomew/cvsroot/userfs/lib/ThreadComm.cc,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- ThreadComm.cc       1998/05/08 23:23:54     1.1.1.1
+++ ThreadComm.cc       1998/05/08 23:44:14     1.2
@@ -17,7 +17,7 @@
 
 class Thread_doreq: public Comm_doreq
 {
-       friend static void op_proc(int, char **, void *);
+       friend void op_proc(int, char **, void *);
        friend class ThreadComm;
 
        // Argument for thread

Reply via email to