xref: /illumos-gate/usr/src/test/os-tests/tests/sdevfs/sdevfs_eisdir.c (revision 66582b606a8194f7f3ba5b3a3a6dca5b0d346361)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2016 Joyent, Inc.
14  */
15 
16 /*
17  * open(2) should return EISDIR when asking for write access on a dir.
18  * This test should return the same results in both GZ and NGZ contexts.
19  */
20 #include <stdio.h>
21 #include <strings.h>
22 #include <errno.h>
23 #include <fcntl.h>
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <sys/debug.h>
27 #include <sys/statvfs.h>
28 
29 #define	SD_TEST_DIR	"/dev/zvol"
30 
31 int
32 main(int argc, char *argv[])
33 {
34 	struct stat st;
35 	struct statvfs vfs;
36 	int ret;
37 
38 	if (stat(SD_TEST_DIR, &st) != 0) {
39 		fprintf(stderr, "test failed: failed to stat %s\n",
40 		    SD_TEST_DIR);
41 		return (1);
42 	}
43 
44 	if ((st.st_mode & S_IFMT) != S_IFDIR) {
45 		fprintf(stderr, "test failed: %s is not a dir\n", SD_TEST_DIR);
46 		return (1);
47 	}
48 
49 	if (statvfs(SD_TEST_DIR, &vfs) != 0) {
50 		fprintf(stderr, "test failed: failed to stat vfs for %s: %s\n",
51 		    SD_TEST_DIR, strerror(errno));
52 		return (1);
53 	}
54 
55 	if (strncmp("dev", vfs.f_basetype, FSTYPSZ) != 0) {
56 		fprintf(stderr, "test failed: asked to run on non-dev\n");
57 		return (1);
58 	}
59 
60 	ret = open(SD_TEST_DIR, O_RDWR, 0);
61 	VERIFY3S(ret, ==, -1);
62 	VERIFY3S(errno, ==, EISDIR);
63 
64 	/*
65 	 * It's important to test both O_RDWR and O_RDWR | O_CREAT
66 	 * because of the different code paths taken in sdev.
67 	 */
68 	ret = open(SD_TEST_DIR, O_RDWR | O_CREAT, 0);
69 	VERIFY3S(ret, ==, -1);
70 	VERIFY3S(errno, ==, EISDIR);
71 
72 	return (0);
73 }
74