]> git.saurik.com Git - apple/hfs.git/blob - tests/cases/test-cas-bsdflags.c
hfs-522.0.9.tar.gz
[apple/hfs.git] / tests / cases / test-cas-bsdflags.c
1 #include <unistd.h>
2 #include <fcntl.h>
3 #include <stdio.h>
4 #include <sys/mman.h>
5 #include <string.h>
6 #include <sys/attr.h>
7 #include <sys/types.h>
8 #include <sys/sysctl.h>
9 #include <sys/stat.h>
10 #include <sys/xattr.h>
11 #include <sys/mount.h>
12 #include <sys/param.h>
13
14 #include <System/sys/fsctl.h>
15
16 #include "hfs-tests.h"
17 #include "test-utils.h"
18 #include "disk-image.h"
19
20 //TEST(cas_bsdflags)
21
22 static bool
23 cas_bsd_flags(int fd, uint32_t expected_flags, uint32_t new_flags)
24 {
25 struct fsioc_cas_bsdflags cas;
26
27 cas.expected_flags = expected_flags;
28 cas.new_flags = new_flags;
29 cas.actual_flags = ~0; /* poison */
30
31 assert_no_err(ffsctl(fd, FSIOC_CAS_BSDFLAGS, &cas, 0));
32 return (cas.expected_flags == cas.actual_flags);
33 }
34
35 int run_cas_bsdflags(__unused test_ctx_t *ctx)
36 {
37 disk_image_t *di = disk_image_get();
38 struct stat sb;
39 int fd;
40
41 char *file;
42 asprintf(&file, "%s/cas_bsdflags.data", di->mount_point);
43
44 assert_with_errno((fd = open(file,
45 O_CREAT | O_RDWR | O_TRUNC, 0666)) >= 0);
46
47 assert_no_err(fchflags(fd, UF_HIDDEN));
48 assert_no_err(fstat(fd, &sb));
49 assert(sb.st_flags == UF_HIDDEN);
50
51 assert(cas_bsd_flags(fd, 0, UF_NODUMP) == false);
52 assert_no_err(fstat(fd, &sb));
53 assert(sb.st_flags == UF_HIDDEN);
54
55 assert(cas_bsd_flags(fd, UF_HIDDEN, UF_NODUMP) == true);
56 assert_no_err(fstat(fd, &sb));
57 assert(sb.st_flags == UF_NODUMP);
58
59 assert(cas_bsd_flags(fd, UF_NODUMP, 0) == true);
60 assert_no_err(fstat(fd, &sb));
61 assert(sb.st_flags == 0);
62
63 close(fd);
64 assert_no_err(unlink(file));
65 free(file);
66
67 return 0;
68 }
69