📄 symlink01.c
字号:
}/*********************************************************************** * This routine checks out the chdir(2) system call for a successful * invocation * * Argument is pointer to test_objects array of structures of type * all_test_cases ***********************************************************************/voiddo_chdir(tc_ptr)struct all_test_cases *tc_ptr;{ if (mkdir(tc_ptr->fn_arg[2],MODE) == -1) tst_resm(TFAIL, "Could not create a setup directory file"); else { sprintf(Buf, "mkdir(%s, %#o) was successful\n", tc_ptr->fn_arg[2],MODE); strcat(Buffer, Buf); if (chdir(tc_ptr->fn_arg[1]) == -1) tst_resm(TFAIL, "%sCould not change a directory file through a %s", Buffer, "symbolic link which which pointed at object"); else { char buf [PATH_MAX]; char *cwd; char expected_location[PATH_MAX]; /* * Build expected current directory position */ strcpy(expected_location, TESTDIR); strcat(expected_location, "/"); strcat(expected_location, tc_ptr->fn_arg[2]); if ((cwd = getcwd(buf, sizeof (buf))) == NULL) tst_resm(TFAIL, "getcwd(3) FAILURE"); else if (strcmp(cwd, expected_location) == 0) if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST ) tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]); else Tst_count++; else { tst_resm(TFAIL, "%s%s %s %s not equal to expected %s", Buffer, "chdir(2) returned successfully, but getcwd(3) indicated", "new current working directory location", cwd, expected_location); } chdir(TESTDIR); } rmdir(tc_ptr->fn_arg[2]); }}/*********************************************************************** * This routine checks out the link(2) system call for a successful * invocation * * Argument is pointer to test_objects array of structures of type * all_test_cases ***********************************************************************/voiddo_link(tc_ptr)struct all_test_cases *tc_ptr;{ struct stat stbuf; if (link(tc_ptr->fn_arg[1], "nick") == -1) { tst_resm(TFAIL, "%slink(%s, \"nick\") failed, errno: %d\n%s %s", Buffer, tc_ptr->fn_arg[1], errno, "link of new file to object file via symbolic link file failed", "when expected not to"); } else { sprintf(Buf, "link(%s, \"nick\") was successful\n", tc_ptr->fn_arg[1]); strcat(Buffer, Buf); if ( STD_FUNCTIONAL_TEST ) { /* * Check that links counts were properly set */ if (lstat(tc_ptr->fn_arg[1], &asymlink) == -1) { tst_resm(TBROK, "lstat(%s) failed. errno: %d", tc_ptr->fn_arg[1], errno); } else if (lstat("nick", &statter) == -1) { tst_resm(TBROK, "lstat(nick) failed, errno:%d", errno); } else { if (statter.st_ino == asymlink.st_ino) { if ((statter.st_nlink ==2) && (asymlink.st_nlink == 2)) { if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST ) tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]); else Tst_count++; } else { lstat(tc_ptr->fn_arg[2], &stbuf); tst_resm(TFAIL, "%slink(%s, %s) failed to adjust link count.\n\ count for nick is %d, count for %s is %d, count for %s is %d.", Buffer, tc_ptr->fn_arg[1], "nick", statter.st_nlink, tc_ptr->fn_arg[1], asymlink.st_nlink, tc_ptr->fn_arg[2], stbuf.st_nlink); } } else { tst_resm(TFAIL, "%sA lstat of %s (ino:%d) and of\n\t\t\%s (ino:%d), does not show them being the same ino.", Buffer, tc_ptr->fn_arg[1], asymlink.st_ino, "nick", statter.st_ino); } } } delete_files("nick", NULL); }}/*********************************************************************** * This routine checks out the unlink(2) system call for a successful * invocation * * Argument is pointer to test_objects array of structures of type * all_test_cases ***********************************************************************/voiddo_unlink(tc_ptr)struct all_test_cases *tc_ptr;{ if (stat(tc_ptr->fn_arg[2], &asymlink) == -1) tst_resm(TBROK, "stat(2) Failure when accessing %s object file", tc_ptr->fn_arg[2]); else if (unlink(tc_ptr->fn_arg[1]) == -1) tst_resm(TFAIL, "unlink(2) failed when removing symbolic link file"); else { sprintf(Buf, "unlink(%s) was successful\n", tc_ptr->fn_arg[1]); strcat(Buffer, Buf); if (stat(tc_ptr->fn_arg[2], &statter) == -1) tst_resm(TFAIL,"%s %s", "unlink(2) failed because it not only removed symbolic link", "file which pointed at object file, but object file as well"); else if ((statter.st_ino == asymlink.st_ino) && (statter.st_dev == asymlink.st_dev) && (statter.st_size == asymlink.st_size)) if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST ) tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]); else Tst_count++; else tst_resm(TFAIL, "%s%s %s %s", Buffer, "unlink(2) failed because it not only removed symbolic link", "file which pointed at object file, but it changed object", "file inode information"); }}/*********************************************************************** * This routine checks out the chmod(2) system call for a successful * invocation * * Argument is pointer to test_objects array of structures of type * all_test_cases ***********************************************************************/voiddo_chmod(tc_ptr)struct all_test_cases *tc_ptr;{ if (stat(tc_ptr->fn_arg[2], &asymlink) == -1) tst_resm(TBROK, "stat(2) Failure when accessing %s object file", tc_ptr->fn_arg[2]); else if (chmod(tc_ptr->fn_arg[1], (MODE | MASK)) == -1) tst_resm(TFAIL, "%s%s %s", Buffer, "chmod(2) failed when changing file permission", "through symbolic link file"); else { sprintf(Buf, "chmod(%s, %#o) was successful\n", tc_ptr->fn_arg[1], (MODE | MASK)); strcat(Buffer, Buf); if (stat(tc_ptr->fn_arg[2], &statter) == -1) tst_resm(TBROK, "stat(2) Failure when accessing %s object file", tc_ptr->fn_arg[2]); else if ((statter.st_mode == (MODE | MASK)) && (statter.st_mode != asymlink.st_mode)) if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST ) tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]); else Tst_count++; else tst_resm(TFAIL, "%s%s %o to %o %s", Buffer, "chmod(2) failed to change object file permissions from", asymlink.st_mode, (MODE | MASK), "through symbolic link file"); }}/*********************************************************************** * This routine checks out the utime(2) system call for a successful * invocation * * Argument is pointer to test_objects array of structures of type * all_test_cases ***********************************************************************/voiddo_utime(tc_ptr)struct all_test_cases *tc_ptr;{ struct utimbuf utimes; if (stat(tc_ptr->fn_arg[2], &asymlink) == -1) tst_resm(TBROK, "stat(2) Failure when accessing %s object file", tc_ptr->fn_arg[2]); else { /* Now add a few values to access and modify times */ utimes.actime = asymlink.st_atime + a_time_value; utimes.modtime = asymlink.st_mtime + a_time_value; /* Now hand off to utime(2) via symbolic link file*/ if (utime(tc_ptr->fn_arg[1], &utimes) == -1) tst_resm(TFAIL, "%s %s", "utime(2) failed to process object file access and modify", "time updates through symbolic link"); else { /* Now verify changes were made */ if (stat(tc_ptr->fn_arg[2], &statter) == -1) tst_resm(TBROK, "stat(2) Failure when accessing %s object file", tc_ptr->fn_arg[2]); else { time_t temp, diff; temp = statter.st_atime - asymlink.st_atime; diff = (statter.st_mtime - asymlink.st_mtime) - temp; if (! diff) if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST ) tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]); else Tst_count++; else tst_resm(TFAIL, "%s %s %d greater than original times", "utime(2) failed to change object file access and", "modify times through symbolic link to a value", a_time_value); } } }}/*********************************************************************** * This routine checks out the rename(2) system call for a successful * invocation * * Argument is pointer to test_objects array of structures of type * all_test_cases ***********************************************************************/voiddo_rename(tc_ptr)struct all_test_cases *tc_ptr;{ int pts_at_object = 0; if (stat(tc_ptr->fn_arg[2], &statter) != -1) pts_at_object=1; TEST (rename(tc_ptr->fn_arg[1], A_S_FILE) ); errno=TEST_ERRNO; if (TEST_RETURN == -1) tst_resm(TFAIL, "rename(3) failed to rename %s symbolic link file to %s", tc_ptr->fn_arg[2], A_S_FILE); else if (pts_at_object) if (ck_both(tc_ptr->fn_arg[0], A_S_FILE, tc_ptr->fn_arg[2])) if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST ) tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]); else Tst_count++; else tst_resm(TFAIL, test_msg); else if ( ! ck_symlink(tc_ptr->fn_arg[0], A_S_FILE, NULL)) tst_resm(TFAIL, test_msg); else if (stat(tc_ptr->fn_arg[1], &asymlink) != -1) tst_resm(TFAIL, "rename(3) did not remove %s when renaming to %s", tc_ptr->fn_arg[1], A_S_FILE); else if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST ) tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]); else Tst_count++;}/*********************************************************************** * This routine checks out the open(2) system call for a successful * invocation * * Argument is pointer to test_objects array of structures of type * all_test_cases ***********************************************************************/voiddo_open(tc_ptr)struct all_test_cases *tc_ptr;{ int fd = -1; int ret, pts_at_object = 0; char scratch[PATH_MAX]; if (stat(tc_ptr->fn_arg[2], &statter) != -1) pts_at_object=1; if (pts_at_object) { TEST( open(tc_ptr->fn_arg[1], O_RDWR) ); errno=TEST_ERRNO; if ((fd=TEST_RETURN) == -1) { tst_resm(TFAIL, "open(2) Failure when opening object file through symbolic link file"); return; } } else { TEST(open(tc_ptr->fn_arg[1], (O_CREAT | O_RDWR), MODE) ); errno=TEST_ERRNO; if ((fd=TEST_RETURN) == -1) { tst_resm(TFAIL, "open(2) Failure when creating object file through symbolic link file"); return; } } if ((ret=write(fd, BIG_STRING, strlen(BIG_STRING))) == -1) { tst_resm(TFAIL, "write(2) Failure to object file opened through a symbolic link file: errno:%d", errno); } else if (ret != strlen(BIG_STRING)) { tst_resm(TFAIL, "write(2) Failed to write %d bytes to object file opened through a symbolic link file", strlen(BIG_STRING)); } else if (lseek(fd, 0L, 0) == -1) { tst_resm(TFAIL, "lseek(2) Failed to position to beginning of object file opened through a symbolic link file: errno = %d", errno); } else if ((ret=read(fd, scratch, strlen(BIG_STRING))) == -1) { tst_resm(TFAIL, "read(2) Failure of object file opened through a symbolic link file: errno = %d", errno); } else if (ret != strlen(BIG_STRING)) { tst_resm(TFAIL, "read(2) Failed to read %d bytes to object file opened through a symbolic link file", strlen(BIG_STRING)); } else if (strncmp(BIG_STRING, scratch, strlen(BIG_STRING)) != 0) { tst_resm(TFAIL, "Content of write(2) and read(2) Failed to object file through symbolic link file was not as expected. Expected %s and read returned %s", BIG_STRING, scratch); } else { /* * Close off symbolic link file to object file access */ if (close(fd) == -1) { tst_resm(TFAIL, "close(2) Failure when closing object file accessed symbolic link file"); } /* * Now, lets open up and read object file and compare contents */ else if ((fd=open(tc_ptr->fn_arg[0], O_RDONLY)) == -1) { tst_resm(TFAIL, "open(2) Failure when opening %s file: errno:%d %s", tc_ptr->fn_arg[0], errno, strerror(errno)); } else if ((ret=read(fd, scratch, strlen(BIG_STRING))) == -1) { tst_resm(TFAIL, "read(2) Failure of object file opened through a symbolic link file: errno:%d", errno); } else if (ret != strlen(BIG_STRING)) { tst_resm(TFAIL, "read(2) Failed to read %d bytes to object file opened through a symbolic link file", strlen(BIG_STRING)); } else if (strncmp(BIG_STRING, scratch, strlen(BIG_STRING)) != 0) { tst_resm(TFAIL, "Content of write(2) and read(2) Fai
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -