]>
git.saurik.com Git - apple/hfs.git/blob - tests/cases/test-mmap-mod-time.c
9 #include "test-utils.h"
10 #include "disk-image.h"
14 static disk_image_t
*di
;
16 int run_mmap_mod_time(__unused test_ctx_t
*ctx
)
18 di
= disk_image_get();
21 asprintf(&file
, "%s/mmap_mod_time_test.dat", di
->mount_point
);
25 assert_with_errno((fd
= open(file
,
26 O_RDWR
| O_CREAT
| O_TRUNC
, 0666)) >= 0);
28 assert_no_err(ftruncate(fd
, 65536));
29 assert_no_err(fsync(fd
));
31 struct attrlist attrlist
= {
32 .bitmapcount
= ATTR_BIT_MAP_COUNT
,
33 .commonattr
= ATTR_CMN_MODTIME
| ATTR_CMN_GEN_COUNT
,
38 struct timespec mod_time
;
43 assert_no_err(fgetattrlist(fd
, &attrlist
, &attrs
[0], sizeof(attrs
[0]),
44 FSOPT_ATTR_CMN_EXTENDED
));
46 assert_no_err(close(fd
));
48 assert_no_err(getattrlist(file
,
49 &attrlist
, &attrs
[1], sizeof(attrs
[1]),
50 FSOPT_ATTR_CMN_EXTENDED
));
52 assert(attrs
[1].gen_count
== attrs
[0].gen_count
);
56 assert_with_errno((fd
= open(file
,
60 assert_with_errno((p
= mmap(NULL
, 65536, PROT_WRITE
,
61 MAP_SHARED
, fd
, 0)) != MAP_FAILED
);
63 char data
[] = "mmap_mod_time_test";
64 memcpy(p
, data
, sizeof(data
) - 1);
66 assert_no_err(msync(p
, 65536, MS_SYNC
));
68 assert_no_err(munmap(p
, 65536));
70 assert_no_err(fgetattrlist(fd
, &attrlist
, &attrs
[1], sizeof(attrs
[1]),
71 FSOPT_ATTR_CMN_EXTENDED
));
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
);
76 assert(attrs
[1].gen_count
!= attrs
[0].gen_count
);
78 assert_no_err(unlink(file
));