예제 #1
0
파일: testnfs.c 프로젝트: john-peterson/nfs
/* hard links are also tested a bunch in test_rename */
void test_link(char *workdir) {
    char file1[1024], file2[1024], file3[1024];
    struct stat sb;

    printf("Testing link\n");

    sprintf(file1, "%s/original", workdir);
    sprintf(file2, "%s/link", workdir);

    my_create(file1);
    my_stat(file1, &sb);
    my_link(file1, file2);
    verify_inum(file2, &sb);
    my_unlink(file2);
    verify_inum(file1, &sb);

    /* Test deletion of the original file after a hard link has been
       created */
    my_link(file1, file2);
    my_unlink(file1);
    verify_inum(file2, &sb);
    /* Make sure the original file really isn't accessible */
    verify_no_exist(file1);
    my_unlink(file2);
    verify_no_exist(file2);

    /* Try renaming a hard link */
    my_create(file1);
    my_stat(file1, &sb);
    my_link(file1, file2);
    sprintf(file3, "%s/file3", workdir);
    my_rename(file2, file3);
    verify_inum(file3, &sb);
    verify_no_exist(file2);

    my_unlink(file3);
    verify_no_exist(file3);

    my_unlink(file1);

}
예제 #2
0
파일: tests.c 프로젝트: dbhoekman/CS360
//This tests the link function;
int linkTest()
{
  MINODE *test_mip = running->cwd;
  INODE *ip = NULL;
  int ino = 0;
  int actual = 0;
  int expected1 = 0;
  int expected2 = 22;

  strcpy(pathname, "");
  cd(pathname);
  test_mip = running->cwd;
  printf("\n\n-------- TESTING LINK FUNCTION --------\n\n");
  printf("Testing >link tiny new\n");
  strcpy(pathname, "tiny");
  strcpy(third, "new");
  my_link(pathname);

  //strcpy(pathname, "tiny");
  //ino = my_search(pathname);
  printf("ino of tiny is: %d\n", 24);
  strcpy(pathname, "new");
  actual = my_search(pathname);
  printf("ino of new is: %d\n", actual);

  if (24 != actual)
  {
    printf("TEST FAILED!\n\n");
    return 0;
  }
  printf("TEST PASSED!\n\n");

	printf("ALL LINK TESTS PASSED!\n\n\n");

	return 1;
}
예제 #3
0
파일: testnfs.c 프로젝트: john-peterson/nfs
void test_rename(char *workdir) {
    char file1[1024], file2[1024], link[1024],
         subdir[1024], newdir[1024];
    struct stat sb1, sb2;
    int fd;

    printf("testing rename\n");

    sprintf(file1, "%s/file1", workdir);
    sprintf(file2, "%s/file2", workdir);

    /* test stat first.. since we need it to test rename */
    my_stat(file1, &sb1);

    /* Not much to look at, really..  how about making sure that
       the modification time of the file is not in the future.
       allow ten seconds of slack */
    if (sb1.st_mtime > time(NULL) + 10) {
        printf("Modification time of %s is in the future!\n",
               file1);
        exit(1);
    }

    my_rename(file1, file2);

    /* try repeat */
    if (!rename(file1, file2)) {
        printf("repeat rename(%s,%s) worked.. but it shouldn't have\n",
               file1, file2);
        exit(1);
    }


    /* inode number of file2 should be the same as it was for file1 */
    verify_inum(file2, &sb1);


    /* rename back */
    my_rename(file2, file1);

    verify_inum(file1, &sb1);

    /* Make a subdir, which will be renamed */
    sprintf(subdir, "%s/rename_this_dir", workdir);

    my_mkdir(subdir);
    my_stat(subdir, &sb2);

    /* Test moving a file into a subdir */
    sprintf(file2, "%s/file1", subdir);
    my_rename(file1, file2);
    verify_inum(file2, &sb1);

    /* Add in a hard link to spice things up */
    sprintf(link, "%s/link", subdir);
    my_link(file2, link);

    sprintf(newdir, "%s/newdirname", workdir);
    my_rename(subdir, newdir);
    verify_inum(newdir, &sb2);
    sprintf(file2, "%s/file1", newdir);
    verify_inum(file2, &sb1);
    sprintf(link, "%s/newdirname/link", workdir);
    verify_inum(link, &sb1);

    /* Test moving up in the tree */
    my_rename(file2,file1);
    verify_inum(file1, &sb1);

    my_unlink(link);

    my_rmdir(newdir);

}