@@ -245,6 +245,12 @@ static int local_utime(void *opaque, const char *path,
return utime(rpath(path), buf);
}
+static int local_remove(void *opaque, const char *path)
+{
+ return remove(rpath(path));
+}
+
+
static V9fsPosixFileOperations ops = {
.lstat = local_lstat,
.setuid = local_setuid,
@@ -272,6 +278,7 @@ static V9fsPosixFileOperations ops = {
.rename = local_rename,
.chown = local_chown,
.utime = local_utime,
+ .remove = local_remove,
};
V9fsPosixFileOperations *virtio_9p_init_local(const char *path)
@@ -237,6 +237,11 @@ static int posix_utime(V9fsState *s, V9fsString *path,
return s->ops->utime(s->ops->opaque, path->data, buf);
}
+static int posix_remove(V9fsState *s, V9fsString *path)
+{
+ return s->ops->remove(s->ops->opaque, path->data);
+}
+
static void v9fs_string_init(V9fsString *str)
{
str->data = NULL;
@@ -1719,10 +1724,55 @@ static void v9fs_flush(V9fsState *s, V9fsPDU *pdu)
pprint_pdu(pdu);
}
+typedef struct V9fsRemoveState {
+ V9fsPDU *pdu;
+ size_t offset;
+ int32_t fid;
+ V9fsFidState *fidp;
+} V9fsRemoveState;
+
+static void v9fs_remove_post_remove(V9fsState *s, V9fsRemoveState *vs,
+ int err)
+{
+ if (err) {
+ err = -errno;
+ goto out;
+ }
+
+ err = free_fid(s, vs->fid);
+ if (err < 0)
+ goto out;
+
+ err = vs->offset;
+out:
+ complete_pdu(s, vs->pdu, err);
+ qemu_free(vs);
+}
+
static void v9fs_remove(V9fsState *s, V9fsPDU *pdu)
{
- if (debug_9p_pdu)
- pprint_pdu(pdu);
+ V9fsRemoveState *vs;
+ int err = 0;
+
+ vs = qemu_malloc(sizeof(*vs));
+ vs->pdu = pdu;
+ vs->offset = 7;
+
+ pdu_unmarshal(vs->pdu, vs->offset, "d", &vs->fid);
+
+ vs->fidp = lookup_fid(s, vs->fid);
+ if (vs->fidp == NULL) {
+ err = -EINVAL;
+ goto out;
+ }
+
+ err = posix_remove(s, &vs->fidp->path);
+ v9fs_remove_post_remove(s, vs, err);
+ return;
+
+out:
+ complete_pdu(s, pdu, err);
+ qemu_free(vs);
}
static mode_t v9mode_to_mode(uint32_t mode, V9fsString *extension)