xref: /freebsd/tests/sys/kern/pipe/pipe_ino_test.c (revision 42b38843)
1e30a6200SEnji Cooper /*-
2e30a6200SEnji Cooper  * Copyright (c) 2011 Giovanni Trematerra <giovanni.trematerra@gmail.com>
3e30a6200SEnji Cooper  * All rights reserved.
4e30a6200SEnji Cooper  *
5e30a6200SEnji Cooper  * Redistribution and use in source and binary forms, with or without
6e30a6200SEnji Cooper  * modification, are permitted provided that the following conditions
7e30a6200SEnji Cooper  * are met:
8e30a6200SEnji Cooper  * 1. Redistributions of source code must retain the above copyright
9e30a6200SEnji Cooper  *    notice, this list of conditions and the following disclaimer.
10e30a6200SEnji Cooper  * 2. Redistributions in binary form must reproduce the above copyright
11e30a6200SEnji Cooper  *    notice, this list of conditions and the following disclaimer in the
12e30a6200SEnji Cooper  *    documentation and/or other materials provided with the distribution.
13e30a6200SEnji Cooper  *
14e30a6200SEnji Cooper  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15e30a6200SEnji Cooper  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16e30a6200SEnji Cooper  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17e30a6200SEnji Cooper  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18e30a6200SEnji Cooper  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19e30a6200SEnji Cooper  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20e30a6200SEnji Cooper  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21e30a6200SEnji Cooper  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22e30a6200SEnji Cooper  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23e30a6200SEnji Cooper  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24e30a6200SEnji Cooper  * SUCH DAMAGE.
25e30a6200SEnji Cooper  */
26e30a6200SEnji Cooper 
27e30a6200SEnji Cooper /*
28e30a6200SEnji Cooper  * Test conformance to stat(2) SUSv4 description:
29e30a6200SEnji Cooper  *  "For all other file types defined in this volume of POSIX.1-2008, the
30e30a6200SEnji Cooper  *  structure members st_mode, st_ino, st_dev, st_uid, st_gid, st_atim,
31e30a6200SEnji Cooper  *  st_ctim, and st_mtim shall have meaningful values ...".
32e30a6200SEnji Cooper  * Check that st_dev and st_ino are meaningful.
33e30a6200SEnji Cooper  */
34e30a6200SEnji Cooper 
35e30a6200SEnji Cooper #include <sys/types.h>
36e30a6200SEnji Cooper #include <sys/stat.h>
37e30a6200SEnji Cooper #include <err.h>
38e30a6200SEnji Cooper #include <stdio.h>
39e30a6200SEnji Cooper #include <unistd.h>
40e30a6200SEnji Cooper 
41e30a6200SEnji Cooper int
main(void)42e30a6200SEnji Cooper main(void)
43e30a6200SEnji Cooper {
44e30a6200SEnji Cooper 	int pipefd[2];
45e30a6200SEnji Cooper 	struct stat st1, st2;
46e30a6200SEnji Cooper 
47e30a6200SEnji Cooper 	if (pipe(pipefd) == -1)
48e30a6200SEnji Cooper 		err(1, "FAIL: pipe");
49e30a6200SEnji Cooper 
50e30a6200SEnji Cooper 	if (fstat(pipefd[0], &st1) == -1)
51e30a6200SEnji Cooper 		err(1, "FAIL: fstat st1");
52e30a6200SEnji Cooper 	if (fstat(pipefd[1], &st2) == -1)
53e30a6200SEnji Cooper 		err(1, "FAIL: fstat st2");
54e30a6200SEnji Cooper 	if (st1.st_dev != st2.st_dev || st1.st_dev == 0 || st2.st_dev == 0)
551c324569SKonstantin Belousov 		errx(1, "FAIL: wrong dev number %ju %ju",
561c324569SKonstantin Belousov 		    (uintmax_t)st1.st_dev, (uintmax_t)st2.st_dev);
57e30a6200SEnji Cooper 	if (st1.st_ino == st2.st_ino)
581c324569SKonstantin Belousov 		errx(1, "FAIL: inode numbers are equal: %ju",
591c324569SKonstantin Belousov 		    (uintmax_t)st1.st_ino);
60e30a6200SEnji Cooper 
61e30a6200SEnji Cooper 	close(pipefd[0]);
62e30a6200SEnji Cooper 	close(pipefd[1]);
63e30a6200SEnji Cooper 	printf("PASS\n");
64e30a6200SEnji Cooper 
65e30a6200SEnji Cooper 	return (0);
66e30a6200SEnji Cooper }
67