]>
git.saurik.com Git - apple/hfs.git/blob - tests/cases/test-mod-time.c
2f5566291f6aa025d4413c6ab6d1e50f90ca0895
11 #include <sys/types.h>
12 #include <sys/fcntl.h>
13 #include <sys/resource.h>
14 #include <TargetConditionals.h>
16 #include "hfs-tests.h"
17 #include "test-utils.h"
18 #include "disk-image.h"
22 static disk_image_t
*di
;
24 static void run_test(void)
29 asprintf(&file
, "%s/tstfile", di
->mount_point
);
30 assert((fd
= open(file
, O_CREAT
| O_RDWR
| O_TRUNC
, 0666)) >= 0);
32 char data
[] = "The quick brown fox jumps over the lazy dog\n";
34 check_io(write(fd
, data
, sizeof (data
) - 1), sizeof(data
) - 1);
36 struct timeval times
[] = {
41 assert_no_err(futimes(fd
, times
));
43 /* Have to open file again because whether it's writable comes from
44 the file descriptor, *not* how we map. */
47 assert_with_errno((fd2
= open(file
, O_RDONLY
)) >= 0);
50 assert((p
= mmap(NULL
, NBPG
, PROT_READ
, MAP_SHARED
, fd2
, 0)) != MAP_FAILED
);
52 assert_no_err(msync(p
, NBPG
, MS_INVALIDATE
));
55 assert_no_err(fstat(fd
, &sb
));
57 assert (sb
.st_mtimespec
.tv_sec
== times
[1].tv_sec
);
59 assert_no_err(close(fd
));
60 assert_no_err(close(fd2
));
61 assert_no_err(unlink(file
));
64 int run_mod_time(__unused test_ctx_t
*ctx
)
66 di
= disk_image_get();
68 // We need to run the test twice because the sync runs every 30 secs or so