xref: /qemu/hw/9pfs/9p-synth.h (revision 439346ce8fa32095433a9abb2aa3564d11283372)
19db221aeSAneesh Kumar K.V /*
2364031f1SWei Liu  * 9p
39db221aeSAneesh Kumar K.V  *
49db221aeSAneesh Kumar K.V  * Copyright IBM, Corp. 2011
59db221aeSAneesh Kumar K.V  *
69db221aeSAneesh Kumar K.V  * Authors:
79db221aeSAneesh Kumar K.V  *  Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
89db221aeSAneesh Kumar K.V  *
99db221aeSAneesh Kumar K.V  * This work is licensed under the terms of the GNU GPL, version 2.  See
109db221aeSAneesh Kumar K.V  * the COPYING file in the top-level directory.
119db221aeSAneesh Kumar K.V  *
129db221aeSAneesh Kumar K.V  */
139db221aeSAneesh Kumar K.V 
14121d0712SMarkus Armbruster #ifndef QEMU_9P_SYNTH_H
15121d0712SMarkus Armbruster #define QEMU_9P_SYNTH_H
169db221aeSAneesh Kumar K.V 
179db221aeSAneesh Kumar K.V typedef struct V9fsSynthNode V9fsSynthNode;
189db221aeSAneesh Kumar K.V typedef ssize_t (*v9fs_synth_read)(void *buf, int len, off_t offset,
199db221aeSAneesh Kumar K.V                                    void *arg);
209db221aeSAneesh Kumar K.V typedef ssize_t (*v9fs_synth_write)(void *buf, int len, off_t offset,
219db221aeSAneesh Kumar K.V                                     void *arg);
229db221aeSAneesh Kumar K.V typedef struct V9fsSynthNodeAttr {
239db221aeSAneesh Kumar K.V     int mode;
249db221aeSAneesh Kumar K.V     int inode;
259db221aeSAneesh Kumar K.V     int nlink;
269db221aeSAneesh Kumar K.V     v9fs_synth_read read;
279db221aeSAneesh Kumar K.V     v9fs_synth_write write;
289db221aeSAneesh Kumar K.V } V9fsSynthNodeAttr;
299db221aeSAneesh Kumar K.V 
309db221aeSAneesh Kumar K.V struct V9fsSynthNode {
319db221aeSAneesh Kumar K.V     QLIST_HEAD(, V9fsSynthNode) child;
329db221aeSAneesh Kumar K.V     QLIST_ENTRY(V9fsSynthNode) sibling;
339db221aeSAneesh Kumar K.V     char name[NAME_MAX];
349db221aeSAneesh Kumar K.V     V9fsSynthNodeAttr *attr;
359db221aeSAneesh Kumar K.V     V9fsSynthNodeAttr actual_attr;
369db221aeSAneesh Kumar K.V     void *private;
379db221aeSAneesh Kumar K.V     int open_count;
389db221aeSAneesh Kumar K.V };
399db221aeSAneesh Kumar K.V 
409db221aeSAneesh Kumar K.V typedef struct V9fsSynthOpenState {
419db221aeSAneesh Kumar K.V     off_t offset;
429db221aeSAneesh Kumar K.V     V9fsSynthNode *node;
43635324e8SGreg Kurz     struct dirent dent;
44*e64e27d5SVitaly Chikunov     /*
45*e64e27d5SVitaly Chikunov      * Ensure there is enough space for 'dent' above, some systems have a
46*e64e27d5SVitaly Chikunov      * d_name size of just 1, which would cause a buffer overrun.
47*e64e27d5SVitaly Chikunov      */
48*e64e27d5SVitaly Chikunov     char dent_trailing_space[NAME_MAX];
499db221aeSAneesh Kumar K.V } V9fsSynthOpenState;
509db221aeSAneesh Kumar K.V 
51bc70a592SGreg Kurz int qemu_v9fs_synth_mkdir(V9fsSynthNode *parent, int mode,
529db221aeSAneesh Kumar K.V                           const char *name, V9fsSynthNode **result);
53bc70a592SGreg Kurz int qemu_v9fs_synth_add_file(V9fsSynthNode *parent, int mode,
549db221aeSAneesh Kumar K.V                              const char *name, v9fs_synth_read read,
559db221aeSAneesh Kumar K.V                              v9fs_synth_write write, void *arg);
56cb9c377fSPaolo Bonzini 
572893ddd5SGreg Kurz /* qtest stuff */
582893ddd5SGreg Kurz 
592893ddd5SGreg Kurz #define QTEST_V9FS_SYNTH_WALK_FILE "WALK%d"
6082469aaeSGreg Kurz #define QTEST_V9FS_SYNTH_LOPEN_FILE "LOPEN"
61354b86f8SGreg Kurz #define QTEST_V9FS_SYNTH_WRITE_FILE "WRITE"
622893ddd5SGreg Kurz 
63af46a3b2SChristian Schoenebeck /* for READDIR test */
64af46a3b2SChristian Schoenebeck #define QTEST_V9FS_SYNTH_READDIR_DIR "ReadDirDir"
65af46a3b2SChristian Schoenebeck #define QTEST_V9FS_SYNTH_READDIR_FILE "ReadDirFile%d"
66af46a3b2SChristian Schoenebeck #define QTEST_V9FS_SYNTH_READDIR_NFILES 100
67af46a3b2SChristian Schoenebeck 
68357e2f7fSGreg Kurz /* Any write to the "FLUSH" file is handled one byte at a time by the
69357e2f7fSGreg Kurz  * backend. If the byte is zero, the backend returns success (ie, 1),
70357e2f7fSGreg Kurz  * otherwise it forces the server to try again forever. Thus allowing
71357e2f7fSGreg Kurz  * the client to cancel the request.
72357e2f7fSGreg Kurz  */
73357e2f7fSGreg Kurz #define QTEST_V9FS_SYNTH_FLUSH_FILE "FLUSH"
74357e2f7fSGreg Kurz 
75cb9c377fSPaolo Bonzini #endif
76