Skip to content

Commit

Permalink
[nfs] Add support for NFS protocol
Browse files Browse the repository at this point in the history
Tested-by: Robin Smidsrød <robin@smidsrod.no>
Signed-off-by: Marin Hannache <git@mareo.fr>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
Mareo authored and mcb30 committed Jul 15, 2013
1 parent ed28c83 commit 30de9e8
Show file tree
Hide file tree
Showing 21 changed files with 2,238 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Makefile
Expand Up @@ -61,7 +61,7 @@ ZLIB_DIR := /usr
SRCDIRS :=
SRCDIRS += libgcc
SRCDIRS += core
SRCDIRS += net net/tcp net/udp net/infiniband net/80211
SRCDIRS += net net/oncrpc net/tcp net/udp net/infiniband net/80211
SRCDIRS += image
SRCDIRS += drivers/bus
SRCDIRS += drivers/net
Expand Down
3 changes: 3 additions & 0 deletions src/config/config.c
Expand Up @@ -129,6 +129,9 @@ REQUIRE_OBJECT ( https );
#ifdef DOWNLOAD_PROTO_FTP
REQUIRE_OBJECT ( ftp );
#endif
#ifdef DOWNLOAD_PROTO_NFS
REQUIRE_OBJECT ( nfs_open );
#endif
#ifdef DOWNLOAD_PROTO_SLAM
REQUIRE_OBJECT ( slam );
#endif
Expand Down
1 change: 1 addition & 0 deletions src/config/general.h
Expand Up @@ -59,6 +59,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#undef DOWNLOAD_PROTO_HTTPS /* Secure Hypertext Transfer Protocol */
#undef DOWNLOAD_PROTO_FTP /* File Transfer Protocol */
#undef DOWNLOAD_PROTO_SLAM /* Scalable Local Area Multicast */
#undef DOWNLOAD_PROTO_NFS /* Network File System Protocol */

/*
* SAN boot protocols
Expand Down
2 changes: 2 additions & 0 deletions src/include/big_bswap.h
@@ -1,6 +1,8 @@
#ifndef ETHERBOOT_BIG_BSWAP_H
#define ETHERBOOT_BIG_BSWAP_H

#define htonll(x) (x)
#define ntohll(x) (x)
#define ntohl(x) (x)
#define htonl(x) (x)
#define ntohs(x) (x)
Expand Down
12 changes: 12 additions & 0 deletions src/include/ipxe/dhcp.h
Expand Up @@ -450,6 +450,18 @@ struct dhcp_netdev_desc {
*/
#define DHCP_EB_REVERSE_PASSWORD DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xc1 )

/** User ID
*
* This will be used as the user id for AUTH_SYS based authentication in NFS.
*/
#define DHCP_EB_UID DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xc2 )

/** Group ID
*
* This will be used as the group id for AUTH_SYS based authentication in NFS.
*/
#define DHCP_EB_GID DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xc3 )

/** iPXE version number */
#define DHCP_EB_VERSION DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xeb )

Expand Down
6 changes: 6 additions & 0 deletions src/include/ipxe/errfile.h
Expand Up @@ -208,6 +208,12 @@ FILE_LICENCE ( GPL2_OR_LATER );
#define ERRFILE_fcoe ( ERRFILE_NET | 0x002e0000 )
#define ERRFILE_fcns ( ERRFILE_NET | 0x002f0000 )
#define ERRFILE_vlan ( ERRFILE_NET | 0x00300000 )
#define ERRFILE_oncrpc ( ERRFILE_NET | 0x00310000 )
#define ERRFILE_portmap ( ERRFILE_NET | 0x00320000 )
#define ERRFILE_nfs ( ERRFILE_NET | 0x00330000 )
#define ERRFILE_nfs_open ( ERRFILE_NET | 0x00340000 )
#define ERRFILE_mount ( ERRFILE_NET | 0x00350000 )
#define ERRFILE_oncrpc_iob ( ERRFILE_NET | 0x00360000 )

#define ERRFILE_image ( ERRFILE_IMAGE | 0x00000000 )
#define ERRFILE_elf ( ERRFILE_IMAGE | 0x00010000 )
Expand Down
1 change: 1 addition & 0 deletions src/include/ipxe/features.h
Expand Up @@ -54,6 +54,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#define DHCP_EB_FEATURE_VLAN 0x26 /**< VLAN support */
#define DHCP_EB_FEATURE_MENU 0x27 /**< Menu support */
#define DHCP_EB_FEATURE_SDI 0x28 /**< SDI image support */
#define DHCP_EB_FEATURE_NFS 0x29 /**< NFS protocol */

/** @} */

Expand Down
76 changes: 76 additions & 0 deletions src/include/ipxe/mount.h
@@ -0,0 +1,76 @@
#ifndef _IPXE_MOUNT_H
#define _IPXE_MOUNT_H

#include <ipxe/nfs.h>

/** @file
*
* NFS MOUNT protocol.
*
*/

FILE_LICENCE ( GPL2_OR_LATER );

/** NFS MOUNT protocol number */
#define ONCRPC_MOUNT 100005
/** NFS MOUNT protocol version */
#define MOUNT_VERS 3


/** No error */
#define MNT3_OK 0
/** Not owner */
#define MNT3ERR_PERM 1
/** No such file or directory */
#define MNT3ERR_NOENT 2
/** I/O error */
#define MNT3ERR_IO 5
/** Permission denied */
#define MNT3ERR_ACCES 13
/** Not a directory */
#define MNT3ERR_NOTDIR 20
/** Invalid argument */
#define MNT3ERR_INVAL 22
/** Filename too long */
#define MNT3ERR_NAMETOOLONG 63
/** Operation not supported */
#define MNT3ERR_NOTSUPP 10004
/** A failure on the server */
#define MNT3ERR_SERVERFAULT 10006


/**
* A MOUNT MNT reply
*
*/
struct mount_mnt_reply {
/** Reply status */
uint32_t status;
/** Root file handle */
struct nfs_fh fh;
};

/**
* Prepare an ONC RPC session to be used as a MOUNT session
*
* @v session ONC RPC session
* @v credential ONC RPC credential
*
* The credential parameter must not be NULL, use 'oncrpc_auth_none' if you
* don't want a particular scheme to be used.
*/
static inline void mount_init_session ( struct oncrpc_session *session,
struct oncrpc_cred *credential ) {
oncrpc_init_session ( session, credential, &oncrpc_auth_none,
ONCRPC_MOUNT, MOUNT_VERS );
}

int mount_mnt ( struct interface *intf, struct oncrpc_session *session,
const char *mountpoint );
int mount_umnt ( struct interface *intf, struct oncrpc_session *session,
const char *mountpoint );

int mount_get_mnt_reply ( struct mount_mnt_reply *mnt_reply,
struct oncrpc_reply *reply );

#endif /* _IPXE_MOUNT_H */
157 changes: 157 additions & 0 deletions src/include/ipxe/nfs.h
@@ -0,0 +1,157 @@
#ifndef _IPXE_NFS_H
#define _IPXE_NFS_H

#include <stdint.h>
#include <ipxe/oncrpc.h>

/** @file
*
* Network File System protocol.
*
*/

FILE_LICENCE ( GPL2_OR_LATER );

/** NFS protocol number */
#define ONCRPC_NFS 100003

/** NFS protocol version */
#define NFS_VERS 3

/** No error*/
#define NFS3_OK 0
/** Not owner */
#define NFS3ERR_PERM 1
/** No such file or directory */
#define NFS3ERR_NOENT 2
/** I/O error */
#define NFS3ERR_IO 5
/** No such device or address */
#define NFS3ERR_NXIO 6
/** Permission denied */
#define NFS3ERR_ACCES 13
/** The file specified already exists */
#define NFS3ERR_EXIST 17
/** Attempt to do a cross-device hard link */
#define NFS3ERR_XDEV 18
/** No such device */
#define NFS3ERR_NODEV 19
/** Not a directory */
#define NFS3ERR_NOTDIR 20
/**Is a directory */
#define NFS3ERR_ISDIR 21
/** Invalid argument */
#define NFS3ERR_INVAL 22
/** Filename too long */
#define NFS3ERR_NAMETOOLONG 63
/** Invalid file handle */
#define NFS3ERR_STALE 70
/** Too many levels of remote in path */
#define NFS3ERR_REMOTE 71
/** Illegal NFS file handle */
#define NFS3ERR_BADHANDLE 10001
/** READDIR or READDIRPLUS cookie is stale */
#define NFS3ERR_BAD_COOKIE 10003
/** Operation not supported */
#define NFS3ERR_NOTSUPP 10004
/** Buffer or request is too small */
#define NFS3ERR_TOOSMALL 10005
/** An error occurred on the server which does not map to any of the legal NFS
* version 3 protocol error values */
#define NFS3ERR_SERVERFAULT 10006
/** The server initiated the request, but was not able to complete it in a
* timely fashion */
#define NFS3ERR_JUKEBOX 10008

enum nfs_attr_type {
NFS_ATTR_SYMLINK = 5,
};

/**
* A NFS file handle
*
*/
struct nfs_fh {
uint8_t fh[64];
size_t size;
};

/**
* A NFS LOOKUP reply
*
*/
struct nfs_lookup_reply {
/** Reply status */
uint32_t status;
/** Entity type */
enum nfs_attr_type ent_type;
/** File handle */
struct nfs_fh fh;
};

/**
* A NFS READLINK reply
*
*/
struct nfs_readlink_reply {
/** Reply status */
uint32_t status;
/** File path length */
uint32_t path_len;
/** File path */
char *path;
};


/**
* A NFS READ reply
*
*/
struct nfs_read_reply {
/** Reply status */
uint32_t status;
/** File size */
uint64_t filesize;
/** Bytes read */
uint32_t count;
/** End-of-File indicator */
uint32_t eof;
/** Data length */
uint32_t data_len;
/** Data read */
void *data;
};

size_t nfs_iob_get_fh ( struct io_buffer *io_buf, struct nfs_fh *fh );
size_t nfs_iob_add_fh ( struct io_buffer *io_buf, const struct nfs_fh *fh );

/**
* Prepare an ONC RPC session to be used as a NFS session
*
* @v session ONC RPC session
* @v credential ONC RPC credential
*
* The credential parameter must not be NULL, use 'oncrpc_auth_none' if you
* don't want a particular scheme to be used.
*/
static inline void nfs_init_session ( struct oncrpc_session *session,
struct oncrpc_cred *credential ) {
oncrpc_init_session ( session, credential, &oncrpc_auth_none,
ONCRPC_NFS, NFS_VERS );
}

int nfs_lookup ( struct interface *intf, struct oncrpc_session *session,
const struct nfs_fh *fh, const char *filename );
int nfs_readlink ( struct interface *intf, struct oncrpc_session *session,
const struct nfs_fh *fh );
int nfs_read ( struct interface *intf, struct oncrpc_session *session,
const struct nfs_fh *fh, uint64_t offset, uint32_t count );

int nfs_get_lookup_reply ( struct nfs_lookup_reply *lookup_reply,
struct oncrpc_reply *reply );
int nfs_get_readlink_reply ( struct nfs_readlink_reply *readlink_reply,
struct oncrpc_reply *reply );
int nfs_get_read_reply ( struct nfs_read_reply *read_reply,
struct oncrpc_reply *reply );

#endif /* _IPXE_NFS_H */
12 changes: 12 additions & 0 deletions src/include/ipxe/nfs_open.h
@@ -0,0 +1,12 @@
#ifndef _IPXE_NFS_OPEN_H
#define _IPXE_NFS_OPEN_H

/** @file
*
* Network File System protocol.
*
*/

FILE_LICENCE ( GPL2_OR_LATER );

#endif /* _IPXE_NFS_OPEN_H */

0 comments on commit 30de9e8

Please sign in to comment.