6253 F_GETLK doesn't always return lock owner
[illumos-gate.git] / usr / src / cmd / fs.d / cachefs / cfsfstype / cfsfstype.c
blobcb56090afe16d2fb228713d9fd5f8fd492dc23db
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
31 * cfsfstype.c
33 * Cache FS admin utility. Used to glean information out of the
34 * rootfs, frontfs, and backfs variables in the kernel.
37 #include <locale.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <unistd.h>
41 #include <string.h>
42 #include <errno.h>
43 #include <limits.h>
44 #include <dirent.h>
45 #include <ftw.h>
46 #include <fcntl.h>
47 #include <ctype.h>
48 #include <stdarg.h>
49 #include <sys/param.h>
50 #include <sys/types.h>
51 #include <sys/filio.h>
52 #include <sys/stat.h>
53 #include <sys/statvfs.h>
54 #include <sys/fs/cachefs_fs.h>
55 #include <sys/fs/cachefs_dir.h>
58 static void pr_err(char *fmt, ...);
59 static void usage(char *);
63 * main
65 * Description:
66 * Main routine for the cfsfstype program.
67 * Arguments:
68 * argc number of command line arguments
69 * argv command line arguments
70 * Returns:
71 * Returns 0 for failure, > 0 for an error.
72 * Preconditions:
75 int
76 main(int argc, char **argv)
78 int c;
79 int nflag = 0;
80 struct statvfs64 svb;
81 int fd;
83 /* verify root running command */
84 if (getuid() != 0) {
85 pr_err(gettext("must be run by root"));
86 return (1);
89 (void) setlocale(LC_ALL, "");
90 #if !defined(TEXT_DOMAIN)
91 #define TEXT_DOMAIN "SYS_TEST"
92 #endif
93 (void) textdomain(TEXT_DOMAIN);
95 /* parse the command line arguments */
96 while ((c = getopt(argc, argv, "n")) != EOF) {
97 switch (c) {
99 case 'n':
100 nflag = 1;
101 break;
103 default:
104 usage(gettext("illegal option"));
105 return (1);
108 argc -= optind;
109 argv += optind;
110 if (argc > 1) {
111 usage(gettext("too many file names specified"));
112 return (1);
115 /* if just path is specified, just statvfs it */
116 if (!nflag) {
117 if (argc != 1) {
118 usage(gettext("no file name"));
119 return (1);
121 if (statvfs64(*argv, &svb) < 0) {
122 pr_err(gettext("Cannot open %s: %s"), *argv,
123 strerror(errno));
124 return (1);
126 (void) printf("%s\n", svb.f_basetype);
127 return (0);
130 fd = open("/", O_RDONLY);
131 if (fd < 0) {
132 perror(gettext("Open of root directory"));
133 return (1);
136 if (argc == 1) {
137 close(fd);
138 fd = open(*argv, O_RDONLY);
139 if (fd < 0) {
140 perror(gettext("open of specified directory"));
141 return (1);
145 if (ioctl(fd, _FIOSTOPCACHE)) {
146 perror(gettext("Convert ioctl fault"));
147 return (1);
149 return (0);
154 * usage
156 * Description:
157 * Prints a usage message for this utility.
158 * Arguments:
159 * msgp message to include with the usage message
160 * Returns:
161 * Preconditions:
162 * precond(msgp)
165 static void
166 usage(char *msgp)
168 fprintf(stderr, gettext("cfsfstype: %s\n"), msgp);
169 fprintf(stderr, gettext("usage: cfsfstype file\n"));
174 * pr_err
176 * Description:
177 * Prints an error message to stderr.
178 * Arguments:
179 * fmt printf style format
180 * ... arguments for fmt
181 * Returns:
182 * Preconditions:
183 * precond(fmt)
186 static void
187 pr_err(char *fmt, ...)
189 va_list ap;
191 va_start(ap, fmt);
192 (void) fprintf(stderr, gettext("cfsfstype: "));
193 (void) vfprintf(stderr, fmt, ap);
194 (void) fprintf(stderr, "\n");
195 va_end(ap);