Skip to content

Commit bc880b6

Browse files
committed
Implemented rename for 9P file system
1 parent c206950 commit bc880b6

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

Changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Version 6.5.3
22
- Implemented NAN() method for Spin2
3+
- Implemented rename for host (9P) file system
34
- Improved error message for objects that are not found
45
- Reduced likelihood of duplicate function definitions in sub-objects
56

include/filesys/fs9p/fs9p_internal.cc

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,57 @@ int fs_stat(fs9_file *dir, const char *path, struct stat *buf)
560560
return r;
561561
}
562562

563+
int fs_rename(fs9_file *dir, const char *origname, const char *newname)
564+
{
565+
fs9_file f;
566+
uint8_t *ptr, *szptr;
567+
unsigned sz;
568+
int r = fs_open_relative(dir, &f, origname, 0);
569+
if (r != 0) {
570+
#ifdef _DEBUG_9P
571+
__builtin_printf("rename: open_relative failed with %d\n", r);
572+
#endif
573+
return r;
574+
}
575+
// set up rename command
576+
ptr = doPut4(txbuf, 0); // space for total message size
577+
ptr = doPut1(ptr, t_wstat); // command
578+
ptr = doPut2(ptr, NOTAG); // only one command, so no tag needed
579+
ptr = doPut4(ptr, (unsigned)&f);
580+
szptr = ptr; // save pointer to size of wstat struct
581+
ptr += 4; // skip two 2 byte sizes
582+
583+
// fill in type[2] dev[4] qid[13] mode[4] atime[4] mtime[4] length[8]
584+
// so 2 + 4 + 13 + 20 = 39 bytes total
585+
memset(ptr, 0xff, 39);
586+
ptr += 39;
587+
588+
// now copy in the new file name
589+
ptr = doPutStr(ptr, newname);
590+
591+
// and some empty strings for uid, gid, muid
592+
ptr = doPutStr(ptr, "");
593+
ptr = doPutStr(ptr, "");
594+
ptr = doPutStr(ptr, "");
595+
596+
sz = (ptr-szptr) - 2;
597+
598+
// fill in the earlier size fields
599+
szptr = doPut2(szptr, sz);
600+
szptr = doPut2(szptr, sz-2);
601+
602+
// now send the request
603+
r = (*sendRecv)(txbuf, ptr, maxlen);
604+
if (r < 5 || txbuf[4] != r_wstat) {
605+
#ifdef _DEBUG_9P
606+
__builtin_printf("rename: sendRecv failed with r=%d\n", r);
607+
#endif
608+
return -EINVAL;
609+
}
610+
return 0;
611+
}
612+
613+
563614
//
564615
// VFS versions of the above
565616
//
@@ -825,8 +876,7 @@ static int v_rmdir(const char *name)
825876

826877
static int v_rename(const char *oldname, const char *newname)
827878
{
828-
// FIXME: should use wstat to implement the rename
829-
return -ENOSYS;
879+
return fs_rename(&rootdir, oldname, newname);
830880
}
831881

832882
static int v_open(vfs_file_t *fil, const char *name, int flags)

0 commit comments

Comments
 (0)