make vfs & filesystems use failable copying
[minix3.git] / test / tvnd.c
blobf868800ba31b8a5ba4023f3b3a0acde583451c9c
1 /* Tests for the VND driver API. Part of testvnd.sh. */
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <sys/ioctl.h>
5 #include <unistd.h>
6 #include <fcntl.h>
7 #include <errno.h>
8 #include <string.h>
11 * For now, just test the most dreaded case: the driver being told to use the
12 * file descriptor used to configure the device. Without appropriate checks,
13 * this would cause a deadlock in VFS, since the corresponding filp object is
14 * locked to perform the ioctl(2) call when VFS gets the copyfd(2) back-call.
16 int
17 main(int argc, char **argv)
19 struct vnd_ioctl vnd;
20 int fd;
22 if (argc != 2) {
23 fprintf(stderr, "usage: %s /dev/vnd0\n", argv[0]);
24 return EXIT_FAILURE;
27 if ((fd = open(argv[1], O_RDONLY)) < 0) {
28 perror("open");
29 return EXIT_FAILURE;
32 memset(&vnd, 0, sizeof(vnd));
34 if (ioctl(fd, VNDIOCCLR, &vnd) < 0) {
35 perror("ioctl(VNDIOCCLR)");
36 return EXIT_FAILURE;
39 vnd.vnd_fildes = fd;
41 if (ioctl(fd, VNDIOCSET, &vnd) >= 0) {
42 fprintf(stderr, "ioctl(VNDIOCSET): unexpected success\n");
43 return EXIT_FAILURE;
46 if (errno != EBADF) {
47 perror("ioctl(VNDIOCSET)");
48 return EXIT_FAILURE;
51 close(fd);
53 return EXIT_SUCCESS;