xref: /qemu/hw/9pfs/9p-synth.c (revision a9e0c9c0f14e19d23443ac24c8080b4708d2eab8)
1 /*
2  * 9p synthetic file system support
3  *
4  * Copyright IBM, Corp. 2011
5  *
6  * Authors:
7  *  Malahal Naineni <malahal@us.ibm.com>
8  *  Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
9  *
10  * This work is licensed under the terms of the GNU GPL, version 2.  See
11  * the COPYING file in the top-level directory.
12  *
13  */
14 
15 /*
16  * Not so fast! You might want to read the 9p developer docs first:
17  * https://wiki.qemu.org/Documentation/9p
18  */
19 
20 #include "qemu/osdep.h"
21 #include "9p.h"
22 #include "fsdev/qemu-fsdev.h"
23 #include "9p-synth.h"
24 #include "qemu/rcu.h"
25 #include "qemu/rcu_queue.h"
26 #include "qemu/cutils.h"
27 #include "system/qtest.h"
28 
29 /* Root node for synth file system */
30 static V9fsSynthNode synth_root = {
31     .name = "/",
32     .actual_attr = {
33         .mode = 0555 | S_IFDIR,
34         .nlink = 1,
35     },
36     .attr = &synth_root.actual_attr,
37 };
38 
39 static QemuMutex  synth_mutex;
40 static int synth_node_count;
41 /* set to 1 when the synth fs is ready */
42 static int synth_fs;
43 
v9fs_add_dir_node(V9fsSynthNode * parent,int mode,const char * name,V9fsSynthNodeAttr * attr,int inode)44 static V9fsSynthNode *v9fs_add_dir_node(V9fsSynthNode *parent, int mode,
45                                         const char *name,
46                                         V9fsSynthNodeAttr *attr, int inode)
47 {
48     V9fsSynthNode *node;
49 
50     /* Add directory type and remove write bits */
51     mode = ((mode & 0777) | S_IFDIR) & ~(S_IWUSR | S_IWGRP | S_IWOTH);
52     node = g_new0(V9fsSynthNode, 1);
53     if (attr) {
54         /* We are adding .. or . entries */
55         node->attr = attr;
56         node->attr->nlink++;
57     } else {
58         node->attr = &node->actual_attr;
59         node->attr->inode = inode;
60         node->attr->nlink = 1;
61         /* We don't allow write to directories */
62         node->attr->mode   = mode;
63         node->attr->write = NULL;
64         node->attr->read  = NULL;
65     }
66     node->private = node;
67     pstrcpy(node->name, sizeof(node->name), name);
68     QLIST_INSERT_HEAD_RCU(&parent->child, node, sibling);
69     return node;
70 }
71 
qemu_v9fs_synth_mkdir(V9fsSynthNode * parent,int mode,const char * name,V9fsSynthNode ** result)72 int qemu_v9fs_synth_mkdir(V9fsSynthNode *parent, int mode,
73                           const char *name, V9fsSynthNode **result)
74 {
75     V9fsSynthNode *node, *tmp;
76 
77     if (!synth_fs) {
78         return -EAGAIN;
79     }
80     if (!name || (strlen(name) >= NAME_MAX)) {
81         return -EINVAL;
82     }
83     if (!parent) {
84         parent = &synth_root;
85     }
86     QEMU_LOCK_GUARD(&synth_mutex);
87     QLIST_FOREACH(tmp, &parent->child, sibling) {
88         if (!strcmp(tmp->name, name)) {
89             return -EEXIST;
90         }
91     }
92     /* Add the name */
93     node = v9fs_add_dir_node(parent, mode, name, NULL, ++synth_node_count);
94     v9fs_add_dir_node(node, parent->attr->mode, "..",
95                       parent->attr, parent->attr->inode);
96     v9fs_add_dir_node(node, node->attr->mode, ".",
97                       node->attr, node->attr->inode);
98     *result = node;
99     return 0;
100 }
101 
qemu_v9fs_synth_add_file(V9fsSynthNode * parent,int mode,const char * name,v9fs_synth_read read,v9fs_synth_write write,void * arg)102 int qemu_v9fs_synth_add_file(V9fsSynthNode *parent, int mode,
103                              const char *name, v9fs_synth_read read,
104                              v9fs_synth_write write, void *arg)
105 {
106     V9fsSynthNode *node, *tmp;
107 
108     if (!synth_fs) {
109         return -EAGAIN;
110     }
111     if (!name || (strlen(name) >= NAME_MAX)) {
112         return -EINVAL;
113     }
114     if (!parent) {
115         parent = &synth_root;
116     }
117 
118     QEMU_LOCK_GUARD(&synth_mutex);
119     QLIST_FOREACH(tmp, &parent->child, sibling) {
120         if (!strcmp(tmp->name, name)) {
121             return -EEXIST;
122         }
123     }
124     /* Add file type and remove write bits */
125     mode = ((mode & 0777) | S_IFREG);
126     node = g_new0(V9fsSynthNode, 1);
127     node->attr         = &node->actual_attr;
128     node->attr->inode  = ++synth_node_count;
129     node->attr->nlink  = 1;
130     node->attr->read   = read;
131     node->attr->write  = write;
132     node->attr->mode   = mode;
133     node->private      = arg;
134     pstrcpy(node->name, sizeof(node->name), name);
135     QLIST_INSERT_HEAD_RCU(&parent->child, node, sibling);
136     return 0;
137 }
138 
synth_fill_statbuf(V9fsSynthNode * node,struct stat * stbuf)139 static void synth_fill_statbuf(V9fsSynthNode *node, struct stat *stbuf)
140 {
141     stbuf->st_dev = 0;
142     stbuf->st_ino = node->attr->inode;
143     stbuf->st_mode = node->attr->mode;
144     stbuf->st_nlink = node->attr->nlink;
145     stbuf->st_uid = 0;
146     stbuf->st_gid = 0;
147     stbuf->st_rdev = 0;
148     stbuf->st_size = 0;
149     stbuf->st_blksize = 0;
150     stbuf->st_blocks = 0;
151     stbuf->st_atime = 0;
152     stbuf->st_mtime = 0;
153     stbuf->st_ctime = 0;
154 }
155 
synth_lstat(FsContext * fs_ctx,V9fsPath * fs_path,struct stat * stbuf)156 static int synth_lstat(FsContext *fs_ctx,
157                             V9fsPath *fs_path, struct stat *stbuf)
158 {
159     V9fsSynthNode *node = *(V9fsSynthNode **)fs_path->data;
160 
161     synth_fill_statbuf(node, stbuf);
162     return 0;
163 }
164 
synth_fstat(FsContext * fs_ctx,int fid_type,V9fsFidOpenState * fs,struct stat * stbuf)165 static int synth_fstat(FsContext *fs_ctx, int fid_type,
166                             V9fsFidOpenState *fs, struct stat *stbuf)
167 {
168     V9fsSynthOpenState *synth_open = fs->private;
169     synth_fill_statbuf(synth_open->node, stbuf);
170     return 0;
171 }
172 
synth_opendir(FsContext * ctx,V9fsPath * fs_path,V9fsFidOpenState * fs)173 static int synth_opendir(FsContext *ctx,
174                              V9fsPath *fs_path, V9fsFidOpenState *fs)
175 {
176     V9fsSynthOpenState *synth_open;
177     V9fsSynthNode *node = *(V9fsSynthNode **)fs_path->data;
178 
179     /*
180      * V9fsSynthOpenState contains 'struct dirent' which have OS-specific
181      * properties, thus it's zero cleared on allocation here and below
182      * in synth_open.
183      */
184     synth_open = g_new0(V9fsSynthOpenState, 1);
185     synth_open->node = node;
186     node->open_count++;
187     fs->private = synth_open;
188     return 0;
189 }
190 
synth_closedir(FsContext * ctx,V9fsFidOpenState * fs)191 static int synth_closedir(FsContext *ctx, V9fsFidOpenState *fs)
192 {
193     V9fsSynthOpenState *synth_open = fs->private;
194     V9fsSynthNode *node = synth_open->node;
195 
196     node->open_count--;
197     g_free(synth_open);
198     fs->private = NULL;
199     return 0;
200 }
201 
synth_telldir(FsContext * ctx,V9fsFidOpenState * fs)202 static off_t synth_telldir(FsContext *ctx, V9fsFidOpenState *fs)
203 {
204     V9fsSynthOpenState *synth_open = fs->private;
205     return synth_open->offset;
206 }
207 
synth_seekdir(FsContext * ctx,V9fsFidOpenState * fs,off_t off)208 static void synth_seekdir(FsContext *ctx, V9fsFidOpenState *fs, off_t off)
209 {
210     V9fsSynthOpenState *synth_open = fs->private;
211     synth_open->offset = off;
212 }
213 
synth_rewinddir(FsContext * ctx,V9fsFidOpenState * fs)214 static void synth_rewinddir(FsContext *ctx, V9fsFidOpenState *fs)
215 {
216     synth_seekdir(ctx, fs, 0);
217 }
218 
synth_direntry(V9fsSynthNode * node,struct dirent * entry,off_t off)219 static void synth_direntry(V9fsSynthNode *node,
220                                 struct dirent *entry, off_t off)
221 {
222     size_t sz = strlen(node->name) + 1;
223     /*
224      * 'entry' is always inside of V9fsSynthOpenState which have NAME_MAX
225      * back padding. Ensure we do not overflow it.
226      */
227     g_assert(sizeof(struct dirent) + NAME_MAX >=
228              offsetof(struct dirent, d_name) + sz);
229     memcpy(entry->d_name, node->name, sz);
230     entry->d_ino = node->attr->inode;
231 #ifdef CONFIG_DARWIN
232     entry->d_seekoff = off + 1;
233 #else
234     entry->d_off = off + 1;
235 #endif
236 }
237 
synth_get_dentry(V9fsSynthNode * dir,struct dirent * entry,off_t off)238 static struct dirent *synth_get_dentry(V9fsSynthNode *dir,
239                                             struct dirent *entry, off_t off)
240 {
241     int i = 0;
242     V9fsSynthNode *node;
243 
244     rcu_read_lock();
245     QLIST_FOREACH(node, &dir->child, sibling) {
246         /* This is the off child of the directory */
247         if (i == off) {
248             break;
249         }
250         i++;
251     }
252     rcu_read_unlock();
253     if (!node) {
254         /* end of directory */
255         return NULL;
256     }
257     synth_direntry(node, entry, off);
258     return entry;
259 }
260 
synth_readdir(FsContext * ctx,V9fsFidOpenState * fs)261 static struct dirent *synth_readdir(FsContext *ctx, V9fsFidOpenState *fs)
262 {
263     struct dirent *entry;
264     V9fsSynthOpenState *synth_open = fs->private;
265     V9fsSynthNode *node = synth_open->node;
266     entry = synth_get_dentry(node, &synth_open->dent, synth_open->offset);
267     if (entry) {
268         synth_open->offset++;
269     }
270     return entry;
271 }
272 
synth_open(FsContext * ctx,V9fsPath * fs_path,int flags,V9fsFidOpenState * fs)273 static int synth_open(FsContext *ctx, V9fsPath *fs_path,
274                            int flags, V9fsFidOpenState *fs)
275 {
276     V9fsSynthOpenState *synth_open;
277     V9fsSynthNode *node = *(V9fsSynthNode **)fs_path->data;
278 
279     synth_open = g_new0(V9fsSynthOpenState, 1);
280     synth_open->node = node;
281     node->open_count++;
282     fs->private = synth_open;
283     return 0;
284 }
285 
synth_open2(FsContext * fs_ctx,V9fsPath * dir_path,const char * name,int flags,FsCred * credp,V9fsFidOpenState * fs)286 static int synth_open2(FsContext *fs_ctx, V9fsPath *dir_path,
287                             const char *name, int flags,
288                             FsCred *credp, V9fsFidOpenState *fs)
289 {
290     errno = ENOSYS;
291     return -1;
292 }
293 
synth_close(FsContext * ctx,V9fsFidOpenState * fs)294 static int synth_close(FsContext *ctx, V9fsFidOpenState *fs)
295 {
296     V9fsSynthOpenState *synth_open = fs->private;
297     V9fsSynthNode *node = synth_open->node;
298 
299     node->open_count--;
300     g_free(synth_open);
301     fs->private = NULL;
302     return 0;
303 }
304 
synth_pwritev(FsContext * ctx,V9fsFidOpenState * fs,const struct iovec * iov,int iovcnt,off_t offset)305 static ssize_t synth_pwritev(FsContext *ctx, V9fsFidOpenState *fs,
306                                   const struct iovec *iov,
307                                   int iovcnt, off_t offset)
308 {
309     int i, count = 0, wcount;
310     V9fsSynthOpenState *synth_open = fs->private;
311     V9fsSynthNode *node = synth_open->node;
312     if (!node->attr->write) {
313         errno = EPERM;
314         return -1;
315     }
316     for (i = 0; i < iovcnt; i++) {
317         wcount = node->attr->write(iov[i].iov_base, iov[i].iov_len,
318                                    offset, node->private);
319         offset += wcount;
320         count  += wcount;
321         /* If we wrote less than requested. we are done */
322         if (wcount < iov[i].iov_len) {
323             break;
324         }
325     }
326     return count;
327 }
328 
synth_preadv(FsContext * ctx,V9fsFidOpenState * fs,const struct iovec * iov,int iovcnt,off_t offset)329 static ssize_t synth_preadv(FsContext *ctx, V9fsFidOpenState *fs,
330                                  const struct iovec *iov,
331                                  int iovcnt, off_t offset)
332 {
333     int i, count = 0, rcount;
334     V9fsSynthOpenState *synth_open = fs->private;
335     V9fsSynthNode *node = synth_open->node;
336     if (!node->attr->read) {
337         errno = EPERM;
338         return -1;
339     }
340     for (i = 0; i < iovcnt; i++) {
341         rcount = node->attr->read(iov[i].iov_base, iov[i].iov_len,
342                                   offset, node->private);
343         offset += rcount;
344         count  += rcount;
345         /* If we read less than requested. we are done */
346         if (rcount < iov[i].iov_len) {
347             break;
348         }
349     }
350     return count;
351 }
352 
synth_truncate(FsContext * ctx,V9fsPath * path,off_t offset)353 static int synth_truncate(FsContext *ctx, V9fsPath *path, off_t offset)
354 {
355     errno = ENOSYS;
356     return -1;
357 }
358 
synth_ftruncate(FsContext * ctx,int fid_type,V9fsFidOpenState * fs,off_t size)359 static int synth_ftruncate(FsContext *ctx, int fid_type, V9fsFidOpenState *fs,
360                            off_t size)
361 {
362     errno = ENOSYS;
363     return -1;
364 }
365 
synth_chmod(FsContext * fs_ctx,V9fsPath * path,FsCred * credp)366 static int synth_chmod(FsContext *fs_ctx, V9fsPath *path, FsCred *credp)
367 {
368     errno = EPERM;
369     return -1;
370 }
371 
synth_mknod(FsContext * fs_ctx,V9fsPath * path,const char * buf,FsCred * credp)372 static int synth_mknod(FsContext *fs_ctx, V9fsPath *path,
373                        const char *buf, FsCred *credp)
374 {
375     errno = EPERM;
376     return -1;
377 }
378 
synth_mkdir(FsContext * fs_ctx,V9fsPath * path,const char * buf,FsCred * credp)379 static int synth_mkdir(FsContext *fs_ctx, V9fsPath *path,
380                        const char *buf, FsCred *credp)
381 {
382     errno = EPERM;
383     return -1;
384 }
385 
synth_readlink(FsContext * fs_ctx,V9fsPath * path,char * buf,size_t bufsz)386 static ssize_t synth_readlink(FsContext *fs_ctx, V9fsPath *path,
387                                    char *buf, size_t bufsz)
388 {
389     errno = ENOSYS;
390     return -1;
391 }
392 
synth_symlink(FsContext * fs_ctx,const char * oldpath,V9fsPath * newpath,const char * buf,FsCred * credp)393 static int synth_symlink(FsContext *fs_ctx, const char *oldpath,
394                               V9fsPath *newpath, const char *buf, FsCred *credp)
395 {
396     errno = EPERM;
397     return -1;
398 }
399 
synth_link(FsContext * fs_ctx,V9fsPath * oldpath,V9fsPath * newpath,const char * buf)400 static int synth_link(FsContext *fs_ctx, V9fsPath *oldpath,
401                            V9fsPath *newpath, const char *buf)
402 {
403     errno = EPERM;
404     return -1;
405 }
406 
synth_rename(FsContext * ctx,const char * oldpath,const char * newpath)407 static int synth_rename(FsContext *ctx, const char *oldpath,
408                              const char *newpath)
409 {
410     errno = EPERM;
411     return -1;
412 }
413 
synth_chown(FsContext * fs_ctx,V9fsPath * path,FsCred * credp)414 static int synth_chown(FsContext *fs_ctx, V9fsPath *path, FsCred *credp)
415 {
416     errno = EPERM;
417     return -1;
418 }
419 
synth_utimensat(FsContext * fs_ctx,V9fsPath * path,const struct timespec * buf)420 static int synth_utimensat(FsContext *fs_ctx, V9fsPath *path,
421                                 const struct timespec *buf)
422 {
423     errno = EPERM;
424     return 0;
425 }
426 
synth_futimens(FsContext * fs_ctx,int fid_type,V9fsFidOpenState * fs,const struct timespec * buf)427 static int synth_futimens(FsContext *fs_ctx, int fid_type, V9fsFidOpenState *fs,
428                           const struct timespec *buf)
429 {
430     errno = ENOSYS;
431     return -1;
432 }
433 
synth_remove(FsContext * ctx,const char * path)434 static int synth_remove(FsContext *ctx, const char *path)
435 {
436     errno = EPERM;
437     return -1;
438 }
439 
synth_fsync(FsContext * ctx,int fid_type,V9fsFidOpenState * fs,int datasync)440 static int synth_fsync(FsContext *ctx, int fid_type,
441                             V9fsFidOpenState *fs, int datasync)
442 {
443     errno = ENOSYS;
444     return 0;
445 }
446 
synth_statfs(FsContext * s,V9fsPath * fs_path,struct statfs * stbuf)447 static int synth_statfs(FsContext *s, V9fsPath *fs_path,
448                              struct statfs *stbuf)
449 {
450     stbuf->f_type = 0xABCD;
451     stbuf->f_bsize = 512;
452     stbuf->f_blocks = 0;
453     stbuf->f_files = synth_node_count;
454 #ifndef CONFIG_DARWIN
455     stbuf->f_namelen = NAME_MAX;
456 #endif
457     return 0;
458 }
459 
synth_lgetxattr(FsContext * ctx,V9fsPath * path,const char * name,void * value,size_t size)460 static ssize_t synth_lgetxattr(FsContext *ctx, V9fsPath *path,
461                                     const char *name, void *value, size_t size)
462 {
463     errno = ENOTSUP;
464     return -1;
465 }
466 
synth_llistxattr(FsContext * ctx,V9fsPath * path,void * value,size_t size)467 static ssize_t synth_llistxattr(FsContext *ctx, V9fsPath *path,
468                                      void *value, size_t size)
469 {
470     errno = ENOTSUP;
471     return -1;
472 }
473 
synth_lsetxattr(FsContext * ctx,V9fsPath * path,const char * name,void * value,size_t size,int flags)474 static int synth_lsetxattr(FsContext *ctx, V9fsPath *path,
475                                 const char *name, void *value,
476                                 size_t size, int flags)
477 {
478     errno = ENOTSUP;
479     return -1;
480 }
481 
synth_lremovexattr(FsContext * ctx,V9fsPath * path,const char * name)482 static int synth_lremovexattr(FsContext *ctx,
483                                    V9fsPath *path, const char *name)
484 {
485     errno = ENOTSUP;
486     return -1;
487 }
488 
synth_name_to_path(FsContext * ctx,V9fsPath * dir_path,const char * name,V9fsPath * target)489 static int synth_name_to_path(FsContext *ctx, V9fsPath *dir_path,
490                                    const char *name, V9fsPath *target)
491 {
492     V9fsSynthNode *node;
493     V9fsSynthNode *dir_node;
494 
495     /* "." and ".." are not allowed */
496     if (!strcmp(name, ".") || !strcmp(name, "..")) {
497         errno = EINVAL;
498         return -1;
499 
500     }
501     if (!dir_path) {
502         dir_node = &synth_root;
503     } else {
504         dir_node = *(V9fsSynthNode **)dir_path->data;
505     }
506     if (!strcmp(name, "/")) {
507         node = dir_node;
508         goto out;
509     }
510     /* search for the name in the children */
511     rcu_read_lock();
512     QLIST_FOREACH(node, &dir_node->child, sibling) {
513         if (!strcmp(node->name, name)) {
514             break;
515         }
516     }
517     rcu_read_unlock();
518 
519     if (!node) {
520         errno = ENOENT;
521         return -1;
522     }
523 out:
524     /* Copy the node pointer to fid */
525     g_free(target->data);
526     target->data = g_memdup(&node, sizeof(void *));
527     target->size = sizeof(void *);
528     return 0;
529 }
530 
synth_renameat(FsContext * ctx,V9fsPath * olddir,const char * old_name,V9fsPath * newdir,const char * new_name)531 static int synth_renameat(FsContext *ctx, V9fsPath *olddir,
532                                const char *old_name, V9fsPath *newdir,
533                                const char *new_name)
534 {
535     errno = EPERM;
536     return -1;
537 }
538 
synth_unlinkat(FsContext * ctx,V9fsPath * dir,const char * name,int flags)539 static int synth_unlinkat(FsContext *ctx, V9fsPath *dir,
540                                const char *name, int flags)
541 {
542     errno = EPERM;
543     return -1;
544 }
545 
v9fs_synth_qtest_write(void * buf,int len,off_t offset,void * arg)546 static ssize_t v9fs_synth_qtest_write(void *buf, int len, off_t offset,
547                                       void *arg)
548 {
549     return 1;
550 }
551 
v9fs_synth_qtest_flush_write(void * buf,int len,off_t offset,void * arg)552 static ssize_t v9fs_synth_qtest_flush_write(void *buf, int len, off_t offset,
553                                             void *arg)
554 {
555     bool should_block = !!*(uint8_t *)buf;
556 
557     if (should_block) {
558         /* This will cause the server to call us again until we're cancelled */
559         errno = EINTR;
560         return -1;
561     }
562 
563     return 1;
564 }
565 
synth_init(FsContext * ctx,Error ** errp)566 static int synth_init(FsContext *ctx, Error **errp)
567 {
568     QLIST_INIT(&synth_root.child);
569     qemu_mutex_init(&synth_mutex);
570 
571     /* Add "." and ".." entries for root */
572     v9fs_add_dir_node(&synth_root, synth_root.attr->mode,
573                       "..", synth_root.attr, synth_root.attr->inode);
574     v9fs_add_dir_node(&synth_root, synth_root.attr->mode,
575                       ".", synth_root.attr, synth_root.attr->inode);
576 
577     /* Mark the subsystem is ready for use */
578     synth_fs = 1;
579 
580     if (qtest_enabled()) {
581         V9fsSynthNode *node = NULL;
582         int i, ret;
583 
584         /* Directory hierarchy for WALK test */
585         for (i = 0; i < P9_MAXWELEM; i++) {
586             char *name = g_strdup_printf(QTEST_V9FS_SYNTH_WALK_FILE, i);
587 
588             ret = qemu_v9fs_synth_mkdir(node, 0700, name, &node);
589             assert(!ret);
590             g_free(name);
591         }
592 
593         /* File for LOPEN test */
594         ret = qemu_v9fs_synth_add_file(NULL, 0, QTEST_V9FS_SYNTH_LOPEN_FILE,
595                                        NULL, NULL, ctx);
596         assert(!ret);
597 
598         /* File for WRITE test */
599         ret = qemu_v9fs_synth_add_file(NULL, 0, QTEST_V9FS_SYNTH_WRITE_FILE,
600                                        NULL, v9fs_synth_qtest_write, ctx);
601         assert(!ret);
602 
603         /* File for FLUSH test */
604         ret = qemu_v9fs_synth_add_file(NULL, 0, QTEST_V9FS_SYNTH_FLUSH_FILE,
605                                        NULL, v9fs_synth_qtest_flush_write,
606                                        ctx);
607         assert(!ret);
608 
609         /* Directory for READDIR test */
610         {
611             V9fsSynthNode *dir = NULL;
612             ret = qemu_v9fs_synth_mkdir(
613                 NULL, 0700, QTEST_V9FS_SYNTH_READDIR_DIR, &dir
614             );
615             assert(!ret);
616             for (i = 0; i < QTEST_V9FS_SYNTH_READDIR_NFILES; ++i) {
617                 char *name = g_strdup_printf(
618                     QTEST_V9FS_SYNTH_READDIR_FILE, i
619                 );
620                 ret = qemu_v9fs_synth_add_file(
621                     dir, 0, name, NULL, NULL, ctx
622                 );
623                 assert(!ret);
624                 g_free(name);
625             }
626         }
627     }
628 
629     return 0;
630 }
631 
synth_has_valid_file_handle(int fid_type,V9fsFidOpenState * fs)632 static bool synth_has_valid_file_handle(int fid_type, V9fsFidOpenState *fs)
633 {
634     return false;
635 }
636 
637 FileOperations synth_ops = {
638     .init         = synth_init,
639     .lstat        = synth_lstat,
640     .readlink     = synth_readlink,
641     .close        = synth_close,
642     .closedir     = synth_closedir,
643     .open         = synth_open,
644     .opendir      = synth_opendir,
645     .rewinddir    = synth_rewinddir,
646     .telldir      = synth_telldir,
647     .readdir      = synth_readdir,
648     .seekdir      = synth_seekdir,
649     .preadv       = synth_preadv,
650     .pwritev      = synth_pwritev,
651     .chmod        = synth_chmod,
652     .mknod        = synth_mknod,
653     .mkdir        = synth_mkdir,
654     .fstat        = synth_fstat,
655     .open2        = synth_open2,
656     .symlink      = synth_symlink,
657     .link         = synth_link,
658     .truncate     = synth_truncate,
659     .rename       = synth_rename,
660     .chown        = synth_chown,
661     .utimensat    = synth_utimensat,
662     .remove       = synth_remove,
663     .fsync        = synth_fsync,
664     .statfs       = synth_statfs,
665     .lgetxattr    = synth_lgetxattr,
666     .llistxattr   = synth_llistxattr,
667     .lsetxattr    = synth_lsetxattr,
668     .lremovexattr = synth_lremovexattr,
669     .name_to_path = synth_name_to_path,
670     .renameat     = synth_renameat,
671     .unlinkat     = synth_unlinkat,
672     .has_valid_file_handle = synth_has_valid_file_handle,
673     .ftruncate    = synth_ftruncate,
674     .futimens     = synth_futimens,
675 };
676