--- MiNT/src/unifs.c 2018/04/24 17:57:22 1.1.1.4 +++ MiNT/src/unifs.c 2018/04/24 17:58:54 1.1.1.6 @@ -2,7 +2,7 @@ Copyright 1991,1992 Eric R. Smith. -Copyright 1992,1993 Atari Corporation. +Copyright 1992,1993,1994 Atari Corporation. All rights reserved. @@ -128,6 +128,8 @@ typedef struct unifile { struct unifile *next; + short cdate, ctime; + } UNIFILE; @@ -138,6 +140,34 @@ static UNIFILE *u_root = 0; +static long do_ulookup P_((fcookie *, const char *, fcookie *, UNIFILE **)); + + + +FILESYS * + +get_filesys (dev) + + int dev; + +{ + + UNIFILE *u; + + + + for (u = u_root; u; u = u->next) + + if (u->dev == dev) + + return u->fs; + + return (FILESYS *) 0L; + +} + + + void unifs_init() @@ -160,6 +190,10 @@ unifs_init() u->dev = i; + u->cdate = datestamp; + + u->ctime = timestamp; + if (i == PROCDRV) { strcpy(u->name, "proc"); @@ -250,6 +284,32 @@ uni_lookup(dir, name, fc) { + return do_ulookup(dir, name, fc, (UNIFILE **)0); + +} + + + +/* worker function for uni_lookup; can also return the UNIFILE + + * pointer for the root directory + + */ + +static long + +do_ulookup(dir, name, fc, up) + + fcookie *dir; + + const char *name; + + fcookie *fc; + + UNIFILE **up; + +{ + UNIFILE *u; long drvs; @@ -298,7 +358,7 @@ uni_lookup(dir, name, fc) for (u = u_root; u; u = u->next) { - if (!stricmp(name, u->name)) { + if (!strnicmp(name, u->name, NAME_MAX)) { if ( (u->mode & S_IFMT) == S_IFDIR ) { @@ -306,6 +366,8 @@ uni_lookup(dir, name, fc) fs = u->fs; + if (up) *up = u; + return (*fs->root)(u->dev,fc); } @@ -340,6 +402,8 @@ uni_lookup(dir, name, fc) } + if (up) *up = u; + return 0; } @@ -380,7 +444,7 @@ uni_getxattr(fc, xattr) xattr->index = fc->index; - xattr->dev = fc->dev; + xattr->dev = xattr->rdev = fc->dev; xattr->nlink = 1; @@ -418,9 +482,9 @@ uni_getxattr(fc, xattr) } - xattr->mtime = xattr->atime = xattr->ctime = 0; + xattr->mtime = xattr->atime = xattr->ctime = u->ctime; - xattr->mdate = xattr->adate = xattr->cdate = 0; + xattr->mdate = xattr->adate = xattr->cdate = u->cdate; return 0; @@ -534,10 +598,14 @@ uni_remove(dir, name) while (u) { - if (!strncmp(u->name, name, NAME_MAX)) { + if (!strnicmp(u->name, name, NAME_MAX)) { if ( (u->mode & S_IFMT) != S_IFLNK ) return EFILNF; + if (curproc->euid && (u->dev != curproc->euid)) + + return EACCDN; + kfree(u->data); if (lastu) @@ -702,6 +770,14 @@ uni_getname(root, dir, pathname, size) + if (!fs) { + + *pathname = 0; + + return 0; + + } + if (!(fs->fsflags & FS_LONGPATH)) { r = (*fs->getname)(&curproc->root[dir->dev], dir, tmppath, PATH_MAX); @@ -756,7 +832,7 @@ uni_rename(olddir, oldname, newdir, newn for (u = u_root; u; u = u->next) { - if (!stricmp(u->name, oldname)) + if (!strnicmp(u->name, oldname, NAME_MAX)) break; @@ -1066,6 +1142,14 @@ uni_pathconf(dir, which) return DP_CASEINSENS; + case DP_MODEATTR: + + return DP_FT_DIR|DP_FT_LNK; + + case DP_XATTRFIELDS: + + return DP_INDEX|DP_DEV|DP_NLINK|DP_SIZE; + default: return EINVFN; @@ -1160,6 +1244,12 @@ uni_symlink(dir, name, to) + if (curproc->egid) + + return EACCDN; /* only members of admin group may do that */ + + + u = kmalloc(SIZEOF(UNIFILE)); if (!u) return EACCDN; @@ -1186,12 +1276,16 @@ uni_symlink(dir, name, to) u->mode = S_IFLNK | DEFAULT_DIRMODE; - u->dev = curproc->ruid; + u->dev = curproc->euid; u->next = u_root; u->fs = &uni_filesys; + u->cdate = datestamp; + + u->ctime = timestamp; + u_root = u; return 0; @@ -1324,7 +1418,7 @@ uni_fscntl(dir, name, cmd, arg) - if (cmd == FS_INSTALL) { /* install a new filesystem */ + if (cmd == (int)FS_INSTALL) { /* install a new filesystem */ struct fs_descr *d = (struct fs_descr*)arg; @@ -1346,7 +1440,7 @@ uni_fscntl(dir, name, cmd, arg) return (long)&kernelinfo; /* return pointer to kernel info as OK */ - } else if (cmd == FS_MOUNT) { /* install a new gemdos-only device for this FS */ + } else if (cmd == (int)FS_MOUNT) { /* install a new gemdos-only device for this FS */ struct fs_descr *d = (struct fs_descr*)arg; @@ -1408,7 +1502,7 @@ uni_fscntl(dir, name, cmd, arg) return (long)u->dev; - } else if (cmd == FS_UNMOUNT) { /* remove a file system's directory */ + } else if (cmd == (int)FS_UNMOUNT) { /* remove a file system's directory */ struct fs_descr *d = (struct fs_descr*)arg; @@ -1420,7 +1514,9 @@ uni_fscntl(dir, name, cmd, arg) /* first check that directory exists */ - r = uni_lookup(dir, name, &fc); + /* use special uni_lookup mode to get the unifile entry */ + + r = do_ulookup(dir, name, &fc, &u); if (r != 0) return EFILNF; /* name does not exist */ @@ -1432,10 +1528,10 @@ uni_fscntl(dir, name, cmd, arg) return EFILNF; /* not the right name! */ - u = (UNIFILE*)fc.index; - release_cookie(&fc); + + if (!u || (u->fs != d->file_system)) return EFILNF; @@ -1472,7 +1568,7 @@ uni_fscntl(dir, name, cmd, arg) return uni_remove(dir, name); - } else if (cmd == FS_UNINSTALL) { /* remove file system from kernel list */ + } else if (cmd == (int)FS_UNINSTALL) { /* remove file system from kernel list */ struct fs_descr *d = (struct fs_descr*)arg;