changeset 247:1ba0ca4113e1

tweak
author menikon
date Sun, 02 Feb 2020 00:23:12 +0900
parents 4cf83e6ce534
children c6cbe4711e02
files src/impl/fs_impl.cbc src/interface/fs.dg
diffstat 2 files changed, 94 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/impl/fs_impl.cbc	Sat Feb 01 18:08:31 2020 +0900
+++ b/src/impl/fs_impl.cbc	Sun Feb 02 00:23:12 2020 +0900
@@ -149,7 +149,11 @@
 
 typedef struct stat stat;
 __code statifs_impl(struct fs_impl* fs , struct inode* ip, struct stat* st, __code next(...)) { //:skip
-
+    st->dev = ip->dev;
+    st->ino = ip->inum;
+    st->type = ip->type;
+    st->nlink = ip->nlink;
+    st->size = ip->size;
     goto next(...);
 }
 
@@ -178,13 +182,95 @@
     goto next(...);
 }
 
-__code nameifs_impl(struct fs_impl* fs, char* path, __code next(...)) {
+static struct inode* iget (uint dev, uint inum);
+
+static char* skipelem (char *path, char *name)
+{
+    char *s;
+    int len;
+
+    while (*path == '/') {
+        path++;
+    }
+
+    if (*path == 0) {
+        return 0;
+    }
+
+    s = path;
 
-    goto next(...);
+    while (*path != '/' && *path != 0) {
+        path++;
+    }
+
+    len = path - s;
+
+    if (len >= DIRSIZ) {
+        memmove(name, s, DIRSIZ);
+    } else {
+        memmove(name, s, len);
+        name[len] = 0;
+    }
+
+    while (*path == '/') {
+        path++;
+    }
+
+    return path;
 }
 
-__code nameiparentfs_impl(struct fs_impl* fs, char* path, char* name, __code next(...)) {
+
+static struct inode* namex (char *path, int nameiparent, char *name)
+{
+    struct inode *ip, *next;
+
+    if (*path == '/') {
+        ip = iget(ROOTDEV, ROOTINO);
+    } else {
+        ip = idup(proc->cwd);
+    }
+
+    while ((path = skipelem(path, name)) != 0) {
+        ilock(ip);
+
+        if (ip->type != T_DIR) {
+            iunlockput(ip);
+            return 0;
+        }
 
-    goto next(...);
+        if (nameiparent && *path == '\0') {
+            // Stop one level early.
+            iunlock(ip);
+            return ip;
+        }
+
+        if ((next = dirlookup(ip, name, 0)) == 0) {
+            iunlockput(ip);
+            return 0;
+        }
+
+        iunlockput(ip);
+        ip = next;
+    }
+
+    if (nameiparent) {
+        iput(ip);
+        return 0;
+    }
+
+    return ip;
 }
 
+__code nameifs_impl(struct fs_impl* fs, char* path, __code next(int namex_val, ...)) {
+    char name[DIRSIZ];
+    namex_val = namex(path, 0, name);
+    goto next(namex_val, ...);
+}
+
+__code nameiparentfs_impl(struct fs_impl* fs, char* path, char* name, __code next(int namex_val, ...)) {
+
+    namex_val = namex(path, 1, name);
+    goto next(namex_val, ...);
+
+}
+
--- a/src/interface/fs.dg	Sat Feb 01 18:08:31 2020 +0900
+++ b/src/interface/fs.dg	Sun Feb 02 00:23:12 2020 +0900
@@ -16,7 +16,7 @@
     uint inum;
     char* path;
     char* src;
-
+    int namex_val;
 
     __code readsb(Impl* fs, uint dev, struct superblock* sb, __code next(...));
     __code iinit(Impl* fs, __code next(...));
@@ -33,7 +33,7 @@
     __code namecmp(Impl* fs, const char* s, const char* t, __code next(...));
     __code dirlookup(struct inode* dp, char* name, uint* poff, __code next(...));
     __code dirlink(Impl* fs, struct inode* dp, char* name, uint inum, __code next(...));
-    __code namei(Impl* fs, char* path, __code next(...));
-    __code nameiparent(Impl* fs, char* path, char* name, __code next(...));
+    __code namei(Impl* fs, char* path, __code next(int namex_val, ...));
+    __code nameiparent(Impl* fs, char* path, char* name, __code next(int namex_val, ...));
     __code next(...);
 } fs;