Whamcloud - gitweb
b=10960
[fs/lustre-release.git] / lustre / liblustre / tests / sanity.c
index 16014bc..6822189 100644 (file)
@@ -554,7 +554,7 @@ int t18b(char *name)
         LEAVE();
 }
 
-static int check_file_size(char *file, off_t size)
+static int check_file_size(char *file, long long size)
 {
         struct stat statbuf;
 
@@ -778,7 +778,7 @@ int t23(char *name)
         char path[MAX_PATH_LENGTH];
         int fd;
         long long ret;
-        loff_t off;
+        long long off;
 
         ENTRY("handle seek > 2GB");
         snprintf(path, MAX_PATH_LENGTH, "%s/f%s", lustre_path, name);
@@ -986,7 +986,7 @@ int t50b(char *name)
         loff_t off_array[] = {1, 17, 255, 258, 4095, 4097, 8191,
                               1024*1024*1024*1024ULL};
         int i;
-        loff_t offset;
+        long long offset;
 
         ENTRY("4k un-aligned i/o sanity");
         for (i = 0; i < sizeof(off_array)/sizeof(loff_t); i++) {
@@ -1012,7 +1012,7 @@ int t51(char *name)
 {
         char file[MAX_PATH_LENGTH] = "";
         int fd;
-        off_t size;
+        long long size;
         int result;
 
         ENTRY("truncate() should truncate file to proper length");
@@ -1170,7 +1170,9 @@ int t54(char *name)
 }
 
 /* for O_DIRECTORY */
+#ifndef _GNU_SOURCE
 #define _GNU_SOURCE
+#endif
 
 #define STRIPE_SIZE       (2048 * 2048)
 #define STRIPE_OFFSET           0
@@ -1333,6 +1335,45 @@ int t55(char *name)
         LEAVE();
 }
 
+/*
+ * getdirentries should return -1 and set errno to EINVAL when the size
+ * specified as an argument is too small to contain at least one entry
+ * (see bugzilla ticket 12229)
+ */
+int t56(char *name)
+{
+        int fd;
+        size_t nbytes;
+        off_t basep = 0;
+        ssize_t rc = 0;
+        struct dirent dir;
+
+        ENTRY("getdirentries should fail if nbytes is too small");
+
+        /* Set count to be very small.  The result should be EINVAL */
+        nbytes = 8;
+
+        /* open the directory and call getdirentries */
+        fd = t_opendir(lustre_path);
+
+        rc = getdirentries(fd, (char *)&dir, nbytes, &basep);
+
+        if (rc != -1) {
+                printf("Test failed: getdirentries returned %d\n", rc);
+                t_close(fd);
+                return -1;
+        }
+        if (errno != EINVAL) {
+                printf("Test failed: getdirentries returned %d but errno is set"
+                                " to %d (should be EINVAL)\n", rc, errno);
+                t_close(fd);
+                return -1;
+        }
+        t_close(fd);
+
+        LEAVE();
+}
+
 extern void __liblustre_setup_(void);
 extern void __liblustre_cleanup_(void);
 
@@ -1380,6 +1421,7 @@ struct testlist {
         { t53, "53" },
         { t54, "54" },
         { t55, "55" },
+        { t56, "56" },
         { NULL, NULL }
 };