iPXE
mount.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2013 Marin Hannache <ipxe@mareo.fr>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  */
00019 
00020 #include <stdint.h>
00021 #include <stdlib.h>
00022 #include <stdio.h>
00023 #include <string.h>
00024 #include <assert.h>
00025 #include <errno.h>
00026 #include <libgen.h>
00027 #include <byteswap.h>
00028 #include <ipxe/time.h>
00029 #include <ipxe/iobuf.h>
00030 #include <ipxe/open.h>
00031 #include <ipxe/features.h>
00032 #include <ipxe/oncrpc.h>
00033 #include <ipxe/oncrpc_iob.h>
00034 #include <ipxe/nfs.h>
00035 #include <ipxe/mount.h>
00036 
00037 /** @file
00038  *
00039  * NFS MOUNT protocol
00040  *
00041  */
00042 
00043 /** MNT procedure number */
00044 #define MOUNT_MNT       1
00045 /** UMNT procedure number */
00046 #define MOUNT_UMNT      3
00047 
00048 /**
00049  * Send a MNT request
00050  *
00051  * @v intf              Interface to send the request on
00052  * @v session           ONC RPC session
00053  * @v mountpoinrt       The path of the directory to mount.
00054  * @ret rc              Return status code
00055  */
00056 int mount_mnt ( struct interface *intf, struct oncrpc_session *session,
00057                 const char *mountpoint ) {
00058         struct oncrpc_field fields[] = {
00059                 ONCRPC_FIELD ( str, mountpoint ),
00060                 ONCRPC_FIELD_END,
00061         };
00062 
00063         return oncrpc_call ( intf, session, MOUNT_MNT, fields );
00064 }
00065 
00066 /**
00067  * Send a UMNT request
00068  *
00069  * @v intf              Interface to send the request on
00070  * @v session           ONC RPC session
00071  * @v mountpoinrt       The path of the directory to unmount.
00072  * @ret rc              Return status code
00073  */
00074 int mount_umnt ( struct interface *intf, struct oncrpc_session *session,
00075                  const char *mountpoint ) {
00076         struct oncrpc_field fields[] = {
00077                 ONCRPC_FIELD ( str, mountpoint ),
00078                 ONCRPC_FIELD_END,
00079         };
00080 
00081         return oncrpc_call ( intf, session, MOUNT_UMNT, fields );
00082 }
00083 
00084 /**
00085  * Parse an MNT reply
00086  *
00087  * @v mnt_reply         A structure where the data will be saved
00088  * @v reply             The ONC RPC reply to get data from
00089  * @ret rc              Return status code
00090  */
00091 int mount_get_mnt_reply ( struct mount_mnt_reply *mnt_reply,
00092                           struct oncrpc_reply *reply ) {
00093         if (  ! mnt_reply || ! reply )
00094                 return -EINVAL;
00095 
00096         mnt_reply->status = oncrpc_iob_get_int ( reply->data );
00097 
00098         switch ( mnt_reply->status )
00099         {
00100         case MNT3_OK:
00101                 break;
00102         case MNT3ERR_NOENT:
00103                 return -ENOENT;
00104         case MNT3ERR_IO:
00105                 return -EIO;
00106         case MNT3ERR_ACCES:
00107                 return -EACCES;
00108         case MNT3ERR_NOTDIR:
00109                 return -ENOTDIR;
00110         case MNT3ERR_NAMETOOLONG:
00111                 return -ENAMETOOLONG;
00112         default:
00113                 return -EPROTO;
00114         }
00115 
00116         nfs_iob_get_fh ( reply->data, &mnt_reply->fh );
00117 
00118         return 0;
00119 }