[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

MiNT 1.09: allow Dfree on any drive



Currently, Dfree only works if the drive is a root, a current
directory or an alias, or one of the standard drives.  This patch
extends it to work for any drive.  It adds a new function to unifs.c
to return the filesystem structure for a given drive number, that can
then be used to get a cookie for the root directory.  Currently, all
of the special filesystems like /proc ignore the cookie in the dfree
call, but others could use it to distinguish between different drives.

--- orig/dosdir.c	Mon Aug  2 18:57:34 1993
+++ dosdir.c	Mon Dec 27 17:22:34 1993
@@ -43,6 +43,9 @@
 	int d;
 {
 	fcookie *dir = 0;
+	FILESYS *fs;
+	fcookie root;
+	long r;
 	extern int aliasdrv[];
 
 	TRACE(("Dfree(%d)", d));
@@ -53,12 +56,9 @@
 	else
 		d = curproc->curdrv;
 
-/* Hack to make programs (like df) which use drive
- * information from Fxattr() work more often.
- * BUG: this works only if the drive is a root,
- * a current directory or an alias, or one of the
- * standard drives.
- */
+/* If it's not a standard drive or an alias of one, get the pointer to
+   the filesystem structure and use the root directory of the
+   drive. */
 	if (d < 0 || d >= NUM_DRIVES) {
 		int i;
 
@@ -67,16 +67,17 @@
 				d = i;
 				goto aliased;
 			}
-			if (curproc->curdir[i].dev == d) {
-				dir = &curproc->curdir[i];
-			} else if (curproc->root[i].dev == d) {
-				dir = &curproc->root[i];
-			}
-		}
-		if (dir && dir->fs) {
-			return (*dir->fs->dfree)(dir, buf);
 		}
-		return EDRIVE;
+
+		fs = get_filesys (d);
+		if (!fs)
+		  return EDRIVE;
+		r = fs->root (d, &root);
+		if (r < 0)
+		  return r;
+		r = (*fs->dfree) (&root, buf);
+		release_cookie (&root);
+		return r;
 	}
 
 /* check for a media change -- we don't care much either way, but it
--- orig/proto.h	Tue Jul 27 22:31:54 1993
+++ proto.h	Thu Dec  9 23:28:58 1993
@@ -338,6 +338,7 @@
 /* tosfs.c */
 
 /* unifs.c */
+FILESYS *get_filesys P_((int));
 void unifs_init P_((void));
 
 /* debug.c */
--- orig/unifs.c	Tue Jul 27 22:05:06 1993
+++ unifs.c	Sat Dec 25 22:25:26 1993
@@ -68,6 +68,18 @@
 static UNIFILE u_drvs[UNI_NUM_DRVS];
 static UNIFILE *u_root = 0;
 
+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()
 {