Changeset View
Standalone View
lib/libstand/nfs.c
Show First 20 Lines • Show All 217 Lines • ▼ Show 20 Lines | |||||
/* | /* | ||||
* Fetch the root file handle (call mount daemon) | * Fetch the root file handle (call mount daemon) | ||||
* Return zero or error number. | * Return zero or error number. | ||||
*/ | */ | ||||
int | int | ||||
nfs_getrootfh(struct iodesc *d, char *path, u_char *fhp) | nfs_getrootfh(struct iodesc *d, char *path, u_char *fhp) | ||||
{ | { | ||||
int len; | int len; | ||||
char *env, *end; | |||||
struct args { | struct args { | ||||
n_long len; | n_long len; | ||||
rpokala: `nfs_read_size` is (int); while `strtol()` returns (long); cast accordingly. | |||||
Not Done Inline Actionswell, the compiler should take care, but I do not mind anyhow:) tsoome: well, the compiler should take care, but I do not mind anyhow:) | |||||
char path[FNAME_SIZE]; | char path[FNAME_SIZE]; | ||||
Not Done Inline ActionsIs it legal to check for non-zero errno? I thought errno in general is only set to a non-zero value of failure, but not set to zero on success. So, a previous failure would set errno to non-zero, and it would stay non-zero even if the getenv() succeeded. rpokala: Is it legal to check for non-zero `errno`? I thought `errno` in general is only set to a non… | |||||
Not Done Inline ActionsI set it 0 at line 227 (modulo typo;), so w have it set 0 just before the call to strtol. tsoome: I set it 0 at line 227 (modulo typo;), so w have it set 0 just before the call to strtol. | |||||
Not Done Inline ActionsRight, but I'm not sure that's actually legal. I know in some contexts errno is actually a function-like macro or something wacky, so for example different threads don't stomp on it. Granted, that might not be relevant in the context of the bootloader. :-) In any case, the rule I learned is "never set errno to zero, only to non-zero on failure". rpokala: Right, but I'm not sure that's actually legal. I know in some contexts errno is actually a… | |||||
Not Done Inline ActionsWell yes, standalone boot is a special environment and as here we run as one big single threaded app, there is nothing to reset it for us and since libstand does not reset it either, we can have errno set anywhere else and not in strtol() so we can end up having errno == ERANGE from anywhere but strtol() itself:) tsoome: Well yes, standalone boot is a special environment and as here we run as one big single… | |||||
} *args; | } *args; | ||||
struct repl { | struct repl { | ||||
n_long errno; | n_long errno; | ||||
u_char fh[NFS_FHSIZE]; | u_char fh[NFS_FHSIZE]; | ||||
} *repl; | } *repl; | ||||
struct { | struct { | ||||
n_long h[RPC_HEADER_WORDS]; | n_long h[RPC_HEADER_WORDS]; | ||||
struct args d; | struct args d; | ||||
Show All 30 Lines | if (cc < 4) | ||||
return (EBADRPC); | return (EBADRPC); | ||||
if (repl->errno) | if (repl->errno) | ||||
return (ntohl(repl->errno)); | return (ntohl(repl->errno)); | ||||
bcopy(repl->fh, fhp, sizeof(repl->fh)); | bcopy(repl->fh, fhp, sizeof(repl->fh)); | ||||
/* | /* | ||||
* Improve boot performance over NFS | * Improve boot performance over NFS | ||||
*/ | */ | ||||
if (getenv("nfs.read_size") != NULL) | if ((env = getenv("nfs.read_size")) != NULL) { | ||||
nfs_read_size = strtol(getenv("nfs.read_size"), NULL, 0); | nfs_read_size = strtol(env, &end, 0); | ||||
if (*env != '\0' || *end != '\0') { | |||||
printf("%s: bad value: \"%s\", defaulting to %d\n", | |||||
"nfs.read_size", env, NFSREAD_MIN_SIZE); | |||||
nfs_read_size = NFSREAD_MIN_SIZE; | |||||
} | |||||
} | |||||
if (nfs_read_size < NFSREAD_MIN_SIZE) | if (nfs_read_size < NFSREAD_MIN_SIZE) | ||||
nfs_read_size = NFSREAD_MIN_SIZE; | nfs_read_size = NFSREAD_MIN_SIZE; | ||||
if (nfs_read_size > NFSREAD_MAX_SIZE) | if (nfs_read_size > NFSREAD_MAX_SIZE) | ||||
nfs_read_size = NFSREAD_MAX_SIZE; | nfs_read_size = NFSREAD_MAX_SIZE; | ||||
return (0); | return (0); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,211 Lines • Show Last 20 Lines |
nfs_read_size is (int); while strtol() returns (long); cast accordingly.