4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
26 * nfs_inet.h contains definitions specific to inetboot's nfs implementation.
32 #pragma ident "%Z%%M% %I% %E% SMI"
38 #include <netinet/in.h>
39 #include <sys/socket.h>
41 #include <netinet/if_ether.h>
42 #include <netinet/in_systm.h>
43 #include <netinet/ip.h>
44 #include <netinet/udp.h>
46 #include <rpcsvc/nfs_prot.h>
47 #include <rpcsvc/nfs4_prot.h>
50 #include <sys/dirent.h>
52 #define NFSBUF_SIZE (READ_SIZE+1024)
53 #define READ_SIZE (8192) /* NFS readsize */
54 #define NFS_READ_DECR (1024) /* NFS readsize decrement */
55 #define NFS3BUF_SIZE (READ3_SIZE+1024)
56 #define READ3_SIZE (32 * 1024) /* NFS3 readsize */
57 #define NFS4BUF_SIZE (READ4_SIZE+1024)
58 #define READ4_SIZE (32 * 1024) /* NFS4 readsize */
59 #define NFS4_MAX_UTF8STRING (8 * 1024)
60 #define NFS4_MAX_BITWORDS (2)
61 #define NFS_MAX_FERRS (3) /* MAX frame errors before decr read size */
62 #define NFS_REXMIT_MIN (3) /* NFS retry min in secs */
63 #define NFS_REXMIT_MAX (15) /* NFS retry max in secs */
65 extern int nfs_readsize
;
66 extern struct nfs_file roothandle
;
67 extern CLIENT
*root_CLIENT
;
70 * Boot specific V4 fh with maximum allowed data statically allocated
74 char data
[NFS4_FHSIZE
];
78 * Boot specific V3 fh with maximum allowed data statically allocated
82 char data
[NFS3_FHSIZE
];
104 * NFS: This structure represents the current open file.
109 union _nfs_ftype ftype
;
111 union _nfs_cookie cookie
;
120 #define cfile_is_dir(cf) (((cf)->version == NFS_VERSION) ? \
121 ((cf)->ftype.type2 == NFDIR) : \
122 (((cf)->version == NFS_V3) ? \
123 ((cf)->ftype.type3 == NF3DIR) : \
124 (((cf)->version == NFS_V4) ? \
125 ((cf)->ftype.type4 == NF4DIR) : 0)))
127 #define cfile_is_lnk(cf) (((cf)->version == NFS_VERSION) ? \
128 ((cf)->ftype.type2 == NFLNK) : \
129 (((cf)->version == NFS_V3) ? \
130 ((cf)->ftype.type3 == NF3LNK) : \
131 (((cf)->version == NFS_V4) ? \
132 ((cf)->ftype.type4 == NF4LNK) : 0)))
135 * Predefine an attribute bitmap that inetboot will most likely be
138 typedef union attr4_bitmap1_u
{
141 #ifdef _BIT_FIELDS_HTOL
144 b_fattr4_filehandle
: 1,
151 b_supported_attrs
: 1;
153 #ifdef _BIT_FIELDS_LTOH
154 b_supported_attrs
: 1,
161 b_fattr4_filehandle
: 1,
169 #define bm_supported_attrs bitmap_s.b_supported_attrs
170 #define bm_fattr4_type bitmap_s.b_fattr4_type
171 #define bm_fattr4_size bitmap_s.b_fattr4_size
172 #define bm_fattr4_fsid bitmap_s.b_fattr4_fsid
173 #define bm_fattr4_fileid bitmap_s.b_fattr4_fileid
174 #define bm_fattr4_filehandle bitmap_s.b_fattr4_filehandle
176 typedef union attr4_bitmap2_u
{
179 #ifdef _BIT_FIELDS_HTOL
181 b_fattr4_time_modify
: 1,
182 b_fattr4_time_metadata
: 1,
184 b_fattr4_time_access
: 1,
189 #ifdef _BIT_FIELDS_LTOH
193 b_fattr4_time_access
: 1,
195 b_fattr4_time_metadata
: 1,
196 b_fattr4_time_modify
: 1,
203 #define bm_fattr4_mode bitmap_s.b_fattr4_mode
204 #define bm_fattr4_time_access bitmap_s.b_fattr4_time_access
205 #define bm_fattr4_time_metadata bitmap_s.b_fattr4_time_metadata
206 #define bm_fattr4_time_modify bitmap_s.b_fattr4_time_modify
208 typedef struct b_bitmap4
{
210 uint_t b_bitmap_val
[NFS4_MAX_BITWORDS
];
214 * Define a usable set of v4 atttributes for inetboot.
216 typedef struct b_fattr4_s
{
217 b_bitmap4_t b_supported_attrs
;
218 nfs_ftype4 b_fattr4_type
;
219 uint64_t b_fattr4_size
;
221 struct nfs_bfh4 b_fattr4_filehandle
;
222 uint64_t b_fattr4_fileid
;
224 nfstime4 b_fattr4_time_access
;
225 nfstime4 b_fattr4_time_metadata
;
226 nfstime4 b_fattr4_time_modify
;
230 * common to putfh and putfhroot.
232 typedef struct putfh4arg_s
{
233 uint_t pf_opnum
; /* can either be putfh or putrootfh */
234 struct nfs_bfh4 pf_filehandle
; /* only used by putfh */
238 * Use this struct to construct our OTW compound procedures. Layout makes for
239 * easy XDR'ing. Include putfh.
241 typedef union compound_u
{
244 uint_t minorversion
; /* 0 */
245 uint_t argarray_len
; /* 1 + n for putfh */
246 bool_t isputrootfh
; /* flag */
247 putfh4arg_t opputfh
; /* putfh args */
250 nfsstat4 status
; /* status of last op */
252 uint_t resarray_len
; /* 1 + n for putfh */
253 uint_t opputfh
; /* putfh opnum */
254 nfsstat4 putfh_status
; /* putfh status */
259 * Define some macros for easy access into the compound structrue
261 #define ca_tag compound_ua_s.tag
262 #define ca_minorversion compound_ua_s.minorversion
263 #define ca_argarray_len compound_ua_s.argarray_len
264 #define ca_isputrootfh compound_ua_s.isputrootfh
265 #define ca_opputfh compound_ua_s.opputfh
267 #define cr_status compound_ur_s.status
268 #define cr_tag compound_ur_s.tag
269 #define cr_resarray_len compound_ur_s.resarray_len
270 #define cr_opputfh compound_ur_s.opputfh
271 #define cr_putfh_status compound_ur_s.putfh_status
273 * Define simple compound structs that include op specific data
275 typedef struct getattrres_cmn
{
276 uint_t gc_opgetattr
; /* getattr opnum */
277 nfsstat4 gc_attr_status
; /* getattr result */
278 b_bitmap4_t gc_retattr
; /* getattr result */
279 uint_t gc_attrlist_len
; /* getattr result */
280 b_fattr4_t gc_attrs
; /* getattr result */
284 * getattr: putfh/getattr
286 typedef struct getattr4arg_s
{
287 b_compound_t ga_arg
; /* compound + putfh */
288 uint_t ga_opgetattr
; /* getattr opnum */
289 b_bitmap4_t ga_attr_req
; /* getattr arg */
292 typedef struct getattr4res_s
{
293 b_compound_t gr_res
; /* compound + putfh */
294 getattrres_cmn_t gr_cmn
;
297 #define gr_opgetattr gr_cmn.gc_opgetattr
298 #define gr_attr_status gr_cmn.gc_attr_status
299 #define gr_retattr gr_cmn.gc_retattr
300 #define gr_attrs gr_cmn.gc_attrs
303 * lookup: putfh/lookup/getattr
305 typedef struct lookup4arg_s
{
306 b_compound_t la_arg
; /* compound + putfh */
307 uint_t la_oplookup
; /* lookup opnum */
308 component4 la_pathname
; /* lookup arg */
309 uint_t la_opgetattr
; /* getattr opnum */
310 b_bitmap4_t la_attr_req
; /* getattr arg */
313 typedef struct lookup4res_s
{
314 b_compound_t lr_res
; /* compound + putfh */
315 uint_t lr_oplookup
; /* lookup opnum */
316 nfsstat4 lr_lookup_status
; /* lookup result */
317 getattrres_cmn_t lr_gcmn
; /* getattr result */
320 #define lr_opgetattr lr_gcmn.gc_opgetattr
321 #define lr_attr_status lr_gcmn.gc_attr_status
322 #define lr_retattr lr_gcmn.gc_retattr
323 #define lr_attrs lr_gcmn.gc_attrs
326 * lookupp: putfh/lookupp/getattr
328 * For results: use the lookup4res_t
330 typedef struct lookupp4arg_s
{
331 b_compound_t la_arg
; /* compound + putfh */
332 uint_t la_oplookupp
; /* lookupp opnum */
333 uint_t la_opgetattr
; /* lookupp arg */
334 b_bitmap4_t la_attr_req
; /* lookupp arg */
340 typedef struct read4arg_s
{
341 b_compound_t r_arg
; /* compound + putfh */
342 uint_t r_opread
; /* read opnum */
343 stateid4 r_stateid
; /* read arg */
344 offset4 r_offset
; /* read arg */
345 count4 r_count
; /* read arg */
348 typedef struct read4res_s
{
349 b_compound_t r_res
; /* compound + putfh */
350 uint_t r_opread
; /* read opnum */
351 nfsstat4 r_status
; /* read result */
352 bool_t r_eof
; /* read result */
353 uint_t r_data_len
; /* read result */
354 char *r_data_val
; /* read result */
357 typedef struct b_entry4_s
{
358 nfs_cookie4 b_cookie
;
361 struct b_entry4_s
*b_nextentry
;
365 * readdir: putfh/readdir/getattr
367 typedef struct readdir4arg_s
{
368 b_compound_t rd_arg
; /* compoud + putfh */
369 uint_t rd_opreaddir
; /* readdir opnum */
370 nfs_cookie4 rd_cookie
; /* readdir arg */
371 verifier4 rd_cookieverf
; /* readdir arg */
372 count4 rd_dircount
; /* readdir arg */
373 count4 rd_maxcount
; /* readdir arg */
374 b_bitmap4_t rd_attr_req
; /* readdir arg */
377 typedef struct readdir4res_s
{
378 b_compound_t rd_res
; /* compound + putfh */
379 uint_t rd_opreaddir
; /* readdir opnum */
380 nfsstat4 rd_status
; /* readdir result */
381 verifier4 rd_cookieverf
; /* readdir result */
382 b_entry4_t
*rd_entries
; /* readdir result */
383 bool_t rd_eof
; /* readdir result */
387 * readlink: putfh/readlink
389 typedef struct readlink4arg_s
{
390 b_compound_t rl_arg
; /* compound + putfh */
391 uint_t rl_opreadlink
; /* readlink opnum */
394 typedef struct readlink4res_s
{
395 b_compound_t rl_res
; /* compound + putfh */
396 uint_t rl_opreadlink
; /* readlink opnum */
397 nfsstat4 rl_status
; /* readlink result */
398 utf8string rl_link
; /* readlink result */
402 * Generic NFS functions
404 extern int boot_nfs_mountroot(char *);
405 extern int boot_nfs_unmountroot(void);
406 extern int lookup(char *pathname
, struct nfs_file
*, bool_t
);
407 extern bool_t
whoami(void);
408 extern bool_t
getfile(char *, char *, struct in_addr
*, char *);
411 * NFS Version 2 specific functions
413 extern void nfs_error(enum nfsstat
);
414 extern ssize_t
nfsread(struct nfs_file
*, char *, size_t);
415 extern int nfsgetattr(struct nfs_file
*, struct vattr
*);
416 extern int nfsgetdents(struct nfs_file
*, struct dirent
*, unsigned);
417 extern struct nfs_file
*nfslookup(struct nfs_file
*, char *, int *);
418 extern int nfsgetsymlink(struct nfs_file
*cfile
, char **path
);
421 * NFS Version 3 specific functions
423 extern void nfs3_error(enum nfsstat3
);
424 extern ssize_t
nfs3read(struct nfs_file
*, char *, size_t);
425 extern int nfs3getattr(struct nfs_file
*, struct vattr
*);
426 extern int nfs3getdents(struct nfs_file
*, struct dirent
*, unsigned);
427 extern struct nfs_file
*nfs3lookup(struct nfs_file
*, char *, int *);
428 extern int nfs3getsymlink(struct nfs_file
*, char **);
431 * NFS Version 4 specific functions
433 extern void nfs4_error(enum nfsstat4
);
434 extern ssize_t
nfs4read(struct nfs_file
*, char *, size_t);
435 extern int nfs4getattr(struct nfs_file
*, struct vattr
*);
436 extern int nfs4_getdents(struct nfs_file
*, struct dirent
*, unsigned);
437 extern struct nfs_file
*nfs4lookup(struct nfs_file
*, char *, int *);
438 extern struct nfs_file
*nfs4lookupp(struct nfs_file
*, int *, uint64_t *);
439 extern int nfs4getsymlink(struct nfs_file
*, char **);
440 extern void compound_init(b_compound_t
*, utf8string
*, uint_t
, uint_t
,
446 extern bool_t
xdr_getattr4_args(XDR
*, getattr4arg_t
*);
447 extern bool_t
xdr_getattr4_res(XDR
*, getattr4res_t
*);
448 extern bool_t
xdr_lookup4_args(XDR
*, lookup4arg_t
*);
449 extern bool_t
xdr_lookup4_res(XDR
*, lookup4res_t
*);
450 extern bool_t
xdr_lookupp4_args(XDR
*, lookupp4arg_t
*);
451 extern bool_t
xdr_read4_args(XDR
*, read4arg_t
*);
452 extern bool_t
xdr_read4_res(XDR
*, read4res_t
*);
453 extern bool_t
xdr_readdir4_args(XDR
*, readdir4arg_t
*);
454 extern bool_t
xdr_readdir4_res(XDR
*, readdir4res_t
*);
455 extern bool_t
xdr_readlink4_args(XDR
*, readlink4arg_t
*);
456 extern bool_t
xdr_readlink4_res(XDR
*, readlink4res_t
*);
462 #endif /* _NFS_INET_H */