Changeset View
Changeset View
Standalone View
Standalone View
sys/boot/zfs/zfs.c
Show First 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | |||||
struct file { | struct file { | ||||
off_t f_seekp; /* seek pointer */ | off_t f_seekp; /* seek pointer */ | ||||
dnode_phys_t f_dnode; | dnode_phys_t f_dnode; | ||||
uint64_t f_zap_type; /* zap type for readdir */ | uint64_t f_zap_type; /* zap type for readdir */ | ||||
uint64_t f_num_leafs; /* number of fzap leaf blocks */ | uint64_t f_num_leafs; /* number of fzap leaf blocks */ | ||||
zap_leaf_phys_t *f_zap_leaf; /* zap leaf buffer */ | zap_leaf_phys_t *f_zap_leaf; /* zap leaf buffer */ | ||||
}; | }; | ||||
static int zfs_env_index = 0; | |||||
/* | /* | ||||
* Open a file. | * Open a file. | ||||
*/ | */ | ||||
static int | static int | ||||
zfs_open(const char *upath, struct open_file *f) | zfs_open(const char *upath, struct open_file *f) | ||||
{ | { | ||||
struct zfsmount *mount = (struct zfsmount *)f->f_devdata; | struct zfsmount *mount = (struct zfsmount *)f->f_devdata; | ||||
struct file *fp; | struct file *fp; | ||||
▲ Show 20 Lines • Show All 595 Lines • ▼ Show 20 Lines | zfs_list(const char *name) | ||||
poolname[len] = '\0'; | poolname[len] = '\0'; | ||||
spa = spa_find_by_name(poolname); | spa = spa_find_by_name(poolname); | ||||
if (!spa) | if (!spa) | ||||
return (ENXIO); | return (ENXIO); | ||||
rv = zfs_lookup_dataset(spa, dsname, &objid); | rv = zfs_lookup_dataset(spa, dsname, &objid); | ||||
if (rv != 0) | if (rv != 0) | ||||
return (rv); | return (rv); | ||||
rv = zfs_list_dataset(spa, objid); | rv = zfs_list_dataset(spa, objid); | ||||
smh: Avoid assignment and just:
return (zfs_list_dataset(spa, objid)); | |||||
return (rv); | |||||
} | |||||
int | |||||
zfs_bootenv(const char *name) | |||||
{ | |||||
static char poolname[ZFS_MAXNAMELEN]; | |||||
uint64_t objid; | |||||
spa_t *spa; | |||||
const char *dsname; | |||||
char *index_str; | |||||
int len; | |||||
int rv; | |||||
Done Inline Actionsstyle(9) braces around return. smh: style(9) braces around return. | |||||
setenv("zfs_beroot", name, 1); | |||||
Done Inline ActionsInstead of unchecked malloc you could use static buffers? then in the next snprintf instead of hardcoding the size you could sizeof(envname) And the free in the end becomes useless bapt: Instead of unchecked malloc you could use static buffers?
char envname[32] ?
then in the next… | |||||
Done Inline Actionscheck the return codes? more below too. smh: check the return codes? more below too. | |||||
zfs_env_index = 4; | |||||
len = strlen(name); | |||||
dsname = strchr(name, '/'); | |||||
if (dsname != NULL) { | |||||
len = dsname - name; | |||||
dsname++; | |||||
} else | |||||
dsname = ""; | |||||
memcpy(poolname, name, len); | |||||
poolname[len] = '\0'; | |||||
spa = spa_find_by_name(poolname); | |||||
if (!spa) | |||||
return (ENXIO); | |||||
rv = zfs_lookup_dataset(spa, dsname, &objid); | |||||
if (rv != 0) | |||||
return (rv); | |||||
Done Inline Actionsmove up to return early. smh: move up to return early. | |||||
rv = zfs_callback_dataset(spa, objid, zfs_set_env); | |||||
if (rv != 0) | |||||
return (rv); | |||||
index_str = malloc(20); | |||||
snprintf(index_str, 20, "%d", zfs_env_index - 1); | |||||
rv = setenv("bootenv_count", index_str, 1); | |||||
return (rv); | |||||
} | |||||
int | |||||
zfs_set_env(const char *name) | |||||
{ | |||||
char *envname = NULL, *envval = NULL, *beroot; | |||||
int rv, i; | |||||
beroot = getenv("zfs_beroot"); | |||||
Done Inline Actionsstyle(9) more below too. if (rv != 0) return (rv); smh: style(9) more below too.
if (rv != 0)
return (rv); | |||||
if (beroot == NULL) | |||||
Done Inline ActionsCould the early returns here leave it in an inconsistent state that may course an issue? smh: Could the early returns here leave it in an inconsistent state that may course an issue? | |||||
Done Inline ActionsPossibly, switching them to break allanjude: Possibly, switching them to break | |||||
return (1); | |||||
envname = malloc(32); | |||||
Done Inline Actionsuse sizeof(envname), more below. smh: use sizeof(envname), more below. | |||||
envval = malloc(256); | |||||
/* Don't overflow the menu, shuffle entries down to show the newest */ | |||||
if (zfs_env_index == 9) { | |||||
for (i = 4; i < 8; i++) { | |||||
snprintf(envname, 32, "bootenvmenu_caption[%d]", i); | |||||
snprintf(envval, 32, "bootenvmenu_caption[%d]", i + 1); | |||||
setenv(envname, getenv(envval), 1); | |||||
snprintf(envname, 32, "bootenvansi_caption[%d]", i); | |||||
snprintf(envval, 32, "bootenvansi_caption[%d]", i + 1); | |||||
setenv(envname, getenv(envval), 1); | |||||
snprintf(envname, 32, "bootenv_root[%d]", i); | |||||
Done Inline Actionsuse sizeof(enval) smh: use sizeof(enval) | |||||
snprintf(envval, 32, "bootenv_root[%d]", i + 1); | |||||
setenv(envname, getenv(envval), 1); | |||||
} | |||||
zfs_env_index = 8; | |||||
} | |||||
snprintf(envname, 32, "bootenvmenu_caption[%d]", zfs_env_index); | |||||
Done Inline ActionsAs zfs_env_index is always incremented could be extracted above so we have the following instead? zfs_env_index++; if (zfs_env_index > ZFS_BE_LAST) break; smh: As zfs_env_index is always incremented could be extracted above so we have the following… | |||||
snprintf(envval, 256, "%s", name); | |||||
rv = setenv(envname, envval, 1); | |||||
snprintf(envname, 32, "bootenvansi_caption[%d]", zfs_env_index); | |||||
rv = setenv(envname, envval, 1); | |||||
snprintf(envname, 32, "bootenvmenu_command[%d]", zfs_env_index); | |||||
rv = setenv(envname, "set_bootenv", 1); | |||||
Done Inline Actionsuse sizeof(envname) more below smh: use sizeof(envname) more below | |||||
snprintf(envname, 32, "bootenv_root[%d]", zfs_env_index); | |||||
snprintf(envval, 256, "zfs:%s/%s", beroot, name); | |||||
rv = setenv(envname, envval, 1); | |||||
if (zfs_env_index <= 8) | |||||
zfs_env_index++; | |||||
free(envname); | |||||
free(envval); | |||||
return (rv); | return (rv); | ||||
Done Inline Actionsrv here is likely to be useless due to use by loop above, should that use a seperate var or just (void)unsetenv(envname) ? smh: rv here is likely to be useless due to use by loop above, should that use a seperate var or… | |||||
} | } | ||||
No newline at end of file |
Avoid assignment and just: