2 * Copyright (c) 2008 Robert N. M. Watson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * This regression test attempts to confirm that the flags used at open-time
29 * for a file descriptor properly limit system calls that should be affected
30 * by those flags. Currently:
32 * System call Policy Tested
33 * __acl_aclcheck_fd(2) any no
34 * __acl_delete_fd(2) any no
35 * __acl_get_fd(2) any no
36 * __acl_set_fd(2) any no
38 * aio_read(2) O_RDONLY or O_RDWR yes
39 * aio_write(2) O_WRONLY or O_RDWR yes
42 * extattr_delete_fd(2) O_WRONLY or O_RDWR no
43 * extattr_get_fd(2) O_RDONLY or O_RDWR no
44 * extattr_list_fd(2) O_RDONLY or O_RDWR no
45 * extattr_set_fd(2) O_WRONLY or O_RDWR no
46 * fchdir(2) any directory yes
51 * fpathconf(2) any yes
55 * ftruncate(2) O_WRONLY or O_RDWR yes
57 * getdents(2) O_RDONLY directory yes
59 * mmap(2) PROT_READ O_RDONLY or O_RDWR yes
60 * mmap(2) PROT_WRITE O_WRONLY or O_RDWR yes
61 * mmap(2) PROT_WRITE + MAP_PRIV O_RDONLY or O_RDWR yes
62 * mmap(2) PROT_EXEC O_RDONLY or O_RDWR yes
63 * pread(2) O_RDONLY or O_RDWR yes
64 * preadv(2) O_RDONLY or O_RDWR yes
65 * pwrite(2) O_WRONLY or O_RDWR yes
66 * pwritev(2) O_WRONLY or O_RDWR yes
67 * read(2) O_RDONLY or O_RDWR yes
68 * readv(2) O_RDONLY or O_RDWR yes
69 * sendfile(2) O_RDONLY or O_RDWR on file yes
70 * write(2) O_WRONLY or O_RDWR yes
71 * writev(2) O_WRONLY or O_RDWR yes
73 * These checks do not verify that original permissions would allow the
74 * operation or that open is properly impacted by permissions, just that once
75 * a file descriptor is held, open-time limitations are implemented.
77 * We do, however, test that directories cannot be opened as writable.
79 * XXXRW: Arguably we should also test combinations of bits to mmap(2).
81 * XXXRW: Should verify mprotect() remapping limits.
83 * XXXRW: kqueue(2)/kevent(2), poll(2), select(2)
85 * XXXRW: oaio_read(2), oaio_write(2), freebsd6_*(2).
89 * XXXRW: message queue and shared memory fds?
92 #include <sys/cdefs.h>
93 __FBSDID("$FreeBSD$");
95 #include <sys/param.h>
97 #include <sys/mount.h>
98 #include <sys/socket.h>
100 #include <sys/sysctl.h>
114 #define PERM_FILE 0644 /* Allow read, write. Someday exec? */
115 #define PERM_DIR 0755 /* Allow read, write, exec. */
118 * Modes to try all tests with.
120 static const int file_modes[] = { O_RDONLY, O_WRONLY, O_RDWR,
121 O_RDONLY | O_TRUNC, O_WRONLY | O_TRUNC, O_RDWR | O_TRUNC };
122 static const int file_modes_count = sizeof(file_modes) / sizeof(int);
124 static const int dir_modes[] = { O_RDONLY };
125 static const int dir_modes_count = sizeof(dir_modes) / sizeof(int);
128 static int aio_present;
131 ok_mode(const char *testname, const char *comment, int mode)
136 printf("ok %d - %s # mode 0x%x\n", testnum, testname, mode);
138 printf("ok %d - %s # mode 0x%x - %s\n", testnum, testname,
143 notok_mode(const char *testname, const char *comment, int mode)
148 printf("not ok %d - %s # mode 0x%x\n", testnum, testname,
151 printf("not ok %d - %s # mode 0x%x - %s\n", testnum, testname,
156 * Before we get started, confirm that we can't open directories writable.
159 try_directory_open(const char *testname, const char *directory,
160 int mode, int expected_errno)
164 dfd = open(directory, mode);
167 notok_mode(testname, "opened", mode);
169 ok_mode(testname, NULL, mode);
172 if (expected_errno && expected_errno == expected_errno)
173 ok_mode(testname, NULL, mode);
174 else if (expected_errno)
175 notok_mode(testname, "wrong errno", mode);
177 notok_mode(testname, "failed", mode);
182 check_directory_open_modes(const char *directory, const int *modes,
185 int expected_errno, i, mode;
188 * Directories should only open with O_RDONLY. Notice that we use
189 * file_modes and not dirmodes.
191 for (i = 0; i < modes_count; i++) {
193 if (mode == O_RDONLY)
196 expected_errno = EISDIR;
197 try_directory_open(__func__, directory, mode,
203 check_dup(const char *testname, const char *path, const int *modes,
206 int dfd, fd, i, mode;
209 * dup() should work regardless of open mode.
211 for (i = 0; i < modes_count; i++) {
213 fd = open(path, mode);
215 notok_mode(testname, "open", mode);
220 ok_mode(testname, NULL, mode);
223 notok_mode(testname, NULL, mode);
229 check_dup2(const char *testname, const char *path, const int *modes,
232 int dfd, fd, i, mode;
235 * dup2() should work regardless of open mode.
237 for (i = 0; i < modes_count; i++) {
239 fd = open(path, mode);
241 notok_mode(testname, "open", mode);
244 dfd = dup2(fd, 500); /* Arbitrary but high number. */
246 ok_mode(testname, NULL, mode);
249 notok_mode(testname, NULL, mode);
255 check_fchdir(const char *testname, const char *path, const int *modes,
261 * fchdir() should work regardless of open mode.
263 for (i = 0; i < modes_count; i++) {
265 fd = open(path, mode);
267 notok_mode(testname, "open", mode);
271 ok_mode(testname, NULL, mode);
273 notok_mode(testname, "failed", mode);
279 check_fchflags(const char *testname, const char *path, const int *modes,
285 * fchflags() should work regardless of open mode.
287 for (i = 0; i < modes_count; i++) {
289 fd = open(path, mode);
291 notok_mode(testname, "open", mode);
294 if (fchflags(fd, UF_NODUMP) == 0)
295 ok_mode(testname, NULL, mode);
297 notok_mode(testname, "failed", mode);
303 check_fchmod(const char *testname, const char *path, int setmode,
304 const int *modes, int modes_count)
309 * fchmod() should work regardless of open mode.
311 for (i = 0; i < modes_count; i++) {
313 fd = open(path, mode);
315 notok_mode(testname, "open", mode);
318 if (fchmod(fd, setmode) == 0)
319 ok_mode(testname, NULL, mode);
321 notok_mode(testname, "failed", mode);
327 check_fchown(const char *testname, const char *path, const int *modes,
333 * fchown() should work regardless of open mode.
335 for (i = 0; i < modes_count; i++) {
337 fd = open(path, mode);
339 notok_mode(testname, "open", mode);
342 if (fchown(fd, -1, -1) == 0)
343 ok_mode(testname, NULL, mode);
345 notok_mode(testname, "failed", mode);
351 check_flock(const char *testname, const char *path, const int *modes,
357 * flock() should work regardless of open mode.
359 for (i = 0; i < modes_count; i++) {
361 fd = open(path, mode);
363 notok_mode(testname, "open", mode);
366 if (flock(fd, LOCK_EX) == 0)
367 ok_mode(testname, NULL, mode);
369 notok_mode(testname, "failed", mode);
375 check_fpathconf(const char *testname, const char *path, const int *modes,
382 * fpathconf() should work regardless of open mode.
384 for (i = 0; i < modes_count; i++) {
386 fd = open(path, mode);
388 notok_mode(testname, "open", mode);
391 l = fpathconf(fd, _PC_FILESIZEBITS);
393 ok_mode(testname, NULL, mode);
395 notok_mode(testname, "failed", mode);
401 check_fstat(const char *testname, const char *path, const int *modes,
408 * fstat() should work regardless of open mode.
410 for (i = 0; i < modes_count; i++) {
412 fd = open(path, mode);
414 notok_mode(testname, "open", mode);
417 if (fstat(fd, &sb) == 0)
418 ok_mode(testname, NULL, mode);
420 notok_mode(testname, "failed", mode);
426 check_fstatfs(const char *testname, const char *path, const int *modes,
429 struct statfs statfs;
433 * fstatfs() should work regardless of open mode.
435 for (i = 0; i < modes_count; i++) {
437 fd = open(path, mode);
439 notok_mode(testname, "open", mode);
442 if (fstatfs(fd, &statfs) == 0)
443 ok_mode(testname, NULL, mode);
445 notok_mode(testname, "failed", mode);
451 check_fsync(const char *testname, const char *path, const int *modes,
457 * fstatfs() should work regardless of open mode.
459 for (i = 0; i < modes_count; i++) {
461 fd = open(path, mode);
463 notok_mode(testname, "open", mode);
467 ok_mode(testname, NULL, mode);
469 notok_mode(testname, "failed", mode);
475 check_ftruncate(const char *testname, const char *path, const int *modes,
482 * ftruncate() should work as long as long as (mode & O_ACCMODE) is
483 * O_RDWR or O_WRONLY.
485 * Directories should never be writable, so this test should always
486 * pass for directories...
488 for (i = 0; i < modes_count; i++) {
490 fd = open(path, mode);
492 notok_mode(testname, "open", mode);
493 notok_mode(testname, "truncate1 skipped", mode);
494 notok_mode(testname, "truncate2 skipped", mode);
495 notok_mode(testname, "truncate3 skipped", mode);
498 if (fstat(fd, &sb) < 0) {
499 notok_mode(testname, "fstat", mode);
500 notok_mode(testname, "truncate1 skipped", mode);
501 notok_mode(testname, "truncate2 skipped", mode);
502 notok_mode(testname, "truncate3 skipped", mode);
506 ok_mode(testname, "setup", mode);
508 /* Truncate to grow file. */
509 if (ftruncate(fd, sb.st_size + 1) == 0) {
510 if (((mode & O_ACCMODE) == O_WRONLY) ||
511 ((mode & O_ACCMODE) == O_RDWR))
512 ok_mode(testname, "truncate1 succeeded",
515 notok_mode(testname, "truncate1 succeeded",
517 notok_mode(testname, "truncate2 skipped",
519 notok_mode(testname, "truncate3 skipped",
525 if (((mode & O_ACCMODE) == O_WRONLY) ||
526 ((mode & O_ACCMODE) == O_RDWR)) {
527 notok_mode(testname, "truncate1 failed",
529 notok_mode(testname, "truncate2 skipped",
531 notok_mode(testname, "truncate3 skipped",
536 ok_mode(testname, "truncate1 failed", mode);
539 /* Truncate to same size. */
540 if (ftruncate(fd, sb.st_size + 1) == 0) {
541 if (((mode & O_ACCMODE) == O_WRONLY) ||
542 ((mode & O_ACCMODE) == O_RDWR))
543 ok_mode(testname, "truncate2 succeeded",
546 notok_mode(testname, "truncate2 succeeded",
548 notok_mode(testname, "truncate3 skipped",
554 if (((mode & O_ACCMODE) == O_WRONLY) ||
555 ((mode & O_ACCMODE) == O_RDWR)) {
556 notok_mode(testname, "truncate2 failed",
558 notok_mode(testname, "truncate3 skipped",
563 ok_mode(testname, "truncate2 failed", mode);
566 /* Truncate to shrink. */
567 if (ftruncate(fd, sb.st_size) == 0) {
568 if (((mode & O_ACCMODE) == O_WRONLY) ||
569 ((mode & O_ACCMODE) == O_RDWR))
570 ok_mode(testname, "truncate3 succeeded",
573 notok_mode(testname, "truncate3 succeeded",
576 if (((mode & O_ACCMODE) == O_WRONLY) ||
577 ((mode & O_ACCMODE) == O_RDWR))
578 notok_mode(testname, "truncate3 failed",
581 ok_mode(testname, "truncate3 failed", mode);
588 check_futimes(const char *testname, const char *path, const int *modes,
594 * futimes() should work regardless of open mode.
596 for (i = 0; i < modes_count; i++) {
598 fd = open(path, mode);
600 notok_mode(testname, "open", mode);
603 if (futimes(fd, NULL) == 0)
604 ok_mode(testname, NULL, mode);
606 notok_mode(testname, "failed", mode);
612 check_lseek(const char *testname, const char *path, const int *modes,
618 * lseek() should work regardless of open mode.
620 for (i = 0; i < modes_count; i++) {
622 fd = open(path, mode);
624 notok_mode(testname, "open", mode);
627 if (lseek(fd, 100, SEEK_SET) == 100)
628 ok_mode(testname, NULL, mode);
630 notok_mode(testname, "failed", mode);
636 check_getdents(const char *testname, const char *path, int isdir,
637 const int *modes, int modes_count)
643 * getdents() should always work on directories and never on files,
644 * assuming directories are always opened for read (which they are).
646 for (i = 0; i < modes_count; i++) {
648 fd = open(path, mode);
650 notok_mode(testname, "open", mode);
653 if (getdents(fd, buf, sizeof(buf)) >= 0) {
654 if (isdir && ((mode & O_ACCMODE) == O_RDONLY))
655 ok_mode(testname, "directory succeeded",
658 notok_mode(testname, "directory succeeded",
661 notok_mode(testname, "file succeeded", mode);
663 if (isdir && ((mode & O_ACCMODE) == O_RDONLY))
664 notok_mode(testname, "directory failed",
667 ok_mode(testname, "directory failed", mode);
669 ok_mode(testname, "file failed", mode);
676 check_sendfile(const char *testname, const char *path, int isdir,
677 const int *modes, int modes_count)
679 int fd, i, mode, sv[2];
683 * sendfile() should work only on files, and only when the access mode
684 * is O_RDONLY or O_RDWR.
686 for (i = 0; i < modes_count; i++) {
688 fd = open(path, mode);
690 notok_mode(testname, "open", mode);
693 if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) < 0) {
694 notok_mode(testname, "socketpair", mode);
697 if (sendfile(fd, sv[0], 0, 1, NULL, &sent, 0) == 0) {
699 notok_mode(testname, "directory succeeded",
701 else if (((mode & O_ACCMODE) == O_RDONLY) ||
702 ((mode & O_ACCMODE) == O_RDWR))
703 ok_mode(testname, "succeeded", mode);
705 notok_mode(testname, "succeeded", mode);
708 ok_mode(testname, "directory failed", mode);
709 else if (((mode & O_ACCMODE) == O_RDONLY) ||
710 ((mode & O_ACCMODE) == O_RDWR))
711 notok_mode(testname, "failed", mode);
713 ok_mode(testname, "failed", mode);
722 * Various functions write, so just make write-like wrappers for them.
724 typedef ssize_t (*write_fn)(int d, const void *buf, size_t nbytes);
727 writev_wrapper(int d, const void *buf, size_t nbytes)
731 iov.iov_base = (void *)buf;
732 iov.iov_len = nbytes;
733 return (writev(d, &iov, 1));
737 pwrite_wrapper(int d, const void *buf, size_t nbytes)
740 return (pwrite(d, buf, nbytes, 0));
744 pwritev_wrapper(int d, const void *buf, size_t nbytes)
748 iov.iov_base = (void *)buf;
749 iov.iov_len = nbytes;
750 return (pwritev(d, &iov, 1, 0));
754 aio_write_wrapper(int d, const void *buf, size_t nbytes)
756 struct aiocb aiocb, *aiocb_array[1];
758 bzero(&aiocb, sizeof(aiocb));
759 aiocb.aio_fildes = d;
760 aiocb.aio_buf = (void *)buf;
761 aiocb.aio_nbytes = nbytes;
762 if (aio_write(&aiocb) < 0)
764 aiocb_array[0] = &aiocb;
765 if (aio_suspend(aiocb_array, 1, NULL) < 0)
767 return (aio_return(&aiocb));
771 check_write(const char *testname, write_fn fn, const char *path,
772 const int *modes, int modes_count)
778 * write() should never succeed for directories, but especially
779 * because they can only be opened read-only. write() on files
780 * should succeed for O_WRONLY and O_RDWR descriptors.
783 for (i = 0; i < modes_count; i++) {
785 fd = open(path, mode);
787 notok_mode(testname, "open", mode);
790 if (fn(fd, &ch, sizeof(ch)) < 0) {
791 if ((mode & O_ACCMODE) == O_WRONLY ||
792 (mode & O_ACCMODE) == O_RDWR)
793 notok_mode(testname, "write failed", mode);
795 ok_mode(testname, "write failed", mode);
797 if (!((mode & O_ACCMODE) == O_WRONLY ||
798 (mode & O_ACCMODE) == O_RDWR))
799 notok_mode(testname, "write suceeded", mode);
801 ok_mode(testname, "write succeeded", mode);
808 * Various functions read, so just make read-like wrappers for them.
810 typedef ssize_t (*read_fn)(int d, void *buf, size_t nbytes);
813 readv_wrapper(int d, void *buf, size_t nbytes)
818 iov.iov_len = nbytes;
819 return (readv(d, &iov, 1));
823 pread_wrapper(int d, void *buf, size_t nbytes)
826 return (pread(d, buf, nbytes, 0));
830 preadv_wrapper(int d, void *buf, size_t nbytes)
835 iov.iov_len = nbytes;
836 return (preadv(d, &iov, 1, 0));
840 aio_read_wrapper(int d, void *buf, size_t nbytes)
842 struct aiocb aiocb, *aiocb_array[1];
844 bzero(&aiocb, sizeof(aiocb));
845 aiocb.aio_fildes = d;
847 aiocb.aio_nbytes = nbytes;
848 if (aio_read(&aiocb) < 0)
850 aiocb_array[0] = &aiocb;
851 if (aio_suspend(aiocb_array, 1, NULL) < 0)
853 return (aio_return(&aiocb));
857 check_read(const char *testname, read_fn fn, const char *path,
858 const int *modes, int modes_count)
864 * read() should (generally) succeeded on directories. read() on
865 * files should succeed for O_RDONLY and O_RDWR descriptors.
867 for (i = 0; i < modes_count; i++) {
869 fd = open(path, mode);
871 notok_mode(testname, "open", mode);
874 if (fn(fd, &ch, sizeof(ch)) < 0) {
875 if ((mode & O_ACCMODE) == O_RDONLY ||
876 (mode & O_ACCMODE) == O_RDWR)
877 notok_mode(testname, "read failed", mode);
879 ok_mode(testname, "read failed", mode);
881 if (!((mode & O_ACCMODE) == O_RDONLY ||
882 (mode & O_ACCMODE) == O_RDWR))
883 notok_mode(testname, "read suceeded", mode);
885 ok_mode(testname, "read succeeded", mode);
892 check_mmap_read(const char *testname, const char *path, int isdir,
893 const int *modes, int modes_count)
899 * mmap() read should fail for directories (ideally?) but succeed for
900 * O_RDONLY and O_RDWR file descriptors.
902 for (i = 0; i < modes_count; i++) {
904 fd = open(path, mode);
906 notok_mode(testname, "open", mode);
909 addr = mmap(NULL, getpagesize(), PROT_READ, MAP_SHARED, fd,
911 if (addr == MAP_FAILED) {
913 ok_mode(testname, "mmap dir failed", mode);
914 else if ((mode & O_ACCMODE) == O_RDONLY ||
915 (mode & O_ACCMODE) == O_RDWR)
916 notok_mode(testname, "mmap file failed",
919 ok_mode(testname, "mmap file failed", mode);
922 notok_mode(testname, "mmap dir succeeded",
924 else if ((mode & O_ACCMODE) == O_RDONLY ||
925 (mode & O_ACCMODE) == O_RDWR)
926 ok_mode(testname, "mmap file succeeded",
929 notok_mode(testname, "mmap file succeeded",
931 (void)munmap(addr, getpagesize());
938 check_mmap_write(const char *testname, const char *path, const int *modes,
945 * mmap() will always fail for directories (ideally) as they are
946 * always open O_RDONLY. Check for O_WRONLY or O_RDWR to permit a
947 * write mapping. This variant does a MAP_SHARED mapping, but we
948 * are also interested in MAP_PRIVATE.
950 for (i = 0; i < modes_count; i++) {
952 fd = open(path, mode);
954 notok_mode(testname, "open", mode);
957 addr = mmap(NULL, getpagesize(), PROT_WRITE, MAP_SHARED, fd,
959 if (addr == MAP_FAILED) {
960 if ((mode & O_ACCMODE) == O_WRONLY ||
961 (mode & O_ACCMODE) == O_RDWR)
962 notok_mode(testname, "mmap failed",
965 ok_mode(testname, "mmap failed", mode);
967 if ((mode & O_ACCMODE) == O_WRONLY ||
968 (mode & O_ACCMODE) == O_RDWR)
969 ok_mode(testname, "mmap succeeded",
972 notok_mode(testname, "mmap succeeded", mode);
973 (void)munmap(addr, getpagesize());
980 check_mmap_exec(const char *testname, const char *path, int isdir,
981 const int *modes, int modes_count)
987 * mmap() exec should fail for directories (ideally?) but succeed for
988 * O_RDONLY and O_RDWR file descriptors.
990 for (i = 0; i < modes_count; i++) {
992 fd = open(path, mode);
994 notok_mode(testname, "open", mode);
997 addr = mmap(NULL, getpagesize(), PROT_EXEC, MAP_SHARED, fd,
999 if (addr == MAP_FAILED) {
1001 ok_mode(testname, "mmap dir failed", mode);
1002 else if ((mode & O_ACCMODE) == O_RDONLY ||
1003 (mode & O_ACCMODE) == O_RDWR)
1004 notok_mode(testname, "mmap file failed",
1007 ok_mode(testname, "mmap file failed", mode);
1010 notok_mode(testname, "mmap dir succeeded",
1012 else if ((mode & O_ACCMODE) == O_RDONLY ||
1013 (mode & O_ACCMODE) == O_RDWR)
1014 ok_mode(testname, "mmap file succeeded",
1017 notok_mode(testname, "mmap file succeeded",
1019 (void)munmap(addr, getpagesize());
1026 check_mmap_write_private(const char *testname, const char *path, int isdir,
1027 const int *modes, int modes_count)
1033 * mmap() write private should succeed for readable descriptors
1034 * except for directories.
1036 for (i = 0; i < modes_count; i++) {
1038 fd = open(path, mode);
1040 notok_mode(testname, "open", mode);
1043 addr = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE,
1044 MAP_PRIVATE, fd, 0);
1045 if (addr == MAP_FAILED) {
1047 ok_mode(testname, "mmap dir failed", mode);
1048 else if ((mode & O_ACCMODE) == O_RDONLY ||
1049 (mode & O_ACCMODE) == O_RDWR)
1050 notok_mode(testname, "mmap file failed",
1053 ok_mode(testname, "mmap file failed", mode);
1056 notok_mode(testname, "mmap dir succeeded",
1058 else if ((mode & O_ACCMODE) == O_RDONLY ||
1059 (mode & O_ACCMODE) == O_RDWR)
1060 ok_mode(testname, "mmap file succeeded",
1063 notok_mode(testname, "mmap file succeeded",
1065 (void)munmap(addr, getpagesize());
1072 main(int argc, char *argv[])
1074 char dir_path[PATH_MAX], file_path[PATH_MAX];
1079 size = sizeof(dummy);
1080 if (sysctlbyname("vfs.aio", &dummy, &size, NULL, 0) < 0) {
1081 if (errno == EISDIR)
1085 strlcpy(dir_path, "/tmp/open-dir.XXXXXXXXXXX", sizeof(dir_path));
1086 if (mkdtemp(dir_path) == NULL)
1088 if (chmod(dir_path, PERM_DIR) < 0) {
1089 warn("chmod %s", dir_path);
1090 (void)rmdir(dir_path);
1093 strlcpy(file_path, "/tmp/open-file.XXXXXXXXXXX", sizeof(file_path));
1094 fd = mkstemp(file_path);
1097 (void)rmdir(dir_path);
1101 if (chmod(file_path, PERM_FILE) < 0) {
1102 warn("chmod %s", file_path);
1103 (void)unlink(file_path);
1104 (void)rmdir(dir_path);
1107 check_directory_open_modes(dir_path, file_modes, file_modes_count);
1109 check_dup("check_dup_dir", dir_path, dir_modes, dir_modes_count);
1110 check_dup("check_dup_file", file_path, file_modes, file_modes_count);
1112 check_dup2("check_dup2_dir", dir_path, dir_modes, dir_modes_count);
1113 check_dup2("check_dup2_file", file_path, file_modes,
1116 check_fchdir("check_fchdir", dir_path, dir_modes, dir_modes_count);
1118 check_fchflags("check_fchflags_dir", dir_path, dir_modes,
1120 check_fchflags("check_fchflags_file", file_path, file_modes,
1123 check_fchmod("check_fchmod_dir", dir_path, PERM_DIR, dir_modes,
1125 check_fchmod("check_fchmod_file", file_path, PERM_FILE, file_modes,
1128 check_fchown("check_fchown_dir", dir_path, dir_modes,
1130 check_fchown("check_fchown_file", file_path, file_modes,
1133 check_flock("check_flock_dir", dir_path, dir_modes, dir_modes_count);
1134 check_flock("check_flock_file", file_path, file_modes,
1137 check_fpathconf("check_fpathconf_dir", dir_path, dir_modes,
1139 check_fpathconf("check_fpathconf_file", file_path, file_modes,
1142 check_fstat("check_fstat_dir", dir_path, dir_modes, dir_modes_count);
1143 check_fstat("check_fstat_file", file_path, file_modes,
1146 check_fstatfs("check_fstatfs_dir", dir_path, dir_modes,
1148 check_fstatfs("check_fstatfs_file", file_path, file_modes,
1151 check_fsync("check_fsync_dir", dir_path, dir_modes, dir_modes_count);
1152 check_fsync("check_fsync_file", file_path, file_modes,
1155 check_ftruncate("check_ftruncate_dir", dir_path, dir_modes,
1157 check_ftruncate("check_ftruncate_file", file_path, file_modes,
1160 check_futimes("check_futimes_dir", dir_path, dir_modes,
1162 check_futimes("check_futimes_file", file_path, file_modes,
1165 check_lseek("check_lseek_dir", dir_path, dir_modes, dir_modes_count);
1166 check_lseek("check_lseek_file", file_path, file_modes,
1169 check_getdents("check_getdents_dir", dir_path, 1, dir_modes,
1171 check_getdents("check_getdents_file", file_path, 0, file_modes,
1174 check_sendfile("check_sendfile_dir", dir_path, 1, dir_modes,
1176 check_sendfile("check_sendfile_file", file_path, 0, file_modes,
1179 check_write("check_write_dir", write, dir_path, dir_modes,
1181 check_write("check_write_file", write, file_path, file_modes,
1184 check_write("check_writev_dir", writev_wrapper, dir_path, dir_modes,
1186 check_write("check_writev_file", writev_wrapper, file_path,
1187 file_modes, file_modes_count);
1189 check_write("check_pwrite_dir", pwrite_wrapper, dir_path, dir_modes,
1191 check_write("check_pwrite_file", pwrite_wrapper, file_path,
1192 file_modes, file_modes_count);
1194 check_write("check_pwritev_dir", pwritev_wrapper, dir_path,
1195 dir_modes, dir_modes_count);
1196 check_write("check_pwritev_file", pwritev_wrapper, file_path,
1197 file_modes, file_modes_count);
1200 check_write("check_aio_write_dir", aio_write_wrapper,
1201 dir_path, dir_modes, dir_modes_count);
1202 check_write("check_aio_write_file", aio_write_wrapper,
1203 file_path, file_modes, file_modes_count);
1206 check_read("check_read_dir", read, dir_path, dir_modes,
1208 check_read("check_read_file", read, file_path, file_modes,
1211 check_read("check_readv_dir", readv_wrapper, dir_path, dir_modes,
1213 check_read("check_readv_file", readv_wrapper, file_path,
1214 file_modes, file_modes_count);
1216 check_read("check_pread_dir", pread_wrapper, dir_path, dir_modes,
1218 check_read("check_pread_file", pread_wrapper, file_path,
1219 file_modes, file_modes_count);
1221 check_read("check_preadv_dir", preadv_wrapper, dir_path,
1222 dir_modes, dir_modes_count);
1223 check_read("check_preadv_file", preadv_wrapper, file_path,
1224 file_modes, file_modes_count);
1227 check_read("check_aio_read_dir", aio_read_wrapper, dir_path,
1228 dir_modes, dir_modes_count);
1229 check_read("check_aio_read_file", aio_read_wrapper,
1230 file_path, file_modes, file_modes_count);
1233 check_mmap_read("check_mmap_read_dir", dir_path, 1, dir_modes,
1235 check_mmap_read("check_mmap_read_file", file_path, 0, file_modes,
1238 check_mmap_write("check_mmap_write_dir", dir_path, dir_modes,
1240 check_mmap_write("check_mmap_write_file", file_path, file_modes,
1243 check_mmap_exec("check_mmap_exec_dir", dir_path, 1, dir_modes,
1245 check_mmap_exec("check_mmap_exec_file", file_path, 0, file_modes,
1248 check_mmap_write_private("check_mmap_write_private_dir", dir_path, 1,
1249 dir_modes, dir_modes_count);
1250 check_mmap_write_private("check_mmap_write_private_file", file_path,
1251 0, file_modes, file_modes_count);
1253 (void)unlink(file_path);
1254 (void)rmdir(dir_path);