Commits

Paweł Wieczorek  committed f9aea6c

* fatfs: obsługa . i ..
* vfs: zalążek locków

  • Participants
  • Parent commits 4986c5f
  • Branches impala-fatfs

Comments (0)

Files changed (11)

File sys/fs/fatfs/fat_dirent.c

     dentry = bp->addr;
     dirent = list_head(&dir->dirents);
     for (int i = 0; i < fatfs->maxroot && dirent; ) {
+        if (str_eq(dirent->name, ".") || str_eq(dirent->name,"..")) continue;
         i += fill_dentry(&dentry[i], dirent, fatfs->maxroot - i, i);
         dirent = list_next(&dir->dirents, dirent);
     }
     const fatfs_dentry_t *table;
     fatfs_t *fatfs = dir->node->fatfs;
     iobuf_t *bp;
-    vfatlname_t vfc; //XXX
+    vfatlname_t vfc;
+    fatfs_dirent_t *dirent;
+
+    dirent  = kmem_zalloc(sizeof(*dirent), KM_SLEEP);
+    str_cpy(dirent->name, ".");
+    dirent->firstclu = dir->node->firstclu;
+    dirent->size = 0;
+    dirent->dirnode = dir->node;
+    dirent->node = dir->node;
+    list_insert_tail(&dir->dirents, dirent);
+
+    dirent = kmem_zalloc(sizeof(*dirent), KM_SLEEP);
+    str_cpy(dirent->name, "..");
+    dirent->firstclu = dir->node->firstclu;
+    dirent->size = 0;
+    dirent->dirnode = dir->node;
+    dirent->node = dir->node;
+    list_insert_tail(&dir->dirents, dirent);
+
     bp = bio_read(fatfs->dev, fatfs->blkno_root, fatfs->maxroot*32);
     if ( ISSET(bp->flags, BIO_ERROR) ) {
         bio_release(bp);
             check_dentry(&table[i], &vln, dir);
         }
     }
+
     dir->node->csize = (off + (fatfs->clusize-1))/fatfs->clusize;
     return 0;
 }
         return;
     }
     if (dentry->attr == 0 || ISSET(dentry->attr, FATFS_SKIP)) return;
-    if ( mem_cmp(dentry->name, ".       ", 8) == 0) return;
-    if ( mem_cmp(dentry->name, "..      ", 8) == 0) return;
-
+    if ( mem_cmp(dentry->name, ".       ", 8) == 0) {
+        fatfs_dirent_t *dirent = kmem_zalloc(sizeof(*dirent), KM_SLEEP);
+        str_cpy(dirent->name, ".");
+        dirent->firstclu = dir->node->firstclu;
+        dirent->size = 0;
+        dirent->dirnode = dir->node;
+        dirent->node = dir->node;
+        list_insert_tail(&dir->dirents, dirent);
+    } else
+    if ( mem_cmp(dentry->name, "..      ", 8) == 0) {
+        fatfs_dirent_t *dirent = kmem_zalloc(sizeof(*dirent), KM_SLEEP);
+        str_cpy(dirent->name, "..");
+        dirent->firstclu = dir->node->dirent->dirnode->firstclu;
+        dirent->size = 0;
+        dirent->dirnode = dir->node;
+        dirent->node = dir->node->dirent->dirnode;
+        list_insert_tail(&dir->dirents, dirent);
+    } else
     if (dentry->name[0] != 0xe5) {
         fatfs_dirent_t *dirent = kmem_zalloc(sizeof(*dirent), KM_SLEEP);
         fatfs_node_t *node;

File sys/fs/fatfs/fat_node.c

 #include <sys/kernel.h>
 #include <sys/bio.h>
 #include <sys/vfs.h>
+#include <sys/vfs/vfs_gen.h>
 #include <fs/fatfs/fatfs.h>
 
 
     fatfs_symlink,
     fatfs_access,
     fatfs_sync,
-    fatfs_inactive
+    fatfs_inactive,
+    vfs_gen_lock,
+    vfs_gen_unlock
 };
 
 /*============================================================================

File sys/fs/fifofs/fifofs.c

 #include <sys/types.h>
 #include <sys/utils.h>
 #include <sys/vfs.h>
+#include <sys/vfs/vfs_gen.h>
 #include <fs/fifofs/fifofs.h>
 #include <fs/fifofs/fifofs_internal.h>
 #include <sys/kmem.h>
     .vop_symlink = fifofs_symlink,
     .vop_sync    = fifofs_node_sync,
     .vop_inactive = fifofs_inactive,
+    .vop_lock   = vfs_gen_lock,
+    .vop_unlock = vfs_gen_unlock
 };
 
 static int _get_read_vnode(fifofs_node_t *node, vnode_t **vpp);

File sys/fs/mfs/mfs_node.c

 #include <sys/utils.h>
 #include <sys/bio.h>
 #include <sys/vfs.h>
+#include <sys/vfs/vfs_gen.h>
 #include <fs/mfs/mfs.h>
 #include <sys/kmem.h>
 #include <sys/errno.h>
     .vop_access = mfs_access,
     .vop_symlink = mfs_symlink,
     .vop_inactive = mfs_inactive,
+    .vop_lock = vfs_gen_lock,
+    .vop_unlock = vfs_gen_unlock
 };
 
 int

File sys/kern/Makefile

 	kern_uio.c\
 	kern_utils.c\
 	vfs.c\
+	vfs_gen.c\
 	vfs_node.c\
 	vm.c\
 	vm_lpool.c\

File sys/kern/sc/open.c

         attr.va_size = 0;
         attr.va_dev = NULL;
         error = VOP_CREATE(parent, &node, _get_last_cmpt(fname), &attr);
+        VOP_UNLOCK(parent);
         if(error)
             return error;
+        VOP_LOCK(node);
     } else {
         //plik istnieje
         if((flags & O_CREAT) && (flags & O_EXCL)) {
     if(ISSET(flags, O_RDWR | O_WRONLY) && ISSET(flags, O_TRUNC)
        && node->v_type == VNODE_TYPE_REG)
         VOP_TRUNCATE(node, 0);
+
     if((error = f_alloc(proc, node, flags, &fd))) {
+        vrele(node); // <- powinno to tutaj by�, dopisa�em bo nie by�o.
         return error;
     }
-
+    VOP_UNLOCK(node);
     r->result = fd;
-    return -EOK;
+    return 0;
 }
 

File sys/kern/vfs_gen.c

+/*
+ * Copyright (C) 2009 University of Wroclaw. Department of Computer Science
+ *    http://www.ii.uni.wroc.pl/
+ * Copyright (C) 2009 Mateusz Kocielski, Artur Koninski, Pawel Wieczorek
+ *    http://trzask.codepainters.com/impala/trac/
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *  notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id $
+ */
+
+#include <sys/types.h>
+#include <sys/kernel.h>
+#include <sys/vfs.h>
+#include <sys/vfs/vfs_gen.h>
+
+
+void
+vfs_gen_lock(vnode_t *vn)
+{
+    MUTEX_LOCK(&vn->v_mtx, "vfsgenlock");
+}
+
+void
+vfs_gen_unlock(vnode_t *vn)
+{
+    mutex_unlock(&vn->v_mtx);
+}

File sys/libkutil/string.c

 {
     const uint8_t *ma = a;
     const uint8_t *mb = b;
-    for (int i = 0; i < n; i++, a++, b++) {
+    for (int i = 0; i < n; i++, ma++, mb++) {
         if (*ma != *mb) {
             return *ma - *mb;
         }

File sys/sys/vfs/vfs_gen.h

+/*
+ * Copyright (C) 2009 University of Wroclaw. Department of Computer Science
+ *    http://www.ii.uni.wroc.pl/
+ * Copyright (C) 2009 Mateusz Kocielski, Artur Koninski, Pawel Wieczorek
+ *    http://trzask.codepainters.com/impala/trac/
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *  notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id $
+ */
+
+#ifndef __SYS_VFS_VFS_GEN_H
+#define __SYS_VFS_VFS_GEN_H
+
+vnode_lock_t vfs_gen_lock;
+vnode_unlock_t vfs_gen_unlock;
+
+
+#endif

File sys/sys/vfs/vfs_node.h

     vnode_ops_t    *v_ops;         ///< wska�nik do vnode_ops z tego fs
     devd_t         *v_dev;         ///< urz�dzenie, je�li to vnode urz�dzenia
     void           *v_private;     ///< prywatne dane fs-a... np. inode
+    mutex_t         v_mtx;         ///< blokada do synchronizacji
 };
 
 
 #define VOP_GETDENTS(v, d, f, c) (v)->v_ops->vop_getdents((v), (d), (f), (c))
 #define VOP_READLINK(v, b, s) (v)->v_ops->vop_readlink((v), (b), (s))
 #define VOP_SYMLINK(v, n, d) (v)->v_ops->vop_symlink((v), (n), (d))
-//#define VOP_RMDIR(v) (v)->v_ops->vop_rmdir((v))
 #define VOP_ACCESS(v, m, c) (v)->v_ops->vop_access((v), (m), (c))
 #define VOP_SYNC(v) (v)->v_ops->vop_sync((v))
 #define VOP_INACTIVE(v) (v)->v_ops->vop_inactive((v))
+#define VOP_LOCK(v) //(v)->v_ops->vop_lock(v)
+#define VOP_UNLOCK(v) //(v)->v_ops->vop_unlock(v)
 
 ///@todo chyba wypada doda� proces otwieraj�cy
 typedef int vnode_open_t(vnode_t *v, int flags, mode_t mode);
 //typedef int vnode_rmdir_t(vnode_t *v);
 typedef int vnode_sync_t(vnode_t *v);
 typedef int vnode_inactive_t(vnode_t *v);
-
-
+typedef void vnode_lock_t(vnode_t *v);
+typedef void vnode_unlock_t(vnode_t *v);
 
 struct vnode_ops {
     vnode_open_t      *vop_open;
     vnode_access_t    *vop_access;
     vnode_sync_t      *vop_sync;
     vnode_inactive_t  *vop_inactive;
+    vnode_lock_t      *vop_lock;
+    vnode_unlock_t    *vop_unlock;
 //    vnode_rmdir_t     *vop_rmdir;
 /*    vnode_link_t      *vop_link;
      */

File usr/bin/truncate/truncate.c

     for (int i = 0; i < argc; i++) {
         int fd;
         fd = open(argv[i], progopt.openflags, 0750);
-        ftruncate(fd, progopt.size);
+        if (ftruncate(fd, progopt.size)) {
+            perror("truncate");
+        }
         close(fd);
     }