--- MiNT/src/unifs.c 2018/04/24 17:55:54 1.1.1.2 +++ MiNT/src/unifs.c 2018/04/24 17:56:34 1.1.1.3 @@ -1,6 +1,10 @@ /* -Copyright 1991,1992 Eric R. Smith. All rights reserved. +Copyright 1991,1992 Eric R. Smith. + +Copyright 1992 Atari Corporation. + +All rights reserved. */ @@ -36,7 +40,9 @@ static long ARGS_ON_STACK uni_rmdir P_(( static long ARGS_ON_STACK uni_remove P_((fcookie *dir, const char *name)); -static long ARGS_ON_STACK uni_getname P_((fcookie *root, fcookie *dir, char *pathname)); +static long ARGS_ON_STACK uni_getname P_((fcookie *root, fcookie *dir, + + char *pathname, int size)); static long ARGS_ON_STACK uni_rename P_((fcookie *olddir, char *oldname, @@ -66,7 +72,7 @@ FILESYS uni_filesys = { (FILESYS *)0, - 0, + FS_LONGPATH, uni_root, @@ -248,6 +254,8 @@ uni_lookup(dir, name, fc) FILESYS *fs; + fcookie *tmp; + extern long dosdrvs; @@ -272,7 +280,7 @@ uni_lookup(dir, name, fc) if (!*name || !strcmp(name, ".") || !strcmp(name, "..")) { - *fc = *dir; + dup_cookie(fc, dir); return 0; @@ -304,20 +312,22 @@ uni_lookup(dir, name, fc) return EPTHNF; - *fc = curproc->root[u->dev]; + tmp = &curproc->root[u->dev]; - if (!fc->fs) { /* drive changed? */ + if (!tmp->fs) { /* drive changed? */ - changedrv(fc->dev); + changedrv(tmp->dev); - *fc = curproc->root[u->dev]; + tmp = &curproc->root[u->dev]; - if (!fc->fs) + if (!tmp->fs) return EPTHNF; } + dup_cookie(fc, tmp); + } else { /* a symbolic link */ fc->fs = &uni_filesys; @@ -556,10 +566,12 @@ uni_remove(dir, name) static long ARGS_ON_STACK -uni_getname(root, dir, pathname) +uni_getname(root, dir, pathname, size) fcookie *root, *dir; char *pathname; + int size; + { FILESYS *fs; @@ -570,12 +582,20 @@ uni_getname(root, dir, pathname) fcookie relto; + char tmppath[PATH_MAX]; + + long r; + UNUSED(root); + if (size <= 0) return ERANGE; + + + fs = dir->fs; if (dir->dev == UNIDRV) { @@ -594,10 +614,16 @@ uni_getname(root, dir, pathname) *pathname++ = '\\'; - for (n = u->name; *n; ) + if (--size <= 0) return ERANGE; + + for (n = u->name; *n; ) { *pathname++ = *n++; + if (--size <= 0) return ERANGE; + + } + break; } @@ -620,7 +646,37 @@ uni_getname(root, dir, pathname) if ((*fs->root)(dir->dev, &relto) == 0) { - return (*fs->getname)(&relto, dir, pathname); + if (!(fs->fsflags & FS_LONGPATH)) { + + r = (*fs->getname)(&relto, dir, tmppath, PATH_MAX); + + release_cookie(&relto); + + if (r) { + + return r; + + } + + if (strlen(tmppath) < size) { + + strcpy(pathname, tmppath); + + return 0; + + } else { + + return ERANGE; + + } + + } + + r = (*fs->getname)(&relto, dir, pathname, size); + + release_cookie(&relto); + + return r; } else { @@ -644,7 +700,27 @@ uni_getname(root, dir, pathname) - return (*fs->getname)(&curproc->root[dir->dev], dir, pathname); + if (!(fs->fsflags & FS_LONGPATH)) { + + r = (*fs->getname)(&curproc->root[dir->dev], dir, tmppath, PATH_MAX); + + if (r) return r; + + if (strlen(tmppath) < size) { + + strcpy(pathname, tmppath); + + return 0; + + } else { + + return ERANGE; + + } + + } + + return (*fs->getname)(&curproc->root[dir->dev], dir, pathname, size); } @@ -700,6 +776,12 @@ uni_rename(olddir, oldname, newdir, newn r = uni_lookup(newdir, newname, &fc); + if (r == 0) + + release_cookie(&fc); + + + if (r != EFILNF) { DEBUG(("uni_rename: error %ld", r)); @@ -840,7 +922,7 @@ tryagain: } - *fc = curproc->root[u->dev]; + dup_cookie(fc, &curproc->root[u->dev]); if (!fc->fs) { /* drive not yet initialized */ @@ -872,7 +954,13 @@ tryagain: namelen -= (int)sizeof(long); - if (namelen <= 0) return ERANGE; + if (namelen <= 0) { + + release_cookie(fc); + + return ERANGE; + + } *((long *)name) = index; @@ -882,10 +970,14 @@ tryagain: strncpy(name, dirname, namelen-1); - if (strlen(name) < strlen(dirname)) + if (strlen(name) < strlen(dirname)) { + + release_cookie(fc); return ENAMETOOLONG; + } + return 0; } @@ -1054,7 +1146,13 @@ uni_symlink(dir, name, to) r = uni_lookup(dir, name, &fc); - if (r == 0) return EACCDN; /* file already exists */ + if (r == 0) { + + release_cookie(&fc); + + return EACCDN; /* file already exists */ + + } if (r != EFILNF) return r; /* some other error */