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 #include <stdint.h>
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <assert.h>
25 #include <errno.h>
26 #include <libgen.h>
27 #include <byteswap.h>
28 #include <ipxe/time.h>
29 #include <ipxe/iobuf.h>
30 #include <ipxe/open.h>
31 #include <ipxe/features.h>
32 #include <ipxe/oncrpc.h>
33 #include <ipxe/oncrpc_iob.h>
34 #include <ipxe/nfs.h>
35 #include <ipxe/mount.h>
36 
37 /** @file
38  *
39  * NFS MOUNT protocol
40  *
41  */
42 
43 /** MNT procedure number */
44 #define MOUNT_MNT 1
45 /** UMNT procedure number */
46 #define MOUNT_UMNT 3
47 
48 /**
49  * Send a MNT request
50  *
51  * @v intf Interface to send the request on
52  * @v session ONC RPC session
53  * @v mountpoinrt The path of the directory to mount.
54  * @ret rc Return status code
55  */
56 int mount_mnt ( struct interface *intf, struct oncrpc_session *session,
57  const char *mountpoint ) {
58  struct oncrpc_field fields[] = {
59  ONCRPC_FIELD ( str, mountpoint ),
61  };
62 
63  return oncrpc_call ( intf, session, MOUNT_MNT, fields );
64 }
65 
66 /**
67  * Send a UMNT request
68  *
69  * @v intf Interface to send the request on
70  * @v session ONC RPC session
71  * @v mountpoinrt The path of the directory to unmount.
72  * @ret rc Return status code
73  */
74 int mount_umnt ( struct interface *intf, struct oncrpc_session *session,
75  const char *mountpoint ) {
76  struct oncrpc_field fields[] = {
77  ONCRPC_FIELD ( str, mountpoint ),
79  };
80 
81  return oncrpc_call ( intf, session, MOUNT_UMNT, fields );
82 }
83 
84 /**
85  * Parse an MNT reply
86  *
87  * @v mnt_reply A structure where the data will be saved
88  * @v reply The ONC RPC reply to get data from
89  * @ret rc Return status code
90  */
91 int mount_get_mnt_reply ( struct mount_mnt_reply *mnt_reply,
92  struct oncrpc_reply *reply ) {
93  if ( ! mnt_reply || ! reply )
94  return -EINVAL;
95 
96  mnt_reply->status = oncrpc_iob_get_int ( reply->data );
97 
98  switch ( mnt_reply->status )
99  {
100  case MNT3_OK:
101  break;
102  case MNT3ERR_NOENT:
103  return -ENOENT;
104  case MNT3ERR_IO:
105  return -EIO;
106  case MNT3ERR_ACCES:
107  return -EACCES;
108  case MNT3ERR_NOTDIR:
109  return -ENOTDIR;
110  case MNT3ERR_NAMETOOLONG:
111  return -ENAMETOOLONG;
112  default:
113  return -EPROTO;
114  }
115 
116  nfs_iob_get_fh ( reply->data, &mnt_reply->fh );
117 
118  return 0;
119 }
#define ONCRPC_FIELD(type, value)
Definition: oncrpc.h:28
#define EINVAL
Invalid argument.
Definition: errno.h:428
int mount_get_mnt_reply(struct mount_mnt_reply *mnt_reply, struct oncrpc_reply *reply)
Parse an MNT reply.
Definition: mount.c:91
Error codes.
I/O buffers.
#define ENOENT
No such file or directory.
Definition: errno.h:514
#define EACCES
Permission denied.
Definition: errno.h:298
#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:46
#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:109
struct ntlm_data session
Session key.
Definition: ntlm.h:24
#define ENOTDIR
Not a directory.
Definition: errno.h:574
Feature list.
SUN ONC RPC protocol.
#define EPROTO
Protocol error.
Definition: errno.h:624
#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:59
#define MOUNT_MNT
MNT procedure number.
Definition: mount.c:44
int mount_mnt(struct interface *intf, struct oncrpc_session *session, const char *mountpoint)
Send a MNT request.
Definition: mount.c:56
#define ONCRPC_FIELD_END
Definition: oncrpc.h:32
Network File System protocol.
#define EIO
Input/output error.
Definition: errno.h:433
#define ENAMETOOLONG
Filename too long.
Definition: errno.h:473
#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:74
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