]>
Commit | Line | Data |
---|---|---|
558d2836 A |
1 | #include <stdio.h> |
2 | #include <sys/fcntl.h> | |
3 | #include <sys/mman.h> | |
4 | #include <unistd.h> | |
5 | #include <sys/stat.h> | |
6 | #include <sys/attr.h> | |
7 | ||
8 | #include "hfs-tests.h" | |
9 | #include "test-utils.h" | |
10 | #include "disk-image.h" | |
11 | ||
12 | TEST(mmap_mod_time) | |
13 | ||
14 | static disk_image_t *di; | |
15 | ||
16 | int run_mmap_mod_time(__unused test_ctx_t *ctx) | |
17 | { | |
18 | di = disk_image_get(); | |
19 | ||
20 | char *file; | |
21 | asprintf(&file, "%s/mmap_mod_time_test.dat", di->mount_point); | |
22 | ||
23 | int fd; | |
24 | ||
25 | assert_with_errno((fd = open(file, | |
26 | O_RDWR | O_CREAT | O_TRUNC, 0666)) >= 0); | |
27 | ||
28 | assert_no_err(ftruncate(fd, 65536)); | |
29 | assert_no_err(fsync(fd)); | |
30 | ||
31 | struct attrlist attrlist = { | |
32 | .bitmapcount = ATTR_BIT_MAP_COUNT, | |
33 | .commonattr = ATTR_CMN_MODTIME | ATTR_CMN_GEN_COUNT, | |
34 | }; | |
35 | #pragma pack(push, 4) | |
36 | struct { | |
37 | uint32_t len; | |
38 | struct timespec mod_time; | |
39 | uint32_t gen_count; | |
40 | } attrs[2]; | |
41 | #pragma pack(pop) | |
42 | ||
43 | assert_no_err(fgetattrlist(fd, &attrlist, &attrs[0], sizeof(attrs[0]), | |
44 | FSOPT_ATTR_CMN_EXTENDED)); | |
45 | ||
46 | assert_no_err(close(fd)); | |
47 | ||
48 | assert_no_err(getattrlist(file, | |
49 | &attrlist, &attrs[1], sizeof(attrs[1]), | |
50 | FSOPT_ATTR_CMN_EXTENDED)); | |
51 | ||
52 | assert(attrs[1].gen_count == attrs[0].gen_count); | |
53 | ||
54 | sleep(2); | |
55 | ||
56 | assert_with_errno((fd = open(file, | |
57 | O_RDWR)) >= 0); | |
58 | ||
59 | void *p; | |
60 | assert_with_errno((p = mmap(NULL, 65536, PROT_WRITE, | |
61 | MAP_SHARED, fd, 0)) != MAP_FAILED); | |
62 | ||
63 | char data[] = "mmap_mod_time_test"; | |
64 | memcpy(p, data, sizeof(data) - 1); | |
65 | ||
66 | assert_no_err(msync(p, 65536, MS_SYNC)); | |
67 | ||
68 | assert_no_err(munmap(p, 65536)); | |
69 | ||
70 | assert_no_err(fgetattrlist(fd, &attrlist, &attrs[1], sizeof(attrs[1]), | |
71 | FSOPT_ATTR_CMN_EXTENDED)); | |
72 | ||
73 | assert(attrs[0].mod_time.tv_sec != attrs[1].mod_time.tv_sec | |
74 | || attrs[0].mod_time.tv_nsec != attrs[1].mod_time.tv_nsec); | |
75 | ||
76 | assert(attrs[1].gen_count != attrs[0].gen_count); | |
77 | ||
78 | assert_no_err(unlink(file)); | |
79 | ||
80 | free(file); | |
81 | ||
82 | return 0; | |
83 | } |