h_fsmacros.h revision 1.5 1 /* $NetBSD: h_fsmacros.h,v 1.5 2010/07/09 14:30:53 njoly Exp $ */
2
3 /*-
4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Nicolas Joly.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #ifndef __H_FSMACROS_H_
33 #define __H_FSMACROS_H_
34
35 #include <sys/mount.h>
36
37 #include <atf-c.h>
38 #include <string.h>
39
40 #include "ext2fs.c"
41 #include "ffs.c"
42 #include "lfs.c"
43 #include "msdosfs.c"
44 #include "sysvbfs.c"
45 #include "tmpfs.c"
46
47 #define IMGNAME "image.fs"
48 #define IMGSIZE (10000 * 512)
49 #define MNTNAME "/mnt"
50
51 #define ATF_TC_FSADD(fs,type,func,desc) \
52 ATF_TC(fs##_##func); \
53 ATF_TC_HEAD(fs##_##func,tc) \
54 { \
55 atf_tc_set_md_var(tc, "descr", type " test for " desc); \
56 atf_tc_set_md_var(tc, "use.fs", "true"); \
57 } \
58 ATF_TC_BODY(fs##_##func,tc) \
59 { \
60 void *tmp; \
61 atf_check_fstype(tc, type); \
62 if (fs##_newfs(&tmp, IMGNAME, IMGSIZE) != 0) \
63 atf_tc_fail("newfs failed"); \
64 if (fs##_mount(tmp, MNTNAME, 0) != 0) \
65 atf_tc_fail("mount failed"); \
66 func(type,MNTNAME); \
67 if (fs##_unmount(MNTNAME, 0) != 0) \
68 atf_tc_fail("unmount failed"); \
69 if (fs##_delfs(tmp) != 0) \
70 atf_tc_fail("delfs failed"); \
71 }
72
73 #define ATF_TP_FSADD(fs,func) \
74 ATF_TP_ADD_TC(tp,fs##_##func)
75
76 #define ATF_TC_FSAPPLY(func,desc) \
77 ATF_TC_FSADD(ext2fs,MOUNT_EXT2FS,func,desc) \
78 ATF_TC_FSADD(ffs,MOUNT_FFS,func,desc) \
79 ATF_TC_FSADD(lfs,MOUNT_LFS,func,desc) \
80 ATF_TC_FSADD(msdosfs,MOUNT_MSDOS,func,desc) \
81 ATF_TC_FSADD(sysvbfs,MOUNT_SYSVBFS,func,desc) \
82 ATF_TC_FSADD(tmpfs,MOUNT_TMPFS,func,desc)
83
84 #define ATF_TP_FSAPPLY(func) \
85 ATF_TP_FSADD(ext2fs,func); \
86 ATF_TP_FSADD(ffs,func); \
87 ATF_TP_FSADD(lfs,func); \
88 ATF_TP_FSADD(msdosfs,func); \
89 ATF_TP_FSADD(sysvbfs,func); \
90 ATF_TP_FSADD(tmpfs,func);
91
92 #define ATF_FSAPPLY(func,desc) \
93 ATF_TC_FSAPPLY(func,desc); \
94 ATF_TP_ADD_TCS(tp) \
95 { \
96 ATF_TP_FSAPPLY(func); \
97 return atf_no_error(); \
98 }
99
100 static void
101 atf_check_fstype(const atf_tc_t *tc, const char *fs)
102 {
103 const char *fstype;
104
105 if (!atf_tc_has_config_var(tc, "fstype"))
106 return;
107 fstype = atf_tc_get_config_var(tc, "fstype");
108 if (strcmp(fstype, fs) == 0)
109 return;
110 atf_tc_skip("filesystem not selected");
111 }
112
113 #define FSTYPE_EXT2FS(type) (strcmp(type, MOUNT_EXT2FS) == 0)
114 #define FSTYPE_FFS(type) (strcmp(type, MOUNT_FFS) == 0)
115 #define FSTYPE_LFS(type) (strcmp(type, MOUNT_LFS) == 0)
116 #define FSTYPE_MSDOS(type) (strcmp(type, MOUNT_MSDOS) == 0)
117 #define FSTYPE_SYSVBFS(type) (strcmp(type, MOUNT_SYSVBFS) == 0)
118 #define FSTYPE_TMPFS(type) (strcmp(type, MOUNT_TMPFS) == 0)
119
120 #endif /* __H_FSMACROS_H_ */
121