]> git.saurik.com Git - apple/hfs.git/blob - tests/cases/test-access.c
hfs-556.100.11.tar.gz
[apple/hfs.git] / tests / cases / test-access.c
1 #include <errno.h>
2 #include <fcntl.h>
3 #include <unistd.h>
4 #include <sys/stat.h>
5 #include <sys/ioctl.h>
6 #include <libgen.h>
7
8 #include "hfs-tests.h"
9 #include "test-utils.h"
10 #include "disk-image.h"
11
12 TEST(access)
13
14 struct ext_access_t {
15 uint32_t flags; /* IN: access requested (i.e. R_OK) */
16 uint32_t num_files; /* IN: number of files to process */
17 uint32_t map_size; /* IN: size of the bit map */
18 uint32_t *file_ids; /* IN: Array of file ids */
19 char *bitmap; /* OUT: hash-bitmap of interesting directory ids */
20 short *access; /* OUT: access info for each file (0 for 'has access') */
21 uint32_t num_parents; /* future use */
22 uint32_t *parents; /* future use */
23 };
24
25 int run_access(__unused test_ctx_t *ctx)
26 {
27 disk_image_t *di = disk_image_get();
28
29 char *path;
30 asprintf(&path, "%s/acces_check.data", di->mount_point);
31
32 int fd;
33 assert_with_errno((fd = open(path, O_RDWR | O_CREAT, 0666)) >= 0);
34
35 struct stat sb;
36 assert_no_err(fstat(fd, &sb));
37
38 assert_no_err(unlink(path));
39
40 char dir_map[1 << 16] = { 0 };
41 short access_vector[1024] = { 0 };
42
43 struct ext_access_t params = {
44 .flags = R_OK,
45 .num_files = 1,
46 .map_size = sizeof(dir_map),
47 .file_ids = (uint32_t[]){ (uint32_t)sb.st_ino },
48 .bitmap = dir_map,
49 .access = access_vector,
50 };
51
52 #define HFSIOC_EXT_BULKACCESS _IOW('h', 15, struct ext_access_t)
53
54 char *base_path = strdup(path);
55 base_path = dirname(base_path);
56 assert_no_err(fsctl(base_path, HFSIOC_EXT_BULKACCESS, &params, 0));
57
58 if (access_vector[0] != ENOENT)
59 assert_fail("access_vector[0] != ENOENT (== %u)!", access_vector[0]);
60
61 free(path);
62 assert_no_err (close(fd));
63
64 return 0;
65 }