be.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*-
  2. * SPDX-License-Identifier: BSD-2-Clause
  3. *
  4. * Copyright (c) 2017 Kyle J. Kneitinger <kyle@kneit.in>
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  16. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  21. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  23. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25. * SUCH DAMAGE.
  26. */
  27. #ifndef _LIBBE_H
  28. #define _LIBBE_H
  29. #include <libnvpair.h>
  30. #include <stdbool.h>
  31. #define BE_MAXPATHLEN 512
  32. typedef struct libbe_handle libbe_handle_t;
  33. typedef enum be_error {
  34. BE_ERR_SUCCESS = 0, /* No error */
  35. BE_ERR_INVALIDNAME, /* invalid boot env name */
  36. BE_ERR_EXISTS, /* boot env name already taken */
  37. BE_ERR_NOENT, /* boot env doesn't exist */
  38. BE_ERR_PERMS, /* insufficient permissions */
  39. BE_ERR_DESTROYACT, /* cannot destroy active boot env */
  40. BE_ERR_DESTROYMNT, /* destroying a mounted be requires force */
  41. BE_ERR_BADPATH, /* path not suitable for operation */
  42. BE_ERR_PATHBUSY, /* requested path is busy */
  43. BE_ERR_PATHLEN, /* provided name exceeds maximum length limit */
  44. BE_ERR_BADMOUNT, /* mountpoint is not '/' */
  45. BE_ERR_NOORIGIN, /* could not open snapshot's origin */
  46. BE_ERR_MOUNTED, /* boot environment is already mounted */
  47. BE_ERR_NOMOUNT, /* boot environment is not mounted */
  48. BE_ERR_ZFSOPEN, /* calling zfs_open() failed */
  49. BE_ERR_ZFSCLONE, /* error when calling zfs_clone to create be */
  50. BE_ERR_IO, /* error when doing some I/O operation */
  51. BE_ERR_NOPOOL, /* operation not supported on this pool */
  52. BE_ERR_NOMEM, /* insufficient memory */
  53. BE_ERR_UNKNOWN, /* unknown error */
  54. BE_ERR_INVORIGIN, /* invalid origin */
  55. BE_ERR_HASCLONES, /* snapshot has clones */
  56. } be_error_t;
  57. /* Library handling functions: be.c */
  58. libbe_handle_t *libbe_init(const char *root);
  59. void libbe_close(libbe_handle_t *);
  60. /* Bootenv information functions: be_info.c */
  61. const char *be_active_name(libbe_handle_t *);
  62. const char *be_active_path(libbe_handle_t *);
  63. const char *be_nextboot_name(libbe_handle_t *);
  64. const char *be_nextboot_path(libbe_handle_t *);
  65. const char *be_root_path(libbe_handle_t *);
  66. int be_get_bootenv_props(libbe_handle_t *, nvlist_t *);
  67. int be_get_dataset_props(libbe_handle_t *, const char *, nvlist_t *);
  68. int be_get_dataset_snapshots(libbe_handle_t *, const char *, nvlist_t *);
  69. int be_prop_list_alloc(nvlist_t **be_list);
  70. void be_prop_list_free(nvlist_t *be_list);
  71. int be_activate(libbe_handle_t *, const char *, bool);
  72. int be_deactivate(libbe_handle_t *, const char *, bool);
  73. bool be_is_auto_snapshot_name(libbe_handle_t *, const char *);
  74. /* Bootenv creation functions */
  75. int be_create(libbe_handle_t *, const char *);
  76. int be_create_depth(libbe_handle_t *, const char *, const char *, int);
  77. int be_create_from_existing(libbe_handle_t *, const char *, const char *);
  78. int be_create_from_existing_snap(libbe_handle_t *, const char *, const char *);
  79. int be_snapshot(libbe_handle_t *, const char *, const char *, bool, char *);
  80. /* Bootenv manipulation functions */
  81. int be_rename(libbe_handle_t *, const char *, const char *);
  82. /* Bootenv removal functions */
  83. typedef enum {
  84. BE_DESTROY_FORCE = 1 << 0,
  85. BE_DESTROY_ORIGIN = 1 << 1,
  86. BE_DESTROY_AUTOORIGIN = 1 << 2,
  87. } be_destroy_opt_t;
  88. int be_destroy(libbe_handle_t *, const char *, int);
  89. /* Bootenv mounting functions: be_access.c */
  90. typedef enum {
  91. BE_MNT_FORCE = 1 << 0,
  92. BE_MNT_DEEP = 1 << 1,
  93. } be_mount_opt_t;
  94. int be_mount(libbe_handle_t *, const char *, const char *, int, char *);
  95. int be_unmount(libbe_handle_t *, const char *, int);
  96. int be_mounted_at(libbe_handle_t *, const char *path, nvlist_t *);
  97. /* Error related functions: be_error.c */
  98. int libbe_errno(libbe_handle_t *);
  99. const char *libbe_error_description(libbe_handle_t *);
  100. void libbe_print_on_error(libbe_handle_t *, bool);
  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. int be_export(libbe_handle_t *, const char *, int fd);
  107. int be_import(libbe_handle_t *, const char *, int fd);
  108. #if SOON
  109. int be_add_child(libbe_handle_t *, const char *, bool);
  110. #endif
  111. void be_nicenum(uint64_t num, char *buf, size_t buflen);
  112. #endif /* _LIBBE_H */