1 /* 2 * Copyright (c) 2017 Kyle J. Kneitinger <kyle@kneit.in> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7 #include <sys/cdefs.h> 8 #include "be.h" 9 #include "be_impl.h" 10 11 /* 12 * Usage 13 */ 14 int libbe_errno(libbe_handle_t * lbh)15libbe_errno(libbe_handle_t *lbh) 16 { 17 18 return (lbh->error); 19 } 20 21 22 const char * libbe_error_description(libbe_handle_t * lbh)23libbe_error_description(libbe_handle_t *lbh) 24 { 25 26 switch (lbh->error) { 27 case BE_ERR_INVALIDNAME: 28 return ("invalid boot environment name"); 29 30 case BE_ERR_EXISTS: 31 return ("boot environment name already taken"); 32 33 case BE_ERR_NOENT: 34 return ("specified boot environment does not exist"); 35 36 case BE_ERR_PERMS: 37 return ("insufficient permissions"); 38 39 case BE_ERR_DESTROYACT: 40 return ("cannot destroy active boot environment"); 41 42 case BE_ERR_DESTROYMNT: 43 return ("cannot destroy mounted boot env unless forced"); 44 45 case BE_ERR_BADPATH: 46 return ("path not suitable for operation"); 47 48 case BE_ERR_PATHBUSY: 49 return ("specified path is busy"); 50 51 case BE_ERR_PATHLEN: 52 return ("provided path name exceeds maximum length limit"); 53 54 case BE_ERR_BADMOUNT: 55 return ("mountpoint is not \"/\""); 56 57 case BE_ERR_NOORIGIN: 58 return ("could not open snapshot's origin"); 59 60 case BE_ERR_MOUNTED: 61 return ("boot environment is already mounted"); 62 63 case BE_ERR_NOMOUNT: 64 return ("boot environment is not mounted"); 65 66 case BE_ERR_ZFSOPEN: 67 return ("calling zfs_open() failed"); 68 69 case BE_ERR_ZFSCLONE: 70 return ("error when calling zfs_clone() to create boot env"); 71 72 case BE_ERR_IO: 73 return ("input/output error"); 74 75 case BE_ERR_NOPOOL: 76 return ("operation not supported on this pool"); 77 78 case BE_ERR_NOMEM: 79 return ("insufficient memory"); 80 81 case BE_ERR_UNKNOWN: 82 return ("unknown error"); 83 84 case BE_ERR_INVORIGIN: 85 return ("invalid origin"); 86 87 case BE_ERR_HASCLONES: 88 return ("snapshot has clones"); 89 90 default: 91 assert(lbh->error == BE_ERR_SUCCESS); 92 return ("no error"); 93 } 94 } 95 96 97 void libbe_print_on_error(libbe_handle_t * lbh,bool val)98libbe_print_on_error(libbe_handle_t *lbh, bool val) 99 { 100 101 lbh->print_on_err = val; 102 libzfs_print_on_error(lbh->lzh, val); 103 } 104 105 106 int set_error(libbe_handle_t * lbh,be_error_t err)107set_error(libbe_handle_t *lbh, be_error_t err) 108 { 109 110 lbh->error = err; 111 if (lbh->print_on_err && (err != BE_ERR_SUCCESS)) 112 fprintf(stderr, "%s\n", libbe_error_description(lbh)); 113 114 return (err); 115 } 116