Fix build failure.
[xfstests-dev.git] / dmapi / src / suite2 / src / test_invis.c
index 57d447308174b0f8bb618babf8c4ff1182face12..115ffb7b79a08095257f5ed174ec2a84a9f07cb5 100644 (file)
@@ -1,33 +1,19 @@
 /*
 /*
- * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- * 
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
+ * Copyright (c) 2000-2001 Silicon Graphics, Inc.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
  * published by the Free Software Foundation.
  * published by the Free Software Foundation.
- * 
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * 
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- * 
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc., 59
- * Temple Place - Suite 330, Boston MA 02111-1307, USA.
- * 
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- * 
- * http://www.sgi.com 
- * 
- * For further information regarding this notice, see: 
- * 
- * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
 #include <sys/types.h>
  */
 
 #include <sys/types.h>
@@ -38,9 +24,9 @@
 #include <lib/hsm.h>
 #include <lib/errtest.h>
 
 #include <lib/hsm.h>
 #include <lib/errtest.h>
 
-#ifdef linux
+#include <getopt.h>
 #include <string.h>
 #include <string.h>
-#endif
+#include <time.h>
 
 /*---------------------------------------------------------------------------
 
 
 /*---------------------------------------------------------------------------
 
@@ -79,8 +65,6 @@ char  *Progname;
 static void
 usage(void)
 {
 static void
 usage(void)
 {
-       int     i;
-
        fprintf(stderr, "usage:\t%s [-v] [-s sid] ls_path pathname\n", 
                Progname);
        exit(1);
        fprintf(stderr, "usage:\t%s [-v] [-s sid] ls_path pathname\n", 
                Progname);
        exit(1);
@@ -144,7 +128,7 @@ main(
        dir_name = argv[optind+1];
 
        if (dm_init_service(&name) == -1)  {
        dir_name = argv[optind+1];
 
        if (dm_init_service(&name) == -1)  {
-               fprintf(stderr, "Can't inititalize the DMAPI\n");
+               fprintf(stderr, "Can't initialize the DMAPI\n");
                exit(1);
        }
        if (sid == DM_NO_SESSION)
                exit(1);
        }
        if (sid == DM_NO_SESSION)
@@ -152,7 +136,7 @@ main(
        
        /* Get a random character for read/write tests */
        srand((unsigned int)time(NULL));
        
        /* Get a random character for read/write tests */
        srand((unsigned int)time(NULL));
-       ch = (char)rand(); 
+       ch = (u_char)rand(); 
 
        printf("Invisible read/write tests beginning...\n");
        
 
        printf("Invisible read/write tests beginning...\n");
        
@@ -192,13 +176,11 @@ main(
              continue;
            }
            
              continue;
            }
            
-printf("test_invis/%d: checking length(%d)>0\n", __LINE__, length);
            if (length > curlength) {
            if (length > curlength) {
-printf("test_invis/%d: bufp malloc(%d)\n", __LINE__, length);
              if(curlength>0)
                free(bufp);
              if ((bufp = malloc(length)) == NULL) {
              if(curlength>0)
                free(bufp);
              if ((bufp = malloc(length)) == NULL) {
-               fprintf(stderr, "malloc of %d bytes failed\n", length);
+               fprintf(stderr, "malloc of %llu bytes failed\n", length);
                continue;
              }
              curlength = length;
                continue;
              }
              curlength = length;
@@ -226,7 +208,7 @@ printf("test_invis/%d: bufp malloc(%d)\n", __LINE__, length);
                      test_file);
            }
            else {
                      test_file);
            }
            else {
-#if 0
+#ifdef __sgi
              if ((statbuf.st_atim.tv_sec == checkbuf.st_atim.tv_sec) &&
              (statbuf.st_atim.tv_nsec == checkbuf.st_atim.tv_nsec) &&
              (statbuf.st_mtim.tv_sec == checkbuf.st_mtim.tv_sec) &&
              if ((statbuf.st_atim.tv_sec == checkbuf.st_atim.tv_sec) &&
              (statbuf.st_atim.tv_nsec == checkbuf.st_atim.tv_nsec) &&
              (statbuf.st_mtim.tv_sec == checkbuf.st_mtim.tv_sec) &&
@@ -262,9 +244,8 @@ printf("test_invis/%d: bufp malloc(%d)\n", __LINE__, length);
            else {
              /* Be sure the buffer is filled with the test char */
              error_reported = 0;
            else {
              /* Be sure the buffer is filled with the test char */
              error_reported = 0;
-printf("%s/%d: i=%d\n", __FILE__, __LINE__, i);
              for (k=0; k<i; k++){
              for (k=0; k<i; k++){
-               if (((char *)bufp)[k] == ch) {
+               if (((u_char *)bufp)[k] == ch) {
                  if (Vflag) printf(".");
                }
                else {
                  if (Vflag) printf(".");
                }
                else {
@@ -284,7 +265,7 @@ printf("%s/%d: i=%d\n", __FILE__, __LINE__, i);
                      test_file);
            }
            else {
                      test_file);
            }
            else {
-#if 0
+#ifdef __sgi
              if ((statbuf.st_atim.tv_sec == checkbuf.st_atim.tv_sec) &&
              (statbuf.st_atim.tv_nsec == checkbuf.st_atim.tv_nsec) &&
              (statbuf.st_mtim.tv_sec == checkbuf.st_mtim.tv_sec) &&
              if ((statbuf.st_atim.tv_sec == checkbuf.st_atim.tv_sec) &&
              (statbuf.st_atim.tv_nsec == checkbuf.st_atim.tv_nsec) &&
              (statbuf.st_mtim.tv_sec == checkbuf.st_mtim.tv_sec) &&
@@ -323,7 +304,7 @@ printf("%s/%d: i=%d\n", __FILE__, __LINE__, i);
        |* Beginning improper-input testing. *|
        \*************************************/
        sprintf(test_file, "%s/DMAPI_invis_test_file.ERRNO", 
        |* Beginning improper-input testing. *|
        \*************************************/
        sprintf(test_file, "%s/DMAPI_invis_test_file.ERRNO", 
-               dir_name, i);
+               dir_name);
        sprintf(command, "cp %s %s\n", ls_path, test_file); 
        system(command);
 
        sprintf(command, "cp %s %s\n", ls_path, test_file); 
        system(command);
 
@@ -332,49 +313,57 @@ printf("%s/%d: i=%d\n", __FILE__, __LINE__, i);
                  test_file);
        }
        else {
                  test_file);
        }
        else {
+         dm_off_t offset;
 
          /* Try writing a character waaaaaay up in the millions range */
          sprintf(bufp, "%c", ch);
 
          /* Try writing a character waaaaaay up in the millions range */
          sprintf(bufp, "%c", ch);
+          if (stat(test_file, &statbuf)){
+           fprintf(stdout, 
+                    "Error: unable to stat the test file; %s \n", 
+                    test_file);
+          }
+          offset = ((1000000*(dm_off_t)(ch)) > statbuf.st_size) ? 
+                            statbuf.st_size : (1000000*(dm_off_t)(ch));
          if (dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN, 0, 
          if (dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN, 0, 
-                            (1000000*(unsigned int)(ch)), 1, bufp)==-1){
-           printf("Error invis-writing %s at byte %d million: %s\n", 
-                  (char*)bufp, (unsigned int)ch, ERR_NAME);
+                            offset, 1, bufp)==-1){
+           printf("Error invis-writing 0x%x at byte 0x%x million: %s\n", 
+                  *(u_char *)bufp, (unsigned int)ch, ERR_NAME);
          }
          else if (dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN,
          }
          else if (dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN,
-                                (1000000*(unsigned int)(ch)), 1, bufp)==-1){
-           printf("Error invis-reading at byte %d million: %s\n", ch,
+                                offset, 1, bufp)==-1){
+           printf("Error invis-reading at byte %u million: %s\n",
                   (unsigned int)ch, ERR_NAME);
          }
                   (unsigned int)ch, ERR_NAME);
          }
-         else if (((char*)bufp)[0]!=ch) {
+         else if (((u_char *)bufp)[0]!=ch) {
            printf("Error: wanted to read %c and instead got %s.\n",
            printf("Error: wanted to read %c and instead got %s.\n",
-                  ch, (char*)bufp);
+                  ch, (u_char *)bufp);
          }
          else if (Vflag) {
          }
          else if (Vflag) {
-           printf("Report: \"%c\" was written and \"%s\" was read "
-                  "at byte %d million.\n", ch, (char*)bufp, ch);
+           printf("Report: \"0x%x\" was written and \"0x%x\" was read "
+                  "at byte %d million.\n", ch, *(u_char *)bufp, ch);
          }
 
          }
 
-#if 0
+#ifdef __sgi
          /* Try writing a character in the 2 gigabyte (2^31) range */
          sprintf(bufp, "%c", ch);
          if (dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN, 0, 
                             2147840000, 1, bufp)==-1){
            printf("Error invis-writing %s at 2 gigabytes: %s\n", 
          /* Try writing a character in the 2 gigabyte (2^31) range */
          sprintf(bufp, "%c", ch);
          if (dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN, 0, 
                             2147840000, 1, bufp)==-1){
            printf("Error invis-writing %s at 2 gigabytes: %s\n", 
-                  (char*)bufp, (unsigned int)ch, ERR_NAME);
+                  (u_char *)bufp, ERR_NAME);
          }
          else if (dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN,
                                 2147840000, 1, bufp)==-1){
          }
          else if (dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN,
                                 2147840000, 1, bufp)==-1){
-           printf("Error invis-reading at 2 gigabytes: %s\n", ch,
-                  (unsigned int)ch, ERR_NAME);
+           printf("Error invis-reading at 2 gigabytes: %s\n",
+                  ERR_NAME);
          }
          }
-         else if (((char*)bufp)[0]!=ch) {
+         else if (((u_char *)bufp)[0]!=ch) {
            printf("Error: wanted to read %c and instead got %s.\n",
            printf("Error: wanted to read %c and instead got %s.\n",
-                  ch, (char*)bufp);
+                  ch, (u_char *)bufp);
          }
          else if (Vflag) {
          }
          else if (Vflag) {
-           printf("Report: \"%c\" was written and \"%s\" was read "
+           printf("Report: \"0x%x\" was written and \"0x%x\" was read "
                   "at 2147840000 bytes\n\t(a bit over 2 gigabytes).\n", 
                   "at 2147840000 bytes\n\t(a bit over 2 gigabytes).\n", 
-                  ch, (char*)bufp);
+                  ch, *(u_char *)bufp);
          }
 #endif
 
          }
 #endif
 
@@ -414,42 +403,47 @@ printf("%s/%d: i=%d\n", __FILE__, __LINE__, i);
                  dm_write_invis(sid, NULL, hlen, DM_NO_TOKEN,
                                 0, 0, 0, NULL))
          /*---------------------------------------------------------*/
                  dm_write_invis(sid, NULL, hlen, DM_NO_TOKEN,
                                 0, 0, 0, NULL))
          /*---------------------------------------------------------*/
-         /* PROBLEM: write_invis refuses to produce EINVAL for 
-         /* lengths that will not fit in a dm_size_t.
+#if 0
+         PROBLEM: write_invis refuses to produce EINVAL for 
+         lengths that will not fit in a dm_size_t.
+
          ERRTEST(EINVAL,
                  "(bad length) write",
                  dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN,
                                 0, 4096, (long long)0xFFFFFFFFFFFFFFFFLL,
                                 "write invalid length test"))
          ERRTEST(EINVAL,
                  "(bad length) write",
                  dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN,
                                 0, 4096, (long long)0xFFFFFFFFFFFFFFFFLL,
                                 "write invalid length test"))
+#endif
          /*---------------------------------------------------------*/
          /*---------------------------------------------------------*/
-         /* PROBLEM (somewhat fixed): A signal is sent, rather than EFBIG.
-         /* Presumably, this signal is needed to comply with...something.
-         /* If this is uncommented, the program will abort here, with the 
-         /* error message "exceeded file size limit". 
+#if 0
+         PROBLEM (somewhat fixed): A signal is sent, rather than EFBIG.
+         Presumably, this signal is needed to comply with...something.
+         If this is uncommented, the program will abort here, with the 
+         error message "exceeded file size limit". 
+
          ERRTEST(EFBIG,
                  "write",
                  dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN,
                                 0, (long long)0xFFFFFFFFFFLL, 
                                 (long long)0xFFFFFFFFFFLL,
                                 "foo foo foo"))
          ERRTEST(EFBIG,
                  "write",
                  dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN,
                                 0, (long long)0xFFFFFFFFFFLL, 
                                 (long long)0xFFFFFFFFFFLL,
                                 "foo foo foo"))
+#endif
          /*---------------------------------------------------------*/
          /*---------------------------------------------------------*/
-#if 0
+#ifdef VERITAS_21
          ERRTEST(EINVAL,
                  "(bad offset) write",
                  dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN,
          ERRTEST(EINVAL,
                  "(bad offset) write",
                  dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN,
-#ifdef VERITAS_21
                                 0, (dm_size_t) ULONG_MAX, 5,
                                 0, (dm_size_t) ULONG_MAX, 5,
-#else
-                                0, (dm_size_t) ULONGLONG_MAX, 5,
-#endif
                                 "write invalid offset test"))
 #else
                                 "write invalid offset test"))
 #else
+#ifndef linux
          ERRTEST(EINVAL,
                  "(bad offset) write",
                  dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN,
          ERRTEST(EINVAL,
                  "(bad offset) write",
                  dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN,
-                                0, (dm_size_t) ULONG_MAX, 5,
+                                0, (dm_size_t) ULONGLONG_MAX, 5,
                                 "write invalid offset test"))
 #endif
                                 "write invalid offset test"))
 #endif
+#endif
+
          /*---------------------------------------------------------*/
          ERRTEST(EINVAL,
                  "(bad sid) write",
          /*---------------------------------------------------------*/
          ERRTEST(EINVAL,
                  "(bad sid) write",
@@ -473,21 +467,20 @@ printf("%s/%d: i=%d\n", __FILE__, __LINE__, i);
                  dm_read_invis(sid, NULL, hlen, DM_NO_TOKEN,
                                 0, 0, bufp))
          /*---------------------------------------------------------*/
                  dm_read_invis(sid, NULL, hlen, DM_NO_TOKEN,
                                 0, 0, bufp))
          /*---------------------------------------------------------*/
-#if 0
+#ifdef VERITAS_21
          ERRTEST(EINVAL,
                  "(bad offset) read",
                  dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN,
          ERRTEST(EINVAL,
                  "(bad offset) read",
                  dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN,
-#ifdef VERITAS_21
-                               ULONG_MAX, 5, bufp))
-#else
-                               ULONGLONG_MAX, 5, bufp))
-#endif
+                               ULONG_MAX, 5, bufp));
 #else
 #else
+#ifndef linux
          ERRTEST(EINVAL,
                  "(bad offset) read",
                  dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN,
          ERRTEST(EINVAL,
                  "(bad offset) read",
                  dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN,
-                               ULONG_MAX, 5, bufp))
+                               ULONGLONG_MAX, 5, bufp));
+#endif
 #endif
 #endif
+
          /*---------------------------------------------------------*/
          ERRTEST(EINVAL,
                  "(bad sid) read",
          /*---------------------------------------------------------*/
          ERRTEST(EINVAL,
                  "(bad sid) read",
@@ -497,7 +490,7 @@ printf("%s/%d: i=%d\n", __FILE__, __LINE__, i);
          printf("\t(errno subtests complete!)\n");
        }
        sprintf(test_file, "%s/DMAPI_invis_test_file.ERRNO", 
          printf("\t(errno subtests complete!)\n");
        }
        sprintf(test_file, "%s/DMAPI_invis_test_file.ERRNO", 
-               dir_name, i);
+               dir_name);
        sprintf(command, "rm %s \n", test_file); 
        system(command);
 
        sprintf(command, "rm %s \n", test_file); 
        system(command);