iPXE
nfs.h
Go to the documentation of this file.
00001 #ifndef _IPXE_NFS_H
00002 #define _IPXE_NFS_H
00003 
00004 #include <stdint.h>
00005 #include <ipxe/oncrpc.h>
00006 
00007 /** @file
00008  *
00009  * Network File System protocol.
00010  *
00011  */
00012 
00013 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00014 
00015 /** NFS protocol number */
00016 #define ONCRPC_NFS 100003
00017 
00018 /** NFS protocol version */
00019 #define NFS_VERS   3
00020 
00021 /** No error*/
00022 #define NFS3_OK             0
00023 /** Not owner */
00024 #define NFS3ERR_PERM        1
00025 /** No such file or directory */
00026 #define NFS3ERR_NOENT       2
00027 /** I/O error */
00028 #define NFS3ERR_IO          5
00029 /** No such device or address */
00030 #define NFS3ERR_NXIO        6
00031 /** Permission denied */
00032 #define NFS3ERR_ACCES       13
00033 /** The file specified already exists */
00034 #define NFS3ERR_EXIST       17
00035 /**  Attempt to do a cross-device hard link */
00036 #define NFS3ERR_XDEV        18
00037 /** No such device */
00038 #define NFS3ERR_NODEV       19
00039 /** Not a directory */
00040 #define NFS3ERR_NOTDIR      20
00041  /**Is a directory */
00042 #define NFS3ERR_ISDIR       21
00043 /** Invalid argument */
00044 #define NFS3ERR_INVAL       22
00045 /** Filename too long */
00046 #define NFS3ERR_NAMETOOLONG 63
00047 /** Invalid file handle */
00048 #define NFS3ERR_STALE       70
00049 /** Too many levels of remote in path */
00050 #define NFS3ERR_REMOTE      71
00051 /** Illegal NFS file handle */
00052 #define NFS3ERR_BADHANDLE   10001
00053 /**  READDIR or READDIRPLUS cookie is stale */
00054 #define NFS3ERR_BAD_COOKIE  10003
00055 /** Operation not supported */
00056 #define NFS3ERR_NOTSUPP     10004
00057 /** Buffer or request is too small */
00058 #define NFS3ERR_TOOSMALL    10005
00059 /** An error occurred on the server which does not map to any  of the legal NFS
00060  * version 3 protocol error values */
00061 #define NFS3ERR_SERVERFAULT 10006
00062 /** The server initiated the request, but was not able to complete it in a
00063  * timely fashion */
00064 #define NFS3ERR_JUKEBOX     10008
00065 
00066 enum nfs_attr_type {
00067         NFS_ATTR_SYMLINK = 5,
00068 };
00069 
00070 /**
00071  * A NFS file handle
00072  *
00073  */
00074 struct nfs_fh {
00075         uint8_t               fh[64];
00076         size_t                size;
00077 };
00078 
00079 /**
00080  * A NFS LOOKUP reply
00081  *
00082  */
00083 struct nfs_lookup_reply {
00084         /** Reply status */
00085         uint32_t             status;
00086         /** Entity type */
00087         enum nfs_attr_type   ent_type;
00088         /** File handle */
00089         struct nfs_fh        fh;
00090 };
00091 
00092 /**
00093  * A NFS READLINK reply
00094  *
00095  */
00096 struct nfs_readlink_reply {
00097         /** Reply status */
00098         uint32_t             status;
00099         /** File path length */
00100         uint32_t             path_len;
00101         /** File path */
00102         char                 *path;
00103 };
00104 
00105 
00106 /**
00107  * A NFS READ reply
00108  *
00109  */
00110 struct nfs_read_reply {
00111         /** Reply status */
00112         uint32_t             status;
00113         /** File size */
00114         uint64_t             filesize;
00115         /** Bytes read */
00116         uint32_t             count;
00117         /** End-of-File indicator */
00118         uint32_t             eof;
00119         /** Data length */
00120         uint32_t             data_len;
00121         /** Data read */
00122         void                 *data;
00123 };
00124 
00125 size_t nfs_iob_get_fh ( struct io_buffer *io_buf, struct nfs_fh *fh );
00126 size_t nfs_iob_add_fh ( struct io_buffer *io_buf, const struct nfs_fh *fh );
00127 
00128 /**
00129  * Prepare an ONC RPC session to be used as a NFS session
00130  *
00131  * @v session           ONC RPC session
00132  * @v credential        ONC RPC credential
00133  *
00134  * The credential parameter must not be NULL, use 'oncrpc_auth_none' if you
00135  * don't want a particular scheme to be used.
00136  */
00137 static inline void nfs_init_session ( struct oncrpc_session *session,
00138                                       struct oncrpc_cred *credential ) {
00139         oncrpc_init_session ( session, credential, &oncrpc_auth_none,
00140                               ONCRPC_NFS, NFS_VERS );
00141 }
00142 
00143 int nfs_lookup ( struct interface *intf, struct oncrpc_session *session,
00144                  const struct nfs_fh *fh, const char *filename );
00145 int nfs_readlink ( struct interface *intf, struct oncrpc_session *session,
00146                    const struct nfs_fh *fh );
00147 int nfs_read ( struct interface *intf, struct oncrpc_session *session,
00148                const struct nfs_fh *fh, uint64_t offset, uint32_t count );
00149 
00150 int nfs_get_lookup_reply ( struct nfs_lookup_reply *lookup_reply,
00151                            struct oncrpc_reply *reply );
00152 int nfs_get_readlink_reply ( struct nfs_readlink_reply *readlink_reply,
00153                              struct oncrpc_reply *reply );
00154 int nfs_get_read_reply ( struct nfs_read_reply *read_reply,
00155                          struct oncrpc_reply *reply );
00156 
00157 #endif /* _IPXE_NFS_H */