]>
git.saurik.com Git - apple/hfs.git/blob - livefiles_cs_plugin/livefiles_cs_tester.c
2 // Copyright (c) 2019 Apple Inc. All rights reserved.
4 // @APPLE_LICENSE_HEADER_START@
6 // This file contains Original Code and/or Modifications of Original Code
7 // as defined in and that are subject to the Apple Public Source License
8 // Version 2.0 (the 'License'). You may not use this file except in
9 // compliance with the License. Please obtain a copy of the License at
10 // http://www.opensource.apple.com/apsl/ and read it before using this
13 // The Original Code and all software distributed under the License are
14 // distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 // EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 // INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 // Please see the License for the specific language governing rights and
19 // limitations under the License.
21 // @APPLE_LICENSE_HEADER_END@
23 // livefiles_cs_tester.c - Implements unit tests for livefiles
24 // Apple_CoreStorage plugin.
34 #include <UserFS/UserVFS.h>
36 extern UVFSFSOps cs_fsops
;
39 // Enums describing file-system formats.
48 INVALID_FS_TYPE
= INT8_MAX
,
52 // Array describing file-system name and analogous types.
55 const char *const fs_name
;
56 lf_cspt_fstype_t fs_type
;
57 } lf_cspt_fstype_arr_t
[] = {
63 {"APPLE_CS", APPLE_CS
},
65 {NULL
, INVALID_FS_TYPE
}
69 // Validate file-system types that is supported by this program.
72 is_fstype_valid(const char *fs_name
, lf_cspt_fstype_t
*fs_type
)
76 for (idx
= 0; lf_cspt_fstype_arr_t
[idx
].fs_name
!= NULL
; idx
++) {
77 if (strcmp(fs_name
, lf_cspt_fstype_arr_t
[idx
].fs_name
) == 0) {
78 *fs_type
= lf_cspt_fstype_arr_t
[idx
].fs_type
;
87 // Usage string returned to user.
90 usage(const char *prog_name
)
92 fprintf(stderr
, "Usage: %s filesystem-format device-path\n",
98 main(int argc
, char *argv
[])
101 lf_cspt_fstype_t fs_type
;
104 return usage(argv
[0]);
107 if (!is_fstype_valid(argv
[1], &fs_type
)) {
108 fprintf(stderr
, "Unknown file-system type %s\n", argv
[1]);
112 fd
= open(argv
[2], O_RDWR
);
114 fprintf(stderr
, "Failed to open device [%s]: %d\n",
119 error
= cs_fsops
.fsops_init();
120 printf("Init for fs_type %s returned [%d]\n", argv
[1], error
);
125 error
= cs_fsops
.fsops_taste(fd
);
133 // Taste with these disk-image is expected to retrun
134 // ENOTSUP. Thus supress the error here.
136 if (error
== ENOTSUP
) {
145 // Control should not come here.
148 fprintf(stderr
, "Bug in test.\n");
150 printf("Taste for fs_type %s returned [%d]\n", argv
[1], error
);
151 cs_fsops
.fsops_fini();
154 printf("Test result [%d]\n", error
);