be_access.c (b29bf2f84ea838b1b7dad4e80858b637395930ae) be_access.c (843e39ce7bf6449f5cbb9144774d589574fda3b1)
1/*
2 * be_access.c
3 *
4 * Copyright (c) 2017 Kyle J. Kneitinger <kyle@kneit.in>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 15 unchanged lines hidden (view full) ---

24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include "be.h"
30#include "be_impl.h"
31
1/*
2 * be_access.c
3 *
4 * Copyright (c) 2017 Kyle J. Kneitinger <kyle@kneit.in>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 15 unchanged lines hidden (view full) ---

24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include "be.h"
30#include "be_impl.h"
31
32struct be_mountcheck_info {
33 const char *path;
34 char *name;
35};
36
37static int
38be_mountcheck_cb(zfs_handle_t *zfs_hdl, void *data)
39{
40 struct be_mountcheck_info *info;
41 char *mountpoint;
42
43 if (data == NULL)
44 return (1);
45 info = (struct be_mountcheck_info *)data;
46 if (!zfs_is_mounted(zfs_hdl, &mountpoint))
47 return (0);
48 if (strcmp(mountpoint, info->path) == 0) {
49 info->name = strdup(zfs_get_name(zfs_hdl));
50 return (1);
51 }
52 return (0);
53}
54
32/*
33 * usage
34 */
35int
55/*
56 * usage
57 */
58int
59be_mounted_at(libbe_handle_t *lbh, const char *path, nvlist_t *details)
60{
61 char be[BE_MAXPATHLEN + 1];
62 zfs_handle_t *root_hdl;
63 struct be_mountcheck_info info;
64 prop_data_t propinfo;
65
66 bzero(&be, BE_MAXPATHLEN + 1);
67 if ((root_hdl = zfs_open(lbh->lzh, lbh->root,
68 ZFS_TYPE_FILESYSTEM)) == NULL)
69 return (BE_ERR_ZFSOPEN);
70
71 info.path = path;
72 info.name = NULL;
73 zfs_iter_filesystems(root_hdl, be_mountcheck_cb, &info);
74 zfs_close(root_hdl);
75
76 if (info.name != NULL) {
77 if (details != NULL) {
78 if ((root_hdl = zfs_open(lbh->lzh, lbh->root,
79 ZFS_TYPE_FILESYSTEM)) == NULL) {
80 free(info.name);
81 return (BE_ERR_ZFSOPEN);
82 }
83
84 propinfo.lbh = lbh;
85 propinfo.list = details;
86 prop_list_builder_cb(root_hdl, &propinfo);
87 zfs_close(root_hdl);
88 }
89 free(info.name);
90 return (0);
91 }
92 return (1);
93}
94
95/*
96 * usage
97 */
98int
36be_mount(libbe_handle_t *lbh, char *bootenv, char *mountpoint, int flags,
37 char *result_loc)
38{
39 char be[BE_MAXPATHLEN];
40 char mnt_temp[BE_MAXPATHLEN];
41 char *path;
42 int mntflags;
43 int err;

--- 78 unchanged lines hidden ---
99be_mount(libbe_handle_t *lbh, char *bootenv, char *mountpoint, int flags,
100 char *result_loc)
101{
102 char be[BE_MAXPATHLEN];
103 char mnt_temp[BE_MAXPATHLEN];
104 char *path;
105 int mntflags;
106 int err;

--- 78 unchanged lines hidden ---