iPXE
mount.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Marin Hannache <ipxe@mareo.fr>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  */
19 
20 FILE_SECBOOT ( FORBIDDEN );
21 
22 #include <stdint.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <assert.h>
27 #include <errno.h>
28 #include <libgen.h>
29 #include <byteswap.h>
30 #include <ipxe/time.h>
31 #include <ipxe/iobuf.h>
32 #include <ipxe/open.h>
33 #include <ipxe/features.h>
34 #include <ipxe/oncrpc.h>
35 #include <ipxe/oncrpc_iob.h>
36 #include <ipxe/nfs.h>
37 #include <ipxe/mount.h>
38 
39 /** @file
40  *
41  * NFS MOUNT protocol
42  *
43  */
44 
45 /** MNT procedure number */
46 #define MOUNT_MNT 1
47 /** UMNT procedure number */
48 #define MOUNT_UMNT 3
49 
50 /**
51  * Send a MNT request
52  *
53  * @v intf Interface to send the request on
54  * @v session ONC RPC session
55  * @v mountpoinrt The path of the directory to mount.
56  * @ret rc Return status code
57  */
58 int mount_mnt ( struct interface *intf, struct oncrpc_session *session,
59  const char *mountpoint ) {
60  struct oncrpc_field fields[] = {
61  ONCRPC_FIELD ( str, mountpoint ),
63  };
64 
65  return oncrpc_call ( intf, session, MOUNT_MNT, fields );
66 }
67 
68 /**
69  * Send a UMNT request
70  *
71  * @v intf Interface to send the request on
72  * @v session ONC RPC session
73  * @v mountpoinrt The path of the directory to unmount.
74  * @ret rc Return status code
75  */
76 int mount_umnt ( struct interface *intf, struct oncrpc_session *session,
77  const char *mountpoint ) {
78  struct oncrpc_field fields[] = {
79  ONCRPC_FIELD ( str, mountpoint ),
81  };
82 
83  return oncrpc_call ( intf, session, MOUNT_UMNT, fields );
84 }
85 
86 /**
87  * Parse an MNT reply
88  *
89  * @v mnt_reply A structure where the data will be saved
90  * @v reply The ONC RPC reply to get data from
91  * @ret rc Return status code
92  */
93 int mount_get_mnt_reply ( struct mount_mnt_reply *mnt_reply,
94  struct oncrpc_reply *reply ) {
95  if ( ! mnt_reply || ! reply )
96  return -EINVAL;
97 
98  mnt_reply->status = oncrpc_iob_get_int ( reply->data );
99 
100  switch ( mnt_reply->status )
101  {
102  case MNT3_OK:
103  break;
104  case MNT3ERR_NOENT:
105  return -ENOENT;
106  case MNT3ERR_IO:
107  return -EIO;
108  case MNT3ERR_ACCES:
109  return -EACCES;
110  case MNT3ERR_NOTDIR:
111  return -ENOTDIR;
112  case MNT3ERR_NAMETOOLONG:
113  return -ENAMETOOLONG;
114  default:
115  return -EPROTO;
116  }
117 
118  nfs_iob_get_fh ( reply->data, &mnt_reply->fh );
119 
120  return 0;
121 }
#define ONCRPC_FIELD(type, value)
Definition: oncrpc.h:28
#define EINVAL
Invalid argument.
Definition: errno.h:429
int mount_get_mnt_reply(struct mount_mnt_reply *mnt_reply, struct oncrpc_reply *reply)
Parse an MNT reply.
Definition: mount.c:93
Error codes.
I/O buffers.
#define ENOENT
No such file or directory.
Definition: errno.h:515
#define EACCES
Permission denied.
Definition: errno.h:299
#define MNT3ERR_IO
I/O error.
Definition: mount.h:27
int oncrpc_call(struct interface *intf, struct oncrpc_session *session, uint32_t proc_name, const struct oncrpc_field fields[])
Definition: oncrpc.c:129
#define MOUNT_UMNT
UMNT procedure number.
Definition: mount.c:48
#define oncrpc_iob_get_int(buf)
Get a 32 bits integer from the beginning of an I/O buffer.
Definition: oncrpc_iob.h:38
Assertions.
#define MNT3_OK
No error.
Definition: mount.h:21
struct nfs_fh fh
Root file handle.
Definition: mount.h:50
An object interface.
Definition: interface.h:125
#define ENOTDIR
Not a directory.
Definition: errno.h:575
Feature list.
SUN ONC RPC protocol.
#define EPROTO
Protocol error.
Definition: errno.h:625
#define MNT3ERR_NOENT
No such file or directory.
Definition: mount.h:25
uint32_t status
Reply status.
Definition: mount.h:48
Data transfer interface opening.
size_t nfs_iob_get_fh(struct io_buffer *io_buf, struct nfs_fh *fh)
Extract a file handle from the beginning of an I/O buffer.
Definition: nfs.c:61
#define MOUNT_MNT
MNT procedure number.
Definition: mount.c:46
int mount_mnt(struct interface *intf, struct oncrpc_session *session, const char *mountpoint)
Send a MNT request.
Definition: mount.c:58
FILE_SECBOOT(FORBIDDEN)
#define ONCRPC_FIELD_END
Definition: oncrpc.h:32
Network File System protocol.
#define EIO
Input/output error.
Definition: errno.h:434
#define ENAMETOOLONG
Filename too long.
Definition: errno.h:474
#define MNT3ERR_NAMETOOLONG
Filename too long.
Definition: mount.h:35
int mount_umnt(struct interface *intf, struct oncrpc_session *session, const char *mountpoint)
Send a UMNT request.
Definition: mount.c:76
SUN ONC RPC protocol.
Time source.
A MOUNT MNT reply.
Definition: mount.h:46
String functions.
NFS MOUNT protocol.
struct io_buffer * data
Definition: oncrpc.h:68
#define MNT3ERR_ACCES
Permission denied.
Definition: mount.h:29
#define MNT3ERR_NOTDIR
Not a directory.
Definition: mount.h:31