diff mbox

[RFC,3/3] hw/9pfs: Add synth fs test

Message ID 1315566433-16202-4-git-send-email-aneesh.kumar@linux.vnet.ibm.com
State New
Headers show

Commit Message

Aneesh Kumar K.V Sept. 9, 2011, 11:07 a.m. UTC
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 hw/9pfs/virtio-9p-synth.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/hw/9pfs/virtio-9p-synth.c b/hw/9pfs/virtio-9p-synth.c
index 72a916c..cbf74e4 100644
--- a/hw/9pfs/virtio-9p-synth.c
+++ b/hw/9pfs/virtio-9p-synth.c
@@ -517,8 +517,21 @@  static int v9fs_synth_unlinkat(FsContext *ctx, V9fsPath *dir,
     return -1;
 }
 
+static ssize_t my_test_read(void *in_buf, int len, off_t offset, void *arg)
+{
+    int  copy_len;
+    char buff[] = "Hello World\n";
+    if (offset >= sizeof(buff)) {
+        return 0;
+    }
+    copy_len = MIN(len, sizeof(buff));
+    memcpy(in_buf, buff + offset, copy_len);
+    return copy_len;
+}
+
 static int v9fs_synth_init(FsContext *ctx)
 {
+    V9fsSynthNode *node;
     pthread_rwlockattr_t rwlockattr;
 
     QLIST_INIT(&v9fs_synth_root.child);
@@ -533,6 +546,12 @@  static int v9fs_synth_init(FsContext *ctx)
 
     /* Mark the subsystem is ready for use */
     v9fs_synth_fs = 1;
+
+    /** create some new files as test */
+    qemu_v9fs_synth_mkdir(NULL, 0777, "test", &node);
+    qemu_v9fs_synth_mkdir(&v9fs_synth_root, 0777, "test2", &node);
+    qemu_v9fs_synth_add_file(node, 0777, "testfile",
+                             my_test_read, NULL, NULL);
     return 0;
 }