Skip to content

Commit

Permalink
Implemented rename for 9P file system
Browse files Browse the repository at this point in the history
  • Loading branch information
totalspectrum committed Oct 7, 2023
1 parent c206950 commit bc880b6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Version 6.5.3
- Implemented NAN() method for Spin2
- Implemented rename for host (9P) file system
- Improved error message for objects that are not found
- Reduced likelihood of duplicate function definitions in sub-objects

Expand Down
54 changes: 52 additions & 2 deletions include/filesys/fs9p/fs9p_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,57 @@ int fs_stat(fs9_file *dir, const char *path, struct stat *buf)
return r;
}

int fs_rename(fs9_file *dir, const char *origname, const char *newname)
{
fs9_file f;
uint8_t *ptr, *szptr;
unsigned sz;
int r = fs_open_relative(dir, &f, origname, 0);
if (r != 0) {
#ifdef _DEBUG_9P
__builtin_printf("rename: open_relative failed with %d\n", r);
#endif
return r;
}
// set up rename command
ptr = doPut4(txbuf, 0); // space for total message size
ptr = doPut1(ptr, t_wstat); // command
ptr = doPut2(ptr, NOTAG); // only one command, so no tag needed
ptr = doPut4(ptr, (unsigned)&f);
szptr = ptr; // save pointer to size of wstat struct
ptr += 4; // skip two 2 byte sizes

// fill in type[2] dev[4] qid[13] mode[4] atime[4] mtime[4] length[8]
// so 2 + 4 + 13 + 20 = 39 bytes total
memset(ptr, 0xff, 39);
ptr += 39;

// now copy in the new file name
ptr = doPutStr(ptr, newname);

// and some empty strings for uid, gid, muid
ptr = doPutStr(ptr, "");
ptr = doPutStr(ptr, "");
ptr = doPutStr(ptr, "");

sz = (ptr-szptr) - 2;

// fill in the earlier size fields
szptr = doPut2(szptr, sz);
szptr = doPut2(szptr, sz-2);

// now send the request
r = (*sendRecv)(txbuf, ptr, maxlen);
if (r < 5 || txbuf[4] != r_wstat) {
#ifdef _DEBUG_9P
__builtin_printf("rename: sendRecv failed with r=%d\n", r);
#endif
return -EINVAL;
}
return 0;
}


//
// VFS versions of the above
//
Expand Down Expand Up @@ -825,8 +876,7 @@ static int v_rmdir(const char *name)

static int v_rename(const char *oldname, const char *newname)
{
// FIXME: should use wstat to implement the rename
return -ENOSYS;
return fs_rename(&rootdir, oldname, newname);
}

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

0 comments on commit bc880b6

Please sign in to comment.