aboutsummaryrefslogtreecommitdiff
path: root/lib/libbe
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2018-08-10 04:01:40 +0000
committerKyle Evans <kevans@FreeBSD.org>2018-08-10 04:01:40 +0000
commit73c3d60843efc6116e8dc3bbbf8c32948490d850 (patch)
tree8628e24553512a555c7aed0d7d67c0b85e412475 /lib/libbe
parent506f5fdf2b304197067e094354197e49c35b8bf1 (diff)
downloadsrc-73c3d60843efc6116e8dc3bbbf8c32948490d850.tar.gz
src-73c3d60843efc6116e8dc3bbbf8c32948490d850.zip
libbe(3): more small cleanup, const'ify and light style(9)
Notes
Notes: svn path=/projects/bectl/; revision=337563
Diffstat (limited to 'lib/libbe')
-rw-r--r--lib/libbe/be.c34
-rw-r--r--lib/libbe/be.h14
2 files changed, 23 insertions, 25 deletions
diff --git a/lib/libbe/be.c b/lib/libbe/be.c
index e5dfc53ed0de..fb32d087c0da 100644
--- a/lib/libbe/be.c
+++ b/lib/libbe/be.c
@@ -202,7 +202,7 @@ be_destroy_cb(zfs_handle_t *zfs_hdl, void *data)
* BE_DESTROY_FORCE : forces operation on mounted datasets
*/
int
-be_destroy(libbe_handle_t *lbh, char *name, int options)
+be_destroy(libbe_handle_t *lbh, const char *name, int options)
{
zfs_handle_t *fs;
char path[BE_MAXPATHLEN];
@@ -307,7 +307,7 @@ be_snapshot(libbe_handle_t *lbh, const char *source, const char *snap_name,
* Create the boot environment specified by the name parameter
*/
int
-be_create(libbe_handle_t *lbh, char *name)
+be_create(libbe_handle_t *lbh, const char *name)
{
int err;
@@ -328,11 +328,8 @@ be_deep_clone_prop(int prop, void *cb)
dccb = cb;
/* Skip some properties we don't want to touch */
- switch (prop) {
- case ZFS_PROP_CANMOUNT:
- return (ZPROP_CONT);
- break;
- }
+ if (prop == ZFS_PROP_CANMOUNT)
+ return (ZPROP_CONT);
/* Don't copy readonly properties */
if (zfs_prop_readonly(prop))
@@ -593,7 +590,7 @@ be_validate_name(libbe_handle_t *lbh __unused, const char *name)
* usage
*/
int
-be_rename(libbe_handle_t *lbh, char *old, char *new)
+be_rename(libbe_handle_t *lbh, const char *old, const char *new)
{
char full_old[BE_MAXPATHLEN];
char full_new[BE_MAXPATHLEN];
@@ -638,7 +635,7 @@ be_rename(libbe_handle_t *lbh, char *old, char *new)
int
-be_export(libbe_handle_t *lbh, char *bootenv, int fd)
+be_export(libbe_handle_t *lbh, const char *bootenv, int fd)
{
char snap_name[BE_MAXPATHLEN];
char buf[BE_MAXPATHLEN];
@@ -660,7 +657,7 @@ be_export(libbe_handle_t *lbh, char *bootenv, int fd)
int
-be_import(libbe_handle_t *lbh, char *bootenv, int fd)
+be_import(libbe_handle_t *lbh, const char *bootenv, int fd)
{
char buf[BE_MAXPATHLEN];
time_t rawtime;
@@ -723,14 +720,16 @@ be_import(libbe_handle_t *lbh, char *bootenv, int fd)
int
-be_add_child(libbe_handle_t *lbh, char *child_path, bool cp_if_exists)
+be_add_child(libbe_handle_t *lbh, const char *child_path, bool cp_if_exists)
{
+ struct stat sb;
char active[BE_MAXPATHLEN];
char buf[BE_MAXPATHLEN];
nvlist_t *props;
+ const char *s;
zfs_handle_t *zfs;
- struct stat sb;
- int err;
+ long snap_name;
+ int err, pos;
/* Require absolute paths */
if (*child_path != '/')
@@ -741,7 +740,7 @@ be_add_child(libbe_handle_t *lbh, char *child_path, bool cp_if_exists)
strcpy(buf, active);
/* Create non-mountable parent dataset(s) */
- char *s = child_path;
+ s = child_path;
for (char *p; (p = strchr(s+1, '/')) != NULL; s = p) {
size_t len = p - s;
strncat(buf, s, len);
@@ -753,9 +752,8 @@ be_add_child(libbe_handle_t *lbh, char *child_path, bool cp_if_exists)
nvlist_free(props);
}
-
/* Path does not exist as a descendent of / yet */
- int pos = strlen(active);
+ pos = strlen(active);
/* XXX TODO: Verify that resulting str is less than BE_MAXPATHLEN */
strncpy(&active[pos], child_path, BE_MAXPATHLEN-pos);
@@ -797,7 +795,7 @@ be_add_child(libbe_handle_t *lbh, char *child_path, bool cp_if_exists)
*/
/* XXX TODO: use mktemp */
- long int snap_name = random();
+ snap_name = random();
snprintf(buf, BE_MAXPATHLEN, "%s@%ld", child_path, snap_name);
@@ -854,7 +852,7 @@ be_set_nextboot(libbe_handle_t *lbh, nvlist_t *config, uint64_t pool_guid,
int
-be_activate(libbe_handle_t *lbh, char *bootenv, bool temporary)
+be_activate(libbe_handle_t *lbh, const char *bootenv, bool temporary)
{
char be_path[BE_MAXPATHLEN];
char buf[BE_MAXPATHLEN];
diff --git a/lib/libbe/be.h b/lib/libbe/be.h
index daf04cf70edf..157ed41b0b1a 100644
--- a/lib/libbe/be.h
+++ b/lib/libbe/be.h
@@ -78,16 +78,16 @@ int be_get_dataset_snapshots(libbe_handle_t *, const char *, nvlist_t *);
int be_prop_list_alloc(nvlist_t **be_list);
void be_prop_list_free(nvlist_t *be_list);
-int be_activate(libbe_handle_t *, char *, bool);
+int be_activate(libbe_handle_t *, const char *, bool);
/* Bootenv creation functions */
-int be_create(libbe_handle_t *, char *);
+int be_create(libbe_handle_t *, const char *);
int be_create_from_existing(libbe_handle_t *, const char *, const char *);
int be_create_from_existing_snap(libbe_handle_t *, const char *, const char *);
int be_snapshot(libbe_handle_t *, const char *, const char *, bool, char *);
/* Bootenv manipulation functions */
-int be_rename(libbe_handle_t *, char *, char *);
+int be_rename(libbe_handle_t *, const char *, const char *);
/* Bootenv removal functions */
@@ -95,7 +95,7 @@ typedef enum {
BE_DESTROY_FORCE = 1 << 0,
} be_destroy_opt_t;
-int be_destroy(libbe_handle_t *, char *, int);
+int be_destroy(libbe_handle_t *, const char *, int);
/* Bootenv mounting functions: be_access.c */
@@ -119,10 +119,10 @@ int be_validate_name(libbe_handle_t * __unused, const char *);
int be_validate_snap(libbe_handle_t *, const char *);
bool be_exists(libbe_handle_t *, char *);
-int be_export(libbe_handle_t *, char *, int fd);
-int be_import(libbe_handle_t *, char *, int fd);
+int be_export(libbe_handle_t *, const char *, int fd);
+int be_import(libbe_handle_t *, const char *, int fd);
-int be_add_child(libbe_handle_t *, char *, bool);
+int be_add_child(libbe_handle_t *, const char *, bool);
void be_nicenum(uint64_t num, char *buf, size_t buflen);
#endif /* _LIBBE_H */