2 * Copyright (c) 2000-2003 Silicon Graphics, Inc.
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.
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.
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
20 * Test for filesystem features on given mount point or device
21 * -c test for 32bit chown support (via libc)
22 * -t test for working rlimit/ftruncate64 (via libc)
23 * -q test for quota support (kernel compile option)
24 * -u test for user quota enforcement support (mount option)
25 * -p test for project quota enforcement support (mount option)
26 * -g test for group quota enforcement support (mount option)
27 * -U test for user quota accounting support (mount option)
28 * -G test for group quota accounting support (mount option)
29 * -P test for project quota accounting support (mount option)
30 * Return code: 0 is true, anything else is error/not supported
32 * Test for machine features
33 * -o report a number of online cpus
35 * -w report bits per long
40 #include <sys/quota.h>
41 #include <sys/resource.h>
66 fprintf(stderr, "Usage: feature [-v] -<q|u|g|p|U|G|P> <filesystem>\n");
67 fprintf(stderr, " feature [-v] -c <file>\n");
68 fprintf(stderr, " feature [-v] -t <file>\n");
69 fprintf(stderr, " feature -o | -s | -w\n");
73 int check_big_ID(char *filename)
77 memset(&sbuf, 0, sizeof(struct stat64));
78 if (lstat64(filename, &sbuf) < 0) {
79 fprintf(stderr, "lstat64 failed on ");
84 /* 98789 is greater than 2^16 (65536) */
85 if ((__uint32_t)sbuf.st_uid == 98789 || (__uint32_t)sbuf.st_gid == 98789)
88 fprintf(stderr, "lstat64 on %s gave uid=%d, gid=%d\n",
89 filename, (int)sbuf.st_uid, (int)sbuf.st_gid);
94 haschown32(char *filename)
96 if (check_big_ID(filename) == 0)
99 if (chown(filename, 98789, 98789) < 0) {
100 fprintf(stderr, "chown failed on ");
105 if (check_big_ID(filename) == 0)
111 hastruncate64(char *filename)
113 struct rlimit64 rlimit64;
114 off64_t bigoff = 4294967307LL; /* > 2^32 */
118 getrlimit64(RLIMIT_FSIZE, &rlimit64);
119 rlimit64.rlim_cur = RLIM64_INFINITY;
120 setrlimit64(RLIMIT_FSIZE, &rlimit64);
122 signal(SIGXFSZ, SIG_IGN);
124 if ((fd = open(filename, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR)) < 0) {
125 fprintf(stderr, "open failed on ");
130 if (ftruncate64(fd, bigoff) < 0)
133 if (fstat64(fd, &bigst) < 0) {
134 fprintf(stderr, "fstat64 failed on ");
140 fprintf(stderr, "fstat64 on %s gave sz=%lld (truncsz=%lld)\n",
141 filename, (long long)bigst.st_size, (long long)bigoff);
143 if (bigst.st_size != bigoff)
149 hasxfsquota(int type, int q, char *device)
151 fs_quota_stat_t qstat;
154 memset(&qstat, 0, sizeof(fs_quota_stat_t));
158 if (access("/proc/fs/xfs/xqm", F_OK) < 0) {
160 fprintf(stderr, "can't access /proc/fs/xfs/xqm\n");
166 qcmd = QCMD(Q_XGETQSTAT, type);
169 if (quotactl(Q_SYNC, device, 0, (caddr_t)&qstat) == ENOPKG) {
171 fprintf(stderr, "Q_SYNC not supported\n");
180 if (quotactl(qcmd, device, 0, (caddr_t)&qstat) < 0) {
185 else if (q == XFS_QUOTA_UDQ_ENFD && qstat.qs_flags & XFS_QUOTA_UDQ_ENFD)
187 else if (q == XFS_QUOTA_GDQ_ENFD && qstat.qs_flags & XFS_QUOTA_GDQ_ENFD)
189 else if (q == XFS_QUOTA_PDQ_ENFD && qstat.qs_flags & XFS_QUOTA_PDQ_ENFD)
191 else if (q == XFS_QUOTA_UDQ_ACCT && qstat.qs_flags & XFS_QUOTA_UDQ_ACCT)
193 else if (q == XFS_QUOTA_GDQ_ACCT && qstat.qs_flags & XFS_QUOTA_GDQ_ACCT)
195 else if (q == XFS_QUOTA_PDQ_ACCT && qstat.qs_flags & XFS_QUOTA_PDQ_ACCT)
198 fprintf(stderr, "quota type (%d) not available\n", q);
203 main(int argc, char **argv)
220 while ((c = getopt(argc, argv, "ctgGopPqsuUvw")) != EOF) {
266 /* filesystem features */
267 if (cflag|tflag|uflag|gflag|pflag|qflag|Uflag|Gflag|Pflag) {
268 if (optind != argc-1) /* need a device */
271 } else if (wflag || sflag || oflag) {
278 return(haschown32(fs));
280 return(hastruncate64(fs));
282 return(hasxfsquota(0, 0, fs));
284 return(hasxfsquota(GRPQUOTA, XFS_QUOTA_GDQ_ENFD, fs));
286 return(hasxfsquota(PRJQUOTA, XFS_QUOTA_PDQ_ENFD, fs));
288 return(hasxfsquota(USRQUOTA, XFS_QUOTA_UDQ_ENFD, fs));
290 return(hasxfsquota(GRPQUOTA, XFS_QUOTA_GDQ_ACCT, fs));
292 return(hasxfsquota(PRJQUOTA, XFS_QUOTA_PDQ_ACCT, fs));
294 return(hasxfsquota(USRQUOTA, XFS_QUOTA_UDQ_ACCT, fs));
297 printf("%d\n", getpagesize());
302 printf("%d\n", BITS_PER_LONG);
305 /* This can change under IRIX depending on whether we compile
306 * with -n32/-32 or -64
308 printf("%d\n", (int)(NBBY * sizeof(long)));
318 #if defined(_SC_NPROCESSORS_ONLN)
319 ncpus = sysconf(_SC_NPROCESSORS_ONLN);
320 #elif defined(_SC_NPROC_ONLN)
321 ncpus = sysconf(_SC_NPROC_ONLN);
326 printf("%ld\n", ncpus);
331 fprintf(stderr, "feature: dunno what you're after.\n");