Skip to content

Commit

Permalink
Merge pull request #5 from EnzoEnzoo/update-rename
Browse files Browse the repository at this point in the history
include rename
  • Loading branch information
olivierpierre authored Jan 31, 2022
2 parents 049c2c3 + 73e8f4f commit 2768639
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
6 changes: 6 additions & 0 deletions arch/x86/kernel/isrs.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,11 @@ void syscall_handler(struct state *s)
s->rax = sys_chdir((const char *)s->rdi);
break;
#endif
case 82:
/* rename */

s->rax = sys_rename((const char *)s->rdi, (const char *)s->rsi);
break;

#ifndef DISABLE_SYS_MKDIR
case 83:
Expand Down Expand Up @@ -956,3 +961,4 @@ static void arch_fault_handler(struct state *s)
//do_abort();
sys_exit(-EFAULT);
}

1 change: 1 addition & 0 deletions include/hermit/stddef.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ extern uint64_t tux_start_address;
#define UHYVE_PORT_DUP2 0x530
#define UHYVE_PORT_PIPE 0x531
#define UHYVE_PORT_NEWFSTATAT 0x532
#define UHYVE_PORT_RENAME 0x533

// Networkports
#define UHYVE_PORT_NETINFO 0x505
Expand Down
24 changes: 24 additions & 0 deletions kernel/syscalls/rename.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <hermit/syscall.h>
#include <hermit/logging.h>
#include <asm/page.h>
#include <asm/uhyve.h>
#include <hermit/minifs.h>

typedef struct {
char *oldpath;
char *newpath;
int ret;
} __attribute__((packed)) uhyve_rename_t;

int sys_rename(const char *oldpath, const char *newpath) {
uhyve_rename_t arg;

arg.oldpath = (char *)virt_to_phys((size_t)oldpath);
arg.newpath = (char *)virt_to_phys((size_t)newpath);
arg.ret = -1;

uhyve_send(UHYVE_PORT_RENAME, (unsigned)virt_to_phys((size_t)&arg));

return arg.ret;
}

10 changes: 9 additions & 1 deletion tools/uhyve-syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ typedef enum {
UHYVE_PORT_GETDENTS = 0x529,
UHYVE_PORT_DUP2 = 0X530,
UHYVE_PORT_PIPE = 0X531,
UHYVE_PORT_NEWFSTATAT = 0X532
UHYVE_PORT_NEWFSTATAT = 0X532,
UHYVE_PORT_RENAME = 0X533
} uhyve_syscall_t;

typedef struct {
Expand Down Expand Up @@ -186,6 +187,12 @@ typedef struct {
int ret;
} __attribute__((packed)) uhyve_creat_t;

typedef struct {
char *oldpath;
char *newpath;
int ret;
} __attribute__((packed)) uhyve_rename_t;

typedef struct {
int fd;
int ret;
Expand Down Expand Up @@ -218,3 +225,4 @@ typedef struct {
} __attribute__((packed)) uhyve_newfstatat_t;

#endif // UHYVE_SYSCALLS_H

15 changes: 15 additions & 0 deletions tools/uhyve.c
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,20 @@ static int vcpu_loop(void)

break;
}
case UHYVE_PORT_RENAME: {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_rename_t *arg = (uhyve_rename_t *)(guest_mem + data);

int ret = rename((const char *)(guest_mem+(size_t)arg->oldpath),
(const char *)(guest_mem+(size_t)arg->newpath));

if(ret == -1)
arg->ret = -errno;
else
arg->ret = ret;

break;
}

case UHYVE_PORT_SYNC:
case UHYVE_PORT_FSYNC:
Expand Down Expand Up @@ -2154,3 +2168,4 @@ int uhyve_loop(int argc, char **argv)
// Run first CPU
return vcpu_loop();
}

0 comments on commit 2768639

Please sign in to comment.