Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / include / ipxe / nfs.h
1 #ifndef _IPXE_NFS_H
2 #define _IPXE_NFS_H
3
4 #include <stdint.h>
5 #include <ipxe/oncrpc.h>
6
7 /** @file
8  *
9  * Network File System protocol.
10  *
11  */
12
13 FILE_LICENCE ( GPL2_OR_LATER );
14
15 /** NFS protocol number */
16 #define ONCRPC_NFS 100003
17
18 /** NFS protocol version */
19 #define NFS_VERS   3
20
21 /** No error*/
22 #define NFS3_OK             0
23 /** Not owner */
24 #define NFS3ERR_PERM        1
25 /** No such file or directory */
26 #define NFS3ERR_NOENT       2
27 /** I/O error */
28 #define NFS3ERR_IO          5
29 /** No such device or address */
30 #define NFS3ERR_NXIO        6
31 /** Permission denied */
32 #define NFS3ERR_ACCES       13
33 /** The file specified already exists */
34 #define NFS3ERR_EXIST       17
35 /**  Attempt to do a cross-device hard link */
36 #define NFS3ERR_XDEV        18
37 /** No such device */
38 #define NFS3ERR_NODEV       19
39 /** Not a directory */
40 #define NFS3ERR_NOTDIR      20
41  /**Is a directory */
42 #define NFS3ERR_ISDIR       21
43 /** Invalid argument */
44 #define NFS3ERR_INVAL       22
45 /** Filename too long */
46 #define NFS3ERR_NAMETOOLONG 63
47 /** Invalid file handle */
48 #define NFS3ERR_STALE       70
49 /** Too many levels of remote in path */
50 #define NFS3ERR_REMOTE      71
51 /** Illegal NFS file handle */
52 #define NFS3ERR_BADHANDLE   10001
53 /**  READDIR or READDIRPLUS cookie is stale */
54 #define NFS3ERR_BAD_COOKIE  10003
55 /** Operation not supported */
56 #define NFS3ERR_NOTSUPP     10004
57 /** Buffer or request is too small */
58 #define NFS3ERR_TOOSMALL    10005
59 /** An error occurred on the server which does not map to any  of the legal NFS
60  * version 3 protocol error values */
61 #define NFS3ERR_SERVERFAULT 10006
62 /** The server initiated the request, but was not able to complete it in a
63  * timely fashion */
64 #define NFS3ERR_JUKEBOX     10008
65
66 enum nfs_attr_type {
67         NFS_ATTR_SYMLINK = 5,
68 };
69
70 /**
71  * A NFS file handle
72  *
73  */
74 struct nfs_fh {
75         uint8_t               fh[64];
76         size_t                size;
77 };
78
79 /**
80  * A NFS LOOKUP reply
81  *
82  */
83 struct nfs_lookup_reply {
84         /** Reply status */
85         uint32_t             status;
86         /** Entity type */
87         enum nfs_attr_type   ent_type;
88         /** File handle */
89         struct nfs_fh        fh;
90 };
91
92 /**
93  * A NFS READLINK reply
94  *
95  */
96 struct nfs_readlink_reply {
97         /** Reply status */
98         uint32_t             status;
99         /** File path length */
100         uint32_t             path_len;
101         /** File path */
102         char                 *path;
103 };
104
105
106 /**
107  * A NFS READ reply
108  *
109  */
110 struct nfs_read_reply {
111         /** Reply status */
112         uint32_t             status;
113         /** File size */
114         uint64_t             filesize;
115         /** Bytes read */
116         uint32_t             count;
117         /** End-of-File indicator */
118         uint32_t             eof;
119         /** Data length */
120         uint32_t             data_len;
121         /** Data read */
122         void                 *data;
123 };
124
125 size_t nfs_iob_get_fh ( struct io_buffer *io_buf, struct nfs_fh *fh );
126 size_t nfs_iob_add_fh ( struct io_buffer *io_buf, const struct nfs_fh *fh );
127
128 /**
129  * Prepare an ONC RPC session to be used as a NFS session
130  *
131  * @v session           ONC RPC session
132  * @v credential        ONC RPC credential
133  *
134  * The credential parameter must not be NULL, use 'oncrpc_auth_none' if you
135  * don't want a particular scheme to be used.
136  */
137 static inline void nfs_init_session ( struct oncrpc_session *session,
138                                       struct oncrpc_cred *credential ) {
139         oncrpc_init_session ( session, credential, &oncrpc_auth_none,
140                               ONCRPC_NFS, NFS_VERS );
141 }
142
143 int nfs_lookup ( struct interface *intf, struct oncrpc_session *session,
144                  const struct nfs_fh *fh, const char *filename );
145 int nfs_readlink ( struct interface *intf, struct oncrpc_session *session,
146                    const struct nfs_fh *fh );
147 int nfs_read ( struct interface *intf, struct oncrpc_session *session,
148                const struct nfs_fh *fh, uint64_t offset, uint32_t count );
149
150 int nfs_get_lookup_reply ( struct nfs_lookup_reply *lookup_reply,
151                            struct oncrpc_reply *reply );
152 int nfs_get_readlink_reply ( struct nfs_readlink_reply *readlink_reply,
153                              struct oncrpc_reply *reply );
154 int nfs_get_read_reply ( struct nfs_read_reply *read_reply,
155                          struct oncrpc_reply *reply );
156
157 #endif /* _IPXE_NFS_H */