]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - mkfs/fstyp.c
Update copyright/license notices to match SGI legal prefered boilerplate.
[thirdparty/xfsprogs-dev.git] / mkfs / fstyp.c
1 /*
2 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <xfs/libxfs.h>
20 #include <disk/fstyp.h>
21
22 /*
23 * fstyp allows the user to determine the filesystem identifier of
24 * mounted or unmounted filesystems using heuristics.
25 *
26 * The filesystem type is required by mount(2) and sometimes by mount(8)
27 * to mount filesystems of different types. fstyp uses exactly the same
28 * heuristics that mount does to determine whether the supplied device
29 * special file is of a known filesystem type. If it is, fstyp prints
30 * on standard output the usual filesystem identifier for that type and
31 * exits with a zero return code. If no filesystem is identified, fstyp
32 * prints "Unknown" to indicate failure and exits with a non-zero status.
33 *
34 * WARNING: The use of heuristics implies that the result of fstyp is not
35 * guaranteed to be accurate.
36 */
37
38 int
39 main(int argc, char *argv[])
40 {
41 char *type;
42
43 if (argc != 2) {
44 fprintf(stderr, "Usage: %s <device>\n", basename(argv[0]));
45 exit(1);
46 }
47
48 if (access(argv[1], R_OK) < 0) {
49 perror(argv[1]);
50 exit(1);
51 }
52
53 if ((type = fstype(argv[1])) == NULL) {
54 printf("Unknown\n");
55 exit(1);
56 }
57 printf("%s\n", type);
58 exit(0);
59 }