2 * Copyright (c) 2000 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 * -g test for group quota enforcement support (mount option)
40 * -U test for user quota accounting support (mount option)
41 * -G test for group quota accounting support (mount option)
42 * Return code: 0 is true, anything else is error/not supported
46 #include <sys/quota.h>
47 #include <sys/resource.h>
56 fprintf(stderr, "Usage: feature [-v] -<q|u|g|U|G> <filesystem>\n");
57 fprintf(stderr, " feature [-v] -c <file>\n");
58 fprintf(stderr, " feature [-v] -t <file>\n");
62 int check_big_ID(char *filename)
66 memset(&sbuf, 0, sizeof(struct stat64));
67 if (lstat64(filename, &sbuf) < 0) {
68 fprintf(stderr, "lstat64 failed on ");
73 /* 98789 is greater than 2^16 (65536) */
74 if ((__u32)sbuf.st_uid == 98789 || (__u32)sbuf.st_gid == 98789)
77 fprintf(stderr, "lstat64 on %s gave uid=%d, gid=%d\n",
78 filename, sbuf.st_uid, sbuf.st_gid);
83 haschown32(char *filename)
85 if (check_big_ID(filename) == 0)
88 if (chown(filename, 98789, 98789) < 0) {
89 fprintf(stderr, "chown failed on ");
94 if (check_big_ID(filename) == 0)
100 hastruncate64(char *filename)
102 struct rlimit64 rlimit64;
103 off64_t bigoff = 4294967307; /* > 2^32 */
107 getrlimit64(RLIMIT_FSIZE, &rlimit64);
108 rlimit64.rlim_cur = RLIM64_INFINITY;
109 setrlimit64(RLIMIT_FSIZE, &rlimit64);
111 signal(SIGXFSZ, SIG_IGN);
113 if ((fd = open(filename, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR)) < 0) {
114 fprintf(stderr, "open failed on ");
119 if (ftruncate64(fd, bigoff) < 0)
122 if (fstat64(fd, &bigst) < 0) {
123 fprintf(stderr, "fstat64 failed on ");
129 fprintf(stderr, "fstat64 on %s gave sz=%lld (truncsz=%lld)\n",
130 filename, bigst.st_size, bigoff);
132 if (bigst.st_size != bigoff)
138 hasxfsquota(int type, int q, char *device)
140 fs_quota_stat_t qstat;
143 memset(&qstat, 0, sizeof(fs_quota_stat_t));
144 qcmd = QCMD(Q_XGETQSTAT, type);
145 if (quotactl(qcmd, device, 0, (caddr_t)&qstat) < 0) {
152 else if (q == XFS_QUOTA_UDQ_ENFD && qstat.qs_flags & XFS_QUOTA_UDQ_ENFD)
154 else if (q == XFS_QUOTA_GDQ_ENFD && qstat.qs_flags & XFS_QUOTA_GDQ_ENFD)
156 else if (q == XFS_QUOTA_UDQ_ACCT && qstat.qs_flags & XFS_QUOTA_UDQ_ACCT)
158 else if (q == XFS_QUOTA_GDQ_ACCT && qstat.qs_flags & XFS_QUOTA_GDQ_ACCT)
161 fprintf(stderr, "quota type (%d) not available\n", q);
166 main(int argc, char **argv)
178 while ((c = getopt(argc, argv, "ctgGquUv")) != EOF) {
209 if (!cflag && !tflag && !uflag && !gflag && !qflag && !Uflag && !Gflag)
211 if (optind != argc-1)
216 return(haschown32(fs));
218 return(hastruncate64(fs));
220 return(hasxfsquota(0, 0, fs));
222 return(hasxfsquota(GRPQUOTA, XFS_QUOTA_GDQ_ENFD, fs));
224 return(hasxfsquota(USRQUOTA, XFS_QUOTA_UDQ_ENFD, fs));
226 return(hasxfsquota(GRPQUOTA, XFS_QUOTA_GDQ_ACCT, fs));
228 return(hasxfsquota(USRQUOTA, XFS_QUOTA_UDQ_ACCT, fs));
230 fprintf(stderr, "feature: dunno what you're doing?\n");