1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2003 Silicon Graphics, Inc.
8 * Test for filesystem features on given mount point or device
9 * -c test for 32bit chown support (via libc)
10 * -t test for working rlimit/ftruncate64 (via libc)
11 * -q test for quota support (kernel compile option)
12 * -u test for user quota enforcement support (mount option)
13 * -p test for project quota enforcement support (mount option)
14 * -g test for group quota enforcement support (mount option)
15 * -U test for user quota accounting support (mount option)
16 * -G test for group quota accounting support (mount option)
17 * -P test for project quota accounting support (mount option)
18 * Return code: 0 is true, anything else is error/not supported
20 * Test for machine features
21 * -A test whether AIO syscalls are available
22 * -o report a number of online cpus
24 * -w report bits per long
29 #include <sys/quota.h>
30 #include <sys/resource.h>
59 fprintf(stderr, "Usage: feature [-v] -<q|u|g|p|U|G|P> <filesystem>\n");
60 fprintf(stderr, " feature [-v] -c <file>\n");
61 fprintf(stderr, " feature [-v] -t <file>\n");
62 fprintf(stderr, " feature -A | -o | -s | -w\n");
66 int check_big_ID(char *filename)
70 memset(&sbuf, 0, sizeof(struct stat64));
71 if (lstat64(filename, &sbuf) < 0) {
72 fprintf(stderr, "lstat64 failed on ");
77 /* 98789 is greater than 2^16 (65536) */
78 if ((uint32_t)sbuf.st_uid == 98789 || (uint32_t)sbuf.st_gid == 98789)
81 fprintf(stderr, "lstat64 on %s gave uid=%d, gid=%d\n",
82 filename, (int)sbuf.st_uid, (int)sbuf.st_gid);
87 haschown32(char *filename)
89 if (check_big_ID(filename) == 0)
92 if (chown(filename, 98789, 98789) < 0) {
93 fprintf(stderr, "chown failed on ");
98 if (check_big_ID(filename) == 0)
104 hastruncate64(char *filename)
106 struct rlimit64 rlimit64;
107 off64_t bigoff = 4294967307LL; /* > 2^32 */
111 getrlimit64(RLIMIT_FSIZE, &rlimit64);
112 rlimit64.rlim_cur = RLIM64_INFINITY;
113 setrlimit64(RLIMIT_FSIZE, &rlimit64);
115 signal(SIGXFSZ, SIG_IGN);
117 if ((fd = open(filename, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR)) < 0) {
118 fprintf(stderr, "open failed on ");
123 if (ftruncate64(fd, bigoff) < 0)
126 if (fstat64(fd, &bigst) < 0) {
127 fprintf(stderr, "fstat64 failed on ");
133 fprintf(stderr, "fstat64 on %s gave sz=%lld (truncsz=%lld)\n",
134 filename, (long long)bigst.st_size, (long long)bigoff);
136 if (bigst.st_size != bigoff)
142 hasxfsquota(int type, int q, char *device)
144 fs_quota_stat_t qstat;
147 memset(&qstat, 0, sizeof(fs_quota_stat_t));
151 if (access("/proc/fs/xfs/xqm", F_OK) < 0) {
153 fprintf(stderr, "can't access /proc/fs/xfs/xqm\n");
159 qcmd = QCMD(Q_XGETQSTAT, type);
162 if (quotactl(Q_SYNC, device, 0, (caddr_t)&qstat) == ENOPKG) {
164 fprintf(stderr, "Q_SYNC not supported\n");
173 if (quotactl(qcmd, device, 0, (caddr_t)&qstat) < 0) {
178 else if (q == XFS_QUOTA_UDQ_ENFD && qstat.qs_flags & XFS_QUOTA_UDQ_ENFD)
180 else if (q == XFS_QUOTA_GDQ_ENFD && qstat.qs_flags & XFS_QUOTA_GDQ_ENFD)
182 else if (q == XFS_QUOTA_PDQ_ENFD && qstat.qs_flags & XFS_QUOTA_PDQ_ENFD)
184 else if (q == XFS_QUOTA_UDQ_ACCT && qstat.qs_flags & XFS_QUOTA_UDQ_ACCT)
186 else if (q == XFS_QUOTA_GDQ_ACCT && qstat.qs_flags & XFS_QUOTA_GDQ_ACCT)
188 else if (q == XFS_QUOTA_PDQ_ACCT && qstat.qs_flags & XFS_QUOTA_PDQ_ACCT)
191 fprintf(stderr, "quota type (%d) not available\n", q);
196 check_aio_support(void)
199 struct io_context *ctx = NULL;
202 err = io_setup(1, &ctx);
206 if (err == -ENOSYS) /* CONFIG_AIO=n */
209 fprintf(stderr, "unexpected error from io_setup(): %s\n",
213 /* libaio was unavailable at build time; assume AIO is unsupported */
220 main(int argc, char **argv)
238 while ((c = getopt(argc, argv, "ActgGopPqsuUvw")) != EOF) {
287 /* filesystem features */
288 if (cflag|tflag|uflag|gflag|pflag|qflag|Uflag|Gflag|Pflag) {
289 if (optind != argc-1) /* need a device */
292 } else if (Aflag || wflag || sflag || oflag) {
299 return(haschown32(fs));
301 return(hastruncate64(fs));
303 return(hasxfsquota(0, 0, fs));
305 return(hasxfsquota(GRPQUOTA, XFS_QUOTA_GDQ_ENFD, fs));
307 return(hasxfsquota(PRJQUOTA, XFS_QUOTA_PDQ_ENFD, fs));
309 return(hasxfsquota(USRQUOTA, XFS_QUOTA_UDQ_ENFD, fs));
311 return(hasxfsquota(GRPQUOTA, XFS_QUOTA_GDQ_ACCT, fs));
313 return(hasxfsquota(PRJQUOTA, XFS_QUOTA_PDQ_ACCT, fs));
315 return(hasxfsquota(USRQUOTA, XFS_QUOTA_UDQ_ACCT, fs));
318 return(check_aio_support());
321 printf("%d\n", getpagesize());
326 printf("%d\n", BITS_PER_LONG);
329 /* This can change under IRIX depending on whether we compile
330 * with -n32/-32 or -64
332 printf("%d\n", (int)(NBBY * sizeof(long)));
342 #if defined(_SC_NPROCESSORS_ONLN)
343 ncpus = sysconf(_SC_NPROCESSORS_ONLN);
344 #elif defined(_SC_NPROC_ONLN)
345 ncpus = sysconf(_SC_NPROC_ONLN);
350 printf("%ld\n", ncpus);
355 fprintf(stderr, "feature: dunno what you're after.\n");