Esempio n. 1
0
int main(void)
{
	struct score tmp, *data;
	int i;

	srand(getpid());

	init();

	for (i = 0; i < 1024 * 1024; i++) {
		tmp.id = i;
		tmp.ch = 100 - i;
		//snprintf(tmp.name, NAMESIZE, "stu%d", i);
		rand_name(tmp.name, NAMESIZE);

		insert(&tmp);
	}

	//data = search("stu6");
	//printf("%d %s %d\n", data->id, data->name, data->ch);

	travel();

	return 0;
}
Esempio n. 2
0
 void run_impl() const {
     BlockSet& bs = *block_set();
     std::vector<SequencePtr> seqs = bs.seqs();
     int min_length = opt_value("blast-min-length").as<int>();
     std::set<std::string> names;
     BOOST_FOREACH (const SequencePtr& seq, seqs) {
         seq->set_description("");
         if (seq->size() < min_length) {
             bs.remove_sequence(seq);
         } else {
             if (seq->name().length() > 16) {
                 seq->set_name("");
             }
             while (seq->name().empty() ||
                     names.find(seq->name()) != names.end()) {
                 const int RAND_SEQ_NAME_LENGTH = 8;
                 seq->set_name(rand_name(RAND_SEQ_NAME_LENGTH));
             }
             names.insert(seq->name());
         }
     }
Esempio n. 3
0
/* The main testing program
 */
int
main(int argc, char **argv)
{
  int i, j, k;
  int chunksize;
  int readsize;
  char *buffer;
  char fixedbuf[1024];
  int fds[MAX_FD];
  char *names[MAX_FD];
  int filesize[MAX_FD];
  int nopen;                    /* Number of files simultaneously open */
  int ncreate;                  /* Number of files created in directory */
  int error_count = 0;
  int tmp;
  
  mksfs(1);                     /* Initialize the file system. */

  /* First we open two files and attempt to write data to them.
   */
  for (i = 0; i < 2; i++) {
    names[i] = rand_name();
    fds[i] = sfs_fopen(names[i]);
    if (fds[i] < 0) {
      fprintf(stderr, "ERROR: creating first test file %s\n", names[i]);
      error_count++;
    }
    tmp = sfs_fopen(names[i]);
    if (tmp >= 0 && tmp != fds[i]) {
      fprintf(stderr, "ERROR: file %s was opened twice\n", names[i]);
      error_count++;
    }
    filesize[i] = (rand() % (MAX_BYTES-MIN_BYTES)) + MIN_BYTES;
  }

  for (i = 0; i < 2; i++) {
    for (j = i + 1; j < 2; j++) {
      if (fds[i] == fds[j]) {
        fprintf(stderr, "Warning: the file descriptors probably shouldn't be the same?\n");
      }
    }
  }

  printf("Two files created with zero length:\n");

  for (i = 0; i < 2; i++) {
    for (j = 0; j < filesize[i]; j += chunksize) {
      if ((filesize[i] - j) < 10) {
        chunksize = filesize[i] - j;
      }
      else {
        chunksize = (rand() % (filesize[i] - j)) + 1;
      }

      if ((buffer = malloc(chunksize)) == NULL) {
        fprintf(stderr, "ABORT: Out of memory!\n");
        exit(-1);
      }
      for (k = 0; k < chunksize; k++) {
        buffer[k] = (char) (j+k);
      }
      // printf("////%d//%d\n", (int)strlen(buffer),chunksize);
      // printf("++++%s\n", buffer);
      tmp = sfs_fwrite(fds[i], buffer, chunksize);
      if (tmp != chunksize) {
        fprintf(stderr, "ERROR: Tried to write %d bytes, but wrote %d\n", 
                chunksize, tmp);
        error_count++;
      }
      free(buffer);
    }
  }

  if (sfs_fclose(fds[1]) != 0) {
    fprintf(stderr, "ERROR: close of handle %d failed\n", fds[1]);
    error_count++;
  }

  /* Sneaky attempt to close already closed file handle. */
  if (sfs_fclose(fds[1]) == 0) {
    fprintf(stderr, "ERROR: close of stale handle %d succeeded\n", fds[1]);
    error_count++;
  }

  printf("File %s now has length %d and %s now has length %d:\n",
         names[0], filesize[0], names[1], filesize[1]);

  /* Just to be cruel - attempt to read from a closed file handle. 
   */
  if (sfs_fread(fds[1], fixedbuf, sizeof(fixedbuf)) > 0) {
    fprintf(stderr, "ERROR: read from a closed file handle?\n");
    error_count++;
  }

  fds[1] = sfs_fopen(names[1]);
  
  sfs_fseek(0, 0);
  sfs_fseek(1, 0);
  
  for (i = 0; i < 2; i++) {
    for (j = 0; j < filesize[i]; j += chunksize) {
      if ((filesize[i] - j) < 10) {
        chunksize = filesize[i] - j;
      }
      else {
        chunksize = (rand() % (filesize[i] - j)) + 1;
      }
      if ((buffer = malloc(chunksize)) == NULL) {
        fprintf(stderr, "ABORT: Out of memory!\n");
        exit(-1);
      }
      readsize = sfs_fread(fds[i], buffer, chunksize);

      if (readsize != chunksize) {
        fprintf(stderr, "ERROR: Requested %d bytes, read %d\n", chunksize, readsize);
        readsize = chunksize;
      }
      for (k = 0; k < readsize; k++) {
        if (buffer[k] != (char)(j+k)) {
          fprintf(stderr, "ERROR: data error at offset %d in file %s (%d,%d)\n",
                  j+k, names[i], buffer[k], (char)(j+k));
          error_count++;
          break;
        }
      }
      free(buffer);
    }
  }

  for (i = 0; i < 2; i++) {
    if (sfs_fclose(fds[i]) != 0) {
      fprintf(stderr, "ERROR: closing file %s\n", names[i]);
      error_count++;
    }
  }

  /* Now try to close the files. Don't
   * care about the return codes, really, but just want to make sure
   * this doesn't cause a problem.
   */
  for (i = 0; i < 2; i++) {
    if (sfs_fclose(fds[i]) == 0) {
      fprintf(stderr, "Warning: closing already closed file %s\n", names[i]);
    }
  }

  /* Now just try to open up a bunch of files.
   */
  ncreate = 0;
  for (i = 0; i < MAX_FD; i++) {
    names[i] = rand_name();
    fds[i] = sfs_fopen(names[i]);
    if (fds[i] < 0) {
      break;
    }
    sfs_fclose(fds[i]);
    ncreate++;
  }

  printf("Created %d files in the root directory\n", ncreate);

  nopen = 0;
  for (i = 0; i < ncreate; i++) {
    fds[i] = sfs_fopen(names[i]);
    if (fds[i] < 0) {
      break;
    }
    nopen++;
  }
  printf("Simultaneously opened %d files\n", nopen);

  for (i = 0; i < nopen; i++) {
    tmp = sfs_fwrite(fds[i], test_str, strlen(test_str));
    if (tmp != strlen(test_str)) {
      fprintf(stderr, "ERROR: Tried to write %d, returned %d\n", 
              (int)strlen(test_str), tmp);
      error_count++;
    }
    if (sfs_fclose(fds[i]) != 0) {
      fprintf(stderr, "ERROR: close of handle %d failed\n", fds[i]);
      error_count++;
    }
  }

  /* Re-open in reverse order */
  for (i = nopen-1; i >= 0; i--) {
    fds[i] = sfs_fopen(names[i]);
    if (fds[i] < 0) {
      fprintf(stderr, "ERROR: can't re-open file %s\n", names[i]);
    }
  }

  /* Now test the file contents.
   */
  for (i = 0; i < nopen; i++) {
      sfs_fseek(fds[i], 0);
  }

  for (j = 0; j < strlen(test_str); j++) {
    for (i = 0; i < nopen; i++) {
      char ch;

      if (sfs_fread(fds[i], &ch, 1) != 1) {
        fprintf(stderr, "ERROR: Failed to read 1 character\n");
        error_count++;
      }
      if (ch != test_str[j]) {
        fprintf(stderr, "ERROR: Read wrong byte from %s at %d (%d,%d)\n", 
                names[i], j, ch, test_str[j]);
        error_count++;
        break;
      }
    }
  }

  /* Now close all of the open file handles.
   */
  for (i = 0; i < nopen; i++) {
    if (sfs_fclose(fds[i]) != 0) {
      fprintf(stderr, "ERROR: close of handle %d failed\n", fds[i]);
      error_count++;
    }
  }
  
  /* Now we try to re-initialize the system.
   */
  mksfs(0);

  for (i = 0; i < nopen; i++) {
    fds[i] = sfs_fopen(names[i]);
    sfs_fseek(fds[i], 0);
    if (fds[i] >= 0) {
      readsize = sfs_fread(fds[i], fixedbuf, sizeof(fixedbuf));
      if (readsize != strlen(test_str)) {
        fprintf(stderr, "ERROR: Read wrong number of bytes\n");
        error_count++;
      }

      for (j = 0; j < strlen(test_str); j++) {
        if (test_str[j] != fixedbuf[j]) {
          fprintf(stderr, "ERROR: Wrong byte in %s at %d (%d,%d)\n", 
                  names[i], j, fixedbuf[j], test_str[j]);
          printf("%d\n", fixedbuf[1]);
          error_count++;
          break;
        }
      }

      if (sfs_fclose(fds[i]) != 0) {
        fprintf(stderr, "ERROR: close of handle %d failed\n", fds[i]);
        error_count++;
      }
    }
  }

  printf("Trying to fill up the disk with repeated writes to %s.\n", names[0]);
  printf("(This may take a while).\n");

  /* Now try opening the first file, and just write a huge bunch of junk.
   * This is just to try to fill up the disk, to see what happens.
   */
  fds[0] = sfs_fopen(names[0]);
  if (fds[0] >= 0) {
    for (i = 0; i < 100000; i++) {
      int x;

      if ((i % 100) == 0) {
        fprintf(stderr, "%d\r", i);
      }

      memset(fixedbuf, (char)i, sizeof(fixedbuf));
      x = sfs_fwrite(fds[0], fixedbuf, sizeof(fixedbuf));
      if (x != sizeof(fixedbuf)) {
        /* Sooner or later, this write should fail. The only thing is that
         * it should fail gracefully, without any catastrophic errors.
         */
        printf("Write failed after %d iterations.\n", i);
        printf("If the emulated disk contains just over %d bytes, this is OK\n",
               (i * (int)sizeof(fixedbuf)));
        break;
      }
    }
    sfs_fclose(fds[0]);
  }
  else {
    fprintf(stderr, "ERROR: re-opening file %s\n", names[0]);
  }

  /* Now, having filled up the disk, try one more time to read the
   * contents of the files we created.
   */
  for (i = 0; i < nopen; i++) {
    fds[i] = sfs_fopen(names[i]);
    sfs_fseek(fds[i], 0);
    if (fds[i] >= 0) {
      readsize = sfs_fread(fds[i], fixedbuf, sizeof(fixedbuf));
      if (readsize < strlen(test_str)) {
        fprintf(stderr, "ERROR: Read wrong number of bytes\n");
        error_count++;
      }

      for (j = 0; j < strlen(test_str); j++) {
        if (test_str[j] != fixedbuf[j]) {
          fprintf(stderr, "ERROR: Wrong byte in %s at position %d (%d,%d)\n", 
                  names[i], j, fixedbuf[j], test_str[j]);
          error_count++;
          break;
        }
      }

      if (sfs_fclose(fds[i]) != 0) {
        fprintf(stderr, "ERROR: close of handle %d failed\n", fds[i]);
        error_count++;
      }
    }
  }

  fprintf(stderr, "Test program exiting with %d errors\n", error_count);
  return (error_count);
}
/* The main testing program
*/
    int
main(int argc, char **argv)
{
    int i, j, k;
    int chunksize;
    char *buffer;
    char fixedbuf[1024];
    int fds[MAX_FD];
    char *names[MAX_FD];
    int filesize[MAX_FD];
    int nopen;                    /* Number of files simultaneously open */
    int ncreate;                  /* Number of files created in directory */
    int error_count = 0;
    int tmp;

    mksfs(1);                     /* Initialize the file system. */

    /* First we open two files and attempt to write data to them.
    */
    for (i = 0; i < 2; i++) {
        names[i] = rand_name();
        fds[i] = sfs_fopen(names[i]);
        if (fds[i] < 0) {
            fprintf(stderr, "ERROR: creating first test file %s\n", names[i]);
            error_count++;
        }
        tmp = sfs_fopen(names[i]);
        if (tmp >= 0 && tmp != fds[i]) {
            fprintf(stderr, "ERROR: file %s was opened twice\n", names[i]);
            error_count++;
        }
        filesize[i] = (rand() % (MAX_BYTES-MIN_BYTES)) + MIN_BYTES;
    }

    for (i = 0; i < 2; i++) {
        for (j = i + 1; j < 2; j++) {
            if (fds[i] == fds[j]) {
                fprintf(stderr, "Warning: the file descriptors probably shouldn't be the same?\n");
            }
        }
    }

    printf("Two files created with zero length:\n");
    sfs_ls();
    printf("\n");

    for (i = 0; i < 2; i++) {
        for (j = 0; j < filesize[i]; j += chunksize) {
            if ((filesize[i] - j) < 10) {
                chunksize = filesize[i] - j;
            }
            else {
                chunksize = (rand() % (filesize[i] - j)) + 1;
            }

            if ((buffer = malloc(chunksize)) == NULL) {
                fprintf(stderr, "ABORT: Out of memory!\n");
                exit(-1);
            }
            for (k = 0; k < chunksize; k++) {
                buffer[k] = (char) (j+k);
            }
            printf("file: %d, chunksize: %d\n", i, chunksize);
            sfs_ls();
            sfs_fwrite(fds[i], buffer, chunksize);
	    free(buffer);
        }
    }

    sfs_fclose(fds[1]);

    printf("File %s now has length %d and %s now has length %d:\n",
            names[0], filesize[0], names[1], filesize[1]);
    sfs_ls();

    fds[1] = sfs_fopen(names[1]);

    printf("before doing reads\n\n");

    for (i = 0; i < 2; i++) {
        for (j = 0; j < filesize[i]; j += chunksize) {
            if ((filesize[i] - j) < 10) {
                chunksize = filesize[i] - j;
            }
            else {
                chunksize = (rand() % (filesize[i] - j)) + 1;
            }
            if ((buffer = malloc(chunksize)) == NULL) {
                fprintf(stderr, "ABORT: Out of memory!\n");
                exit(-1);
            }
            printf("before sfs_read\n\n");
            sfs_fread(fds[i], buffer, chunksize);
            printf("After sfs_read\n\n");
            /*
            for (k = 0; k < chunksize; k++) {
                if (buffer[k] != (char)(j+k)) {
                    fprintf(stderr, "ERROR: data error at offset %d in file %s (%d,%d)\n",
                            j+k, names[i], buffer[k], (char)(j+k));
                    error_count++;
                    break;
                }
            }
            */
            free(buffer);
            printf("After doing reads %d\n\n", i);
        }
    }
    printf("After doing reads\n\n");

    for (i = 0; i < 2; i++) {
        sfs_fclose(fds[i]);
        if (sfs_remove(names[i]) != 0) {
            fprintf(stderr, "ERROR: deleting file %s\n", names[i]);
            error_count++;
        }
        printf("After deleting file %s:\n", names[i]);
        sfs_ls();
    }

    /* Now try to close and delete the closed and deleted files. Don't
     * care about the return codes, really, but just want to make sure
     * this doesn't cause a problem.
     */
    for (i = 0; i < 2; i++) {
        sfs_fclose(fds[i]);
        if (sfs_remove(names[i]) == 0) {
            fprintf(stderr, "Warning: deleting already deleted file %s\n", names[i]);
        }
        //free(names[i]);
        names[i] = NULL;
    }

    /* Now just try to open up a bunch of files.
    */
    ncreate = 0;
    for (i = 0; i < MAX_FD; i++) {
        names[i] = rand_name();
        fds[i] = sfs_fopen(names[i]);
        if (fds[i] < 0) {
            break;
        }
        sfs_fclose(fds[i]);
        ncreate++;
    }

    printf("Created %d files in the root directory\n", ncreate);

    nopen = 0;
    for (i = 0; i < ncreate; i++) {
        fds[i] = sfs_fopen(names[i]);
        if (fds[i] < 0) {
            break;
        }
        nopen++;
    }
    printf("Simultaneously opened %d files\n", nopen);

    for (i = 0; i < nopen; i++) {
        sfs_fwrite(fds[i], test_str, strlen(test_str));
        sfs_fclose(fds[i]);
    }

    /* Re-open in reverse order */
    for (i = nopen-1; i >= 0; i--) {
        fds[i] = sfs_fopen(names[i]);
        if (fds[i] < 0) {
            fprintf(stderr, "ERROR: can't re-open file %s\n", names[i]);
        }
    }

    /* Now test the file contents.
    */
    for (j = 0; j < strlen(test_str); j++) {
        for (i = 0; i < nopen; i++) {
            char ch;

            sfs_fread(fds[i], &ch, 1);
            if (ch != test_str[j]) {
                fprintf(stderr, "ERROR: Read wrong byte from %s at %d (%d,%d)\n", 
                        names[i], j, ch, test_str[j]);
                error_count++;
                break;
            }
        }
    }

    /* Now close all of the open file handles.
    */
    for (i = 0; i < nopen; i++) {
        sfs_fclose(fds[i]);
    }

    /* Now we try to re-initialize the system.
    */
    mksfs(0);

    for (i = 0; i < nopen; i++) {
        fds[i] = sfs_fopen(names[i]);
        if (fds[i] >= 0) {
            sfs_fread(fds[i], fixedbuf, sizeof(fixedbuf));

            for (j = 0; j < strlen(test_str); j++) {
                if (test_str[j] != fixedbuf[j]) {
                    fprintf(stderr, "ERROR: Wrong byte in %s at %d (%d,%d)\n", 
                            names[i], j, fixedbuf[j], test_str[j]);
                    error_count++;
                    break;
                }
            }

            sfs_fclose(fds[i]);
        }
    }

    for (i = 0; i < ncreate; i++) {
        sfs_remove(names[i]);
        free(names[i]);
        names[i] = NULL;
    }

    //-------- The following part tests sfs_fseek

    printf("Tests sfs_fseek\n");

    // Prepare a file
    char* f_name = rand_name();
    int f_id = sfs_fopen(f_name);
    buffer = malloc(100);

    for(i = 0; i < 10; i++)
    {
        sfs_fwrite(f_id, "0123456789", 10);
    }

    // sfs_fwrite shouldn't change read pointer
    for(i = 0; i < 10; i++)
    {
        sfs_fread(f_id, buffer, 10);
        if(0 != strncmp(buffer, "0123456789", 10))
        {
            fprintf(stderr, "ERROR: should read '0123456789'\n");
            error_count++;
        }
    }

    // sys_seek changes read pointer
    for(i = 0; i < 100; i += 7)
    {
        sfs_fseek(f_id, i);
        sfs_fread(f_id, buffer, 1);
        if (buffer[0] - 48 != i % 10) {
            fprintf(stderr, "ERROR: postion %d shoud be %c\n", i, i % 10);
            error_count++;
        }
    }

    sfs_fseek(f_id, 80);
    sfs_fwrite(f_id, "9876543210", 10);
    sfs_fseek(f_id, 85);
    sfs_fread(f_id, buffer, 10);
    if(0 != strncmp(buffer, "4321001234", 10))
    {
        fprintf(stderr, "ERROR: should read '4321001234'\n");
        error_count++;
    }

    //free(buffer);

    fprintf(stderr, "Test program exiting with %d errors\n", error_count);
    return (error_count);
}
Esempio n. 5
0
int main(int argc, char *argv[])
{
  NEOERR *err;
  HDF *hdf;
  int x;
  char name[256];
  char value[256];
  double tstart = 0;

  err = hdf_init(&hdf);
  DIE_NOT_OK(err);

  err = hdf_set_value (hdf, "Beware", "1");
  DIE_NOT_OK(err);
  err = hdf_set_value (hdf, "Beware.The", "2");
  DIE_NOT_OK(err);
  err = hdf_set_valuef (hdf, "Beware.The.%s=%d", "Ides", 3);
  DIE_NOT_OK(err);
  err = hdf_set_value (hdf, "Beware.Off", "4");
  DIE_NOT_OK(err);
  err = hdf_set_value (hdf, "Beware.The.Ides.Of", "5");
  DIE_NOT_OK(err);
  err = hdf_set_value (hdf, "Beware.The.Butter", "6");
  DIE_NOT_OK(err);
  err = hdf_set_attr (hdf, "Beware.The.Butter", "Lang", "en");
  DIE_NOT_OK(err);
  err = hdf_set_attr (hdf, "Beware.The.Butter", "Lang", "1");
  DIE_NOT_OK(err);
  err = hdf_set_attr (hdf, "Beware.The.Butter", "Lang", NULL);
  DIE_NOT_OK(err);

  err = hdf_read_file (hdf, "test.hdf");
  DIE_NOT_OK(err);
  hdf_dump(hdf, NULL);


  x = hdf_get_int_value (hdf, "Beware.The.Ides", 0);
  if (x != 3)
  {
    ne_warn("hdf_get_int_value returned %d, expected 3", x);
    return -1;
  } 

  /* test symlinks */
  {
    const char *v;
    err = hdf_set_value(hdf, "Destination.Foo", "bar");
    DIE_NOT_OK(err);
    err = hdf_set_symlink(hdf, "Symlink.baz", "Destination.Foo");
    DIE_NOT_OK(err);
    v = hdf_get_value(hdf, "Symlink.baz", "notfound");
    if (strcmp(v, "bar")) {
      ne_warn("hdf_get_value through symlink returned %s, expected bar", v);
      return -1;
    }
    err = hdf_set_value(hdf, "Symlink.baz", "newvalue");
    DIE_NOT_OK(err);
    v = hdf_get_value(hdf, "Symlink.baz", "notfound");
    if (strcmp(v, "newvalue")) {
      ne_warn("hdf_get_value through symlink returned %s, expected newvalue",
              v);
      return -1;
    }
    err = hdf_set_value(hdf, "Symlink.baz.too", "newtoo");
    DIE_NOT_OK(err);
    v = hdf_get_value(hdf, "Symlink.baz.too", "newtoo");
    if (strcmp(v, "newtoo")) {
      ne_warn("hdf_get_value through symlink returned %s, expected newtoo",
              v);
      return -1;
    }
    v = hdf_get_value(hdf, "Destination.Foo.too", "newtoo");
    if (strcmp(v, "newtoo")) {
      ne_warn("hdf_get_value through symlink returned %s, expected newtoo",
              v);
      return -1;
    }
  }

  for (x = 0; x < 10000; x++)
  {
    rand_name(name, sizeof(name));
    neo_rand_word(value, sizeof(value));
    /* ne_warn("Setting %s = %s", name, value); */
    err = hdf_set_value (hdf, name, value);
    DIE_NOT_OK(err);
  }

  tstart = ne_timef();
  hdf_sort_obj(hdf, sortByName);
  ne_warn("sort took %5.5fs", ne_timef() - tstart);

  hdf_dump(hdf, NULL);

  hdf_destroy(&hdf);

  return 0;
}
Esempio n. 6
0
/* The main testing program
*/
    int
main(int argc, char **argv)
{
    int i, j, k;
    int chunksize;
    char *buffer;
    int fds[MAX_FD];
    char *names[MAX_FD];
    int filesize[MAX_FD];
    int error_count = 0;
    int tmp;

    mksfs(1);                     /* Initialize the file system. */

    /* First we open five files and attempt to write data to them.
    */
    for (i = 0; i < 5; i++) {
        names[i] = rand_name();
        fds[i] = sfs_open(names[i]);
        if (fds[i] < 0) {
            fprintf(stderr, "ERROR: creating first test file %s\n", names[i]);
            error_count++;
        }
        tmp = sfs_open(names[i]);
        if (tmp >= 0 && tmp != fds[i]) {
            fprintf(stderr, "ERROR: file %s was opened twice\n", names[i]);
            error_count++;
        }
        filesize[i] = (rand() % (MAX_BYTES-MIN_BYTES)) + MIN_BYTES;
    }

    for (i = 0; i < 5; i++) {
        for (j = i + 1; j < 2; j++) {
            if (fds[i] == fds[j]) {
                fprintf(stderr, "Warning: the file descriptors probably shouldn't be the same?\n");
            }
        }
    }

    printf("Five files created with zero length:\n");
    sfs_ls();
    printf("\n");

    for (i = 0; i < 5; i++) {
        for (j = 0; j < filesize[i]; j += chunksize) {
            if ((filesize[i] - j) < 10) {
                chunksize = filesize[i] - j;
            }
            else {
                chunksize = (rand() % (filesize[i] - j)) + 1;
            }

            if ((buffer = malloc(chunksize)) == NULL) {
                fprintf(stderr, "ABORT: Out of memory!\n");
                exit(-1);
            }
            for (k = 0; k < chunksize; k++) {
                buffer[k] = (char) (j+k);
            }
            sfs_write(fds[i], buffer, chunksize);
            free(buffer);
        }
    }

    for (i = 0; i < 5; i++)
      sfs_close(fds[i]);

    sfs_ls();
	
    for (i = 0; i < 5; i++)
      fds[i] = sfs_open(names[i]);

    printf("Reopened the files again.. the read/write pointers should be set to front\n");

    for (i = 0; i < 5; i++) {
        for (j = 0; j < filesize[i]; j += chunksize) {
            if ((filesize[i] - j) < 10) {
                chunksize = filesize[i] - j;
            }
            else {
                chunksize = (rand() % (filesize[i] - j)) + 1;
            }
            if ((buffer = malloc(chunksize)) == NULL) {
                fprintf(stderr, "ABORT: Out of memory!\n");
                exit(-1);
            }
            sfs_read(fds[i], buffer, chunksize);
            puts(buffer);
            for (k = 0; k < chunksize; k++) {
                if (buffer[k] != (char)(j+k)) {
                    fprintf(stderr, "ERROR: data error at offset %d in file %s (%x,%x)\n",
                            j+k, names[i], buffer[k], (char)(j+k));
                    error_count++;
                    break;
                }
            }
            free(buffer);
        }
    }

    fprintf(stderr, "Test program exiting with %d errors\n", error_count);
    
    return (error_count);
}