1 /* 2 * Copyright (c) 2017 Kyle J. Kneitinger <kyle@kneit.in> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7 #ifndef _LIBBE_H 8 #define _LIBBE_H 9 10 #include <libnvpair.h> 11 #include <stdbool.h> 12 13 #define BE_MAXPATHLEN 512 14 15 typedef struct libbe_handle libbe_handle_t; 16 17 typedef enum be_error { 18 BE_ERR_SUCCESS = 0, /* No error */ 19 BE_ERR_INVALIDNAME, /* invalid boot env name */ 20 BE_ERR_EXISTS, /* boot env name already taken */ 21 BE_ERR_NOENT, /* boot env doesn't exist */ 22 BE_ERR_PERMS, /* insufficient permissions */ 23 BE_ERR_DESTROYACT, /* cannot destroy active boot env */ 24 BE_ERR_DESTROYMNT, /* destroying a mounted be requires force */ 25 BE_ERR_BADPATH, /* path not suitable for operation */ 26 BE_ERR_PATHBUSY, /* requested path is busy */ 27 BE_ERR_PATHLEN, /* provided name exceeds maximum length limit */ 28 BE_ERR_BADMOUNT, /* mountpoint is not '/' */ 29 BE_ERR_NOORIGIN, /* could not open snapshot's origin */ 30 BE_ERR_MOUNTED, /* boot environment is already mounted */ 31 BE_ERR_NOMOUNT, /* boot environment is not mounted */ 32 BE_ERR_ZFSOPEN, /* calling zfs_open() failed */ 33 BE_ERR_ZFSCLONE, /* error when calling zfs_clone to create be */ 34 BE_ERR_IO, /* error when doing some I/O operation */ 35 BE_ERR_NOPOOL, /* operation not supported on this pool */ 36 BE_ERR_NOMEM, /* insufficient memory */ 37 BE_ERR_UNKNOWN, /* unknown error */ 38 BE_ERR_INVORIGIN, /* invalid origin */ 39 BE_ERR_HASCLONES, /* snapshot has clones */ 40 } be_error_t; 41 42 43 /* Library handling functions: be.c */ 44 libbe_handle_t *libbe_init(const char *root); 45 void libbe_close(libbe_handle_t *); 46 47 /* Bootenv information functions: be_info.c */ 48 const char *be_active_name(libbe_handle_t *); 49 const char *be_active_path(libbe_handle_t *); 50 const char *be_nextboot_name(libbe_handle_t *); 51 const char *be_nextboot_path(libbe_handle_t *); 52 const char *be_root_path(libbe_handle_t *); 53 54 int be_get_bootenv_props(libbe_handle_t *, nvlist_t *); 55 int be_get_dataset_props(libbe_handle_t *, const char *, nvlist_t *); 56 int be_get_dataset_snapshots(libbe_handle_t *, const char *, nvlist_t *); 57 int be_prop_list_alloc(nvlist_t **be_list); 58 void be_prop_list_free(nvlist_t *be_list); 59 60 int be_activate(libbe_handle_t *, const char *, bool); 61 int be_deactivate(libbe_handle_t *, const char *, bool); 62 63 bool be_is_auto_snapshot_name(libbe_handle_t *, const char *); 64 65 /* Bootenv creation functions */ 66 int be_create(libbe_handle_t *, const char *); 67 int be_create_depth(libbe_handle_t *, const char *, const char *, int); 68 int be_create_from_existing(libbe_handle_t *, const char *, const char *); 69 int be_create_from_existing_snap(libbe_handle_t *, const char *, const char *); 70 int be_snapshot(libbe_handle_t *, const char *, const char *, bool, char *); 71 72 /* Bootenv manipulation functions */ 73 int be_rename(libbe_handle_t *, const char *, const char *); 74 75 /* Bootenv removal functions */ 76 77 typedef enum { 78 BE_DESTROY_FORCE = 1 << 0, 79 BE_DESTROY_ORIGIN = 1 << 1, 80 BE_DESTROY_AUTOORIGIN = 1 << 2, 81 } be_destroy_opt_t; 82 83 int be_destroy(libbe_handle_t *, const char *, int); 84 85 /* Bootenv mounting functions: be_access.c */ 86 87 typedef enum { 88 BE_MNT_FORCE = 1 << 0, 89 BE_MNT_DEEP = 1 << 1, 90 } be_mount_opt_t; 91 92 int be_mount(libbe_handle_t *, const char *, const char *, int, char *); 93 int be_unmount(libbe_handle_t *, const char *, int); 94 int be_mounted_at(libbe_handle_t *, const char *path, nvlist_t *); 95 96 /* Error related functions: be_error.c */ 97 int libbe_errno(libbe_handle_t *); 98 const char *libbe_error_description(libbe_handle_t *); 99 void libbe_print_on_error(libbe_handle_t *, bool); 100 101 /* Utility Functions */ 102 int be_root_concat(libbe_handle_t *, const char *, char *); 103 int be_validate_name(libbe_handle_t * __unused, const char *); 104 int be_validate_snap(libbe_handle_t *, const char *); 105 int be_exists(libbe_handle_t *, const char *); 106 107 int be_export(libbe_handle_t *, const char *, int fd); 108 int be_import(libbe_handle_t *, const char *, int fd); 109 110 #if SOON 111 int be_add_child(libbe_handle_t *, const char *, bool); 112 #endif 113 void be_nicenum(uint64_t num, char *buf, size_t buflen); 114 115 #endif /* _LIBBE_H */ 116