1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* nfs_inet.h contains definitions specific to inetboot's nfs implementation.
*/
#ifndef _NFS_INET_H
#define _NFS_INET_H
#pragma ident "%Z%%M% %I% %E% SMI"
#ifdef __cplusplus
extern "C" {
#endif
#include <netinet/in.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/if_ether.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/udp.h>
#include <sys/saio.h>
#include <rpcsvc/nfs_prot.h>
#include <rpcsvc/nfs4_prot.h>
#include "clnt.h"
#include <sys/vfs.h>
#include <sys/dirent.h>
#define NFSBUF_SIZE (READ_SIZE+1024)
#define READ_SIZE (8192) /* NFS readsize */
#define NFS_READ_DECR (1024) /* NFS readsize decrement */
#define NFS3BUF_SIZE (READ3_SIZE+1024)
#define READ3_SIZE (32 * 1024) /* NFS3 readsize */
#define NFS4BUF_SIZE (READ4_SIZE+1024)
#define READ4_SIZE (32 * 1024) /* NFS4 readsize */
#define NFS4_MAX_UTF8STRING (8 * 1024)
#define NFS4_MAX_BITWORDS (2)
#define NFS_MAX_FERRS (3) /* MAX frame errors before decr read size */
#define NFS_REXMIT_MIN (3) /* NFS retry min in secs */
#define NFS_REXMIT_MAX (15) /* NFS retry max in secs */
extern int nfs_readsize;
extern struct nfs_file roothandle;
extern CLIENT *root_CLIENT;
/*
* Boot specific V4 fh with maximum allowed data statically allocated
*/
struct nfs_bfh4 {
uint_t len;
char data[NFS4_FHSIZE];
};
/*
* Boot specific V3 fh with maximum allowed data statically allocated
*/
struct nfs_bfh3 {
uint_t len;
char data[NFS3_FHSIZE];
};
union _nfs_fh {
nfs_fh fh2;
struct nfs_bfh3 fh3;
struct nfs_bfh4 fh4;
};
union _nfs_cookie {
nfscookie cookie2;
cookie3 cookie3;
nfs_cookie4 cookie4;
};
union _nfs_ftype {
ftype type2;
ftype3 type3;
nfs_ftype4 type4;
};
/*
* NFS: This structure represents the current open file.
*/
struct nfs_file {
int version;
ulong_t offset;
union _nfs_ftype ftype;
union _nfs_fh fh;
union _nfs_cookie cookie;
};
struct nfs_fid {
ushort_t nf_len;
ushort_t nf_pad;
struct nfs_fh fh;
};
#define cfile_is_dir(cf) (((cf)->version == NFS_VERSION) ? \
((cf)->ftype.type2 == NFDIR) : \
(((cf)->version == NFS_V3) ? \
((cf)->ftype.type3 == NF3DIR) : \
(((cf)->version == NFS_V4) ? \
((cf)->ftype.type4 == NF4DIR) : 0)))
#define cfile_is_lnk(cf) (((cf)->version == NFS_VERSION) ? \
((cf)->ftype.type2 == NFLNK) : \
(((cf)->version == NFS_V3) ? \
((cf)->ftype.type3 == NF3LNK) : \
(((cf)->version == NFS_V4) ? \
((cf)->ftype.type4 == NF4LNK) : 0)))
/*
* Predefine an attribute bitmap that inetboot will most likely be
* interested in.
*/
typedef union attr4_bitmap1_u {
struct {
unsigned int
#ifdef _BIT_FIELDS_HTOL
b_pad4: 11,
b_fattr4_fileid: 1,
b_fattr4_filehandle: 1,
b_pad3: 10,
b_fattr4_fsid: 1,
b_pad2: 3,
b_fattr4_size: 1,
b_pad1: 2,
b_fattr4_type: 1,
b_supported_attrs: 1;
#endif
#ifdef _BIT_FIELDS_LTOH
b_supported_attrs: 1,
b_fattr4_type: 1,
b_pad1: 2,
b_fattr4_size: 1,
b_pad2: 3,
b_fattr4_fsid: 1,
b_pad3: 10,
b_fattr4_filehandle: 1,
b_fattr4_fileid: 1,
b_pad4: 11;
#endif
} bitmap_s;
uint_t word;
} attr4_bitmap1_t;
#define bm_supported_attrs bitmap_s.b_supported_attrs
#define bm_fattr4_type bitmap_s.b_fattr4_type
#define bm_fattr4_size bitmap_s.b_fattr4_size
#define bm_fattr4_fsid bitmap_s.b_fattr4_fsid
#define bm_fattr4_fileid bitmap_s.b_fattr4_fileid
#define bm_fattr4_filehandle bitmap_s.b_fattr4_filehandle
typedef union attr4_bitmap2_u {
struct {
unsigned int
#ifdef _BIT_FIELDS_HTOL
b_pad4: 10,
b_fattr4_time_modify: 1,
b_fattr4_time_metadata: 1,
b_pad3: 4,
b_fattr4_time_access: 1,
b_pad2: 13,
b_fattr4_mode: 1,
b_pad1: 1;
#endif
#ifdef _BIT_FIELDS_LTOH
b_pad1: 1,
b_fattr4_mode: 1,
b_pad2: 13,
b_fattr4_time_access: 1,
b_pad3: 4,
b_fattr4_time_metadata: 1,
b_fattr4_time_modify: 1,
b_pad4: 10;
#endif
} bitmap_s;
uint_t word;
} attr4_bitmap2_t;
#define bm_fattr4_mode bitmap_s.b_fattr4_mode
#define bm_fattr4_time_access bitmap_s.b_fattr4_time_access
#define bm_fattr4_time_metadata bitmap_s.b_fattr4_time_metadata
#define bm_fattr4_time_modify bitmap_s.b_fattr4_time_modify
typedef struct b_bitmap4 {
uint_t b_bitmap_len;
uint_t b_bitmap_val[NFS4_MAX_BITWORDS];
} b_bitmap4_t;
/*
* Define a usable set of v4 atttributes for inetboot.
*/
typedef struct b_fattr4_s {
b_bitmap4_t b_supported_attrs;
nfs_ftype4 b_fattr4_type;
uint64_t b_fattr4_size;
fsid4 b_fattr4_fsid;
struct nfs_bfh4 b_fattr4_filehandle;
uint64_t b_fattr4_fileid;
mode4 b_fattr4_mode;
nfstime4 b_fattr4_time_access;
nfstime4 b_fattr4_time_metadata;
nfstime4 b_fattr4_time_modify;
} b_fattr4_t;
/*
* common to putfh and putfhroot.
*/
typedef struct putfh4arg_s {
uint_t pf_opnum; /* can either be putfh or putrootfh */
struct nfs_bfh4 pf_filehandle; /* only used by putfh */
} putfh4arg_t;
/*
* Use this struct to construct our OTW compound procedures. Layout makes for
* easy XDR'ing. Include putfh.
*/
typedef union compound_u {
struct {
utf8string tag;
uint_t minorversion; /* 0 */
uint_t argarray_len; /* 1 + n for putfh */
bool_t isputrootfh; /* flag */
putfh4arg_t opputfh; /* putfh args */
} compound_ua_s;
struct {
nfsstat4 status; /* status of last op */
utf8string tag;
uint_t resarray_len; /* 1 + n for putfh */
uint_t opputfh; /* putfh opnum */
nfsstat4 putfh_status; /* putfh status */
} compound_ur_s;
} b_compound_t;
/*
* Define some macros for easy access into the compound structrue
*/
#define ca_tag compound_ua_s.tag
#define ca_minorversion compound_ua_s.minorversion
#define ca_argarray_len compound_ua_s.argarray_len
#define ca_isputrootfh compound_ua_s.isputrootfh
#define ca_opputfh compound_ua_s.opputfh
#define cr_status compound_ur_s.status
#define cr_tag compound_ur_s.tag
#define cr_resarray_len compound_ur_s.resarray_len
#define cr_opputfh compound_ur_s.opputfh
#define cr_putfh_status compound_ur_s.putfh_status
/*
* Define simple compound structs that include op specific data
*/
typedef struct getattrres_cmn {
uint_t gc_opgetattr; /* getattr opnum */
nfsstat4 gc_attr_status; /* getattr result */
b_bitmap4_t gc_retattr; /* getattr result */
uint_t gc_attrlist_len; /* getattr result */
b_fattr4_t gc_attrs; /* getattr result */
} getattrres_cmn_t;
/*
* getattr: putfh/getattr
*/
typedef struct getattr4arg_s {
b_compound_t ga_arg; /* compound + putfh */
uint_t ga_opgetattr; /* getattr opnum */
b_bitmap4_t ga_attr_req; /* getattr arg */
} getattr4arg_t;
typedef struct getattr4res_s {
b_compound_t gr_res; /* compound + putfh */
getattrres_cmn_t gr_cmn;
} getattr4res_t;
#define gr_opgetattr gr_cmn.gc_opgetattr
#define gr_attr_status gr_cmn.gc_attr_status
#define gr_retattr gr_cmn.gc_retattr
#define gr_attrs gr_cmn.gc_attrs
/*
* lookup: putfh/lookup/getattr
*/
typedef struct lookup4arg_s {
b_compound_t la_arg; /* compound + putfh */
uint_t la_oplookup; /* lookup opnum */
component4 la_pathname; /* lookup arg */
uint_t la_opgetattr; /* getattr opnum */
b_bitmap4_t la_attr_req; /* getattr arg */
} lookup4arg_t;
typedef struct lookup4res_s {
b_compound_t lr_res; /* compound + putfh */
uint_t lr_oplookup; /* lookup opnum */
nfsstat4 lr_lookup_status; /* lookup result */
getattrres_cmn_t lr_gcmn; /* getattr result */
} lookup4res_t;
#define lr_opgetattr lr_gcmn.gc_opgetattr
#define lr_attr_status lr_gcmn.gc_attr_status
#define lr_retattr lr_gcmn.gc_retattr
#define lr_attrs lr_gcmn.gc_attrs
/*
* lookupp: putfh/lookupp/getattr
*
* For results: use the lookup4res_t
*/
typedef struct lookupp4arg_s {
b_compound_t la_arg; /* compound + putfh */
uint_t la_oplookupp; /* lookupp opnum */
uint_t la_opgetattr; /* lookupp arg */
b_bitmap4_t la_attr_req; /* lookupp arg */
} lookupp4arg_t;
/*
* read: putfh/read
*/
typedef struct read4arg_s {
b_compound_t r_arg; /* compound + putfh */
uint_t r_opread; /* read opnum */
stateid4 r_stateid; /* read arg */
offset4 r_offset; /* read arg */
count4 r_count; /* read arg */
} read4arg_t;
typedef struct read4res_s {
b_compound_t r_res; /* compound + putfh */
uint_t r_opread; /* read opnum */
nfsstat4 r_status; /* read result */
bool_t r_eof; /* read result */
uint_t r_data_len; /* read result */
char *r_data_val; /* read result */
} read4res_t;
typedef struct b_entry4_s {
nfs_cookie4 b_cookie;
utf8string b_name;
uint64_t b_fileid;
struct b_entry4_s *b_nextentry;
} b_entry4_t;
/*
* readdir: putfh/readdir/getattr
*/
typedef struct readdir4arg_s {
b_compound_t rd_arg; /* compoud + putfh */
uint_t rd_opreaddir; /* readdir opnum */
nfs_cookie4 rd_cookie; /* readdir arg */
verifier4 rd_cookieverf; /* readdir arg */
count4 rd_dircount; /* readdir arg */
count4 rd_maxcount; /* readdir arg */
b_bitmap4_t rd_attr_req; /* readdir arg */
} readdir4arg_t;
typedef struct readdir4res_s {
b_compound_t rd_res; /* compound + putfh */
uint_t rd_opreaddir; /* readdir opnum */
nfsstat4 rd_status; /* readdir result */
verifier4 rd_cookieverf; /* readdir result */
b_entry4_t *rd_entries; /* readdir result */
bool_t rd_eof; /* readdir result */
} readdir4res_t;
/*
* readlink: putfh/readlink
*/
typedef struct readlink4arg_s {
b_compound_t rl_arg; /* compound + putfh */
uint_t rl_opreadlink; /* readlink opnum */
} readlink4arg_t;
typedef struct readlink4res_s {
b_compound_t rl_res; /* compound + putfh */
uint_t rl_opreadlink; /* readlink opnum */
nfsstat4 rl_status; /* readlink result */
utf8string rl_link; /* readlink result */
} readlink4res_t;
/*
* Generic NFS functions
*/
extern int boot_nfs_mountroot(char *);
extern int boot_nfs_unmountroot(void);
extern int lookup(char *pathname, struct nfs_file *, bool_t);
extern bool_t whoami(void);
extern bool_t getfile(char *, char *, struct in_addr *, char *);
/*
* NFS Version 2 specific functions
*/
extern void nfs_error(enum nfsstat);
extern ssize_t nfsread(struct nfs_file *, char *, size_t);
extern int nfsgetattr(struct nfs_file *, struct vattr *);
extern int nfsgetdents(struct nfs_file *, struct dirent *, unsigned);
extern struct nfs_file *nfslookup(struct nfs_file *, char *, int *);
extern int nfsgetsymlink(struct nfs_file *cfile, char **path);
/*
* NFS Version 3 specific functions
*/
extern void nfs3_error(enum nfsstat3);
extern ssize_t nfs3read(struct nfs_file *, char *, size_t);
extern int nfs3getattr(struct nfs_file *, struct vattr *);
extern int nfs3getdents(struct nfs_file *, struct dirent *, unsigned);
extern struct nfs_file *nfs3lookup(struct nfs_file *, char *, int *);
extern int nfs3getsymlink(struct nfs_file *, char **);
/*
* NFS Version 4 specific functions
*/
extern void nfs4_error(enum nfsstat4);
extern ssize_t nfs4read(struct nfs_file *, char *, size_t);
extern int nfs4getattr(struct nfs_file *, struct vattr *);
extern int nfs4_getdents(struct nfs_file *, struct dirent *, unsigned);
extern struct nfs_file *nfs4lookup(struct nfs_file *, char *, int *);
extern struct nfs_file *nfs4lookupp(struct nfs_file *, int *, uint64_t *);
extern int nfs4getsymlink(struct nfs_file *, char **);
extern void compound_init(b_compound_t *, utf8string *, uint_t, uint_t,
struct nfs_bfh4 *);
/*
* NFSv4 xdr ops
*/
extern bool_t xdr_getattr4_args(XDR *, getattr4arg_t *);
extern bool_t xdr_getattr4_res(XDR *, getattr4res_t *);
extern bool_t xdr_lookup4_args(XDR *, lookup4arg_t *);
extern bool_t xdr_lookup4_res(XDR *, lookup4res_t *);
extern bool_t xdr_lookupp4_args(XDR *, lookupp4arg_t *);
extern bool_t xdr_read4_args(XDR *, read4arg_t *);
extern bool_t xdr_read4_res(XDR *, read4res_t *);
extern bool_t xdr_readdir4_args(XDR *, readdir4arg_t *);
extern bool_t xdr_readdir4_res(XDR *, readdir4res_t *);
extern bool_t xdr_readlink4_args(XDR *, readlink4arg_t *);
extern bool_t xdr_readlink4_res(XDR *, readlink4res_t *);
#ifdef __cplusplus
}
#endif
#endif /* _NFS_INET_H */
|