2 * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
34 * Test for filesystem features on given mount point or device
35 * -c test for 32bit chown support (via libc)
36 * -t test for working rlimit/ftruncate64 (via libc)
37 * -q test for quota support (kernel compile option)
38 * -u test for user quota enforcement support (mount option)
39 * -p test for project quota enforcement support (mount option)
40 * -g test for group quota enforcement support (mount option)
41 * -U test for user quota accounting support (mount option)
42 * -G test for group quota accounting support (mount option)
43 * -P test for project quota accounting support (mount option)
44 * Return code: 0 is true, anything else is error/not supported
46 * Test for machine features
48 * -w report bits per long
53 #include <sys/quota.h>
54 #include <sys/resource.h>
78 fprintf(stderr, "Usage: feature [-v] -<q|u|g|p|U|G|P> <filesystem>\n");
79 fprintf(stderr, " feature [-v] -c <file>\n");
80 fprintf(stderr, " feature [-v] -t <file>\n");
81 fprintf(stderr, " feature -s | -w\n");
85 int check_big_ID(char *filename)
89 memset(&sbuf, 0, sizeof(struct stat64));
90 if (lstat64(filename, &sbuf) < 0) {
91 fprintf(stderr, "lstat64 failed on ");
96 /* 98789 is greater than 2^16 (65536) */
97 if ((__uint32_t)sbuf.st_uid == 98789 || (__uint32_t)sbuf.st_gid == 98789)
100 fprintf(stderr, "lstat64 on %s gave uid=%d, gid=%d\n",
101 filename, (int)sbuf.st_uid, (int)sbuf.st_gid);
106 haschown32(char *filename)
108 if (check_big_ID(filename) == 0)
111 if (chown(filename, 98789, 98789) < 0) {
112 fprintf(stderr, "chown failed on ");
117 if (check_big_ID(filename) == 0)
123 hastruncate64(char *filename)
125 struct rlimit64 rlimit64;
126 off64_t bigoff = 4294967307LL; /* > 2^32 */
130 getrlimit64(RLIMIT_FSIZE, &rlimit64);
131 rlimit64.rlim_cur = RLIM64_INFINITY;
132 setrlimit64(RLIMIT_FSIZE, &rlimit64);
134 signal(SIGXFSZ, SIG_IGN);
136 if ((fd = open(filename, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR)) < 0) {
137 fprintf(stderr, "open failed on ");
142 if (ftruncate64(fd, bigoff) < 0)
145 if (fstat64(fd, &bigst) < 0) {
146 fprintf(stderr, "fstat64 failed on ");
152 fprintf(stderr, "fstat64 on %s gave sz=%lld (truncsz=%lld)\n",
153 filename, (long long)bigst.st_size, (long long)bigoff);
155 if (bigst.st_size != bigoff)
161 hasxfsquota(int type, int q, char *device)
163 fs_quota_stat_t qstat;
166 memset(&qstat, 0, sizeof(fs_quota_stat_t));
170 if (access("/proc/fs/xfs/xqm", F_OK) < 0) {
172 fprintf(stderr, "can't access /proc/fs/xfs/xqm\n");
178 qcmd = QCMD(Q_XGETQSTAT, type);
181 if (quotactl(Q_SYNC, device, 0, (caddr_t)&qstat) == ENOPKG) {
183 fprintf(stderr, "Q_SYNC not supported\n");
192 if (quotactl(qcmd, device, 0, (caddr_t)&qstat) < 0) {
197 else if (q == XFS_QUOTA_UDQ_ENFD && qstat.qs_flags & XFS_QUOTA_UDQ_ENFD)
199 else if (q == XFS_QUOTA_GDQ_ENFD && qstat.qs_flags & XFS_QUOTA_GDQ_ENFD)
201 else if (q == XFS_QUOTA_PDQ_ENFD && qstat.qs_flags & XFS_QUOTA_PDQ_ENFD)
203 else if (q == XFS_QUOTA_UDQ_ACCT && qstat.qs_flags & XFS_QUOTA_UDQ_ACCT)
205 else if (q == XFS_QUOTA_GDQ_ACCT && qstat.qs_flags & XFS_QUOTA_GDQ_ACCT)
207 else if (q == XFS_QUOTA_PDQ_ACCT && qstat.qs_flags & XFS_QUOTA_PDQ_ACCT)
210 fprintf(stderr, "quota type (%d) not available\n", q);
215 main(int argc, char **argv)
231 while ((c = getopt(argc, argv, "ctgGpPqsuUvw")) != EOF) {
274 /* filesystem features */
275 if (cflag|tflag|uflag|gflag|pflag|qflag|Uflag|Gflag|Pflag) {
276 if (optind != argc-1) /* need a device */
279 } else if (wflag || sflag) {
286 return(haschown32(fs));
288 return(hastruncate64(fs));
290 return(hasxfsquota(0, 0, fs));
292 return(hasxfsquota(GRPQUOTA, XFS_QUOTA_GDQ_ENFD, fs));
294 return(hasxfsquota(PRJQUOTA, XFS_QUOTA_PDQ_ENFD, fs));
296 return(hasxfsquota(USRQUOTA, XFS_QUOTA_UDQ_ENFD, fs));
298 return(hasxfsquota(GRPQUOTA, XFS_QUOTA_GDQ_ACCT, fs));
300 return(hasxfsquota(PRJQUOTA, XFS_QUOTA_PDQ_ACCT, fs));
302 return(hasxfsquota(USRQUOTA, XFS_QUOTA_UDQ_ACCT, fs));
305 printf("%d\n", getpagesize());
310 printf("%d\n", BITS_PER_LONG);
313 /* This can change under IRIX depending on whether we compile
314 * with -n32/-32 or -64
316 printf("%d\n", (int)(NBBY * sizeof(long)));
324 fprintf(stderr, "feature: dunno what you're after.\n");