# HG changeset patch # User menikon # Date 1580570592 -32400 # Node ID 1ba0ca4113e1621a03f0e953b0a96a8fdb8ca97d # Parent 4cf83e6ce534553502960102dd6e9a2eb71bb91c tweak diff -r 4cf83e6ce534 -r 1ba0ca4113e1 src/impl/fs_impl.cbc --- 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, ...); + +} + diff -r 4cf83e6ce534 -r 1ba0ca4113e1 src/interface/fs.dg --- 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;