WIP-9ns

-------- probably don't want this.  get a real RAM FS instead of using a
dirtab.  rename and #root wstat is all messed up too.

9ns: Increase KNAMELEN from 28

This allows 9ns files to have names larger than 28 bytes, especially
useful in #root.  Arguably we wouldn't need this if we weren't using a
lousy dirtab.

160 + 32 (the rest of the dirtab) is 64 byte aligned.  I wanted 128
bytes of space for the KNAME, and figured we should use the rest of the
space.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
diff --git a/kern/drivers/dev/root.c b/kern/drivers/dev/root.c
index 4ed019a..05cd091 100644
--- a/kern/drivers/dev/root.c
+++ b/kern/drivers/dev/root.c
@@ -439,9 +439,23 @@
 		error(ENODATA, ERROR_FIXME);
 	}
 	/* TODO: handle more things than just the mode */
-	if (!emptystr(dir->name))
+	if (!emptystr(dir->name)) {
 		printk("[%s] attempted rename of %s to %s\n", __FUNCTION__,
 		       file->name, dir->name);	/* strncpy for this btw */
+		// XXX this isn't enough.  they give us the full path, like
+		// attempted rename of SOME_FILE
+		//                     /root/SOME_DIR/SOME_NEW_FILE
+		//
+		// the first one is just the final part.  we don't even know where we
+		// are in the directory hierarchy (is our parent called SOME_DIR?)
+		// we also don't know the name of our mount point for the destination
+		//
+		//  9ns rename creates the new_chan.  that seems fucked
+		//  		might be ok...
+		//  probably leaking shit
+		//  mount detection is wrong
+		strlcpy(file->name, dir->name, KNAMELEN);
+	}
 	if (dir->mode != -1)
 		file->perm = dir->mode | (file->qid.type == QTDIR ? DMDIR : 0);
 	kfree(dir);
diff --git a/kern/include/ns.h b/kern/include/ns.h
index 2e6fa2f..d884f11 100644
--- a/kern/include/ns.h
+++ b/kern/include/ns.h
@@ -105,7 +105,7 @@
 
 #define	STATMAX	65535U	/* max length of machine-independent stat structure */
 #define	ERRMAX			128	/* max length of error string */
-#define	KNAMELEN		28	/* max length of name held in kernel */
+#define	KNAMELEN		160	/* max length of name held in kernel */
 
 /* bits in Qid.type */
 #define QTDIR		0x80	/* type bit for directories */
diff --git a/kern/src/syscall.c b/kern/src/syscall.c
index b516568..2a6f84f 100644
--- a/kern/src/syscall.c
+++ b/kern/src/syscall.c
@@ -2355,7 +2355,8 @@
 	 * into account for the Twstat.
 	 */
 	if (oldchan->mountpoint) {
-		printd("mountpoint: %C\n", oldchan->mountpoint);
+		// XXX this isn't tripping.
+		printk("mountpoint: %C\n", oldchan->mountpoint);
 		if (oldchan->mountpoint->name)
 			mountpointlen = oldchan->mountpoint->name->len;
 	}
@@ -2367,14 +2368,31 @@
 	}
 
 	/* the omode and perm are of no importance. */
+	// XXX this can throw!
 	newchan = namec(to_path, Acreatechan, 0, 0);
 	if (newchan == NULL) {
 		printd("sys_rename %s to %s found no chan\n", from_path, to_path);
 		set_errno(EPERM);
 		goto done;
 	}
-	printd("Newchan: %C\n", newchan);
-	printd("Newchan: mchan %C\n", newchan->mchan);
+	printk("Newchan: %C\n", newchan);
+	printk("Newchan: mchan %C\n", newchan->mchan);
+	// XXX maybe we don't need this - Acreatechan returns the chan for the dir
+	// of the target (to_path).  so it's name is what we can strip
+	// 		maybe get rid of mntpt, mtpt len, etc?
+	// 		wait, what is cname?  name from namec?  relative?  abs?
+	// 			probably whatever path they used to for namec.
+	// 			/root,  \#root, etc
+	// 		also, newchan is the PARENT, but not the mountpoint.  we need the
+	// 		mountpoint of newchan, then strip that out
+	// 				then the device needs to know how to mv btw directories
+	//
+	// 		tried /root/foo2/xme, but failed to find /root/foo2 (prob on the
+	// 		walk for newchan)!
+	// 				err from devwalk, gen -1, j == 0
+	// 			might have been after previous bad renames corrupted something?
+	// 			though root/foo2 was in dumprootdev 
+	printk("Newchan: mtpt %C\n", newchan->mountpoint);
 
 	if ((newchan->dev != oldchan->dev) ||
 		(newchan->type != oldchan->type)) {
@@ -2393,6 +2411,9 @@
 	 * Once stripped, it still has to be an absolute path.
 	 */
 	if (dir.name[0] == '/') {
+		// XXX we're hitting here, but mountpointlen == 0, i think
+		// 		also, should this be fore the newchan's walk, not oldchan?  (in
+		// 		the off chance you use a different path
 		dir.name = to_path + mountpointlen;
 		if (dir.name[0] != '/') {
 			set_errno(EINVAL);
@@ -2424,12 +2445,11 @@
 
 	poperror();
 	if (retval == mlen) {
-		retval = mlen;
+		retval = 0;
 	} else {
-		printk("syswstat did not go well\n");
 		set_errno(EXDEV);
+		retval = -1;
 	};
-	printk("syswstat returns %d\n", retval);
 
 done:
 	free_path(p, from_path);