2 * Copyright (c) 2011 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
6 * by Antonio Huete <tuxillo@quantumachine.net>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * 3. Neither the name of The DragonFly Project nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific, prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 #include <sys/mount.h>
46 #include <libhammer.h>
49 libhammer_find_pfs_mount(int pfsid, uuid_t parentuuid, int ismaster)
51 struct hammer_ioc_info hi;
52 struct statfs *mntbuf;
62 /* Do not continue if there are no mounted filesystems */
63 mntsize = getfsstat(NULL, 0, MNT_NOWAIT);
67 mntbufsize = (mntsize) * sizeof(struct statfs);
68 mntbuf = _libhammer_malloc(mntbufsize);
74 mntsize = getfsstat(mntbuf, (long)mntbufsize, MNT_NOWAIT);
75 curmount = mntsize - 1;
77 asprintf(&trailstr, ":%05d", pfsid);
80 * Iterate all the mounted points looking for the PFS passed to
83 while(curmount >= 0) {
85 * We need to avoid that PFS belonging to other HAMMER
86 * filesystems are showed as mounted, so we compare
87 * against the FSID, which is presumable to be unique.
89 bzero(&hi, sizeof(hi));
90 if ((fd = open(mntbuf[curmount].f_mntfromname, O_RDONLY)) < 0) {
95 if ((ioctl(fd, HAMMERIOC_GET_INFO, &hi)) < 0) {
100 if (strstr(mntbuf[curmount].f_mntfromname, trailstr) != NULL &&
101 (uuid_compare(&hi.vol_fsid, &parentuuid, NULL)) == 0) {
103 if (strstr(mntbuf[curmount].f_mntfromname,
106 strdup(mntbuf[curmount].f_mntonname);
110 if (strstr(mntbuf[curmount].f_mntfromname,
113 strdup(mntbuf[curmount].f_mntonname);
127 * Allocate len bytes of memory and return the pointer.
128 * It'll exit in the case no memory could be allocated.
130 * To be used only by the library itself.
133 _libhammer_malloc(size_t len)
137 m = calloc(len, sizeof(char));
139 errx(1, "Failed to allocate %zd bytes", len);