Annotation of qemu/hw/9pfs/virtio-9p.h, revision 1.1

1.1     ! root        1: #ifndef _QEMU_VIRTIO_9P_H
        !             2: #define _QEMU_VIRTIO_9P_H
        !             3: 
        !             4: #include <sys/types.h>
        !             5: #include <dirent.h>
        !             6: #include <sys/time.h>
        !             7: #include <utime.h>
        !             8: 
        !             9: #include "fsdev/file-op-9p.h"
        !            10: 
        !            11: /* The feature bitmap for virtio 9P */
        !            12: /* The mount point is specified in a config variable */
        !            13: #define VIRTIO_9P_MOUNT_TAG 0
        !            14: 
        !            15: enum {
        !            16:     P9_TLERROR = 6,
        !            17:     P9_RLERROR,
        !            18:     P9_TSTATFS = 8,
        !            19:     P9_RSTATFS,
        !            20:     P9_TLOPEN = 12,
        !            21:     P9_RLOPEN,
        !            22:     P9_TLCREATE = 14,
        !            23:     P9_RLCREATE,
        !            24:     P9_TSYMLINK = 16,
        !            25:     P9_RSYMLINK,
        !            26:     P9_TMKNOD = 18,
        !            27:     P9_RMKNOD,
        !            28:     P9_TRENAME = 20,
        !            29:     P9_RRENAME,
        !            30:     P9_TREADLINK = 22,
        !            31:     P9_RREADLINK,
        !            32:     P9_TGETATTR = 24,
        !            33:     P9_RGETATTR,
        !            34:     P9_TSETATTR = 26,
        !            35:     P9_RSETATTR,
        !            36:     P9_TXATTRWALK = 30,
        !            37:     P9_RXATTRWALK,
        !            38:     P9_TXATTRCREATE = 32,
        !            39:     P9_RXATTRCREATE,
        !            40:     P9_TREADDIR = 40,
        !            41:     P9_RREADDIR,
        !            42:     P9_TFSYNC = 50,
        !            43:     P9_RFSYNC,
        !            44:     P9_TLOCK = 52,
        !            45:     P9_RLOCK,
        !            46:     P9_TGETLOCK = 54,
        !            47:     P9_RGETLOCK,
        !            48:     P9_TLINK = 70,
        !            49:     P9_RLINK,
        !            50:     P9_TMKDIR = 72,
        !            51:     P9_RMKDIR,
        !            52:     P9_TVERSION = 100,
        !            53:     P9_RVERSION,
        !            54:     P9_TAUTH = 102,
        !            55:     P9_RAUTH,
        !            56:     P9_TATTACH = 104,
        !            57:     P9_RATTACH,
        !            58:     P9_TERROR = 106,
        !            59:     P9_RERROR,
        !            60:     P9_TFLUSH = 108,
        !            61:     P9_RFLUSH,
        !            62:     P9_TWALK = 110,
        !            63:     P9_RWALK,
        !            64:     P9_TOPEN = 112,
        !            65:     P9_ROPEN,
        !            66:     P9_TCREATE = 114,
        !            67:     P9_RCREATE,
        !            68:     P9_TREAD = 116,
        !            69:     P9_RREAD,
        !            70:     P9_TWRITE = 118,
        !            71:     P9_RWRITE,
        !            72:     P9_TCLUNK = 120,
        !            73:     P9_RCLUNK,
        !            74:     P9_TREMOVE = 122,
        !            75:     P9_RREMOVE,
        !            76:     P9_TSTAT = 124,
        !            77:     P9_RSTAT,
        !            78:     P9_TWSTAT = 126,
        !            79:     P9_RWSTAT,
        !            80: };
        !            81: 
        !            82: 
        !            83: /* qid.types */
        !            84: enum {
        !            85:     P9_QTDIR = 0x80,
        !            86:     P9_QTAPPEND = 0x40,
        !            87:     P9_QTEXCL = 0x20,
        !            88:     P9_QTMOUNT = 0x10,
        !            89:     P9_QTAUTH = 0x08,
        !            90:     P9_QTTMP = 0x04,
        !            91:     P9_QTSYMLINK = 0x02,
        !            92:     P9_QTLINK = 0x01,
        !            93:     P9_QTFILE = 0x00,
        !            94: };
        !            95: 
        !            96: enum p9_proto_version {
        !            97:     V9FS_PROTO_2000U = 0x01,
        !            98:     V9FS_PROTO_2000L = 0x02,
        !            99: };
        !           100: 
        !           101: #define P9_NOTAG    (u16)(~0)
        !           102: #define P9_NOFID    (u32)(~0)
        !           103: #define P9_MAXWELEM 16
        !           104: static inline const char *rpath(FsContext *ctx, const char *path, char *buffer)
        !           105: {
        !           106:     snprintf(buffer, PATH_MAX, "%s/%s", ctx->fs_root, path);
        !           107:     return buffer;
        !           108: }
        !           109: 
        !           110: /*
        !           111:  * ample room for Twrite/Rread header
        !           112:  * size[4] Tread/Twrite tag[2] fid[4] offset[8] count[4]
        !           113:  */
        !           114: #define P9_IOHDRSZ 24
        !           115: 
        !           116: typedef struct V9fsPDU V9fsPDU;
        !           117: 
        !           118: struct V9fsPDU
        !           119: {
        !           120:     uint32_t size;
        !           121:     uint16_t tag;
        !           122:     uint8_t id;
        !           123:     VirtQueueElement elem;
        !           124:     QLIST_ENTRY(V9fsPDU) next;
        !           125: };
        !           126: 
        !           127: 
        !           128: /* FIXME
        !           129:  * 1) change user needs to set groups and stuff
        !           130:  */
        !           131: 
        !           132: /* from Linux's linux/virtio_9p.h */
        !           133: 
        !           134: /* The ID for virtio console */
        !           135: #define VIRTIO_ID_9P    9
        !           136: #define MAX_REQ         128
        !           137: #define MAX_TAG_LEN     32
        !           138: 
        !           139: #define BUG_ON(cond) assert(!(cond))
        !           140: 
        !           141: typedef struct V9fsFidState V9fsFidState;
        !           142: 
        !           143: typedef struct V9fsString
        !           144: {
        !           145:     int16_t size;
        !           146:     char *data;
        !           147: } V9fsString;
        !           148: 
        !           149: typedef struct V9fsQID
        !           150: {
        !           151:     int8_t type;
        !           152:     int32_t version;
        !           153:     int64_t path;
        !           154: } V9fsQID;
        !           155: 
        !           156: typedef struct V9fsStat
        !           157: {
        !           158:     int16_t size;
        !           159:     int16_t type;
        !           160:     int32_t dev;
        !           161:     V9fsQID qid;
        !           162:     int32_t mode;
        !           163:     int32_t atime;
        !           164:     int32_t mtime;
        !           165:     int64_t length;
        !           166:     V9fsString name;
        !           167:     V9fsString uid;
        !           168:     V9fsString gid;
        !           169:     V9fsString muid;
        !           170:     /* 9p2000.u */
        !           171:     V9fsString extension;
        !           172:    int32_t n_uid;
        !           173:     int32_t n_gid;
        !           174:     int32_t n_muid;
        !           175: } V9fsStat;
        !           176: 
        !           177: enum {
        !           178:     P9_FID_NONE = 0,
        !           179:     P9_FID_FILE,
        !           180:     P9_FID_DIR,
        !           181:     P9_FID_XATTR,
        !           182: };
        !           183: 
        !           184: typedef struct V9fsXattr
        !           185: {
        !           186:     int64_t copied_len;
        !           187:     int64_t len;
        !           188:     void *value;
        !           189:     V9fsString name;
        !           190:     int flags;
        !           191: } V9fsXattr;
        !           192: 
        !           193: struct V9fsFidState
        !           194: {
        !           195:     int fid_type;
        !           196:     int32_t fid;
        !           197:     V9fsString path;
        !           198:     union {
        !           199:        int fd;
        !           200:        DIR *dir;
        !           201:        V9fsXattr xattr;
        !           202:     } fs;
        !           203:     uid_t uid;
        !           204:     V9fsFidState *next;
        !           205: };
        !           206: 
        !           207: typedef struct V9fsState
        !           208: {
        !           209:     VirtIODevice vdev;
        !           210:     VirtQueue *vq;
        !           211:     V9fsPDU pdus[MAX_REQ];
        !           212:     QLIST_HEAD(, V9fsPDU) free_list;
        !           213:     V9fsFidState *fid_list;
        !           214:     FileOperations *ops;
        !           215:     FsContext ctx;
        !           216:     uint16_t tag_len;
        !           217:     uint8_t *tag;
        !           218:     size_t config_size;
        !           219:     enum p9_proto_version proto_version;
        !           220:     int32_t msize;
        !           221: } V9fsState;
        !           222: 
        !           223: typedef struct V9fsCreateState {
        !           224:     V9fsPDU *pdu;
        !           225:     size_t offset;
        !           226:     V9fsFidState *fidp;
        !           227:     V9fsQID qid;
        !           228:     int32_t perm;
        !           229:     int8_t mode;
        !           230:     struct stat stbuf;
        !           231:     V9fsString name;
        !           232:     V9fsString extension;
        !           233:     V9fsString fullname;
        !           234:     int iounit;
        !           235: } V9fsCreateState;
        !           236: 
        !           237: typedef struct V9fsLcreateState {
        !           238:     V9fsPDU *pdu;
        !           239:     size_t offset;
        !           240:     V9fsFidState *fidp;
        !           241:     V9fsQID qid;
        !           242:     int32_t iounit;
        !           243:     struct stat stbuf;
        !           244:     V9fsString name;
        !           245:     V9fsString fullname;
        !           246: } V9fsLcreateState;
        !           247: 
        !           248: typedef struct V9fsStatState {
        !           249:     V9fsPDU *pdu;
        !           250:     size_t offset;
        !           251:     V9fsStat v9stat;
        !           252:     V9fsFidState *fidp;
        !           253:     struct stat stbuf;
        !           254: } V9fsStatState;
        !           255: 
        !           256: typedef struct V9fsStatDotl {
        !           257:     uint64_t st_result_mask;
        !           258:     V9fsQID qid;
        !           259:     uint32_t st_mode;
        !           260:     uint32_t st_uid;
        !           261:     uint32_t st_gid;
        !           262:     uint64_t st_nlink;
        !           263:     uint64_t st_rdev;
        !           264:     uint64_t st_size;
        !           265:     uint64_t st_blksize;
        !           266:     uint64_t st_blocks;
        !           267:     uint64_t st_atime_sec;
        !           268:     uint64_t st_atime_nsec;
        !           269:     uint64_t st_mtime_sec;
        !           270:     uint64_t st_mtime_nsec;
        !           271:     uint64_t st_ctime_sec;
        !           272:     uint64_t st_ctime_nsec;
        !           273:     uint64_t st_btime_sec;
        !           274:     uint64_t st_btime_nsec;
        !           275:     uint64_t st_gen;
        !           276:     uint64_t st_data_version;
        !           277: } V9fsStatDotl;
        !           278: 
        !           279: typedef struct V9fsStatStateDotl {
        !           280:     V9fsPDU *pdu;
        !           281:     size_t offset;
        !           282:     V9fsStatDotl v9stat_dotl;
        !           283:     struct stat stbuf;
        !           284: } V9fsStatStateDotl;
        !           285: 
        !           286: 
        !           287: typedef struct V9fsWalkState {
        !           288:     V9fsPDU *pdu;
        !           289:     size_t offset;
        !           290:     uint16_t nwnames;
        !           291:     int name_idx;
        !           292:     V9fsQID *qids;
        !           293:     V9fsFidState *fidp;
        !           294:     V9fsFidState *newfidp;
        !           295:     V9fsString path;
        !           296:     V9fsString *wnames;
        !           297:     struct stat stbuf;
        !           298: } V9fsWalkState;
        !           299: 
        !           300: typedef struct V9fsOpenState {
        !           301:     V9fsPDU *pdu;
        !           302:     size_t offset;
        !           303:     int32_t mode;
        !           304:     V9fsFidState *fidp;
        !           305:     V9fsQID qid;
        !           306:     struct stat stbuf;
        !           307:     int iounit;
        !           308: } V9fsOpenState;
        !           309: 
        !           310: typedef struct V9fsReadState {
        !           311:     V9fsPDU *pdu;
        !           312:     size_t offset;
        !           313:     int32_t count;
        !           314:     int32_t total;
        !           315:     int64_t off;
        !           316:     V9fsFidState *fidp;
        !           317:     struct iovec iov[128]; /* FIXME: bad, bad, bad */
        !           318:     struct iovec *sg;
        !           319:     off_t dir_pos;
        !           320:     struct dirent *dent;
        !           321:     struct stat stbuf;
        !           322:     V9fsString name;
        !           323:     V9fsStat v9stat;
        !           324:     int32_t len;
        !           325:     int32_t cnt;
        !           326:     int32_t max_count;
        !           327: } V9fsReadState;
        !           328: 
        !           329: typedef struct V9fsWriteState {
        !           330:     V9fsPDU *pdu;
        !           331:     size_t offset;
        !           332:     int32_t len;
        !           333:     int32_t count;
        !           334:     int32_t total;
        !           335:     int64_t off;
        !           336:     V9fsFidState *fidp;
        !           337:     struct iovec iov[128]; /* FIXME: bad, bad, bad */
        !           338:     struct iovec *sg;
        !           339:     int cnt;
        !           340: } V9fsWriteState;
        !           341: 
        !           342: typedef struct V9fsRemoveState {
        !           343:     V9fsPDU *pdu;
        !           344:     size_t offset;
        !           345:     V9fsFidState *fidp;
        !           346: } V9fsRemoveState;
        !           347: 
        !           348: typedef struct V9fsWstatState
        !           349: {
        !           350:     V9fsPDU *pdu;
        !           351:     size_t offset;
        !           352:     int16_t unused;
        !           353:     V9fsStat v9stat;
        !           354:     V9fsFidState *fidp;
        !           355:     struct stat stbuf;
        !           356: } V9fsWstatState;
        !           357: 
        !           358: typedef struct V9fsSymlinkState
        !           359: {
        !           360:     V9fsPDU *pdu;
        !           361:     size_t offset;
        !           362:     V9fsString name;
        !           363:     V9fsString symname;
        !           364:     V9fsString fullname;
        !           365:     V9fsFidState *dfidp;
        !           366:     V9fsQID qid;
        !           367:     struct stat stbuf;
        !           368: } V9fsSymlinkState;
        !           369: 
        !           370: typedef struct V9fsIattr
        !           371: {
        !           372:     int32_t valid;
        !           373:     int32_t mode;
        !           374:     int32_t uid;
        !           375:     int32_t gid;
        !           376:     int64_t size;
        !           377:     int64_t atime_sec;
        !           378:     int64_t atime_nsec;
        !           379:     int64_t mtime_sec;
        !           380:     int64_t mtime_nsec;
        !           381: } V9fsIattr;
        !           382: 
        !           383: typedef struct V9fsSetattrState
        !           384: {
        !           385:     V9fsPDU *pdu;
        !           386:     size_t offset;
        !           387:     V9fsIattr v9iattr;
        !           388:     V9fsFidState *fidp;
        !           389: } V9fsSetattrState;
        !           390: 
        !           391: struct virtio_9p_config
        !           392: {
        !           393:     /* number of characters in tag */
        !           394:     uint16_t tag_len;
        !           395:     /* Variable size tag name */
        !           396:     uint8_t tag[0];
        !           397: } __attribute__((packed));
        !           398: 
        !           399: typedef struct V9fsStatfs
        !           400: {
        !           401:     uint32_t f_type;
        !           402:     uint32_t f_bsize;
        !           403:     uint64_t f_blocks;
        !           404:     uint64_t f_bfree;
        !           405:     uint64_t f_bavail;
        !           406:     uint64_t f_files;
        !           407:     uint64_t f_ffree;
        !           408:     uint64_t fsid_val;
        !           409:     uint32_t f_namelen;
        !           410: } V9fsStatfs;
        !           411: 
        !           412: typedef struct V9fsStatfsState {
        !           413:     V9fsPDU *pdu;
        !           414:     size_t offset;
        !           415:     int32_t fid;
        !           416:     V9fsStatfs v9statfs;
        !           417:     V9fsFidState *fidp;
        !           418:     struct statfs stbuf;
        !           419: } V9fsStatfsState;
        !           420: 
        !           421: typedef struct V9fsMkState {
        !           422:     V9fsPDU *pdu;
        !           423:     size_t offset;
        !           424:     V9fsQID qid;
        !           425:     struct stat stbuf;
        !           426:     V9fsString name;
        !           427:     V9fsString fullname;
        !           428: } V9fsMkState;
        !           429: 
        !           430: typedef struct V9fsRenameState {
        !           431:     V9fsPDU *pdu;
        !           432:     V9fsFidState *fidp;
        !           433:     size_t offset;
        !           434:     int32_t newdirfid;
        !           435:     V9fsString name;
        !           436: } V9fsRenameState;
        !           437: 
        !           438: typedef struct V9fsXattrState
        !           439: {
        !           440:     V9fsPDU *pdu;
        !           441:     size_t offset;
        !           442:     V9fsFidState *file_fidp;
        !           443:     V9fsFidState *xattr_fidp;
        !           444:     V9fsString name;
        !           445:     int64_t size;
        !           446:     int flags;
        !           447:     void *value;
        !           448: } V9fsXattrState;
        !           449: 
        !           450: #define P9_LOCK_SUCCESS 0
        !           451: #define P9_LOCK_BLOCKED 1
        !           452: #define P9_LOCK_ERROR 2
        !           453: #define P9_LOCK_GRACE 3
        !           454: 
        !           455: #define P9_LOCK_FLAGS_BLOCK 1
        !           456: #define P9_LOCK_FLAGS_RECLAIM 2
        !           457: 
        !           458: typedef struct V9fsFlock
        !           459: {
        !           460:     uint8_t type;
        !           461:     uint32_t flags;
        !           462:     uint64_t start; /* absolute offset */
        !           463:     uint64_t length;
        !           464:     uint32_t proc_id;
        !           465:     V9fsString client_id;
        !           466: } V9fsFlock;
        !           467: 
        !           468: typedef struct V9fsLockState
        !           469: {
        !           470:     V9fsPDU *pdu;
        !           471:     size_t offset;
        !           472:     int8_t status;
        !           473:     struct stat stbuf;
        !           474:     V9fsFidState *fidp;
        !           475:     V9fsFlock *flock;
        !           476: } V9fsLockState;
        !           477: 
        !           478: typedef struct V9fsGetlock
        !           479: {
        !           480:     uint8_t type;
        !           481:     uint64_t start; /* absolute offset */
        !           482:     uint64_t length;
        !           483:     uint32_t proc_id;
        !           484:     V9fsString client_id;
        !           485: } V9fsGetlock;
        !           486: 
        !           487: typedef struct V9fsGetlockState
        !           488: {
        !           489:     V9fsPDU *pdu;
        !           490:     size_t offset;
        !           491:     struct stat stbuf;
        !           492:     V9fsFidState *fidp;
        !           493:     V9fsGetlock *glock;
        !           494: } V9fsGetlockState;
        !           495: 
        !           496: typedef struct V9fsReadLinkState
        !           497: {
        !           498:     V9fsPDU *pdu;
        !           499:     size_t offset;
        !           500:     V9fsString target;
        !           501: } V9fsReadLinkState;
        !           502: 
        !           503: size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count,
        !           504:                       size_t offset, size_t size, int pack);
        !           505: 
        !           506: static inline size_t do_pdu_unpack(void *dst, struct iovec *sg, int sg_count,
        !           507:                         size_t offset, size_t size)
        !           508: {
        !           509:     return pdu_packunpack(dst, sg, sg_count, offset, size, 0);
        !           510: }
        !           511: 
        !           512: extern void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq);
        !           513: 
        !           514: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.