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 * -A test whether AIO syscalls are available
34 * -o report a number of online cpus
36 * -w report bits per long
41 #include <sys/quota.h>
42 #include <sys/resource.h>
71 fprintf(stderr, "Usage: feature [-v] -<q|u|g|p|U|G|P> <filesystem>\n");
72 fprintf(stderr, " feature [-v] -c <file>\n");
73 fprintf(stderr, " feature [-v] -t <file>\n");
74 fprintf(stderr, " feature -A | -o | -s | -w\n");
78 int check_big_ID(char *filename)
82 memset(&sbuf, 0, sizeof(struct stat64));
83 if (lstat64(filename, &sbuf) < 0) {
84 fprintf(stderr, "lstat64 failed on ");
89 /* 98789 is greater than 2^16 (65536) */
90 if ((uint32_t)sbuf.st_uid == 98789 || (uint32_t)sbuf.st_gid == 98789)
93 fprintf(stderr, "lstat64 on %s gave uid=%d, gid=%d\n",
94 filename, (int)sbuf.st_uid, (int)sbuf.st_gid);
99 haschown32(char *filename)
101 if (check_big_ID(filename) == 0)
104 if (chown(filename, 98789, 98789) < 0) {
105 fprintf(stderr, "chown failed on ");
110 if (check_big_ID(filename) == 0)
116 hastruncate64(char *filename)
118 struct rlimit64 rlimit64;
119 off64_t bigoff = 4294967307LL; /* > 2^32 */
123 getrlimit64(RLIMIT_FSIZE, &rlimit64);
124 rlimit64.rlim_cur = RLIM64_INFINITY;
125 setrlimit64(RLIMIT_FSIZE, &rlimit64);
127 signal(SIGXFSZ, SIG_IGN);
129 if ((fd = open(filename, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR)) < 0) {
130 fprintf(stderr, "open failed on ");
135 if (ftruncate64(fd, bigoff) < 0)
138 if (fstat64(fd, &bigst) < 0) {
139 fprintf(stderr, "fstat64 failed on ");
145 fprintf(stderr, "fstat64 on %s gave sz=%lld (truncsz=%lld)\n",
146 filename, (long long)bigst.st_size, (long long)bigoff);
148 if (bigst.st_size != bigoff)
154 hasxfsquota(int type, int q, char *device)
156 fs_quota_stat_t qstat;
159 memset(&qstat, 0, sizeof(fs_quota_stat_t));
163 if (access("/proc/fs/xfs/xqm", F_OK) < 0) {
165 fprintf(stderr, "can't access /proc/fs/xfs/xqm\n");
171 qcmd = QCMD(Q_XGETQSTAT, type);
174 if (quotactl(Q_SYNC, device, 0, (caddr_t)&qstat) == ENOPKG) {
176 fprintf(stderr, "Q_SYNC not supported\n");
185 if (quotactl(qcmd, device, 0, (caddr_t)&qstat) < 0) {
190 else if (q == XFS_QUOTA_UDQ_ENFD && qstat.qs_flags & XFS_QUOTA_UDQ_ENFD)
192 else if (q == XFS_QUOTA_GDQ_ENFD && qstat.qs_flags & XFS_QUOTA_GDQ_ENFD)
194 else if (q == XFS_QUOTA_PDQ_ENFD && qstat.qs_flags & XFS_QUOTA_PDQ_ENFD)
196 else if (q == XFS_QUOTA_UDQ_ACCT && qstat.qs_flags & XFS_QUOTA_UDQ_ACCT)
198 else if (q == XFS_QUOTA_GDQ_ACCT && qstat.qs_flags & XFS_QUOTA_GDQ_ACCT)
200 else if (q == XFS_QUOTA_PDQ_ACCT && qstat.qs_flags & XFS_QUOTA_PDQ_ACCT)
203 fprintf(stderr, "quota type (%d) not available\n", q);
208 check_aio_support(void)
211 struct io_context *ctx = NULL;
214 err = io_setup(1, &ctx);
218 if (err == -ENOSYS) /* CONFIG_AIO=n */
221 fprintf(stderr, "unexpected error from io_setup(): %s\n",
225 /* libaio was unavailable at build time; assume AIO is unsupported */
232 main(int argc, char **argv)
250 while ((c = getopt(argc, argv, "ActgGopPqsuUvw")) != EOF) {
299 /* filesystem features */
300 if (cflag|tflag|uflag|gflag|pflag|qflag|Uflag|Gflag|Pflag) {
301 if (optind != argc-1) /* need a device */
304 } else if (Aflag || wflag || sflag || oflag) {
311 return(haschown32(fs));
313 return(hastruncate64(fs));
315 return(hasxfsquota(0, 0, fs));
317 return(hasxfsquota(GRPQUOTA, XFS_QUOTA_GDQ_ENFD, fs));
319 return(hasxfsquota(PRJQUOTA, XFS_QUOTA_PDQ_ENFD, fs));
321 return(hasxfsquota(USRQUOTA, XFS_QUOTA_UDQ_ENFD, fs));
323 return(hasxfsquota(GRPQUOTA, XFS_QUOTA_GDQ_ACCT, fs));
325 return(hasxfsquota(PRJQUOTA, XFS_QUOTA_PDQ_ACCT, fs));
327 return(hasxfsquota(USRQUOTA, XFS_QUOTA_UDQ_ACCT, fs));
330 return(check_aio_support());
333 printf("%d\n", getpagesize());
338 printf("%d\n", BITS_PER_LONG);
341 /* This can change under IRIX depending on whether we compile
342 * with -n32/-32 or -64
344 printf("%d\n", (int)(NBBY * sizeof(long)));
354 #if defined(_SC_NPROCESSORS_ONLN)
355 ncpus = sysconf(_SC_NPROCESSORS_ONLN);
356 #elif defined(_SC_NPROC_ONLN)
357 ncpus = sysconf(_SC_NPROC_ONLN);
362 printf("%ld\n", ncpus);
367 fprintf(stderr, "feature: dunno what you're after.\n");