2 * Copyright (c) 2004 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Chris Pressey <cpressey@catseye.mine.nu>.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * Filesystem predicates.
39 * $Id: fspred.c,v 1.3 2005/02/10 03:33:49 cpressey Exp $
43 #include <sys/param.h>
44 #include <sys/ucred.h>
45 #include <sys/mount.h>
57 is_dir(const char *fmt
, ...)
65 vasprintf(&filename
, fmt
, args
);
68 result
= stat(filename
, &sb
);
72 return(sb
.st_mode
& S_IFDIR
);
78 is_file(const char *fmt
, ...)
86 vasprintf(&filename
, fmt
, args
);
89 result
= stat(filename
, &sb
);
93 return(sb
.st_mode
& S_IFREG
);
99 is_program(const char *fmt
, ...)
107 vasprintf(&filename
, fmt
, args
);
110 result
= stat(filename
, &sb
);
114 return((sb
.st_mode
& S_IFREG
) && (sb
.st_mode
& S_IXOTH
));
120 is_device(const char *fmt
, ...)
128 vasprintf(&filename
, fmt
, args
);
131 result
= stat(filename
, &sb
);
135 return((sb
.st_mode
& S_IFCHR
) | (sb
.st_mode
& S_IFBLK
));
141 is_named_pipe(const char *fmt
, ...)
149 vasprintf(&filename
, fmt
, args
);
152 result
= stat(filename
, &sb
);
157 return(sb
.st_mode
& S_IFIFO
);
163 is_mountpoint_mounted(const char *mtpt
)
165 struct statfs
*mt_array
, *mt_ptr
;
168 count
= getmntinfo(&mt_array
, MNT_WAIT
);
169 for (mt_ptr
= mt_array
; count
> 0; mt_ptr
++, count
--) {
170 if (strcmp(mt_ptr
->f_mntonname
, mtpt
) == 0)
177 is_device_mounted(const char *device
)
179 struct statfs
*mt_array
, *mt_ptr
;
182 count
= getmntinfo(&mt_array
, MNT_WAIT
);
183 for (mt_ptr
= mt_array
; count
> 0; mt_ptr
++, count
--) {
184 if (strcmp(mt_ptr
->f_mntfromname
, device
) == 0)
191 is_any_slice_mounted(const char *diskdev
)
193 struct statfs
*mt_array
, *mt_ptr
;
196 count
= getmntinfo(&mt_array
, MNT_WAIT
);
197 for (mt_ptr
= mt_array
; count
> 0; mt_ptr
++, count
--) {
198 if (strstr(mt_ptr
->f_mntfromname
, diskdev
) ==
199 mt_ptr
->f_mntfromname
)