Browse Source

Start of UFS inode lookup

Signed-off-by: Graham MacDonald <grahamamacdonald@gmail.com>
Graham MacDonald 6 years ago
parent
commit
625987d04f

+ 4 - 16
sys/src/9/port/devufs.c

@@ -258,25 +258,13 @@ testmount()
 		error(Eufsinvalidmp);
 	}
 
-	// Get the root
-	vnode *root = nil;
-	int rcode = ufs_root(mountpoint, 0, &root);
-	if (rcode != 0) {
-		print("couldn't get root: %d", rcode);
-	}
-
-	// TODO Probably need to pass in:
-	//   vdp Root vnode or pwd vnode?  Will an empty struct work?
-	//   vpp nil?  Seems to be the desination.
-	// vpp will be populated with the found vnode.
 	// TODO UFS caches lookups.  We could do that in devufs.
-	/*char path[] = "/";
-	ComponentName cname;
-	cname.cn_pnbuf = path;
-	int rcode = ufs_lookup(mountpoint, &cname);
+	vnode *vn;
+	char *path = "/";
+	int rcode = lookuppath(mountpoint, path, &vn);
 	if (rcode != 0) {
 		print("couldn't lookup path: %s: %d", path, rcode);
-	}*/
+	}
 }
 
 static void

+ 4 - 4
sys/src/9/ufs/ufs/dir.h

@@ -71,14 +71,14 @@
 #define	DIRBLKSIZ	DEV_BSIZE
 #define	UFS_MAXNAMLEN	255
 
-struct	direct {
+typedef struct Direct {
 	uint32_t d_ino;		/* inode number of entry */
 	uint16_t d_reclen;		/* length of this record */
 	uint8_t  d_type; 		/* file type, see below */
 	uint8_t  d_namlen;		/* length of string in d_name */
 	char	  d_name[UFS_MAXNAMLEN + 1];
 					/* name with length <= UFS_MAXNAMLEN */
-};
+} Direct;
 
 /*
  * File types
@@ -108,8 +108,8 @@ struct	direct {
  * 
  */
 #define	DIRECTSIZ(namlen)						\
-	((__offsetof(struct direct, d_name) +				\
-	  ((namlen)+1)*sizeof(((struct direct *)0)->d_name[0]) + 3) & ~3)
+	((__offsetof(Direct, d_name) +				\
+	  ((namlen)+1)*sizeof(((Direct *)0)->d_name[0]) + 3) & ~3)
 #if (BYTE_ORDER == LITTLE_ENDIAN)
 #define	DIRSIZ(oldfmt, dp) \
     ((oldfmt) ? DIRECTSIZ((dp)->d_type) : DIRECTSIZ((dp)->d_namlen))

+ 2 - 0
sys/src/9/ufs/ufs/ufs_lookup.c

@@ -202,6 +202,8 @@ ufs_lookup_ino(vnode *vdp, vnode **vpp, ComponentName *cnp, ino_t *dd_ino)
 	//ino_t ino, ino1;
 	//int ltype;
 
+	print("HARVEY TODO: %s\n", __func__);
+
 	if (vpp != nil)
 		*vpp = nil;
 

+ 2 - 1
sys/src/9/ufs/ufs_ext.h

@@ -51,6 +51,7 @@ int countvnodes(vnode *vn);
 int ffs_mount(MountPoint *mp);
 int ffs_unmount(MountPoint *mp, int mntflags);
 
-// TODO HARVEY Are these here temporarily?
 int ufs_root(MountPoint *mp, int flags, vnode **vpp);
 int ufs_lookup(MountPoint *mp);
+
+int lookuppath(MountPoint *mp, char *path, vnode **vn);

+ 23 - 0
sys/src/9/ufs/ufs_harvey.c

@@ -21,6 +21,7 @@
 
 #include "ufs/quota.h"
 #include "ufs/inode.h"
+#include "ufs/ufs_extern.h"
 
 
 int
@@ -119,3 +120,25 @@ releaseufsvnode(MountPoint *mp, vnode *vn)
 {
 	releasevnode(mp, vn);
 }
+
+int
+lookuppath(MountPoint *mp, char *path, vnode **vn)
+{
+	// Get the root
+	vnode *root = nil;
+	int rcode = ufs_root(mp, 0, &root);
+	if (rcode != 0) {
+		print("couldn't get root: %d", rcode);
+		return -1;
+	}
+
+	// TODO UFS caches lookups.  We could do that in devufs.
+	ComponentName cname = { .cn_pnbuf = path, .cn_nameiop = LOOKUP };
+	rcode = ufs_lookup_ino(root, vn, &cname, nil);
+	if (rcode != 0) {
+		print("couldn't lookup path: %s: %d", path, rcode);
+		return -1;
+	}
+
+	return 0;
+}

+ 8 - 0
sys/src/9/ufs/ufs_harvey.h

@@ -130,6 +130,14 @@ typedef struct vnode {
  */
 #define	FORCECLOSE	0x0002	/* vflush: force file closure */
 
+/*
+ * namei operations
+ */
+#define	LOOKUP		0	/* perform name lookup only */
+#define	CREATE		1	/* setup for file creation */
+#define	DELETE		2	/* setup for file deletion */
+#define	RENAME		3	/* setup for file renaming */
+#define	OPMASK		3	/* mask for operation */
 
 int findexistingvnode(MountPoint *mp, ino_t ino, vnode **vpp);
 int getnewvnode(MountPoint *mp, vnode **vpp);