📄 symlink01.c
字号:
/* * 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 * 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/NoticeExplan/ *//* $Id: symlink01.c,v 1.4 2001/09/15 19:54:04 duda Exp $ *//*********************************************************** * OS Test - Silicon Graphics, Inc.* * TEST IDENTIFIER : symlink01 (symlink)* * TEST TITLE : Make a Symbolic Link to a File* * PARENT DOCUMENT : symtds01* * TEST CASE TOTAL : 5* * WALL CLOCK TIME : 3** TEST IDENTIFIER : readlink01 (readlink)* * TEST TITLE : Reads Value of a Symbolic Link* * PARENT DOCUMENT : symtds01* * TEST CASE TOTAL : 4* * WALL CLOCK TIME : 3** TEST IDENTIFIER : stat04 (stat)* * TEST TITLE : Gets File Status Indirectly From a Symbolic Link * File* * PARENT DOCUMENT : symtds01* * TEST CASE TOTAL : 3* * WALL CLOCK TIME : 3** TEST IDENTIFIER : lstat01 (lstat)* * TEST TITLE : Get file Status About a Symbolic Link File* * PARENT DOCUMENT : symtds01* * TEST CASE TOTAL : 3* * WALL CLOCK TIME : 3** TEST IDENTIFIER : mkdir05 (mkdir)* * TEST TITLE : Fail When Making a Directory File Indirectly From* a Symbolic Link File* * PARENT DOCUMENT : symtds01* * TEST CASE TOTAL : 1* * WALL CLOCK TIME : 3** TEST IDENTIFIER : rmdir03 (rmdir)* * TEST TITLE : Fail When Removing a Directory File Indirectly * From a Symbolic Link File* * PARENT DOCUMENT : symtds01* * TEST CASE TOTAL : 1* * WALL CLOCK TIME : 3** TEST IDENTIFIER : chdir01 (chdir)* * TEST TITLE : Changes Current Working DIrectory Location * Indirectly From a Symbolic Link File* * PARENT DOCUMENT : symtds01* * TEST CASE TOTAL : 3* * WALL CLOCK TIME : 3** TEST IDENTIFIER : link01 (link)* * TEST TITLE : Creates a Link To a File Indirectly From a * Symbolic Link File* * PARENT DOCUMENT : symtds01* * TEST CASE TOTAL : 3* * WALL CLOCK TIME : 3** TEST IDENTIFIER : unlink01 (unlink)* * TEST TITLE : Removes a Link To a File And Not Any Object File* Which Maybe Pointed At* * PARENT DOCUMENT : symtds01* * TEST CASE TOTAL : 1* * WALL CLOCK TIME : 3** TEST IDENTIFIER : chmod01 (chmod)* * TEST TITLE : Change Object File Permissions Indirectly From a* Symbolic Link File* * PARENT DOCUMENT : symtds01* * TEST CASE TOTAL : 3* * WALL CLOCK TIME : 3** TEST IDENTIFIER : utime01 (utime)* * TEST TITLE : Set File Access And Modify Object File Times* Indirectly From a Symbolic Link File* * PARENT DOCUMENT : symtds01* * TEST CASE TOTAL : 3* * WALL CLOCK TIME : 3** TEST IDENTIFIER : rename01 (rename)* * TEST TITLE : Rename a Symbolic Link File And Not Any Object* File* * PARENT DOCUMENT : symtds01* * TEST CASE TOTAL : 3* * WALL CLOCK TIME : 3** TEST IDENTIFIER : open01 (open)* * TEST TITLE : Create/Open a File For Reading Or Writing* Indirectly From a Symbolic Link File* * PARENT DOCUMENT : symtds01* * TEST CASE TOTAL : 5* * WALL CLOCK TIME : 3** EXECUTED BY : whom ever* * CPU TYPES : ALL* * AUTHOR : David Fenner* * CO-PILOT : Jon Hendrickson* * DATE STARTED : 07/25/90* * INITIAL RELEASE : UNICOS 6.0* * TEST CASES* * For symlink** 1. Create symbolic link with abnormal object name path* 2. Create symbolic link with normal object name path* 3. Create symbolic link with path to an existing object file* 4. Receive EEXIST error when creating an already existing symbolic link file.* 5. Receive ENAMETOOLONG error when creating symbolic link which exceeds PATH_MAX in length* * For readlink** 1. Read a symbolic link file which points at no object file* 2. Read a symbolic link file which points at an object file* 3. Receive ENAMETOOLONG error when reading symbolic link which exceeds PATH_MAX in length* 4. Receive an EINVAL error when reading a file which is not a symbolic* link file.* * For stat* * 1. Get object file status through symbolic link file* 2. Receive ENOENT error when accessing non-existent object file through symbolic link file* 3. Receive ELOOP error when nesting of symbolic links exceed maximum** For lstat* * 1. Get symbolic link file status when pointing at no object file* 2. Get symbolic link file status when pointing at an object file* 3. Get object file status when argument is not a symbolic link* file.** For mkdir** 1. Receive EEXIST error when creating a directory through a symbolic link file* * For rmdir** 1. Receive ENOTDIR error when removing an existing directory through a symbolic link file* * For chdir** 1. Change current working directory through a symbolic link file* 2. Receive ENOENT error when accessing non-existent directory through symbolic link file* 3. Receive ELOOP error when nesting of symbolic links exceed maximum* * For link* * 1. Link an object file to a new file through symbolic link file* 2. Receive ENOENT error when accessing non-existent object file through symbolic link file* 3. Receive ELOOP error when nesting of symbolic links exceed maximum** For unlink** 1. Delete a symbolic link file and not the object file which it points at* * For chmod* * 1. Change file permissions of object file through a symbolic link file* 2. Receive ENOENT error when accessing non-existent directory through symbolic link file* 3. Receive ELOOP error when nesting of symbolic links exceed maximum* * For utime** 1. Change inode times of object file through a symbolic link file* 2. Receive ENOENT error when accessing non-existent directory through symbolic link file* 3. Receive ELOOP error when nesting of symbolic links exceed maximum* * For rename** 1. Rename a symbolic link file which points at no object file* 2. Rename a symbolic link file which points at an object file without any object file alterations.* 3. Receive EXDEV when trying to rename a symbolic link file to an address outside of current file system** For open** 1. Create an object file through a symbolic link file* 2. Open an object file through a symbolic link file* 3. Receive EEXIST error when exclusively creating an object file through a symbolic link file* 4. Receive ENOENT error when accessing non-existent object file through symbolic link file* 5. Receive ELOOP error when nesting of symbolic links exceed maximum** ENVIRONMENTAL NEEDS* None* * DETAILED DESCRIPTION** Self-documenting code so see below**#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/#include <stdio.h>#include <signal.h>#include <string.h>#include <fcntl.h> /* open(2) system call */#include <errno.h>#include <sys/types.h>#include <utime.h> /* utime(2) system call */#include <sys/param.h>#include <sys/stat.h> /* stat(2) and lstat(2) system calls */#include "test.h"#include "usctest.h"void setup();void cleanup();void help();void delete_files();void do_EEXIST();void do_ENOENT();void do_ELOOP();void do_ENOTDIR();void do_EXDEV();void do_ENAMETOOLONG();void do_EINVAL();void do_readlink();void do_stat();void do_chdir();void do_link();void do_unlink();void do_chmod();void do_utime();void do_rename();void do_open();#define S_FILE "symbolic" /* Name of symbolic link file */#define O_FILE "object" /* Name of object file */#define A_S_FILE "asymbolic" /* Another name for a symbolic link file */#define Y_A_S_FILE "/NiCkEr" /* Yet another symbolic link file */#define BIG_STRING "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"#define DEFAULT_TCID "symlink01"#define ALL 1#define SYMLINK "symlink01"#define READLINK "readlink01"#define STAT "stat04"#define LSTAT "lstat01"#define MKDIR "mkdir05"#define RMDIR "rmdir03"#define CHDIR "chdir01"#define LINK "link01"#define UNLINK "unlink01"#define CHMOD "chmod01"#define UTIME "utime01"#define RENAME "rename01"#define OPEN "open01"#define cktcsid(s1,s2) (!strcmp(s1,s2))#define BUFMAX 512#define MODE 0700#define MASK 0100777 /* A regular file with r,w,x for all mask *//* * Lets be optimistic and only define messages for passing test cases */const char *msgs[] = { "Creation of symbolic link file to no object file is ok", "Creation of symbolic link file and object file via symbolic link is ok", "Creating an existing symbolic link file error is caught", "Creating a symbolic link which exceeds maximum pathname error is caught", "Reading of symbolic link file contents checks out ok", "Reading a symbolic link which exceeds maximum pathname error is caught", "Getting stat info about object file through symbolic link file is ok", "Stat(2) error when accessing non-existent object through symbolic link is caught", "lstat(2) of symbolic link file which points to no object file is ok", "lstat(2) of symbolic link file which points at an object file is ok", "mkdir(2) of object file through symbolic link file failed as expected", "rmdir(2) of object file through symbolic link file failed as expected", "chdir(2) to object file location through symbolic link file is ok", "chdir(2) to non-existent object file location through symbolic link file failed as expected", "link(2) to a symbolic link, which is pointing to an existing object file worked - file created and link count adjusted", "link(2) to a symbolic link, which is pointing to a non-existing object file worked ok - file created and link count adjusted.", "unlink(2) of symbolic link file with no object file removal is ok", "chmod(2) of object file permissions through symbolic link file is ok", "chmod(2) error when accessing non-existent object through symbolic link is caught", "utime(2) change of object file access and modify times through symbolic link file is ok", "utime(2) error when accessing non-existent object through symbolic link is caught", "rename(3) of symbolic link file name which points at no object file is ok", "rename(3) of symbolic link file name which points at object file is ok", "rename(3) error of symbolic link file name across file systems is caught", "open(2) with (O_CREAT | O_RDWR) to create object file through symbolic link file and all writes, reads, and lseeks are ok", "open(2) with O_RDWR of existing object file through symbolic link file and all writes, reads, and lseeks are ok", "open(2) with (O_CREAT | O_EXCL) error is caught when creating object file through symbolic link file", "open(2) error with O_RDWR is caught when processing symbolic link file which points at no object file", "Nested symbolic link access condition caught. ELOOP is returned", "Reading a nonsymbolic link file error condition is caught. EINVAL is returned", "lstat(2) of object file returns object file inode information", "NULL"};/* * Define test object setup and validation functions */int creat_both(), creat_symlink(), creat_path_max(), ck_symlink(), creat_object(), ck_object(), ck_both(), ck_path_max();/* * Define test cases */struct all_test_cases{ char *tcid; int test_fail;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -