1364031f1SWei Liu /* 2364031f1SWei Liu * 9p 3364031f1SWei Liu * 4364031f1SWei Liu * Copyright IBM, Corp. 2011 5364031f1SWei Liu * 6364031f1SWei Liu * Authors: 7364031f1SWei Liu * Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> 8364031f1SWei Liu * 9364031f1SWei Liu * This work is licensed under the terms of the GNU GPL, version 2. See 10364031f1SWei Liu * the COPYING file in the top-level directory. 11364031f1SWei Liu * 12364031f1SWei Liu */ 13364031f1SWei Liu 14121d0712SMarkus Armbruster #ifndef QEMU_9P_SYNTH_H 15121d0712SMarkus Armbruster #define QEMU_9P_SYNTH_H 16364031f1SWei Liu 17364031f1SWei Liu typedef struct V9fsSynthNode V9fsSynthNode; 18364031f1SWei Liu typedef ssize_t (*v9fs_synth_read)(void *buf, int len, off_t offset, 19364031f1SWei Liu void *arg); 20364031f1SWei Liu typedef ssize_t (*v9fs_synth_write)(void *buf, int len, off_t offset, 21364031f1SWei Liu void *arg); 22364031f1SWei Liu typedef struct V9fsSynthNodeAttr { 23364031f1SWei Liu int mode; 24364031f1SWei Liu int inode; 25364031f1SWei Liu int nlink; 26364031f1SWei Liu v9fs_synth_read read; 27364031f1SWei Liu v9fs_synth_write write; 28364031f1SWei Liu } V9fsSynthNodeAttr; 29364031f1SWei Liu 30364031f1SWei Liu struct V9fsSynthNode { 31364031f1SWei Liu QLIST_HEAD(, V9fsSynthNode) child; 32364031f1SWei Liu QLIST_ENTRY(V9fsSynthNode) sibling; 33364031f1SWei Liu char name[NAME_MAX]; 34364031f1SWei Liu V9fsSynthNodeAttr *attr; 35364031f1SWei Liu V9fsSynthNodeAttr actual_attr; 36364031f1SWei Liu void *private; 37364031f1SWei Liu int open_count; 38364031f1SWei Liu }; 39364031f1SWei Liu 40364031f1SWei Liu typedef struct V9fsSynthOpenState { 41364031f1SWei Liu off_t offset; 42364031f1SWei Liu 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]; 49364031f1SWei Liu } V9fsSynthOpenState; 50364031f1SWei Liu 51bc70a592SGreg Kurz int qemu_v9fs_synth_mkdir(V9fsSynthNode *parent, int mode, 52364031f1SWei Liu const char *name, V9fsSynthNode **result); 53bc70a592SGreg Kurz int qemu_v9fs_synth_add_file(V9fsSynthNode *parent, int mode, 54364031f1SWei Liu const char *name, v9fs_synth_read read, 55364031f1SWei Liu v9fs_synth_write write, void *arg); 56364031f1SWei Liu 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 75364031f1SWei Liu #endif 76