fstests: Replace all __[u]intNN_t types with standard [u]intNN_t
[xfstests-dev.git] / src / feature.c
index 334063b174c69c9bcf6a29af7c8f5f27e9ccff99..0fb834a0273e63045f30659e2248215cf2ea5282 100644 (file)
@@ -30,6 +30,7 @@
  * Return code: 0 is true, anything else is error/not supported
  *
  * Test for machine features
+ *   -A  test whether AIO syscalls are available
  *   -o  report a number of online cpus
  *   -s  report pagesize
  *   -w  report bits per long
 #include <xfs/xqm.h>
 #endif
 
+#ifdef HAVE_LIBAIO_H
+#include <libaio.h>
+#endif
+
 #ifndef USRQUOTA
 #define USRQUOTA  0
 #endif
@@ -66,7 +71,7 @@ usage(void)
        fprintf(stderr, "Usage: feature [-v] -<q|u|g|p|U|G|P> <filesystem>\n");
        fprintf(stderr, "       feature [-v] -c <file>\n");
        fprintf(stderr, "       feature [-v] -t <file>\n");
-       fprintf(stderr, "       feature -o | -s | -w\n");
+       fprintf(stderr, "       feature -A | -o | -s | -w\n");
        exit(1);
 }
 
@@ -82,7 +87,7 @@ int check_big_ID(char *filename)
        }
 
        /* 98789 is greater than 2^16 (65536) */
-       if ((__uint32_t)sbuf.st_uid == 98789 || (__uint32_t)sbuf.st_gid == 98789)
+       if ((uint32_t)sbuf.st_uid == 98789 || (uint32_t)sbuf.st_gid == 98789)
                return(0);
        if (verbose)
                fprintf(stderr, "lstat64 on %s gave uid=%d, gid=%d\n",
@@ -199,10 +204,35 @@ hasxfsquota(int type, int q, char *device)
        return (1);
 }
 
+static int
+check_aio_support(void)
+{
+#ifdef HAVE_LIBAIO_H
+       struct io_context *ctx = NULL;
+       int err;
+
+       err = io_setup(1, &ctx);
+       if (err == 0)
+               return 0;
+
+       if (err == -ENOSYS) /* CONFIG_AIO=n */
+               return 1;
+
+       fprintf(stderr, "unexpected error from io_setup(): %s\n",
+               strerror(-err));
+       return 2;
+#else
+       /* libaio was unavailable at build time; assume AIO is unsupported */
+       return 1;
+#endif
+}
+
+
 int
 main(int argc, char **argv)
 {
        int     c;
+       int     Aflag = 0;
        int     cflag = 0;
        int     tflag = 0;
        int     gflag = 0;
@@ -217,8 +247,11 @@ main(int argc, char **argv)
        int     oflag = 0;
        char    *fs = NULL;
 
-       while ((c = getopt(argc, argv, "ctgGopPqsuUvw")) != EOF) {
+       while ((c = getopt(argc, argv, "ActgGopPqsuUvw")) != EOF) {
                switch (c) {
+               case 'A':
+                       Aflag++;
+                       break;
                case 'c':
                        cflag++;
                        break;
@@ -268,7 +301,7 @@ main(int argc, char **argv)
                if (optind != argc-1)   /* need a device */
                        usage();
                fs = argv[argc-1];
-       } else if (wflag || sflag || oflag) {
+       } else if (Aflag || wflag || sflag || oflag) {
                if (optind != argc)
                        usage();
        } else 
@@ -293,6 +326,9 @@ main(int argc, char **argv)
        if (Uflag)
                return(hasxfsquota(USRQUOTA, XFS_QUOTA_UDQ_ACCT, fs));
 
+       if (Aflag)
+               return(check_aio_support());
+
        if (sflag) {
                printf("%d\n", getpagesize());
                exit(0);