Print this page
NEX-16819 loader UEFI support
Includes work by Toomas Soome <tsoome@me.com>
Upstream commits:
loader: pxe receive cleanup
9475 libefi: Do not return only if ReceiveFilter
installboot: should support efi system partition
8931 boot1.efi: scan all display modes rather than
loader: spinconsole updates
loader: gfx experiment to try GOP Blt() function.
sha1 build test
loader: add sha1 hash calculation
common/sha1: update for loader build
loader: biosdisk rework
uts: 32-bit kernel FB needs mapping in low memory
uts: add diag-device
uts: boot console mirror with diag-device
uts: enable very early console on ttya
kmdb: add diag-device as input/output device
uts: test VGA memory exclusion from mapping
uts: clear boot mapping and protect boot pages test
uts: add dboot map debug printf
uts: need to release FB pages in release_bootstrap()
uts: add screenmap ioctl
uts: update sys/queue.h
loader: add illumos uts/common to include path
loader: tem/gfx font cleanup
loader: vbe checks
uts: gfx_private set KD_TEXT when KD_RESETTEXT is
uts: gfx 8-bit update
loader: gfx 8-bit fix
loader: always set media size from partition.
uts: MB2 support for 32-bit kernel
loader: x86 should have tem 80x25
uts: x86 should have tem 80x25
uts: font update
loader: font update
uts: tem attributes
loader: tem.c comment added
uts: use font module
loader: add font module
loader: build rules for new font setup
uts: gfx_private update for new font structure
uts: early boot update for new font structure
uts: font update
uts: font build rules update for new fonts
uts: tem update to new font structure
loader: module.c needs to include tem_impl.h
uts: gfx_private 8x16 font rework
uts: make font_lookup public
loader: font rework
uts: font rework
9259 libefi: efi_alloc_and_read should check for PMBR
uts: tem utf-8 support
loader: implement tem utf-8 support
loader: tem should be able to display UTF-8
7784 uts: console input should support utf-8
7796 uts: ldterm default to utf-8
uts: do not reset serial console
uts: set up colors even if tem is not console
uts: add type for early boot properties
uts: gfx_private experiment with drm and vga
uts: gfx_private should use setmode drm callback.
uts: identify FB types and set up gfx_private based
loader: replace gop and vesa with framebuffer
uts: boot needs simple tem to support mdb
uts: boot_keyboard should emit esc sequences for
uts: gfx_private FB showuld be written by line
kmdb: set terminal window size
uts: gfx_private needs to keep track of early boot FB
pnglite: move pnglite to usr/src/common
loader: gfx_fb
ficl-sys: add gfx primitives
loader: add illumos.png logo
ficl: add fb-putimage
loader: add png support
loader: add alpha blending for gfx_fb
loader: use term-drawrect for menu frame
ficl: add simple gfx words
uts: provide fb_info via fbgattr dev_specific array.
uts: gfx_private add alpha blending
uts: update sys/ascii.h
uts: tem OSC support (incomplete)
uts: implement env module support and use data from
uts: tem get colors from early boot data
loader: use crc32 from libstand (libz)
loader: optimize for size
loader: pass tem info to the environment
loader: import tem for loader console
loader: UEFI loader needs to set ISADIR based on
loader: need UEFI32 support
8918 loader.efi: add vesa edid support
uts: tem_safe_pix_clear_prom_output() should only
uts: tem_safe_pix_clear_entire_screen() should use
uts: tem_safe_check_first_time() should query cursor
uts: tem implement cls callback & visual_io v4
uts: gfx_vgatext use block cursor for vgatext
uts: gfx_private implement cls callback & visual_io
uts: gfx_private bitmap framebuffer implementation
uts: early start frame buffer console support
uts: font functions should check the input char
uts: font rendering should support 16/24/32bit depths
uts: use smallest font as fallback default.
uts: update terminal dimensions based on selected
7834 uts: vgatext should use gfx_private
uts: add spacing property to 8859-1.bdf
terminfo: add underline for sun-color
terminfo: sun-color has 16 colors
uts: add font load callback type
loader: do not repeat int13 calls with error 0x20 and
8905 loader: add skein/edonr support
8904 common/crypto: make skein and edonr loader
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Revert "NEX-16819 loader UEFI support"
This reverts commit ec06b9fc617b99234e538bf2e7e4d02a24993e0c.
Reverting due to failures in the zfs-tests and the sharefs-tests
NEX-16819 loader UEFI support
Includes work by Toomas Soome <tsoome@me.com>
Upstream commits:
loader: pxe receive cleanup
9475 libefi: Do not return only if ReceiveFilter
installboot: should support efi system partition
8931 boot1.efi: scan all display modes rather than
loader: spinconsole updates
loader: gfx experiment to try GOP Blt() function.
sha1 build test
loader: add sha1 hash calculation
common/sha1: update for loader build
loader: biosdisk rework
uts: 32-bit kernel FB needs mapping in low memory
uts: add diag-device
uts: boot console mirror with diag-device
uts: enable very early console on ttya
kmdb: add diag-device as input/output device
uts: test VGA memory exclusion from mapping
uts: clear boot mapping and protect boot pages test
uts: add dboot map debug printf
uts: need to release FB pages in release_bootstrap()
uts: add screenmap ioctl
uts: update sys/queue.h
loader: add illumos uts/common to include path
loader: tem/gfx font cleanup
loader: vbe checks
uts: gfx_private set KD_TEXT when KD_RESETTEXT is
uts: gfx 8-bit update
loader: gfx 8-bit fix
loader: always set media size from partition.
uts: MB2 support for 32-bit kernel
loader: x86 should have tem 80x25
uts: x86 should have tem 80x25
uts: font update
loader: font update
uts: tem attributes
loader: tem.c comment added
uts: use font module
loader: add font module
loader: build rules for new font setup
uts: gfx_private update for new font structure
uts: early boot update for new font structure
uts: font update
uts: font build rules update for new fonts
uts: tem update to new font structure
loader: module.c needs to include tem_impl.h
uts: gfx_private 8x16 font rework
uts: make font_lookup public
loader: font rework
uts: font rework
libefi: efi_alloc_and_read should check for PMBR
uts: tem utf-8 support
loader: implement tem utf-8 support
loader: tem should be able to display UTF-8
7784 uts: console input should support utf-8
7796 uts: ldterm default to utf-8
uts: do not reset serial console
uts: set up colors even if tem is not console
uts: add type for early boot properties
uts: gfx_private experiment with drm and vga
uts: gfx_private should use setmode drm callback.
uts: identify FB types and set up gfx_private based
loader: replace gop and vesa with framebuffer
uts: boot needs simple tem to support mdb
uts: boot_keyboard should emit esc sequences for
uts: gfx_private FB showuld be written by line
kmdb: set terminal window size
uts: gfx_private needs to keep track of early boot FB
pnglite: move pnglite to usr/src/common
loader: gfx_fb
ficl-sys: add gfx primitives
loader: add illumos.png logo
ficl: add fb-putimage
loader: add png support
loader: add alpha blending for gfx_fb
loader: use term-drawrect for menu frame
ficl: add simple gfx words
uts: provide fb_info via fbgattr dev_specific array.
uts: gfx_private add alpha blending
uts: update sys/ascii.h
uts: tem OSC support (incomplete)
uts: implement env module support and use data from
uts: tem get colors from early boot data
loader: use crc32 from libstand (libz)
loader: optimize for size
loader: pass tem info to the environment
loader: import tem for loader console
loader: UEFI loader needs to set ISADIR based on
loader: need UEFI32 support
8918 loader.efi: add vesa edid support
uts: tem_safe_pix_clear_prom_output() should only
uts: tem_safe_pix_clear_entire_screen() should use
uts: tem_safe_check_first_time() should query cursor
uts: tem implement cls callback & visual_io v4
uts: gfx_vgatext use block cursor for vgatext
uts: gfx_private implement cls callback & visual_io
uts: gfx_private bitmap framebuffer implementation
uts: early start frame buffer console support
uts: font functions should check the input char
uts: font rendering should support 16/24/32bit depths
uts: use smallest font as fallback default.
uts: update terminal dimensions based on selected
7834 uts: vgatext should use gfx_private
uts: add spacing property to 8859-1.bdf
terminfo: add underline for sun-color
terminfo: sun-color has 16 colors
uts: add font load callback type
loader: do not repeat int13 calls with error 0x20 and
8905 loader: add skein/edonr support
8904 common/crypto: make skein and edonr loader
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/boot/lib/libstand/nfs.c
+++ new/usr/src/boot/lib/libstand/nfs.c
1 1 /* $NetBSD: nfs.c,v 1.2 1998/01/24 12:43:09 drochner Exp $ */
2 2
3 3 /*-
4 4 * Copyright (c) 1993 John Brezak
5 5 * All rights reserved.
6 6 *
7 7 * Redistribution and use in source and binary forms, with or without
8 8 * modification, are permitted provided that the following conditions
9 9 * are met:
10 10 * 1. Redistributions of source code must retain the above copyright
11 11 * notice, this list of conditions and the following disclaimer.
12 12 * 2. Redistributions in binary form must reproduce the above copyright
13 13 * notice, this list of conditions and the following disclaimer in the
14 14 * documentation and/or other materials provided with the distribution.
15 15 * 3. The name of the author may not be used to endorse or promote products
16 16 * derived from this software without specific prior written permission.
17 17 *
18 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
19 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 21 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
22 22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 28 * POSSIBILITY OF SUCH DAMAGE.
29 29 */
30 30
31 31 #include <sys/cdefs.h>
32 32
33 33 #include <sys/param.h>
34 34 #include <sys/time.h>
35 35 #include <sys/socket.h>
36 36 #include <sys/stat.h>
37 37 #include <string.h>
38 38 #include <stddef.h>
39 39
40 40 #include <netinet/in.h>
41 41 #include <netinet/in_systm.h>
42 42
43 43 #include "rpcv2.h"
44 44 #include "nfsv2.h"
45 45
46 46 #include "stand.h"
47 47 #include "net.h"
48 48 #include "netif.h"
49 49 #include "rpc.h"
50 50
51 51 #define NFS_DEBUGxx
52 52
53 53 #define NFSREAD_MIN_SIZE 1024
54 54 #define NFSREAD_MAX_SIZE 16384
55 55
56 56 /* NFSv3 definitions */
57 57 #define NFS_V3MAXFHSIZE 64
58 58 #define NFS_VER3 3
59 59 #define RPCMNT_VER3 3
60 60 #define NFSPROCV3_LOOKUP 3
61 61 #define NFSPROCV3_READLINK 5
62 62 #define NFSPROCV3_READ 6
63 63 #define NFSPROCV3_READDIR 16
64 64
65 65 typedef struct {
66 66 uint32_t val[2];
67 67 } n_quad;
68 68
69 69 struct nfsv3_time {
70 70 uint32_t nfs_sec;
71 71 uint32_t nfs_nsec;
72 72 };
73 73
74 74 struct nfsv3_fattrs {
75 75 uint32_t fa_type;
76 76 uint32_t fa_mode;
77 77 uint32_t fa_nlink;
78 78 uint32_t fa_uid;
79 79 uint32_t fa_gid;
80 80 n_quad fa_size;
81 81 n_quad fa_used;
82 82 n_quad fa_rdev;
83 83 n_quad fa_fsid;
84 84 n_quad fa_fileid;
85 85 struct nfsv3_time fa_atime;
86 86 struct nfsv3_time fa_mtime;
87 87 struct nfsv3_time fa_ctime;
88 88 };
89 89
90 90 /*
91 91 * For NFSv3, the file handle is variable in size, so most fixed sized
92 92 * structures for arguments won't work. For most cases, a structure
93 93 * that starts with any fixed size section is followed by an array
94 94 * that covers the maximum size required.
95 95 */
96 96 struct nfsv3_readdir_repl {
97 97 uint32_t errno;
98 98 uint32_t ok;
99 99 struct nfsv3_fattrs fa;
100 100 uint32_t cookiev0;
101 101 uint32_t cookiev1;
102 102 };
103 103
104 104 struct nfsv3_readdir_entry {
105 105 uint32_t follows;
106 106 uint32_t fid0;
107 107 uint32_t fid1;
108 108 uint32_t len;
109 109 uint32_t nameplus[0];
110 110 };
111 111
112 112 struct nfs_iodesc {
113 113 struct iodesc *iodesc;
114 114 off_t off;
115 115 uint32_t fhsize;
116 116 u_char fh[NFS_V3MAXFHSIZE];
117 117 struct nfsv3_fattrs fa; /* all in network order */
|
↓ open down ↓ |
117 lines elided |
↑ open up ↑ |
118 118 uint64_t cookie;
119 119 };
120 120
121 121 /*
122 122 * XXX interactions with tftp? See nfswrapper.c for a confusing
123 123 * issue.
124 124 */
125 125 int nfs_open(const char *path, struct open_file *f);
126 126 static int nfs_close(struct open_file *f);
127 127 static int nfs_read(struct open_file *f, void *buf, size_t size, size_t *resid);
128 -static int nfs_write(struct open_file *f, void *buf, size_t size, size_t *resid);
129 128 static off_t nfs_seek(struct open_file *f, off_t offset, int where);
130 129 static int nfs_stat(struct open_file *f, struct stat *sb);
131 130 static int nfs_readdir(struct open_file *f, struct dirent *d);
132 131
133 132 struct nfs_iodesc nfs_root_node;
134 133
135 134 struct fs_ops nfs_fsops = {
136 135 "nfs",
137 136 nfs_open,
138 137 nfs_close,
139 138 nfs_read,
140 - nfs_write,
139 + null_write,
141 140 nfs_seek,
142 141 nfs_stat,
143 142 nfs_readdir
144 143 };
145 144
146 145 static int nfs_read_size = NFSREAD_MIN_SIZE;
147 146
148 147 /*
149 148 * Improve boot performance over NFS
150 149 */
151 150 static void
152 151 set_nfs_read_size(void)
153 152 {
154 153 char *env, *end;
155 154 char buf[10];
156 155
157 156 if ((env = getenv("nfs.read_size")) != NULL) {
158 157 errno = 0;
159 158 nfs_read_size = strtol(env, &end, 0);
160 159 if (errno != 0 || *env == '\0' || *end != '\0') {
161 160 printf("%s: bad value: \"%s\", defaulting to %d\n",
162 161 "nfs.read_size", env, NFSREAD_MIN_SIZE);
163 162 nfs_read_size = NFSREAD_MIN_SIZE;
164 163 }
165 164 }
166 165 if (nfs_read_size < NFSREAD_MIN_SIZE) {
167 166 printf("%s: bad value: \"%d\", defaulting to %d\n",
168 167 "nfs.read_size", nfs_read_size, NFSREAD_MIN_SIZE);
169 168 nfs_read_size = NFSREAD_MIN_SIZE;
170 169 }
171 170 if (nfs_read_size > NFSREAD_MAX_SIZE) {
172 171 printf("%s: bad value: \"%d\", defaulting to %d\n",
173 172 "nfs.read_size", nfs_read_size, NFSREAD_MIN_SIZE);
174 173 nfs_read_size = NFSREAD_MAX_SIZE;
175 174 }
176 175 snprintf(buf, sizeof (buf), "%d", nfs_read_size);
177 176 setenv("nfs.read_size", buf, 1);
178 177 }
179 178
180 179 /*
181 180 * Fetch the root file handle (call mount daemon)
182 181 * Return zero or error number.
183 182 */
184 183 int
185 184 nfs_getrootfh(struct iodesc *d, char *path, uint32_t *fhlenp, u_char *fhp)
186 185 {
187 186 void *pkt = NULL;
188 187 int len;
189 188 struct args {
190 189 uint32_t len;
191 190 char path[FNAME_SIZE];
192 191 } *args;
193 192 struct repl {
194 193 uint32_t errno;
195 194 uint32_t fhsize;
196 195 u_char fh[NFS_V3MAXFHSIZE];
197 196 uint32_t authcnt;
198 197 uint32_t auth[7];
199 198 } *repl;
200 199 struct {
201 200 uint32_t h[RPC_HEADER_WORDS];
202 201 struct args d;
203 202 } sdata;
204 203 size_t cc;
205 204
206 205 #ifdef NFS_DEBUG
207 206 if (debug)
208 207 printf("nfs_getrootfh: %s\n", path);
209 208 #endif
210 209
211 210 args = &sdata.d;
212 211
213 212 bzero(args, sizeof(*args));
214 213 len = strlen(path);
215 214 if (len > sizeof(args->path))
216 215 len = sizeof(args->path);
217 216 args->len = htonl(len);
218 217 bcopy(path, args->path, len);
219 218 len = sizeof(uint32_t) + roundup(len, sizeof(uint32_t));
220 219
221 220 cc = rpc_call(d, RPCPROG_MNT, RPCMNT_VER3, RPCMNT_MOUNT,
222 221 args, len, (void **)&repl, &pkt);
223 222 if (cc == -1) {
224 223 free(pkt);
225 224 /* errno was set by rpc_call */
226 225 return (errno);
227 226 }
228 227 if (cc < 2 * sizeof (uint32_t)) {
229 228 free(pkt);
230 229 return (EBADRPC);
231 230 }
232 231 if (repl->errno != 0) {
233 232 free(pkt);
234 233 return (ntohl(repl->errno));
235 234 }
236 235 *fhlenp = ntohl(repl->fhsize);
237 236 bcopy(repl->fh, fhp, *fhlenp);
238 237
239 238 set_nfs_read_size();
240 239 free(pkt);
241 240 return (0);
242 241 }
243 242
244 243 /*
245 244 * Lookup a file. Store handle and attributes.
246 245 * Return zero or error number.
247 246 */
248 247 int
249 248 nfs_lookupfh(struct nfs_iodesc *d, const char *name, struct nfs_iodesc *newfd)
250 249 {
251 250 void *pkt = NULL;
252 251 int len, rlen, pos;
253 252 struct args {
254 253 uint32_t fhsize;
255 254 uint32_t fhplusname[1 +
256 255 (NFS_V3MAXFHSIZE + FNAME_SIZE) / sizeof(uint32_t)];
257 256 } *args;
258 257 struct repl {
259 258 uint32_t errno;
260 259 uint32_t fhsize;
261 260 uint32_t fhplusattr[(NFS_V3MAXFHSIZE +
262 261 2 * (sizeof(uint32_t) +
263 262 sizeof(struct nfsv3_fattrs))) / sizeof(uint32_t)];
264 263 } *repl;
265 264 struct {
266 265 uint32_t h[RPC_HEADER_WORDS];
267 266 struct args d;
268 267 } sdata;
269 268 ssize_t cc;
270 269
271 270 #ifdef NFS_DEBUG
272 271 if (debug)
273 272 printf("lookupfh: called\n");
274 273 #endif
275 274
276 275 args = &sdata.d;
277 276
278 277 bzero(args, sizeof(*args));
279 278 args->fhsize = htonl(d->fhsize);
280 279 bcopy(d->fh, args->fhplusname, d->fhsize);
281 280 len = strlen(name);
282 281 if (len > FNAME_SIZE)
283 282 len = FNAME_SIZE;
284 283 pos = roundup(d->fhsize, sizeof(uint32_t)) / sizeof(uint32_t);
285 284 args->fhplusname[pos++] = htonl(len);
286 285 bcopy(name, &args->fhplusname[pos], len);
287 286 len = sizeof(uint32_t) + pos * sizeof(uint32_t) +
288 287 roundup(len, sizeof(uint32_t));
289 288
290 289 cc = rpc_call(d->iodesc, NFS_PROG, NFS_VER3, NFSPROCV3_LOOKUP,
291 290 args, len, (void **)&repl, &pkt);
292 291 if (cc == -1) {
293 292 free(pkt);
294 293 return (errno); /* XXX - from rpc_call */
295 294 }
296 295 if (cc < 2 * sizeof(uint32_t)) {
297 296 free(pkt);
298 297 return (EIO);
299 298 }
300 299 if (repl->errno != 0) {
301 300 free(pkt);
302 301 /* saerrno.h now matches NFS error numbers. */
303 302 return (ntohl(repl->errno));
304 303 }
305 304 newfd->fhsize = ntohl(repl->fhsize);
306 305 bcopy(repl->fhplusattr, &newfd->fh, newfd->fhsize);
307 306 pos = roundup(newfd->fhsize, sizeof(uint32_t)) / sizeof(uint32_t);
308 307 if (repl->fhplusattr[pos++] == 0) {
309 308 free(pkt);
310 309 return (EIO);
311 310 }
312 311 bcopy(&repl->fhplusattr[pos], &newfd->fa, sizeof(newfd->fa));
313 312 free(pkt);
314 313 return (0);
315 314 }
316 315
317 316 /*
318 317 * Get the destination of a symbolic link.
319 318 */
320 319 int
321 320 nfs_readlink(struct nfs_iodesc *d, char *buf)
322 321 {
323 322 void *pkt = NULL;
324 323 struct args {
325 324 uint32_t fhsize;
326 325 u_char fh[NFS_V3MAXFHSIZE];
327 326 } *args;
328 327 struct repl {
329 328 uint32_t errno;
330 329 uint32_t ok;
331 330 struct nfsv3_fattrs fa;
332 331 uint32_t len;
333 332 u_char path[NFS_MAXPATHLEN];
334 333 } *repl;
335 334 struct {
336 335 uint32_t h[RPC_HEADER_WORDS];
337 336 struct args d;
338 337 } sdata;
339 338 ssize_t cc;
340 339 int rc = 0;
341 340
342 341 #ifdef NFS_DEBUG
343 342 if (debug)
344 343 printf("readlink: called\n");
345 344 #endif
346 345
347 346 args = &sdata.d;
348 347
349 348 bzero(args, sizeof(*args));
350 349 args->fhsize = htonl(d->fhsize);
351 350 bcopy(d->fh, args->fh, d->fhsize);
352 351 cc = rpc_call(d->iodesc, NFS_PROG, NFS_VER3, NFSPROCV3_READLINK,
353 352 args, sizeof(uint32_t) + roundup(d->fhsize, sizeof(uint32_t)),
354 353 (void **)&repl, &pkt);
355 354 if (cc == -1)
356 355 return (errno);
357 356
358 357 if (cc < 2 * sizeof(uint32_t)) {
359 358 rc = EIO;
360 359 goto done;
361 360 }
362 361
363 362 if (repl->errno != 0) {
364 363 rc = ntohl(repl->errno);
365 364 goto done;
366 365 }
367 366
368 367 if (repl->ok == 0) {
369 368 rc = EIO;
370 369 goto done;
371 370 }
372 371
373 372 repl->len = ntohl(repl->len);
374 373 if (repl->len > NFS_MAXPATHLEN) {
375 374 rc = ENAMETOOLONG;
376 375 goto done;
377 376 }
378 377
379 378 bcopy(repl->path, buf, repl->len);
380 379 buf[repl->len] = 0;
381 380 done:
382 381 free(pkt);
383 382 return (rc);
384 383 }
385 384
386 385 /*
387 386 * Read data from a file.
388 387 * Return transfer count or -1 (and set errno)
389 388 */
390 389 ssize_t
391 390 nfs_readdata(struct nfs_iodesc *d, off_t off, void *addr, size_t len)
392 391 {
393 392 void *pkt = NULL;
394 393 struct args {
395 394 uint32_t fhsize;
396 395 uint32_t fhoffcnt[NFS_V3MAXFHSIZE / sizeof(uint32_t) + 3];
397 396 } *args;
398 397 struct repl {
399 398 uint32_t errno;
400 399 uint32_t ok;
401 400 struct nfsv3_fattrs fa;
402 401 uint32_t count;
403 402 uint32_t eof;
404 403 uint32_t len;
405 404 u_char data[NFSREAD_MAX_SIZE];
406 405 } *repl;
407 406 struct {
408 407 uint32_t h[RPC_HEADER_WORDS];
409 408 struct args d;
410 409 } sdata;
411 410 size_t cc;
412 411 long x;
413 412 int hlen, rlen, pos;
414 413
415 414 args = &sdata.d;
416 415
417 416 bzero(args, sizeof(*args));
418 417 args->fhsize = htonl(d->fhsize);
419 418 bcopy(d->fh, args->fhoffcnt, d->fhsize);
420 419 pos = roundup(d->fhsize, sizeof(uint32_t)) / sizeof(uint32_t);
421 420 args->fhoffcnt[pos++] = 0;
422 421 args->fhoffcnt[pos++] = htonl((uint32_t)off);
423 422 if (len > nfs_read_size)
424 423 len = nfs_read_size;
425 424 args->fhoffcnt[pos] = htonl((uint32_t)len);
426 425 hlen = offsetof(struct repl, data[0]);
427 426
428 427 cc = rpc_call(d->iodesc, NFS_PROG, NFS_VER3, NFSPROCV3_READ,
429 428 args, 4 * sizeof(uint32_t) + roundup(d->fhsize, sizeof(uint32_t)),
430 429 (void **)&repl, &pkt);
431 430 if (cc == -1) {
432 431 /* errno was already set by rpc_call */
433 432 return (-1);
434 433 }
435 434 if (cc < hlen) {
436 435 errno = EBADRPC;
437 436 free(pkt);
438 437 return (-1);
439 438 }
440 439 if (repl->errno != 0) {
441 440 errno = ntohl(repl->errno);
442 441 free(pkt);
443 442 return (-1);
444 443 }
445 444 rlen = cc - hlen;
446 445 x = ntohl(repl->count);
447 446 if (rlen < x) {
448 447 printf("nfsread: short packet, %d < %ld\n", rlen, x);
449 448 errno = EBADRPC;
450 449 free(pkt);
451 450 return (-1);
452 451 }
453 452 bcopy(repl->data, addr, x);
454 453 free(pkt);
455 454 return (x);
456 455 }
457 456
458 457 /*
459 458 * Open a file.
460 459 * return zero or error number
461 460 */
462 461 int
463 462 nfs_open(const char *upath, struct open_file *f)
464 463 {
465 464 struct iodesc *desc;
466 465 struct nfs_iodesc *currfd;
467 466 char buf[2 * NFS_V3MAXFHSIZE + 3];
468 467 u_char *fh;
469 468 char *cp;
470 469 int i;
471 470 struct nfs_iodesc *newfd;
472 471 struct nfsv3_fattrs *fa;
473 472 char *ncp;
474 473 int c;
475 474 char namebuf[NFS_MAXPATHLEN + 1];
476 475 char linkbuf[NFS_MAXPATHLEN + 1];
477 476 int nlinks = 0;
478 477 int error;
479 478 char *path;
480 479
481 480 if (netproto != NET_NFS)
482 481 return (EINVAL);
483 482
484 483 #ifdef NFS_DEBUG
485 484 if (debug)
486 485 printf("nfs_open: %s (rootpath=%s)\n", upath, rootpath);
487 486 #endif
488 487 if (!rootpath[0]) {
489 488 printf("no rootpath, no nfs\n");
490 489 return (ENXIO);
491 490 }
492 491
493 492 if (f->f_dev->dv_type != DEVT_NET)
494 493 return (EINVAL);
495 494
496 495 if (!(desc = socktodesc(*(int *)(f->f_devdata))))
497 496 return (EINVAL);
498 497
499 498 /* Bind to a reserved port. */
500 499 desc->myport = htons(--rpc_port);
501 500 desc->destip = rootip;
502 501 if ((error = nfs_getrootfh(desc, rootpath, &nfs_root_node.fhsize,
503 502 nfs_root_node.fh)))
504 503 return (error);
505 504 nfs_root_node.fa.fa_type = htonl(NFDIR);
506 505 nfs_root_node.fa.fa_mode = htonl(0755);
507 506 nfs_root_node.fa.fa_nlink = htonl(2);
508 507 nfs_root_node.iodesc = desc;
509 508
510 509 fh = &nfs_root_node.fh[0];
511 510 buf[0] = 'X';
512 511 cp = &buf[1];
513 512 for (i = 0; i < nfs_root_node.fhsize; i++, cp += 2)
514 513 sprintf(cp, "%02x", fh[i]);
515 514 sprintf(cp, "X");
516 515 setenv("boot.nfsroot.server", inet_ntoa(rootip), 1);
517 516 setenv("boot.nfsroot.path", rootpath, 1);
518 517 setenv("boot.nfsroot.nfshandle", buf, 1);
519 518 sprintf(buf, "%d", nfs_root_node.fhsize);
520 519 setenv("boot.nfsroot.nfshandlelen", buf, 1);
521 520
522 521 /* Allocate file system specific data structure */
523 522 currfd = malloc(sizeof(*newfd));
524 523 if (currfd == NULL) {
525 524 error = ENOMEM;
526 525 goto out;
527 526 }
528 527 bcopy(&nfs_root_node, currfd, sizeof(*currfd));
529 528 newfd = NULL;
530 529
531 530 cp = path = strdup(upath);
532 531 if (path == NULL) {
533 532 error = ENOMEM;
534 533 goto out;
535 534 }
536 535 while (*cp) {
537 536 /*
538 537 * Remove extra separators
539 538 */
540 539 while (*cp == '/')
541 540 cp++;
542 541
543 542 if (*cp == '\0')
544 543 break;
545 544 /*
546 545 * Check that current node is a directory.
547 546 */
548 547 if (currfd->fa.fa_type != htonl(NFDIR)) {
549 548 error = ENOTDIR;
550 549 goto out;
551 550 }
552 551
553 552 /* allocate file system specific data structure */
554 553 newfd = malloc(sizeof(*newfd));
555 554 if (newfd == NULL) {
556 555 error = ENOMEM;
557 556 goto out;
558 557 }
559 558 newfd->iodesc = currfd->iodesc;
560 559
561 560 /*
562 561 * Get next component of path name.
563 562 */
564 563 {
565 564 int len = 0;
566 565
567 566 ncp = cp;
568 567 while ((c = *cp) != '\0' && c != '/') {
569 568 if (++len > NFS_MAXNAMLEN) {
570 569 error = ENOENT;
571 570 goto out;
572 571 }
573 572 cp++;
574 573 }
575 574 *cp = '\0';
576 575 }
577 576
578 577 /* lookup a file handle */
579 578 error = nfs_lookupfh(currfd, ncp, newfd);
580 579 *cp = c;
581 580 if (error)
582 581 goto out;
583 582
584 583 /*
585 584 * Check for symbolic link
586 585 */
587 586 if (newfd->fa.fa_type == htonl(NFLNK)) {
588 587 int link_len, len;
589 588
590 589 error = nfs_readlink(newfd, linkbuf);
591 590 if (error)
592 591 goto out;
593 592
594 593 link_len = strlen(linkbuf);
595 594 len = strlen(cp);
596 595
597 596 if (link_len + len > MAXPATHLEN
598 597 || ++nlinks > MAXSYMLINKS) {
599 598 error = ENOENT;
600 599 goto out;
601 600 }
602 601
603 602 bcopy(cp, &namebuf[link_len], len + 1);
604 603 bcopy(linkbuf, namebuf, link_len);
605 604
606 605 /*
607 606 * If absolute pathname, restart at root.
608 607 * If relative pathname, restart at parent directory.
609 608 */
610 609 cp = namebuf;
611 610 if (*cp == '/')
612 611 bcopy(&nfs_root_node, currfd, sizeof(*currfd));
613 612
614 613 free(newfd);
615 614 newfd = NULL;
616 615
617 616 continue;
618 617 }
619 618
620 619 free(currfd);
621 620 currfd = newfd;
622 621 newfd = NULL;
623 622 }
624 623
625 624 error = 0;
626 625
627 626 out:
628 627 free(newfd);
629 628 free(path);
630 629 if (!error) {
631 630 currfd->off = 0;
632 631 currfd->cookie = 0;
633 632 f->f_fsdata = (void *)currfd;
634 633 return (0);
635 634 }
636 635
637 636 #ifdef NFS_DEBUG
638 637 if (debug)
639 638 printf("nfs_open: %s lookupfh failed: %s\n",
640 639 path, strerror(error));
641 640 #endif
642 641 free(currfd);
643 642
644 643 return (error);
645 644 }
646 645
647 646 int
648 647 nfs_close(struct open_file *f)
649 648 {
650 649 struct nfs_iodesc *fp = (struct nfs_iodesc *)f->f_fsdata;
651 650
652 651 #ifdef NFS_DEBUG
653 652 if (debug)
654 653 printf("nfs_close: fp=0x%lx\n", (u_long)fp);
655 654 #endif
656 655
657 656 free(fp);
658 657 f->f_fsdata = NULL;
659 658
660 659 return (0);
661 660 }
662 661
663 662 /*
664 663 * read a portion of a file
665 664 */
666 665 int
667 666 nfs_read(struct open_file *f, void *buf, size_t size, size_t *resid)
668 667 {
669 668 struct nfs_iodesc *fp = (struct nfs_iodesc *)f->f_fsdata;
670 669 ssize_t cc;
671 670 char *addr = buf;
672 671
673 672 #ifdef NFS_DEBUG
674 673 if (debug)
675 674 printf("nfs_read: size=%lu off=%d\n", (u_long)size,
676 675 (int)fp->off);
677 676 #endif
678 677 while ((int)size > 0) {
679 678 twiddle(16);
680 679 cc = nfs_readdata(fp, fp->off, (void *)addr, size);
681 680 /* XXX maybe should retry on certain errors */
682 681 if (cc == -1) {
683 682 #ifdef NFS_DEBUG
684 683 if (debug)
685 684 printf("nfs_read: read: %s", strerror(errno));
686 685 #endif
687 686 return (errno); /* XXX - from nfs_readdata */
688 687 }
689 688 if (cc == 0) {
690 689 #ifdef NFS_DEBUG
691 690 if (debug)
692 691 printf("nfs_read: hit EOF unexpectantly");
693 692 #endif
694 693 goto ret;
695 694 }
696 695 fp->off += cc;
|
↓ open down ↓ |
546 lines elided |
↑ open up ↑ |
697 696 addr += cc;
698 697 size -= cc;
699 698 }
700 699 ret:
701 700 if (resid)
702 701 *resid = size;
703 702
704 703 return (0);
705 704 }
706 705
707 -/*
708 - * Not implemented.
709 - */
710 -int
711 -nfs_write(struct open_file *f, void *buf, size_t size, size_t *resid)
712 -{
713 - return (EROFS);
714 -}
715 -
716 706 off_t
717 707 nfs_seek(struct open_file *f, off_t offset, int where)
718 708 {
719 709 struct nfs_iodesc *d = (struct nfs_iodesc *)f->f_fsdata;
720 710 uint32_t size = ntohl(d->fa.fa_size.val[1]);
721 711
722 712 switch (where) {
723 713 case SEEK_SET:
724 714 d->off = offset;
725 715 break;
726 716 case SEEK_CUR:
727 717 d->off += offset;
728 718 break;
729 719 case SEEK_END:
730 720 d->off = size - offset;
731 721 break;
732 722 default:
733 723 errno = EINVAL;
734 724 return (-1);
735 725 }
736 726
737 727 return (d->off);
738 728 }
739 729
740 730 /* NFNON=0, NFREG=1, NFDIR=2, NFBLK=3, NFCHR=4, NFLNK=5, NFSOCK=6, NFFIFO=7 */
741 731 int nfs_stat_types[9] = {
742 732 0, S_IFREG, S_IFDIR, S_IFBLK, S_IFCHR, S_IFLNK, S_IFSOCK, S_IFIFO, 0 };
743 733
744 734 int
745 735 nfs_stat(struct open_file *f, struct stat *sb)
746 736 {
747 737 struct nfs_iodesc *fp = (struct nfs_iodesc *)f->f_fsdata;
748 738 uint32_t ftype, mode;
749 739
750 740 ftype = ntohl(fp->fa.fa_type);
751 741 mode = ntohl(fp->fa.fa_mode);
752 742 mode |= nfs_stat_types[ftype & 7];
753 743
754 744 sb->st_mode = mode;
755 745 sb->st_nlink = ntohl(fp->fa.fa_nlink);
756 746 sb->st_uid = ntohl(fp->fa.fa_uid);
757 747 sb->st_gid = ntohl(fp->fa.fa_gid);
758 748 sb->st_size = ntohl(fp->fa.fa_size.val[1]);
759 749
760 750 return (0);
761 751 }
762 752
763 753 static int
764 754 nfs_readdir(struct open_file *f, struct dirent *d)
765 755 {
766 756 struct nfs_iodesc *fp = (struct nfs_iodesc *)f->f_fsdata;
767 757 struct nfsv3_readdir_repl *repl;
768 758 struct nfsv3_readdir_entry *rent;
769 759 static void *pkt = NULL;
770 760 static char *buf;
771 761 static struct nfs_iodesc *pfp = NULL;
772 762 static uint64_t cookie = 0;
773 763 size_t cc;
774 764 int pos, rc;
775 765
776 766 struct args {
777 767 uint32_t fhsize;
778 768 uint32_t fhpluscookie[5 + NFS_V3MAXFHSIZE];
779 769 } *args;
780 770 struct {
781 771 uint32_t h[RPC_HEADER_WORDS];
782 772 struct args d;
783 773 } sdata;
784 774
785 775 if (fp != pfp || fp->off != cookie) {
786 776 pfp = NULL;
787 777 refill:
788 778 free(pkt);
789 779 pkt = NULL;
790 780 args = &sdata.d;
791 781 bzero(args, sizeof(*args));
792 782
793 783 args->fhsize = htonl(fp->fhsize);
794 784 bcopy(fp->fh, args->fhpluscookie, fp->fhsize);
795 785 pos = roundup(fp->fhsize, sizeof(uint32_t)) / sizeof(uint32_t);
796 786 args->fhpluscookie[pos++] = htonl(fp->off >> 32);
797 787 args->fhpluscookie[pos++] = htonl(fp->off);
798 788 args->fhpluscookie[pos++] = htonl(fp->cookie >> 32);
799 789 args->fhpluscookie[pos++] = htonl(fp->cookie);
800 790 args->fhpluscookie[pos] = htonl(NFS_READDIRSIZE);
801 791
802 792 cc = rpc_call(fp->iodesc, NFS_PROG, NFS_VER3, NFSPROCV3_READDIR,
803 793 args, 6 * sizeof(uint32_t) +
804 794 roundup(fp->fhsize, sizeof(uint32_t)),
805 795 (void **)&buf, &pkt);
806 796 if (cc == -1) {
807 797 rc = errno;
808 798 goto err;
809 799 }
810 800 repl = (struct nfsv3_readdir_repl *)buf;
811 801 if (repl->errno != 0) {
812 802 rc = ntohl(repl->errno);
813 803 goto err;
814 804 }
815 805 pfp = fp;
816 806 cookie = fp->off;
817 807 fp->cookie = ((uint64_t)ntohl(repl->cookiev0) << 32) |
818 808 ntohl(repl->cookiev1);
819 809 buf += sizeof (struct nfsv3_readdir_repl);
820 810 }
821 811 rent = (struct nfsv3_readdir_entry *)buf;
822 812
823 813 if (rent->follows == 0) {
824 814 /* fid0 is actually eof */
825 815 if (rent->fid0 != 0) {
826 816 rc = ENOENT;
827 817 goto err;
828 818 }
829 819 goto refill;
830 820 }
831 821
832 822 d->d_namlen = ntohl(rent->len);
833 823 bcopy(rent->nameplus, d->d_name, d->d_namlen);
834 824 d->d_name[d->d_namlen] = '\0';
835 825
836 826 pos = roundup(d->d_namlen, sizeof(uint32_t)) / sizeof(uint32_t);
837 827 fp->off = cookie = ((uint64_t)ntohl(rent->nameplus[pos]) << 32) |
838 828 ntohl(rent->nameplus[pos + 1]);
839 829 pos += 2;
840 830 buf = (u_char *)&rent->nameplus[pos];
841 831 return (0);
842 832
843 833 err:
844 834 free(pkt);
845 835 pkt = NULL;
846 836 pfp = NULL;
847 837 cookie = 0;
848 838 return (rc);
849 839 }
|
↓ open down ↓ |
124 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX