1/**
2 * \file
3 * \brief NFS client definitions
4 */
5
6/*
7 * Copyright (c) 2008, 2009, 2011, ETH Zurich.
8 * All rights reserved.
9 *
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
13 */
14
15#ifndef BARRELFISH_NFS_H
16#define BARRELFISH_NFS_H
17
18#include <sys/cdefs.h>
19
20#include <net_sockets/net_sockets.h>
21#include <errors/errno.h>
22
23#include <nfs/xdr.h>
24#include <nfs/mount_rpc.h>
25#include <nfs/nfs_rpc.h>
26
27__BEGIN_DECLS
28
29#define NFS_READDIR_COOKIE 0        ///< initial cookie for readdir
30#define NFS_READDIR_COOKIEVERF NULL ///< initial cookie verifier for readder
31
32#define NULL_NFS_FH ((struct nfs_fh3) { /*data_len*/ 0, /*data_val*/ NULL })
33
34struct nfs_client;
35
36/**
37 * \brief Callback function for mount operation
38 *
39 * \param arg Opaque argument pointer, as provided to nfs_mount()
40 * \param client NFS client instance
41 * \param mountstat Mount status (MNT3_OK on success)
42 * \param fhandle File handle for mount point (only valid if mountstat==MNT3_OK)
43 *
44 * The memory referred to by #fhandle, if any, is now the property of the callee,
45 * and must be freed by the appropriate XDR free operations.
46 */
47typedef void (*nfs_mount_callback_t)(void *arg, struct nfs_client *client,
48                                     enum mountstat3 mountstat,
49                                     struct nfs_fh3 fhandle);
50
51/**
52 * \brief Callback function for getattr operation
53 *
54 * \param arg Opaque argument pointer, as provided to nfs_getattr()
55 * \param client NFS client instance
56 * \param result Result pointer, or NULL on error
57 *
58 * The memory referred to by #result, if any, is now the property of the callee,
59 * and must be freed by the appropriate XDR free operations.
60 */
61typedef void (*nfs_getattr_callback_t)(void *arg, struct nfs_client *client,
62                                       GETATTR3res *result);
63
64/**
65 * \brief Callback function for setattr operation
66 *
67 * \param arg Opaque argument pointer, as provided to nfs_setattr()
68 * \param client NFS client instance
69 * \param result Result pointer, or NULL on error
70 *
71 * The memory referred to by #result, if any, is now the property of the callee,
72 * and must be freed by the appropriate XDR free operations.
73 */
74typedef void (*nfs_setattr_callback_t)(void *arg, struct nfs_client *client,
75                                       SETATTR3res *result);
76
77
78/**
79 * \brief Callback function for readdir operation
80 *
81 * \param arg Opaque argument pointer, as provided to nfs_readdir()
82 * \param client NFS client instance
83 * \param result Result pointer, or NULL on error
84 *
85 * The memory referred to by #result, if any, is now the property of the callee,
86 * and must be freed by the appropriate XDR free operations.
87 */
88typedef void (*nfs_readdir_callback_t)(void *arg, struct nfs_client *client,
89                                       READDIR3res *result);
90
91/**
92 * \brief Callback function for readdirplus operation
93 *
94 * \param arg Opaque argument pointer, as provided to nfs_readdirplus()
95 * \param client NFS client instance
96 * \param result Result pointer, or NULL on error
97 *
98 * The memory referred to by #result, if any, is now the property of the callee,
99 * and must be freed by the appropriate XDR free operations.
100 */
101typedef void (*nfs_readdirplus_callback_t)(void *arg, struct nfs_client *client,
102                                           READDIRPLUS3res *result);
103
104/**
105 * \brief Callback function for lookup operation
106 *
107 * \param arg Opaque argument pointer, as provided to nfs_lookup()
108 * \param client NFS client instance
109 * \param result Result pointer, or NULL on error
110 *
111 * The memory referred to by #result, if any, is now the property of the callee,
112 * and must be freed by the appropriate XDR free operations.
113 */
114typedef void (*nfs_lookup_callback_t)(void *arg, struct nfs_client *client,
115                                      LOOKUP3res *result);
116
117/**
118 * \brief Callback function for access operation
119 *
120 * \param arg Opaque argument pointer, as provided to nfs_access()
121 * \param client NFS client instance
122 * \param result Result pointer, or NULL on error
123 *
124 * The memory referred to by #result, if any, is now the property of the callee,
125 * and must be freed by the appropriate XDR free operations.
126 */
127typedef void (*nfs_access_callback_t)(void *arg, struct nfs_client *client,
128                                      ACCESS3res *result);
129
130/**
131 * \brief Callback function for read operation
132 *
133 * \param arg Opaque argument pointer, as provided to nfs_read()
134 * \param client NFS client instance
135 * \param result Result pointer, or NULL on error
136 *
137 * The memory referred to by #result, if any, is now the property of the callee,
138 * and must be freed by the appropriate XDR free operations.
139 */
140typedef void (*nfs_read_callback_t)(void *arg, struct nfs_client *client,
141                                    READ3res *result);
142
143/**
144 * \brief Callback function for write operation
145 *
146 * \param arg Opaque argument pointer, as provided to nfs_write()
147 * \param client NFS client instance
148 * \param result Result pointer, or NULL on error
149 *
150 * The memory referred to by #result, if any, is now the property of the callee,
151 * and must be freed by the appropriate XDR free operations.
152 */
153typedef void (*nfs_write_callback_t)(void *arg, struct nfs_client *client,
154                                     WRITE3res *result);
155
156/**
157 * \brief Callback function for create operation
158 *
159 * \param arg Opaque argument pointer, as provided to nfs_create()
160 * \param client NFS client instance
161 * \param result Result pointer, or NULL on error
162 *
163 * The memory referred to by #result, if any, is now the property of the callee,
164 * and must be freed by the appropriate XDR free operations.
165 */
166typedef void (*nfs_create_callback_t)(void *arg, struct nfs_client *client,
167                                      CREATE3res *result);
168
169/**
170 * \brief Callback function for mkdir operation
171 *
172 * \param arg Opaque argument pointer, as provided to nfs_mkdir()
173 * \param client NFS client instance
174 * \param result Result pointer, or NULL on error
175 *
176 * The memory referred to by #result, if any, is now the property of the callee,
177 * and must be freed by the appropriate XDR free operations.
178 */
179typedef void (*nfs_mkdir_callback_t)(void *arg, struct nfs_client *client,
180                                     MKDIR3res *result);
181
182/**
183 * \brief Callback function for remove operation
184 *
185 * \param arg Opaque argument pointer, as provided to nfs_remove()
186 * \param client NFS client instance
187 * \param result Result pointer, or NULL on error
188 *
189 * The memory referred to by #result, if any, is now the property of the callee,
190 * and must be freed by the appropriate XDR free operations.
191 */
192typedef void (*nfs_remove_callback_t)(void *arg, struct nfs_client *client,
193                                      REMOVE3res *result);
194
195struct nfs_client *nfs_mount(struct in_addr server, const char *path,
196                             nfs_mount_callback_t callback, void *cbarg);
197errval_t nfs_getattr(struct nfs_client *client, struct nfs_fh3 fh,
198                  nfs_getattr_callback_t callback, void *cbarg);
199errval_t nfs_setattr(struct nfs_client *client, struct nfs_fh3 fh,
200                  sattr3 new_attributes, bool guarded,
201                  nfs_setattr_callback_t callback, void *cbarg);
202errval_t nfs_readdir(struct nfs_client *client, struct nfs_fh3 fh,
203                  cookie3 cookie, cookieverf3 cookieverf,
204                  nfs_readdir_callback_t callback, void *cbarg);
205errval_t nfs_readdirplus(struct nfs_client *client, struct nfs_fh3 fh,
206                      cookie3 cookie, cookieverf3 cookieverf,
207                      nfs_readdirplus_callback_t callback, void *cbarg);
208errval_t nfs_lookup(struct nfs_client *client, struct nfs_fh3 dirfh,
209                 const char *name, nfs_lookup_callback_t callback, void *cbarg);
210errval_t nfs_access(struct nfs_client *client, struct nfs_fh3 fh, uint32_t access,
211                 nfs_access_callback_t callback, void *cbarg);
212errval_t nfs_read(struct nfs_client *client, struct nfs_fh3 fh, offset3 offset,
213               count3 count, nfs_read_callback_t callback, void *cbarg);
214errval_t nfs_write(struct nfs_client *client, struct nfs_fh3 fh, offset3 offset,
215                const void *data, count3 count, stable_how stable,
216                nfs_write_callback_t callback, void *cbarg);
217errval_t nfs_create(struct nfs_client *client, struct nfs_fh3 dir,
218                 const char *name, bool guarded, sattr3 attributes,
219                 nfs_create_callback_t callback, void *cbarg);
220errval_t nfs_mkdir(struct nfs_client *client, struct nfs_fh3 dir, const char *name,
221                sattr3 attributes, nfs_mkdir_callback_t callback, void *cbarg);
222errval_t nfs_remove(struct nfs_client *client, struct nfs_fh3 dir,
223                 const char *name, nfs_remove_callback_t callback,
224                 void *cbarg);
225void nfs_destroy(struct nfs_client *client);
226
227void nfs_copyfh(struct nfs_fh3 *dest, struct nfs_fh3 src);
228void nfs_freefh(struct nfs_fh3 fh);
229
230
231errval_t nfsstat_to_errval(enum nfsstat3 s);
232errval_t mountstat_to_errval(enum mountstat3 s);
233
234__END_DECLS
235
236#endif // BARRELFISH_NFS_H
237