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 * -R test whether IO_URING syscalls are available
23 * -o report a number of online cpus
25 * -w report bits per long
30 #include <sys/quota.h>
31 #include <sys/resource.h>
43 #ifdef HAVE_LIBURING_H
64 fprintf(stderr, "Usage: feature [-v] -<q|u|g|p|U|G|P> <filesystem>\n");
65 fprintf(stderr, " feature [-v] -c <file>\n");
66 fprintf(stderr, " feature [-v] -t <file>\n");
67 fprintf(stderr, " feature -A | -R | -o | -s | -w\n");
71 int check_big_ID(char *filename)
75 memset(&sbuf, 0, sizeof(struct stat64));
76 if (lstat64(filename, &sbuf) < 0) {
77 fprintf(stderr, "lstat64 failed on ");
82 /* 98789 is greater than 2^16 (65536) */
83 if ((uint32_t)sbuf.st_uid == 98789 || (uint32_t)sbuf.st_gid == 98789)
86 fprintf(stderr, "lstat64 on %s gave uid=%d, gid=%d\n",
87 filename, (int)sbuf.st_uid, (int)sbuf.st_gid);
92 haschown32(char *filename)
94 if (check_big_ID(filename) == 0)
97 if (chown(filename, 98789, 98789) < 0) {
98 fprintf(stderr, "chown failed on ");
103 if (check_big_ID(filename) == 0)
109 hastruncate64(char *filename)
111 struct rlimit64 rlimit64;
112 off64_t bigoff = 4294967307LL; /* > 2^32 */
116 getrlimit64(RLIMIT_FSIZE, &rlimit64);
117 rlimit64.rlim_cur = RLIM64_INFINITY;
118 setrlimit64(RLIMIT_FSIZE, &rlimit64);
120 signal(SIGXFSZ, SIG_IGN);
122 if ((fd = open(filename, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR)) < 0) {
123 fprintf(stderr, "open failed on ");
128 if (ftruncate64(fd, bigoff) < 0)
131 if (fstat64(fd, &bigst) < 0) {
132 fprintf(stderr, "fstat64 failed on ");
138 fprintf(stderr, "fstat64 on %s gave sz=%lld (truncsz=%lld)\n",
139 filename, (long long)bigst.st_size, (long long)bigoff);
141 if (bigst.st_size != bigoff)
147 hasxfsquota(int type, int q, char *device)
149 fs_quota_stat_t qstat;
152 memset(&qstat, 0, sizeof(fs_quota_stat_t));
156 if (access("/proc/fs/xfs/xqm", F_OK) < 0) {
158 fprintf(stderr, "can't access /proc/fs/xfs/xqm\n");
164 qcmd = QCMD(Q_XGETQSTAT, type);
167 if (quotactl(Q_SYNC, device, 0, (caddr_t)&qstat) == ENOPKG) {
169 fprintf(stderr, "Q_SYNC not supported\n");
178 if (quotactl(qcmd, device, 0, (caddr_t)&qstat) < 0) {
183 else if (q == XFS_QUOTA_UDQ_ENFD && qstat.qs_flags & XFS_QUOTA_UDQ_ENFD)
185 else if (q == XFS_QUOTA_GDQ_ENFD && qstat.qs_flags & XFS_QUOTA_GDQ_ENFD)
187 else if (q == XFS_QUOTA_PDQ_ENFD && qstat.qs_flags & XFS_QUOTA_PDQ_ENFD)
189 else if (q == XFS_QUOTA_UDQ_ACCT && qstat.qs_flags & XFS_QUOTA_UDQ_ACCT)
191 else if (q == XFS_QUOTA_GDQ_ACCT && qstat.qs_flags & XFS_QUOTA_GDQ_ACCT)
193 else if (q == XFS_QUOTA_PDQ_ACCT && qstat.qs_flags & XFS_QUOTA_PDQ_ACCT)
196 fprintf(stderr, "quota type (%d) not available\n", q);
201 check_aio_support(void)
204 struct io_context *ctx = NULL;
207 err = io_setup(1, &ctx);
211 if (err == -ENOSYS) /* CONFIG_AIO=n */
214 fprintf(stderr, "unexpected error from io_setup(): %s\n",
218 /* libaio was unavailable at build time; assume AIO is unsupported */
224 check_uring_support(void)
226 #ifdef HAVE_LIBURING_H
227 struct io_uring ring;
230 err = io_uring_queue_init(1, &ring, 0);
234 if (err == -ENOSYS) /* CONFIG_IO_URING=n */
237 fprintf(stderr, "unexpected error from io_uring_queue_init(): %s\n",
241 /* liburing is unavailable, assume IO_URING is unsupported */
248 main(int argc, char **argv)
267 while ((c = getopt(argc, argv, "ActgGopPqRsuUvw")) != EOF) {
319 /* filesystem features */
320 if (cflag|tflag|uflag|gflag|pflag|qflag|Uflag|Gflag|Pflag) {
321 if (optind != argc-1) /* need a device */
324 } else if (Aflag || Rflag || wflag || sflag || oflag) {
331 return(haschown32(fs));
333 return(hastruncate64(fs));
335 return(hasxfsquota(0, 0, fs));
337 return(hasxfsquota(GRPQUOTA, XFS_QUOTA_GDQ_ENFD, fs));
339 return(hasxfsquota(PRJQUOTA, XFS_QUOTA_PDQ_ENFD, fs));
341 return(hasxfsquota(USRQUOTA, XFS_QUOTA_UDQ_ENFD, fs));
343 return(hasxfsquota(GRPQUOTA, XFS_QUOTA_GDQ_ACCT, fs));
345 return(hasxfsquota(PRJQUOTA, XFS_QUOTA_PDQ_ACCT, fs));
347 return(hasxfsquota(USRQUOTA, XFS_QUOTA_UDQ_ACCT, fs));
350 return(check_aio_support());
353 return(check_uring_support());
356 printf("%d\n", getpagesize());
361 printf("%d\n", BITS_PER_LONG);
364 /* This can change under IRIX depending on whether we compile
365 * with -n32/-32 or -64
367 printf("%d\n", (int)(NBBY * sizeof(long)));
377 #if defined(_SC_NPROCESSORS_ONLN)
378 ncpus = sysconf(_SC_NPROCESSORS_ONLN);
379 #elif defined(_SC_NPROC_ONLN)
380 ncpus = sysconf(_SC_NPROC_ONLN);
385 printf("%ld\n", ncpus);
390 fprintf(stderr, "feature: dunno what you're after.\n");