[efi] Include installed protocol list in unknown handle names
[ipxe.git] / src / net / oncrpc / mount.c
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 ),
60 ONCRPC_FIELD_END,
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 ),
78 ONCRPC_FIELD_END,
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 }