blob: 36eb7da8026442498176471e4f52eff93d83f36c [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
Garrett Cooper2c282152010-12-16 00:55:50 -08003 *
plars865695b2001-08-27 22:15:12 +00004 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
Garrett Cooper2c282152010-12-16 00:55:50 -08007 *
plars865695b2001-08-27 22:15:12 +00008 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Garrett Cooper2c282152010-12-16 00:55:50 -080011 *
plars865695b2001-08-27 22:15:12 +000012 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
Garrett Cooper2c282152010-12-16 00:55:50 -080018 *
plars865695b2001-08-27 22:15:12 +000019 * You should have received a copy of the GNU General Public License along
Wanlong Gaofed96412012-10-24 10:10:29 +080020 * with this program; if not, write the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Garrett Cooper2c282152010-12-16 00:55:50 -080022 *
plars865695b2001-08-27 22:15:12 +000023 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
Garrett Cooper2c282152010-12-16 00:55:50 -080025 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
plars865695b2001-08-27 22:15:12 +000030 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
31 */
subrata_modak923b23f2009-11-02 13:57:16 +000032/* $Id: symlink01.c,v 1.20 2009/11/02 13:57:19 subrata_modak Exp $ */
subrata_modak56207ce2009-03-23 13:35:39 +000033/*
34 * OS Test - Silicon Graphics, Inc.
35 *
36 * TEST IDENTIFIER : symlink01 (symlink)
37 * TEST TITLE : Make a Symbolic Link to a File
38 * PARENT DOCUMENT : symtds01
39 * TEST CASE TOTAL : 5
40 * WALL CLOCK TIME : 3
41 *
42 * TEST IDENTIFIER : readlink01 (readlink)
43 * TEST TITLE : Reads Value of a Symbolic Link
44 * PARENT DOCUMENT : symtds01
45 * TEST CASE TOTAL : 4
46 * WALL CLOCK TIME : 3
47 *
48 * TEST IDENTIFIER : stat04 (stat)
49 * TEST TITLE : Gets File Status Indirectly From a Symbolic Link File
50 * PARENT DOCUMENT : symtds01
51 * TEST CASE TOTAL : 3
52 * WALL CLOCK TIME : 3
53 *
54 * TEST IDENTIFIER : lstat01 (lstat)
55 * TEST TITLE : Get file Status About a Symbolic Link File
56 * PARENT DOCUMENT : symtds01
57 * TEST CASE TOTAL : 3
58 * WALL CLOCK TIME : 3
59 *
60 * TEST IDENTIFIER : mkdir05 (mkdir)
61 * TEST TITLE : Fail When Making a Directory File Indirectly From
62 * a Symbolic Link File
63 * PARENT DOCUMENT : symtds01
64 * TEST CASE TOTAL : 1
65 * WALL CLOCK TIME : 3
66 *
67 * TEST IDENTIFIER : rmdir03 (rmdir)
68 * TEST TITLE : Fail When Removing a Directory File Indirectly
69 * From a Symbolic Link File
70 * PARENT DOCUMENT : symtds01
71 * TEST CASE TOTAL : 1
72 * WALL CLOCK TIME : 3
73 *
74 * TEST IDENTIFIER : chdir01 (chdir)
75 * TEST TITLE : Changes Current Working DIrectory Location
76 * Indirectly From a Symbolic Link File
77 * PARENT DOCUMENT : symtds01
78 * TEST CASE TOTAL : 3
79 * WALL CLOCK TIME : 3
80 *
81 * TEST IDENTIFIER : link01 (link)
82 * TEST TITLE : Creates a Link To a File Indirectly From a
83 * Symbolic Link File
84 * PARENT DOCUMENT : symtds01
85 * TEST CASE TOTAL : 3
86 * WALL CLOCK TIME : 3
87 *
88 * TEST IDENTIFIER : unlink01 (unlink)
89 * TEST TITLE : Removes a Link To a File And Not Any Object File
90 * Which Maybe Pointed At
91 * PARENT DOCUMENT : symtds01
92 * TEST CASE TOTAL : 1
93 * WALL CLOCK TIME : 3
94 *
95 * TEST IDENTIFIER : chmod01 (chmod)
96 * TEST TITLE : Change Object File Permissions Indirectly From a
97 * Symbolic Link File
98 * PARENT DOCUMENT : symtds01
99 * TEST CASE TOTAL : 3
100 * WALL CLOCK TIME : 3
101 *
102 * TEST IDENTIFIER : utime01 (utime)
103 * TEST TITLE : Set File Access And Modify Object File Times
104 * Indirectly From a Symbolic Link File
105 * PARENT DOCUMENT : symtds01
106 * TEST CASE TOTAL : 3
107 * WALL CLOCK TIME : 3
108 *
109 * TEST IDENTIFIER : rename01 (rename)
110 * TEST TITLE : Rename a Symbolic Link File And Not Any Object
111 * File
112 * PARENT DOCUMENT : symtds01
113 * TEST CASE TOTAL : 3
114 * WALL CLOCK TIME : 3
115 *
116 * TEST IDENTIFIER : open01 (open)
117 * TEST TITLE : Create/Open a File For Reading Or Writing
118 * Indirectly From a Symbolic Link File
119 * PARENT DOCUMENT : symtds01
120 * TEST CASE TOTAL : 5
121 * WALL CLOCK TIME : 3
122 *
123 *
124 * EXECUTED BY : whom ever
125 * CPU TYPES : ALL
126 * AUTHOR : David Fenner
127 * CO-PILOT : Jon Hendrickson
128 * DATE STARTED : 07/25/90
129 * INITIAL RELEASE : UNICOS 6.0
130 *
131 * TEST CASES
132 *
133 * For symlink
134 * 1. Create symbolic link with abnormal object name path
135 * 2. Create symbolic link with normal object name path
136 * 3. Create symbolic link with path to an existing object file
137 * 4. Receive EEXIST error when creating an already existing symbolic link file.
138 * 5. Receive ENAMETOOLONG error when creating symbolic link which exceeds PATH_MAX in length
139 *
140 * For readlink
141 * 1. Read a symbolic link file which points at no object file
142 * 2. Read a symbolic link file which points at an object file
143 * 3. Receive ENAMETOOLONG error when reading symbolic link which exceeds PATH_MAX in length
144 * 4. Receive an EINVAL error when reading a file which is not a symbolic
145 * link file.
146 *
147 * For stat
148 * 1. Get object file status through symbolic link file
149 * 2. Receive ENOENT error when accessing non-existent object file through symbolic link file
150 * 3. Receive ELOOP error when nesting of symbolic links exceed maximum
151 *
152 * For lstat
153 * 1. Get symbolic link file status when pointing at no object file
154 * 2. Get symbolic link file status when pointing at an object file
155 * 3. Get object file status when argument is not a symbolic link
156 * file.
157 *
158 * For mkdir
159 * 1. Receive EEXIST error when creating a directory through a symbolic link file
160 *
161 * For rmdir
162 * 1. Receive ENOTDIR error when removing an existing directory through a symbolic link file
163 *
164 * For chdir
165 * 1. Change current working directory through a symbolic link file
166 * 2. Receive ENOENT error when accessing non-existent directory through symbolic link file
167 * 3. Receive ELOOP error when nesting of symbolic links exceed maximum
168 *
169 * For link
170 * 1. Link an object file to a new file through symbolic link file
171 * 2. Receive ENOENT error when accessing non-existent object file through symbolic link file
172 * 3. Receive ELOOP error when nesting of symbolic links exceed maximum
173 *
174 * For unlink
175 * 1. Delete a symbolic link file and not the object file which it points at
176 *
177 * For chmod
178 * 1. Change file permissions of object file through a symbolic link file
179 * 2. Receive ENOENT error when accessing non-existent directory through symbolic link file
180 * 3. Receive ELOOP error when nesting of symbolic links exceed maximum
181 *
182 * For utime
183 * 1. Change inode times of object file through a symbolic link file
184 * 2. Receive ENOENT error when accessing non-existent directory through symbolic link file
185 * 3. Receive ELOOP error when nesting of symbolic links exceed maximum
186 *
187 * For rename
188 * 1. Rename a symbolic link file which points at no object file
189 * 2. Rename a symbolic link file which points at an object file without any object file alterations.
190 * 3. Receive EXDEV when trying to rename a symbolic link file to an address outside of current file system
191 *
192 * For open
193 * 1. Create an object file through a symbolic link file
194 * 2. Open an object file through a symbolic link file
195 * 3. Receive EEXIST error when exclusively creating an object file through a symbolic link file
196 * 4. Receive ENOENT error when accessing non-existent object file through symbolic link file
197 * 5. Receive ELOOP error when nesting of symbolic links exceed maximum
198 *
199 * ENVIRONMENTAL NEEDS
200 * None
201 *
202 * DETAILED DESCRIPTION
203 *
204 * Self-documenting code so see below
205 */
plars865695b2001-08-27 22:15:12 +0000206
207#include <stdio.h>
208#include <signal.h>
209#include <string.h>
subrata_modak56207ce2009-03-23 13:35:39 +0000210#include <fcntl.h> /* open(2) system call */
plars865695b2001-08-27 22:15:12 +0000211#include <errno.h>
212#include <sys/types.h>
subrata_modak56207ce2009-03-23 13:35:39 +0000213#include <utime.h> /* utime(2) system call */
plars865695b2001-08-27 22:15:12 +0000214#include <sys/param.h>
subrata_modak56207ce2009-03-23 13:35:39 +0000215#include <sys/stat.h> /* stat(2) and lstat(2) system calls */
subrata_modak923b23f2009-11-02 13:57:16 +0000216#include <stdint.h>
plars865695b2001-08-27 22:15:12 +0000217
218#include "test.h"
plars865695b2001-08-27 22:15:12 +0000219
Mike Frysingerc57fba52014-04-09 18:56:30 -0400220void setup(void);
221void cleanup(void);
222void help(void);
223void delete_files(char *path1, char *path2);
224struct all_test_cases;
225void do_EEXIST(struct all_test_cases *tc_ptr);
226void do_ENOENT(struct all_test_cases *tc_ptr);
227void do_ELOOP(struct all_test_cases *tc_ptr);
228void do_ENOTDIR(struct all_test_cases *tc_ptr);
229void do_EXDEV(struct all_test_cases *tc_ptr);
230void do_ENAMETOOLONG(struct all_test_cases *tc_ptr);
231void do_EINVAL(struct all_test_cases *tc_ptr);
232void do_readlink(struct all_test_cases *tc_ptr);
233void do_stat(struct all_test_cases *tc_ptr);
234void do_chdir(struct all_test_cases *tc_ptr);
235void do_link(struct all_test_cases *tc_ptr);
236void do_unlink(struct all_test_cases *tc_ptr);
237void do_chmod(struct all_test_cases *tc_ptr);
238void do_utime(struct all_test_cases *tc_ptr);
239void do_rename(struct all_test_cases *tc_ptr);
240void do_open(struct all_test_cases *tc_ptr);
241struct tcses;
242int do_syscalltests(struct tcses *tcs);
243struct tcses *get_tcs_info(char *ptr);
plars865695b2001-08-27 22:15:12 +0000244
subrata_modak56207ce2009-03-23 13:35:39 +0000245#define S_FILE "symbolic" /* Name of symbolic link file */
246#define O_FILE "object" /* Name of object file */
247#define A_S_FILE "asymbolic" /* Another name for a symbolic link file */
248#define Y_A_S_FILE "/NiCkEr" /* Yet another symbolic link file */
plars865695b2001-08-27 22:15:12 +0000249#define BIG_STRING "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
250
251#define DEFAULT_TCID "symlink01"
252
253#define SYMLINK "symlink01"
254#define READLINK "readlink01"
255#define STAT "stat04"
subrata_modakcc378eb2008-12-18 05:46:04 +0000256#define STAT_64 "stat04_64"
plars865695b2001-08-27 22:15:12 +0000257#define LSTAT "lstat01"
subrata_modakcc378eb2008-12-18 05:46:04 +0000258#define LSTAT_64 "lstat01_64"
plars865695b2001-08-27 22:15:12 +0000259#define MKDIR "mkdir05"
260#define RMDIR "rmdir03"
261#define CHDIR "chdir01"
262#define LINK "link01"
263#define UNLINK "unlink01"
264#define CHMOD "chmod01"
265#define UTIME "utime01"
266#define RENAME "rename01"
267#define OPEN "open01"
268
269#define cktcsid(s1,s2) (!strcmp(s1,s2))
270#define BUFMAX 512
271#define MODE 0700
subrata_modak56207ce2009-03-23 13:35:39 +0000272#define MASK 0100777 /* A regular file with r,w,x for all mask */
plars865695b2001-08-27 22:15:12 +0000273
274/*
275 * Lets be optimistic and only define messages for passing test cases
276 */
Cyril Hrubis0b9589f2014-05-27 17:40:33 +0200277const char *msgs[] = {
subrata_modak56207ce2009-03-23 13:35:39 +0000278 "Creation of symbolic link file to no object file is ok",
279 "Creation of symbolic link file and object file via symbolic link is ok",
280 "Creating an existing symbolic link file error is caught",
281 "Creating a symbolic link which exceeds maximum pathname error is caught",
282 "Reading of symbolic link file contents checks out ok",
283 "Reading a symbolic link which exceeds maximum pathname error is caught",
284 "Getting stat info about object file through symbolic link file is ok",
285 "Stat(2) error when accessing non-existent object through symbolic link is caught",
286 "lstat(2) of symbolic link file which points to no object file is ok",
287 "lstat(2) of symbolic link file which points at an object file is ok",
288 "mkdir(2) of object file through symbolic link file failed as expected",
289 "rmdir(2) of object file through symbolic link file failed as expected",
290 "chdir(2) to object file location through symbolic link file is ok",
291 "chdir(2) to non-existent object file location through symbolic link file failed as expected",
292 "link(2) to a symbolic link, which is pointing to an existing object file worked - file created and link count adjusted",
293 "link(2) to a symbolic link, which is pointing to a non-existing object file worked ok - file created and link count adjusted.",
294 "unlink(2) of symbolic link file with no object file removal is ok",
295 "chmod(2) of object file permissions through symbolic link file is ok",
296 "chmod(2) error when accessing non-existent object through symbolic link is caught",
297 "utime(2) change of object file access and modify times through symbolic link file is ok",
298 "utime(2) error when accessing non-existent object through symbolic link is caught",
299 "rename(3) of symbolic link file name which points at no object file is ok",
300 "rename(3) of symbolic link file name which points at object file is ok",
301 "rename(3) error of symbolic link file name across file systems is caught",
302 "open(2) with (O_CREAT | O_RDWR) to create object file through symbolic link file and all writes, reads, and lseeks are ok",
303 "open(2) with O_RDWR of existing object file through symbolic link file and all writes, reads, and lseeks are ok",
304 "open(2) with (O_CREAT | O_EXCL) error is caught when creating object file through symbolic link file",
305 "open(2) error with O_RDWR is caught when processing symbolic link file which points at no object file",
306 "Nested symbolic link access condition caught. ELOOP is returned",
307 "Reading a nonsymbolic link file error condition is caught. EINVAL is returned",
308 "lstat(2) of object file returns object file inode information",
309 "NULL"
plars865695b2001-08-27 22:15:12 +0000310};
311
312/*
313 * Define test object setup and validation functions
314 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400315int creat_both(char *path1, char *path2, char *path3);
316int creat_symlink(char *path1, char *path2, char *_path3);
317int creat_path_max(char *path1, char *path2, char *path3);
318int ck_symlink(char *path1, char *path2, char *path3);
319int creat_object(char *path1, char *_path2, char *_path3);
320int ck_object(char *path1, char *path2, char *path3);
321int ck_both(char *path1, char *path2, char *path3);
322int ck_path_max(char *path1, char *path2, char *path3);
plars865695b2001-08-27 22:15:12 +0000323
324/*
325 * Define test cases
326 */
subrata_modak56207ce2009-03-23 13:35:39 +0000327struct all_test_cases {
328 char *tcid;
329 int test_fail;
330 int errno_val;
331 int pass_msg;
Mike Frysingerc57fba52014-04-09 18:56:30 -0400332 int (*test_setup) (char *path1, char *path2, char *path3);
333 int (*ck_test) (char *path1, char *path2, char *path3);
subrata_modak56207ce2009-03-23 13:35:39 +0000334 char *fn_arg[3];
335
plars865695b2001-08-27 22:15:12 +0000336} test_objects[] = {
subrata_modak56207ce2009-03-23 13:35:39 +0000337 {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800338 SYMLINK, 0, 0, 0, creat_symlink, ck_symlink, {
339 "%bc+eFhi!k", S_FILE, NULL}}, {
340 SYMLINK, 0, 0, 0, creat_symlink, ck_symlink, {
341 O_FILE, S_FILE, NULL}}, {
342 SYMLINK, 0, 0, 1, creat_both, ck_both, {
343 O_FILE, S_FILE, O_FILE}}, {
344 SYMLINK, 1, EEXIST, 2, creat_symlink, ck_symlink, {
345 O_FILE, S_FILE, NULL}}, {
346 SYMLINK, 1, ENAMETOOLONG, 3, creat_path_max, ck_path_max, {
347 O_FILE, S_FILE, NULL}}, {
348 READLINK, 0, 0, 4, creat_symlink, ck_symlink, {
349 O_FILE, S_FILE, NULL}}, {
350 READLINK, 0, 0, 4, creat_both, ck_both, {
351 O_FILE, S_FILE, O_FILE}}, {
352 READLINK, 1, ENAMETOOLONG, 5, creat_path_max, ck_path_max, {
353 O_FILE, S_FILE, NULL}}, {
354 READLINK, 1, EINVAL, 29, creat_object, ck_object, {
355 O_FILE, NULL, NULL}}, {
356 STAT, 0, 0, 6, creat_both, ck_both, {
357 O_FILE, S_FILE, O_FILE}},
subrata_modak56207ce2009-03-23 13:35:39 +0000358 /* 10 */
359 {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800360 STAT, 1, ENOENT, 7, creat_symlink, ck_symlink, {
361 O_FILE, S_FILE, NULL}}, {
362 STAT, 1, ELOOP, 28, creat_symlink, ck_symlink, {
363 S_FILE, S_FILE, NULL}}, {
364 STAT_64, 0, 0, 6, creat_both, ck_both, {
365 O_FILE, S_FILE, O_FILE}}, {
366 STAT_64, 1, ENOENT, 7, creat_symlink, ck_symlink, {
367 O_FILE, S_FILE, NULL}}, {
368 STAT_64, 1, ELOOP, 28, creat_symlink, ck_symlink, {
369 S_FILE, S_FILE, NULL}}, {
370 LSTAT, 0, 0, 8, creat_symlink, ck_symlink, {
371 O_FILE, S_FILE, NULL}}, {
372 LSTAT, 0, 0, 9, creat_both, ck_both, {
373 O_FILE, S_FILE, O_FILE}}, {
374 LSTAT, 0, 0, 30, creat_object, ck_object, {
375 O_FILE, NULL, NULL}}, {
376 LSTAT_64, 0, 0, 8, creat_symlink, ck_symlink, {
377 O_FILE, S_FILE, NULL}}, {
378 LSTAT_64, 0, 0, 9, creat_both, ck_both, {
379 O_FILE, S_FILE, O_FILE}},
subrata_modak56207ce2009-03-23 13:35:39 +0000380 /* 20 */
381 {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800382 LSTAT_64, 0, 0, 30, creat_object, ck_object, {
383 O_FILE, NULL, NULL}}, {
384 MKDIR, 1, EEXIST, 10, creat_symlink, ck_symlink, {
385 O_FILE, S_FILE, NULL}}, {
386 RMDIR, 1, ENOTDIR, 11, creat_symlink, ck_symlink, {
387 O_FILE, S_FILE, NULL}}, {
388 CHDIR, 0, 0, 12, creat_symlink, ck_symlink, {
389 O_FILE, S_FILE, O_FILE}}, {
390 CHDIR, 1, ENOENT, 13, creat_symlink, ck_symlink, {
391 "%bc+eFhi!k", S_FILE, NULL}}, {
392 CHDIR, 1, ELOOP, 28, creat_symlink, ck_symlink, {
393 S_FILE, S_FILE, NULL}}, {
394 LINK, 0, 0, 14, creat_both, ck_both, {
395 O_FILE, S_FILE, O_FILE}}, {
396 LINK, 0, 0, 15, creat_symlink, ck_symlink, {
397 O_FILE, S_FILE, NULL}},
subrata_modak56207ce2009-03-23 13:35:39 +0000398 /* The following link test case is invalid - leaving it defined so */
399 /* I don't have to change all the entries in the all_tcses array after link */
400 /* It has been disabled at the moment. */
401 {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800402 LINK, 1, -1, -1, creat_symlink, ck_symlink, {
403 NULL, NULL, NULL}}, {
404 UNLINK, 0, 0, 16, creat_both, ck_both, {
405 O_FILE, S_FILE, O_FILE}},
subrata_modak56207ce2009-03-23 13:35:39 +0000406 /* 30 */
407 {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800408 CHMOD, 0, 0, 17, creat_both, ck_both, {
409 O_FILE, S_FILE, O_FILE}}, {
410 CHMOD, 1, ENOENT, 18, creat_symlink, ck_symlink, {
411 O_FILE, S_FILE, NULL}}, {
412 CHMOD, 1, ELOOP, 28, creat_symlink, ck_symlink, {
413 S_FILE, S_FILE, NULL}}, {
414 UTIME, 0, 0, 19, creat_both, ck_both, {
415 O_FILE, S_FILE, O_FILE}}, {
416 UTIME, 1, ENOENT, 20, creat_symlink, ck_symlink, {
417 O_FILE, S_FILE, NULL}}, {
418 UTIME, 1, ELOOP, 28, creat_symlink, ck_symlink, {
419 S_FILE, S_FILE, NULL}}, {
420 RENAME, 0, 0, 21, creat_symlink, ck_symlink, {
421 O_FILE, S_FILE, NULL}}, {
422 RENAME, 0, 0, 22, creat_both, ck_both, {
423 O_FILE, S_FILE, O_FILE}},
subrata_modak56207ce2009-03-23 13:35:39 +0000424 /* The following rename test makes assumption that the link and target */
425 /* files are located in different filesystems, which is incorrect. */
426 /* It has been disabled at the moment. */
427 {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800428 RENAME, 1, EXDEV, 23, creat_both, ck_both, {
429 O_FILE, S_FILE, O_FILE}}, {
430 OPEN, 0, 0, 24, creat_symlink, ck_symlink, {
431 O_FILE, S_FILE, NULL}},
subrata_modak56207ce2009-03-23 13:35:39 +0000432 /* 40 */
433 {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800434 OPEN, 0, 0, 25, creat_both, ck_both, {
435 O_FILE, S_FILE, O_FILE}}, {
436 OPEN, 1, EEXIST, 26, creat_symlink, ck_symlink, {
437 O_FILE, S_FILE, O_FILE}}, {
438 OPEN, 1, ENOENT, 27, creat_symlink, ck_symlink, {
439 O_FILE, S_FILE, NULL}}, {
440 OPEN, 1, ELOOP, 28, creat_symlink, ck_symlink, {
441 S_FILE, S_FILE, NULL}}
plars865695b2001-08-27 22:15:12 +0000442};
443
444/*
445 * Define tcses
446 */
subrata_modak56207ce2009-03-23 13:35:39 +0000447struct tcses {
448 char *tcid;
449 char *syscall;
450 int test_cases; /* number of entries in test_objects array */
451 struct all_test_cases *tc_ptr;
452 char *desc;
plars865695b2001-08-27 22:15:12 +0000453} all_tcses[] = {
454
subrata_modak56207ce2009-03-23 13:35:39 +0000455 {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800456 SYMLINK, "symlink", 5, &test_objects[0],
457 "Make a Symbolic Link to a File"}, {
458 READLINK, "readlink", 4, &test_objects[5],
459 "Reads Value of a Symbolic Link"}, {
subrata_modak56207ce2009-03-23 13:35:39 +0000460 STAT, "stat", 3, &test_objects[9],
461 "Gets File Status Indirectly From a Symbolic Link file"}, {
462 STAT_64, "stat64", 3, &test_objects[12],
463 "Gets File Status Indirectly From a Symbolic Link file"}, {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800464 LSTAT, "lstat", 3, &test_objects[15],
465 "Get file Status About a Symbolic Link File"}, {
subrata_modak56207ce2009-03-23 13:35:39 +0000466 LSTAT_64, "lstat64", 3, &test_objects[18],
467 "Get file Status About a Symbolic Link File"}, {
468 MKDIR, "mkdir", 1, &test_objects[21],
Wanlong Gao354ebb42012-12-07 10:10:04 +0800469 "Fail When Making a Directory File Indirectly from a symlink"},
470 {
subrata_modak56207ce2009-03-23 13:35:39 +0000471 RMDIR, "rmdir", 1, &test_objects[22],
Wanlong Gao354ebb42012-12-07 10:10:04 +0800472 "Fail When Removing a Directory File Indirectly from a symlink"},
473 {
subrata_modak56207ce2009-03-23 13:35:39 +0000474 CHDIR, "chdir", 3, &test_objects[23],
475 "Changes CWD Location Indirectly from a symlink"}, {
476 LINK, "link", 2, &test_objects[26],
477 "Creates a Link To a File Indirectly From a Symbolic"}, {
478 UNLINK, "unlink", 1, &test_objects[29],
479 "Removes a Link To a File but not the Object File"}, {
480 CHMOD, "chmod", 3, &test_objects[30],
Wanlong Gao354ebb42012-12-07 10:10:04 +0800481 "Change Object File Permissions Indirectly From a Symbolic"},
482 {
subrata_modak56207ce2009-03-23 13:35:39 +0000483 UTIME, "utime", 3, &test_objects[33],
Wanlong Gao354ebb42012-12-07 10:10:04 +0800484 "Set File Access And Modify Object File Times via symlink"},
485 {
subrata_modak56207ce2009-03-23 13:35:39 +0000486 RENAME, "rename", 2, &test_objects[36],
487 "Rename a Symbolic Link File And Not Any Object file"}, {
488OPEN, "open", 5, &test_objects[39],
489 "Create/Open a File For Reading Or Writing via symlink"},};
plars865695b2001-08-27 22:15:12 +0000490
491/*
492 * Define GLOBAL variables
493 */
494
495int TST_TOTAL;
496int TEST_RESULT;
497time_t a_time_value = 100;
subrata_modak56207ce2009-03-23 13:35:39 +0000498char *TCID;
499char *Selectedtests = NULL; /* Name (tcid) of selected test cases */
plars865695b2001-08-27 22:15:12 +0000500char test_msg[BUFMAX];
subrata_modak56207ce2009-03-23 13:35:39 +0000501char full_path[PATH_MAX + 1 + 1]; /* Add one for '\0' and another to exceed the PATH_MAX limit, see creat_path_max() */
plars865695b2001-08-27 22:15:12 +0000502
503struct stat asymlink, statter;
504char Buffer[1024];
505char Buf[1024];
506
507char *Tcid = NULL;
508
509option_t Options[] = {
subrata_modak56207ce2009-03-23 13:35:39 +0000510 {"T:", NULL, &Tcid}, /* -T tcid option */
511 {NULL, NULL, NULL}
plars865695b2001-08-27 22:15:12 +0000512};
513
514/***********************************************************************
515 * MAIN
516 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000517int main(int argc, char *argv[])
plars865695b2001-08-27 22:15:12 +0000518{
Mike Frysingerc57fba52014-04-09 18:56:30 -0400519 struct tcses *tcs_ptr;
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200520 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +0200521 const char *msg;
plars865695b2001-08-27 22:15:12 +0000522
523 /***************************************************************
524 * parse standard options, and exit if there is an error
525 ***************************************************************/
Garrett Cooper45e285d2010-11-22 12:19:25 -0800526 if ((msg = parse_opts(argc, argv, Options, &help)) != NULL) {
subrata_modak56207ce2009-03-23 13:35:39 +0000527 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Cooper2c282152010-12-16 00:55:50 -0800528
subrata_modak56207ce2009-03-23 13:35:39 +0000529 }
plars865695b2001-08-27 22:15:12 +0000530
subrata_modak56207ce2009-03-23 13:35:39 +0000531 /*
532 * If the -T option was used, use that TCID or use the default
533 */
534 if (Tcid != NULL) {
535 TCID = Tcid;
536 Selectedtests = Tcid;
plars865695b2001-08-27 22:15:12 +0000537
subrata_modak56207ce2009-03-23 13:35:39 +0000538 }
plars865695b2001-08-27 22:15:12 +0000539#ifndef ALL
subrata_modak56207ce2009-03-23 13:35:39 +0000540 else {
541 TCID = DEFAULT_TCID;
542 Selectedtests = DEFAULT_TCID;
543 }
plars865695b2001-08-27 22:15:12 +0000544#endif
545
subrata_modak56207ce2009-03-23 13:35:39 +0000546 /*
547 * Get test case specification information and assign TST_TOTAL
548 */
549 if ((tcs_ptr = get_tcs_info(Selectedtests)) == NULL) {
550 TST_TOTAL = 1;
Wanlong Gao354ebb42012-12-07 10:10:04 +0800551 tst_brkm(TBROK, cleanup,
552 "Unknown symbolic link test case specification executed");
subrata_modak56207ce2009-03-23 13:35:39 +0000553 }
plars865695b2001-08-27 22:15:12 +0000554
555 /***************************************************************
556 * perform global setup for test
557 ***************************************************************/
558
subrata_modak56207ce2009-03-23 13:35:39 +0000559 setup();
plars865695b2001-08-27 22:15:12 +0000560
561 /***************************************************************
562 * check looping state if -c option given
563 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000564 for (lc = 0; TEST_LOOPING(lc); lc++) {
plars865695b2001-08-27 22:15:12 +0000565
Caspar Zhangd59a6592013-03-07 14:59:12 +0800566 tst_count = 0;
plars865695b2001-08-27 22:15:12 +0000567
subrata_modak56207ce2009-03-23 13:35:39 +0000568 /*
569 * Execute tcs testing function and all defined test cases
570 */
571 do_syscalltests(tcs_ptr);
plars865695b2001-08-27 22:15:12 +0000572
Garrett Cooper2c282152010-12-16 00:55:50 -0800573 }
plars865695b2001-08-27 22:15:12 +0000574
subrata_modak56207ce2009-03-23 13:35:39 +0000575 /*
576 * End appropriately
577 */
578 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800579 tst_exit();
plars865695b2001-08-27 22:15:12 +0000580
plars865695b2001-08-27 22:15:12 +0000581}
582
583/***********************************************************************
584 * This function maps the name of the process to a test case specification
585 * defined in the all_tcses array of tcses structures. Either a pointer
586 * to the mapped test case specification information is returned or a
587 * null pointer.
588 *
589 * Argument is path to program name.
590 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400591struct tcses *get_tcs_info(char *ptr)
plars865695b2001-08-27 22:15:12 +0000592{
subrata_modak56207ce2009-03-23 13:35:39 +0000593 int ctr;
594 struct tcses *tcs_ptr;
plars865695b2001-08-27 22:15:12 +0000595
596#if ALL
subrata_modak56207ce2009-03-23 13:35:39 +0000597 if (ptr == NULL) {
plars865695b2001-08-27 22:15:12 +0000598
subrata_modak56207ce2009-03-23 13:35:39 +0000599 TST_TOTAL = 0;
Wanlong Gao354ebb42012-12-07 10:10:04 +0800600 for (ctr = 1; ctr < sizeof(all_tcses) / sizeof(struct tcses);
601 ctr++)
subrata_modak56207ce2009-03-23 13:35:39 +0000602 TST_TOTAL += all_tcses[ctr].test_cases;
603 return all_tcses;
604 }
plars865695b2001-08-27 22:15:12 +0000605#endif
606
subrata_modak56207ce2009-03-23 13:35:39 +0000607 for (ctr = 0; ctr < (sizeof(all_tcses) / sizeof(struct tcses)); ctr++) {
608 if (strcmp(ptr, all_tcses[ctr].tcid) == 0 ||
609 strcmp(ptr, all_tcses[ctr].syscall) == 0) {
610 tcs_ptr = &all_tcses[ctr];
611 TCID = all_tcses[ctr].tcid;
612 TST_TOTAL = tcs_ptr->test_cases;
613 return (tcs_ptr);
614 }
615
616 }
617 return NULL;
plars865695b2001-08-27 22:15:12 +0000618}
619
620/***********************************************************************
621 * Determines if what path points at is a symbolic link file
622 *
623 * Argument is path to symbolic link file.
624 *
625 * Return status is one if a symbolic link file. Zero if not a symbolic
626 * link file and a minus one if the path doesn't point at a file.
627 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400628static int see_if_a_symlink(char *path)
plars865695b2001-08-27 22:15:12 +0000629{
subrata_modak56207ce2009-03-23 13:35:39 +0000630 if (lstat(path, &asymlink) < 0)
631 return (-1);
plars865695b2001-08-27 22:15:12 +0000632
subrata_modak56207ce2009-03-23 13:35:39 +0000633 if ((asymlink.st_mode & S_IFMT) == S_IFLNK)
634 return 1;
635 else
636 return 0;
plars865695b2001-08-27 22:15:12 +0000637}
638
639/***********************************************************************
640 * This function performs without any hesitation, file(s) deletions
641 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400642void delete_files(char *path1, char *path2)
plars865695b2001-08-27 22:15:12 +0000643{
subrata_modak56207ce2009-03-23 13:35:39 +0000644 unlink(path1);
645 unlink(path2);
plars865695b2001-08-27 22:15:12 +0000646}
647
648/***********************************************************************
649 *
650 * This routine creates a symbolic link file.
651 *
652 * Argument one is symbolic link pathname to point at.
653 * Argument two is name of symbolic link file.
654 *
655 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400656int creat_symlink(char *path1, char *path2, char *_path3)
plars865695b2001-08-27 22:15:12 +0000657{
subrata_modak56207ce2009-03-23 13:35:39 +0000658 TEST(symlink(path1, path2));
659 errno = TEST_ERRNO;
660 if (TEST_RETURN == -1) {
661 TEST_RESULT = TBROK;
662 sprintf(test_msg,
663 "symlink(2) Failure when creating setup %s object file: errno:%d %s",
664 path1, errno, strerror(errno));
665 return 0;
666 } else {
667 sprintf(Buf, "symlink(%s, %s) was succesful.\n", path1, path2);
668 strcat(Buffer, Buf);
plars865695b2001-08-27 22:15:12 +0000669#if DEBUG
subrata_modak56207ce2009-03-23 13:35:39 +0000670 tst_resm(TPASS, "symlink(%s, %s) was succesful.", path1, path2);
plars865695b2001-08-27 22:15:12 +0000671#endif
subrata_modak56207ce2009-03-23 13:35:39 +0000672 }
673 return 1;
plars865695b2001-08-27 22:15:12 +0000674}
Mike Frysingerc57fba52014-04-09 18:56:30 -0400675#define creat_symlink(p1, p2) creat_symlink(p1, p2, NULL)
plars865695b2001-08-27 22:15:12 +0000676
677/***********************************************************************
678 *
679 * This routine creates a regular file.
680 *
681 * Argument one is a pathname
682 *
683 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400684int creat_object(char *path1, char *_path2, char *_path3)
plars865695b2001-08-27 22:15:12 +0000685{
subrata_modak56207ce2009-03-23 13:35:39 +0000686 int fd;
687 if ((fd = creat(path1, MODE)) == -1) {
688 TEST_RESULT = TBROK;
689 sprintf(test_msg,
690 "creat(2) Failure when creating setup %s object file: errno:%d %s",
691 path1, errno, strerror(errno));
692 return 0;
693 } else {
694 sprintf(Buf, "creat(%s, %#o) was succesful.\n", path1, MODE);
695 strcat(Buffer, Buf);
plars865695b2001-08-27 22:15:12 +0000696#if DEBUG
subrata_modak56207ce2009-03-23 13:35:39 +0000697 tst_resm(TPASS, "creat(%s, %#o) was succesful.", path1, MODE);
plars865695b2001-08-27 22:15:12 +0000698#endif
subrata_modak56207ce2009-03-23 13:35:39 +0000699 }
700 if (close(fd) == -1) {
701 TEST_RESULT = TBROK;
702 sprintf(test_msg,
703 "close(2) Failure when closing setup %s object file: errno:%d %s",
704 path1, errno, strerror(errno));
705 return 0;
706 }
707 return 1;
plars865695b2001-08-27 22:15:12 +0000708}
Mike Frysingerc57fba52014-04-09 18:56:30 -0400709#define creat_object(p1) creat_object(p1, NULL, NULL)
plars865695b2001-08-27 22:15:12 +0000710
711/***********************************************************************
712 *
713 * This routine creates a symbolic link file and a regular file.
714 *
715 * Argument one is a pathname of object file
716 * Argument two is symbolic link file name
717 * Argument three is regular file name
718 *
719 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400720int creat_both(char *path1, char *path2, char *path3)
plars865695b2001-08-27 22:15:12 +0000721{
subrata_modak56207ce2009-03-23 13:35:39 +0000722 if (creat_symlink(path1, path2) == -1)
723 return 0;
724 else if (creat_object(path3) == -1)
725 return 0;
726 return 1;
plars865695b2001-08-27 22:15:12 +0000727}
728
729/***********************************************************************
730 *
731 * This routine checks if symbolic link file is a symbolic link file.
732 *
733 * Argument one is a pathname of object file
734 * Argument two is symbolic link file name
735 * Argument three is regular file name
736 *
737 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400738int ck_symlink(char *path1, char *path2, char *path3)
plars865695b2001-08-27 22:15:12 +0000739{
subrata_modak56207ce2009-03-23 13:35:39 +0000740 int ret;
plars865695b2001-08-27 22:15:12 +0000741
subrata_modak56207ce2009-03-23 13:35:39 +0000742 if ((ret = see_if_a_symlink(path2)) == -1) {
743 TEST_RESULT = TBROK;
744 sprintf(test_msg,
745 "lstat(2) Failure when accessing %s symbolic link file which should contain %s path to %s file ",
746 path2, path1, path3);
747 return 0;
748 } else if (ret == 0) {
749 TEST_RESULT = TBROK;
750 sprintf(test_msg,
751 "%s is not a symbolic link file which contains %s path to %s file",
752 path2, path1, path3);
753 return 0;
754 }
755 return 1;
plars865695b2001-08-27 22:15:12 +0000756}
757
758/***********************************************************************
759 *
760 * This routine checks if symbolic link file points at object file.
761 *
762 * Argument one is a pathname of object file
763 * Argument two is symbolic link file name
764 * Argument three is regular file name
765 *
766 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400767int ck_both(char *path1, char *path2, char *path3)
plars865695b2001-08-27 22:15:12 +0000768{
subrata_modak56207ce2009-03-23 13:35:39 +0000769 if (ck_symlink(path1, path2, path3) == 0)
770 return 0;
771 else if ((stat(path3, &statter) == -1) && (errno == ENOENT)) {
772 TEST_RESULT = TBROK;
Wanlong Gao354ebb42012-12-07 10:10:04 +0800773 sprintf(test_msg,
774 "stat(2) Failure when accessing %s object file ",
775 path3);
subrata_modak56207ce2009-03-23 13:35:39 +0000776 return 0;
777 } else if ((stat(path2, &asymlink) == -1) && (errno == ENOENT)) {
778 TEST_RESULT = TBROK;
Wanlong Gao354ebb42012-12-07 10:10:04 +0800779 sprintf(test_msg,
780 "stat(2) Failure when accessing %s symbolic link file ",
781 path2);
subrata_modak56207ce2009-03-23 13:35:39 +0000782 return 0;
783 } else if (statter.st_ino != asymlink.st_ino) {
784 TEST_RESULT = TBROK;
785 sprintf(test_msg,
786 "stat(2) Failure when accessing %s object file through %s symbolic link file ",
787 path3, path2);
788 return 0;
789 }
790 return 1;
791
plars865695b2001-08-27 22:15:12 +0000792}
793
794/***********************************************************************
795 * This routine populates full_path with a pathname whose length exceeds
796 * the PATH_MAX define value in param.h
797 *
798 * Argument one is a pathname of object file
799 * Argument two is symbolic link file name
800 * Argument three is regular file name
801 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400802int creat_path_max(char *path1, char *path2, char *path3)
plars865695b2001-08-27 22:15:12 +0000803{
subrata_modak56207ce2009-03-23 13:35:39 +0000804 int ctr, to_go, size, whole_chunks;
805 char *cwd, *getcwd();
plars865695b2001-08-27 22:15:12 +0000806
Garrett Cooper45e285d2010-11-22 12:19:25 -0800807 if ((cwd = getcwd(NULL, 0)) == NULL) {
subrata_modak56207ce2009-03-23 13:35:39 +0000808 TEST_RESULT = TBROK;
809 sprintf(test_msg,
810 "getcwd(3) Failure in setup of %s %s %s test case object elements",
811 path1, path2, path3);
812 return 0;
813 }
Garrett Cooper45e285d2010-11-22 12:19:25 -0800814 cwd = getcwd(NULL, 0);
subrata_modak56207ce2009-03-23 13:35:39 +0000815 size = strlen(cwd);
plars865695b2001-08-27 22:15:12 +0000816
subrata_modak56207ce2009-03-23 13:35:39 +0000817 to_go = PATH_MAX - size;
818 size = strlen(path1);
819 whole_chunks = to_go / size;
820 strcpy(full_path, cwd);
821 for (ctr = 0; ctr < whole_chunks; ctr++) {
822 strcat(full_path, path1);
823 }
824 size = strlen(full_path);
825 to_go = PATH_MAX - size;
826 strcat(full_path, "/");
827 for (ctr = 0; ctr < to_go; ctr++)
828 strcat(full_path, "Z");
plars865695b2001-08-27 22:15:12 +0000829
subrata_modak56207ce2009-03-23 13:35:39 +0000830 return 1;
plars865695b2001-08-27 22:15:12 +0000831}
832
833/***********************************************************************
834 * This routine checks that full_path's length exceeds the PATH_MAX
835 * define value in param.h
836 *
837 * Argument one is a pathname of object file
838 * Argument two is symbolic link file name
839 * Argument three is regular file name
840 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400841int ck_path_max(char *path1, char *path2, char *path3)
plars865695b2001-08-27 22:15:12 +0000842{
subrata_modak56207ce2009-03-23 13:35:39 +0000843 if (strlen(full_path) == (PATH_MAX + 1))
844 return 1;
845 else {
846 TEST_RESULT = TBROK;
847 sprintf(test_msg, "%s %d %s %s %s %s",
848 "full_path character array length was not",
849 (PATH_MAX + 1),
Wanlong Gao354ebb42012-12-07 10:10:04 +0800850 "characters long for test case object elements", path1,
851 path2, path3);
subrata_modak56207ce2009-03-23 13:35:39 +0000852 return 0;
853 }
plars865695b2001-08-27 22:15:12 +0000854}
855
856/***********************************************************************
857 * This routine checks if the stat(2) and lstat(2) calls return the same
858 * information when the path is not a symbolic link file
859 *
860 * Argument one is a pathname of object file
861 * Argument two is symbolic link file name
862 * Argument three is regular file name
863 *
864 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400865int ck_object(char *path1, char *path2, char *path3)
plars865695b2001-08-27 22:15:12 +0000866{
subrata_modak56207ce2009-03-23 13:35:39 +0000867 int ret;
plars865695b2001-08-27 22:15:12 +0000868
subrata_modak56207ce2009-03-23 13:35:39 +0000869 if ((ret = see_if_a_symlink(path1)) < 0) {
870 TEST_RESULT = TFAIL;
871 sprintf(test_msg,
872 "lstat(2) failed to return inode information for a regular object file");
873 return 0;
874 } else if (ret == 1) {
875 TEST_RESULT = TFAIL;
876 sprintf(test_msg,
877 "lstat(2) detected a regular object file as a symbolic link file");
878 return 0;
879 } else if (stat(path1, &statter) == -1) {
880 TEST_RESULT = TBROK;
881 sprintf(test_msg,
882 "stat(2) failed to return inode information for a regular object file");
883 return 0;
884 } else if (memcmp((char *)&statter, (char *)&asymlink, sizeof(statter))
885 != 0) {
886 TEST_RESULT = TFAIL;
887 sprintf(test_msg,
888 "lstat(2) and stat(2) do not return same inode information for an object file");
889 return 0;
890
891 }
892 return 1;
plars865695b2001-08-27 22:15:12 +0000893}
894
895/***********************************************************************
896 * Main test case processing function
897 *
898 * Argument is a ptr into the all_tcses array of structures of type tcses
899 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400900int do_syscalltests(struct tcses *tcs)
plars865695b2001-08-27 22:15:12 +0000901{
subrata_modak56207ce2009-03-23 13:35:39 +0000902 int ctr, ret;
903 struct all_test_cases *tc_ptr;
plars865695b2001-08-27 22:15:12 +0000904
subrata_modak56207ce2009-03-23 13:35:39 +0000905 /*
906 * loop through desired number of test cases
907 */
908 for (ctr = 0, tc_ptr = tcs->tc_ptr; ctr < TST_TOTAL; ctr++, tc_ptr++) {
plars865695b2001-08-27 22:15:12 +0000909
subrata_modak56207ce2009-03-23 13:35:39 +0000910 Buffer[0] = '\0';
plars865695b2001-08-27 22:15:12 +0000911
subrata_modak56207ce2009-03-23 13:35:39 +0000912 /*
913 * If running all test cases for all tcid, set the TCID if needed.
914 */
915 if (Selectedtests == NULL) {
916 if (strcmp(tcs->tcid, tc_ptr->tcid) != 0) {
917 TCID = tc_ptr->tcid;
Caspar Zhangd59a6592013-03-07 14:59:12 +0800918 tst_count = 0;
subrata_modak56207ce2009-03-23 13:35:39 +0000919 }
920 }
921 /*
922 * Insure that we are executing the correct tcs test case
923 */
924 if (strcmp(tcs->tcid, tc_ptr->tcid) != 0) {
925 tst_resm(TBROK,
926 "%s TCID attempted to execute %s %d %d test case",
Wanlong Gao354ebb42012-12-07 10:10:04 +0800927 tcs->tcid, tc_ptr->tcid, tc_ptr->test_fail,
928 tc_ptr->errno_val);
subrata_modak56207ce2009-03-23 13:35:39 +0000929 continue;
930 }
931 TEST_RESULT = TPASS;
932 delete_files(S_FILE, O_FILE);
933 /*
934 * Perform test case setup
935 */
936 ret =
937 (tc_ptr->test_setup) (tc_ptr->fn_arg[0], tc_ptr->fn_arg[1],
Mike Frysingerc57fba52014-04-09 18:56:30 -0400938 tc_ptr->fn_arg[2]);
plars865695b2001-08-27 22:15:12 +0000939
subrata_modak56207ce2009-03-23 13:35:39 +0000940 /* If an expected error, try it out */
plars865695b2001-08-27 22:15:12 +0000941
subrata_modak56207ce2009-03-23 13:35:39 +0000942 if (tc_ptr->test_fail) {
943 /*
944 * Try to perform test verification function
945 */
946 if (!(tc_ptr->ck_test)
947 (tc_ptr->fn_arg[0], tc_ptr->fn_arg[1],
Mike Frysingerc57fba52014-04-09 18:56:30 -0400948 tc_ptr->fn_arg[2]))
vapiere5fce932009-08-28 14:17:14 +0000949 tst_resm(TEST_RESULT, "%s", test_msg);
subrata_modak56207ce2009-03-23 13:35:39 +0000950 else if (tc_ptr->errno_val == EEXIST)
951 do_EEXIST(tc_ptr);
952 else if (tc_ptr->errno_val == ENOENT)
953 do_ENOENT(tc_ptr);
954 else if (tc_ptr->errno_val == ELOOP)
955 do_ELOOP(tc_ptr);
956 else if (tc_ptr->errno_val == ENOTDIR)
957 do_ENOTDIR(tc_ptr);
958 else if (tc_ptr->errno_val == EXDEV)
959 do_EXDEV(tc_ptr);
960 else if (tc_ptr->errno_val == ENAMETOOLONG)
961 do_ENAMETOOLONG(tc_ptr);
962 else if (tc_ptr->errno_val == EINVAL)
963 do_EINVAL(tc_ptr);
964 else
965 tst_resm(TBROK, "Test Case Declaration Error");
966 } else if (ret == 1) { /* No setup function error */
subrata_modak4bb656a2009-02-26 12:02:09 +0000967
subrata_modak56207ce2009-03-23 13:35:39 +0000968 if (tc_ptr->errno_val != 0)
969 tst_resm(TBROK, "Test Case Declaration Error");
970 else {
971 /*
972 * Perform test verification function
973 */
974 ret =
975 (tc_ptr->ck_test) (tc_ptr->fn_arg[0],
976 tc_ptr->fn_arg[1],
Mike Frysingerc57fba52014-04-09 18:56:30 -0400977 tc_ptr->fn_arg[2]);
plars865695b2001-08-27 22:15:12 +0000978
subrata_modak56207ce2009-03-23 13:35:39 +0000979 /* Perform requested symbolic link system call test */
plars865695b2001-08-27 22:15:12 +0000980
subrata_modak56207ce2009-03-23 13:35:39 +0000981 if ((cktcsid(tc_ptr->tcid, SYMLINK)) ||
982 (cktcsid(tc_ptr->tcid, LSTAT)) ||
983 (cktcsid(tc_ptr->tcid, LSTAT_64))) {
984 if (ret == 1)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800985 tst_resm(TEST_RESULT, "%s",
986 msgs[tc_ptr->
987 pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +0000988 else
Wanlong Gao354ebb42012-12-07 10:10:04 +0800989 tst_resm(TEST_RESULT, "%s",
990 test_msg);
subrata_modak56207ce2009-03-23 13:35:39 +0000991 } else if (ret == 0)
vapiere5fce932009-08-28 14:17:14 +0000992 tst_resm(TEST_RESULT, "%s", test_msg);
subrata_modak56207ce2009-03-23 13:35:39 +0000993 else if (cktcsid(tc_ptr->tcid, READLINK))
994 do_readlink(tc_ptr);
995 else if (cktcsid(tc_ptr->tcid, STAT))
996 do_stat(tc_ptr);
997 else if (cktcsid(tc_ptr->tcid, STAT_64))
998 do_stat(tc_ptr);
999 else if (cktcsid(tc_ptr->tcid, CHDIR))
1000 do_chdir(tc_ptr);
1001 else if (cktcsid(tc_ptr->tcid, LINK))
1002 do_link(tc_ptr);
1003 else if (cktcsid(tc_ptr->tcid, UNLINK))
1004 do_unlink(tc_ptr);
1005 else if (cktcsid(tc_ptr->tcid, CHMOD))
1006 do_chmod(tc_ptr);
1007 else if (cktcsid(tc_ptr->tcid, UTIME))
1008 do_utime(tc_ptr);
1009 else if (cktcsid(tc_ptr->tcid, RENAME))
1010 do_rename(tc_ptr);
1011 else if (cktcsid(tc_ptr->tcid, OPEN))
1012 do_open(tc_ptr);
1013 else
1014 tst_resm(TBROK,
1015 "Unknown test case processing actions declared");
1016 }
1017 } else
1018 tst_resm(TBROK, "Test Case Declaration Error");
1019 }
1020 return 0;
plars865695b2001-08-27 22:15:12 +00001021}
1022
1023/***********************************************************************
1024 * This routine checks for the return of EEXIST errno from requested
1025 * system call
1026 *
1027 * Argument is pointer to test_objects array of structures of type
1028 * all_test_cases
1029 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -04001030void do_EEXIST(struct all_test_cases *tc_ptr)
plars865695b2001-08-27 22:15:12 +00001031{
subrata_modak56207ce2009-03-23 13:35:39 +00001032 if (cktcsid(tc_ptr->tcid, SYMLINK)) {
plars865695b2001-08-27 22:15:12 +00001033
subrata_modak56207ce2009-03-23 13:35:39 +00001034 TEST(symlink(tc_ptr->fn_arg[0], tc_ptr->fn_arg[1]));
1035 errno = TEST_ERRNO;
1036 if ((TEST_RETURN == -1) && (errno == EEXIST))
Cyril Hrubise38b9612014-06-02 17:20:57 +02001037 tst_resm(TPASS, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001038 else
1039 tst_resm(TFAIL, "%s %s",
1040 "Expected EEXIST error when creating a symbolic link file",
1041 "which already existed");
1042 } else if (cktcsid(tc_ptr->tcid, MKDIR)) {
plars865695b2001-08-27 22:15:12 +00001043
subrata_modak56207ce2009-03-23 13:35:39 +00001044 TEST(mkdir(tc_ptr->fn_arg[1], MODE));
1045 errno = TEST_ERRNO;
Cyril Hrubise38b9612014-06-02 17:20:57 +02001046 if ((TEST_RETURN == -1) && (errno == EEXIST)) {
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001047 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001048 } else {
plars865695b2001-08-27 22:15:12 +00001049
subrata_modak56207ce2009-03-23 13:35:39 +00001050 tst_resm(TFAIL, "%s %s",
1051 "Expected EEXIST error when creating a directory by a symbolic",
1052 "link file which pointed at no object file");
1053 rmdir(tc_ptr->fn_arg[1]);
1054 }
1055 } else if (cktcsid(tc_ptr->tcid, OPEN)) {
plars865695b2001-08-27 22:15:12 +00001056
subrata_modak56207ce2009-03-23 13:35:39 +00001057 TEST(open(tc_ptr->fn_arg[1], (O_EXCL | O_CREAT), 0666));
1058 errno = TEST_ERRNO;
Cyril Hrubise38b9612014-06-02 17:20:57 +02001059 if ((TEST_RETURN == -1) && (errno == EEXIST)) {
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001060 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001061 } else {
subrata_modak56207ce2009-03-23 13:35:39 +00001062 tst_resm(TFAIL, "%s %s errno:%d %s",
1063 "Expected EEXIST error for exclusively opening an object file",
1064 "through a symbolic link file was not received:",
1065 errno, strerror(errno));
Cyril Hrubise38b9612014-06-02 17:20:57 +02001066 }
subrata_modak56207ce2009-03-23 13:35:39 +00001067 } else
Wanlong Gao354ebb42012-12-07 10:10:04 +08001068 tst_resm(TBROK,
1069 "Unknown test case processing actions declared");
plars865695b2001-08-27 22:15:12 +00001070}
1071
1072/***********************************************************************
1073 * This routine checks for the return of ENOENT errno from requested
1074 * system call
1075 *
1076 * Argument is pointer to test_objects array of structures of type
1077 * all_test_cases
1078 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -04001079void do_ENOENT(struct all_test_cases *tc_ptr)
plars865695b2001-08-27 22:15:12 +00001080{
subrata_modak56207ce2009-03-23 13:35:39 +00001081 if ((cktcsid(tc_ptr->tcid, STAT)) || (cktcsid(tc_ptr->tcid, STAT_64))) {
plars865695b2001-08-27 22:15:12 +00001082
subrata_modak56207ce2009-03-23 13:35:39 +00001083 if ((stat(tc_ptr->fn_arg[1], &asymlink) == -1)
Cyril Hrubise38b9612014-06-02 17:20:57 +02001084 && (errno == ENOENT)) {
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001085 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001086 } else {
subrata_modak56207ce2009-03-23 13:35:39 +00001087 tst_resm(TFAIL, "%s %s errno:%d %s",
1088 "Expected ENOENT error for stating a non-existent directory",
1089 "through a symbolic link file was not received:",
1090 errno, strerror(errno));
Cyril Hrubise38b9612014-06-02 17:20:57 +02001091 }
subrata_modak56207ce2009-03-23 13:35:39 +00001092 } else if (cktcsid(tc_ptr->tcid, CHDIR)) {
Cyril Hrubise38b9612014-06-02 17:20:57 +02001093 if ((chdir(tc_ptr->fn_arg[1]) == -1) && (errno == ENOENT)) {
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001094 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001095 } else {
subrata_modak56207ce2009-03-23 13:35:39 +00001096 tst_resm(TFAIL, "%s %s errno:%d %s",
1097 "Expected ENOENT error for changing to a non-existent",
1098 "directory through a symbolic link file was not received:",
1099 errno, strerror(errno));
Garrett Cooper0ae003b2010-12-19 10:36:32 -08001100 /* FIXME (garrcoop): memory leak */
Cyril Hrubis9c31ad22014-05-14 17:15:39 +02001101 chdir(tst_get_tmpdir());
subrata_modak56207ce2009-03-23 13:35:39 +00001102 }
1103 } else if (cktcsid(tc_ptr->tcid, LINK)) {
plars865695b2001-08-27 22:15:12 +00001104
subrata_modak56207ce2009-03-23 13:35:39 +00001105 if ((link(tc_ptr->fn_arg[1], "nick") == -1)
Cyril Hrubise38b9612014-06-02 17:20:57 +02001106 && (errno == ENOENT)) {
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001107 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001108 } else {
subrata_modak56207ce2009-03-23 13:35:39 +00001109 tst_resm(TFAIL, "%s %s errno:%d %s",
1110 "Expected ENOENT error condition when link(2) a symbolic",
Wanlong Gao354ebb42012-12-07 10:10:04 +08001111 "link which pointed at no object:", errno,
1112 strerror(errno));
subrata_modak56207ce2009-03-23 13:35:39 +00001113 delete_files("nick", NULL);
1114 }
1115 } else if (cktcsid(tc_ptr->tcid, CHMOD)) {
plars865695b2001-08-27 22:15:12 +00001116
Cyril Hrubise38b9612014-06-02 17:20:57 +02001117 if ((chmod(tc_ptr->fn_arg[1], MODE) == -1) && (errno == ENOENT)) {
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001118 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001119 } else {
subrata_modak56207ce2009-03-23 13:35:39 +00001120 tst_resm(TFAIL, "%s %s errno:%d %s",
1121 "Expected ENOENT error condition when chmod(2) a symbolic",
Wanlong Gao354ebb42012-12-07 10:10:04 +08001122 "link which pointed at no object,", errno,
1123 strerror(errno));
Cyril Hrubise38b9612014-06-02 17:20:57 +02001124 }
subrata_modak56207ce2009-03-23 13:35:39 +00001125 } else if (cktcsid(tc_ptr->tcid, UTIME)) {
plars865695b2001-08-27 22:15:12 +00001126
Cyril Hrubise38b9612014-06-02 17:20:57 +02001127 if ((utime(tc_ptr->fn_arg[1], NULL) == -1) && (errno == ENOENT)) {
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001128 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001129 } else {
subrata_modak56207ce2009-03-23 13:35:39 +00001130 tst_resm(TFAIL, "%s %s errno:%d %s",
1131 "Expected ENOENT error condition when utime(2) a symbolic",
Wanlong Gao354ebb42012-12-07 10:10:04 +08001132 "link which pointed at no object:", errno,
1133 strerror(errno));
Cyril Hrubise38b9612014-06-02 17:20:57 +02001134 }
subrata_modak56207ce2009-03-23 13:35:39 +00001135 } else if (cktcsid(tc_ptr->tcid, OPEN)) {
plars865695b2001-08-27 22:15:12 +00001136
subrata_modak56207ce2009-03-23 13:35:39 +00001137 if ((open(tc_ptr->fn_arg[1], O_RDWR) == -1)
Cyril Hrubise38b9612014-06-02 17:20:57 +02001138 && (errno == ENOENT)) {
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001139 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001140 } else {
subrata_modak56207ce2009-03-23 13:35:39 +00001141 tst_resm(TFAIL, "%s %s errno:%d %s",
1142 "Expected ENOENT error for opening a non-existent object",
1143 " file through a symbolic link file was not received,",
1144 errno, strerror(errno));
Cyril Hrubise38b9612014-06-02 17:20:57 +02001145 }
subrata_modak56207ce2009-03-23 13:35:39 +00001146 } else
Wanlong Gao354ebb42012-12-07 10:10:04 +08001147 tst_resm(TBROK,
1148 "Unknown test case processing actions declared");
plars865695b2001-08-27 22:15:12 +00001149}
1150
1151/***********************************************************************
1152 * This routine checks for the return of ELOOP errno from requested
1153 * system call
1154 *
1155 * Argument is pointer to test_objects array of structures of type
1156 * all_test_cases
1157 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -04001158void do_ELOOP(struct all_test_cases *tc_ptr)
plars865695b2001-08-27 22:15:12 +00001159{
subrata_modak56207ce2009-03-23 13:35:39 +00001160 if ((cktcsid(tc_ptr->tcid, STAT)) || (cktcsid(tc_ptr->tcid, STAT_64))) {
plars865695b2001-08-27 22:15:12 +00001161
subrata_modak56207ce2009-03-23 13:35:39 +00001162 TEST(stat(tc_ptr->fn_arg[1], &asymlink));
1163 errno = TEST_ERRNO;
Cyril Hrubise38b9612014-06-02 17:20:57 +02001164 if ((TEST_RETURN == -1) && (errno == ELOOP)) {
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001165 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1166 } else {
subrata_modak56207ce2009-03-23 13:35:39 +00001167 tst_resm(TEST_RESULT, "%s errno:%d %s",
1168 "Expected ELOOP errno from stat(2) (nested symb link),",
1169 errno, strerror(errno));
Cyril Hrubise38b9612014-06-02 17:20:57 +02001170 }
subrata_modak56207ce2009-03-23 13:35:39 +00001171 } else if (cktcsid(tc_ptr->tcid, CHDIR)) {
plars865695b2001-08-27 22:15:12 +00001172
subrata_modak56207ce2009-03-23 13:35:39 +00001173 TEST(chdir(tc_ptr->fn_arg[1]));
1174 errno = TEST_ERRNO;
Cyril Hrubise38b9612014-06-02 17:20:57 +02001175 if ((TEST_RETURN == -1) && (errno == ELOOP)) {
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001176 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001177 } else {
plars865695b2001-08-27 22:15:12 +00001178
subrata_modak56207ce2009-03-23 13:35:39 +00001179 tst_resm(TFAIL, "%s errno:%d %s",
1180 "Expected ELOOP error condition when chdir(2) a nested symbolic link:",
1181 errno, strerror(errno));
Garrett Cooper0ae003b2010-12-19 10:36:32 -08001182 /* FIXME (garrcoop): memory leak */
Cyril Hrubis9c31ad22014-05-14 17:15:39 +02001183 chdir(tst_get_tmpdir());
subrata_modak56207ce2009-03-23 13:35:39 +00001184 }
1185 } else if (cktcsid(tc_ptr->tcid, LINK)) {
plars865695b2001-08-27 22:15:12 +00001186
subrata_modak56207ce2009-03-23 13:35:39 +00001187 TEST(link(tc_ptr->fn_arg[1], O_FILE));
1188 errno = TEST_ERRNO;
Cyril Hrubise38b9612014-06-02 17:20:57 +02001189 if ((TEST_RETURN == -1) && (errno == ELOOP)) {
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001190 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001191 } else {
subrata_modak56207ce2009-03-23 13:35:39 +00001192 tst_resm(TFAIL, "%s errno:%d %s",
1193 "Expected ELOOP error condition when link(2) a nested symbolic link:",
1194 errno, strerror(errno));
Cyril Hrubise38b9612014-06-02 17:20:57 +02001195 }
subrata_modak56207ce2009-03-23 13:35:39 +00001196 } else if (cktcsid(tc_ptr->tcid, CHMOD)) {
plars865695b2001-08-27 22:15:12 +00001197
subrata_modak56207ce2009-03-23 13:35:39 +00001198 TEST(chmod(tc_ptr->fn_arg[1], MODE));
1199 errno = TEST_ERRNO;
Cyril Hrubise38b9612014-06-02 17:20:57 +02001200 if ((TEST_RETURN == -1) && (errno == ELOOP)) {
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001201 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001202 } else {
subrata_modak56207ce2009-03-23 13:35:39 +00001203 tst_resm(TFAIL, "%s errno:%d %s",
1204 "Expected ELOOP error condition when chmod(2) a nested symbolic link:",
1205 errno, strerror(errno));
Cyril Hrubise38b9612014-06-02 17:20:57 +02001206 }
subrata_modak56207ce2009-03-23 13:35:39 +00001207 return;
1208 } else if (cktcsid(tc_ptr->tcid, UTIME)) {
plars865695b2001-08-27 22:15:12 +00001209
subrata_modak56207ce2009-03-23 13:35:39 +00001210 TEST(utime(tc_ptr->fn_arg[1], NULL));
1211 errno = TEST_ERRNO;
plars865695b2001-08-27 22:15:12 +00001212
Cyril Hrubise38b9612014-06-02 17:20:57 +02001213 if ((TEST_RETURN == -1) && (errno == ELOOP)) {
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001214 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001215 } else {
subrata_modak56207ce2009-03-23 13:35:39 +00001216 tst_resm(TFAIL, "%s errno:%d %s",
1217 "Expected ELOOP error condition when utime(2) a nested symbolic link:",
1218 errno, strerror(errno));
Cyril Hrubise38b9612014-06-02 17:20:57 +02001219 }
subrata_modak56207ce2009-03-23 13:35:39 +00001220 } else if (cktcsid(tc_ptr->tcid, OPEN)) {
plars865695b2001-08-27 22:15:12 +00001221
subrata_modak56207ce2009-03-23 13:35:39 +00001222 int fd;
1223 TEST(open(tc_ptr->fn_arg[1], O_CREAT, 0666));
1224 fd = TEST_RETURN;
1225 errno = TEST_ERRNO;
Cyril Hrubise38b9612014-06-02 17:20:57 +02001226 if ((fd == -1) && (errno == ELOOP)) {
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001227 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001228 } else {
subrata_modak56207ce2009-03-23 13:35:39 +00001229 tst_resm(TFAIL, "%s errno:%d %s",
1230 "Expected ELOOP error condition when open(2) a nested symbolic link:",
1231 errno, strerror(errno));
Cyril Hrubise38b9612014-06-02 17:20:57 +02001232 }
subrata_modak56207ce2009-03-23 13:35:39 +00001233 } else
Wanlong Gao354ebb42012-12-07 10:10:04 +08001234 tst_resm(TBROK,
1235 "Unknown test case processing actions declared");
plars865695b2001-08-27 22:15:12 +00001236}
1237
1238/***********************************************************************
1239 * This routine checks for the return of ENOTDIR errno from requested
1240 * system call
1241 *
1242 * Argument is pointer to test_objects array of structures of type
1243 * all_test_cases
1244 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -04001245void do_ENOTDIR(struct all_test_cases *tc_ptr)
plars865695b2001-08-27 22:15:12 +00001246{
subrata_modak56207ce2009-03-23 13:35:39 +00001247 if (cktcsid(tc_ptr->tcid, RMDIR)) {
plars865695b2001-08-27 22:15:12 +00001248
subrata_modak56207ce2009-03-23 13:35:39 +00001249 TEST(mkdir(tc_ptr->fn_arg[0], MODE));
1250 errno = TEST_ERRNO;
1251 if (TEST_RETURN == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +08001252 tst_resm(TBROK, "mkdir(2) Failure when creating %s",
1253 tc_ptr->fn_arg[0]);
subrata_modak56207ce2009-03-23 13:35:39 +00001254 else if ((rmdir(tc_ptr->fn_arg[1]) == -1) && (errno == ENOTDIR)) {
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001255 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001256 rmdir(tc_ptr->fn_arg[0]);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001257 } else {
subrata_modak56207ce2009-03-23 13:35:39 +00001258 tst_resm(TFAIL, "%s %s errno:%d %s",
1259 "Expected ENOTDIR error for removing a non-existent",
1260 "directory through a symbolic link file was not received,",
1261 errno, strerror(errno));
Cyril Hrubise38b9612014-06-02 17:20:57 +02001262 }
subrata_modak56207ce2009-03-23 13:35:39 +00001263 } else
Wanlong Gao354ebb42012-12-07 10:10:04 +08001264 tst_resm(TBROK,
1265 "Unknown test case processing actions declared");
plars865695b2001-08-27 22:15:12 +00001266}
1267
1268/***********************************************************************
1269 * This routine checks for the return of EXDEV errno from requested
1270 * system call
1271 *
1272 * Argument is pointer to test_objects array of structures of type
1273 * all_test_cases
1274 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -04001275void do_EXDEV(struct all_test_cases *tc_ptr)
plars865695b2001-08-27 22:15:12 +00001276{
subrata_modak56207ce2009-03-23 13:35:39 +00001277 if (cktcsid(tc_ptr->tcid, RENAME)) {
plars865695b2001-08-27 22:15:12 +00001278
subrata_modak56207ce2009-03-23 13:35:39 +00001279 TEST(rename(tc_ptr->fn_arg[1], Y_A_S_FILE));
1280 errno = TEST_ERRNO;
1281 if ((TEST_RETURN == -1) && (errno == EXDEV)) {
Cyril Hrubise38b9612014-06-02 17:20:57 +02001282 if (see_if_a_symlink(Y_A_S_FILE) == -1) {
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001283 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001284 } else {
subrata_modak56207ce2009-03-23 13:35:39 +00001285 tst_resm(TFAIL,
1286 "%s %s %s file outside of current file system",
1287 "rename(3) returned -1 when trying to move symbolic link file",
Wanlong Gao354ebb42012-12-07 10:10:04 +08001288 "outside of current file system, but created",
1289 Y_A_S_FILE);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001290 }
subrata_modak56207ce2009-03-23 13:35:39 +00001291 } else {
1292 tst_resm(TFAIL, "%s %s errno:%d %s",
1293 "Expected EXDEV error for renaming an existing symbolic",
1294 "link file to a location outside of existing file system,",
1295 errno, strerror(errno));
1296 delete_files("/NiCkEr", NULL);
1297 }
1298 } else
Wanlong Gao354ebb42012-12-07 10:10:04 +08001299 tst_resm(TBROK,
1300 "Unknown test case processing actions declared");
plars865695b2001-08-27 22:15:12 +00001301}
1302
1303/***********************************************************************
1304 * This routine checks for the return of ENAMETOOLONG errno from requested
1305 * system call
1306 *
1307 * Argument is pointer to test_objects array of structures of type
1308 * all_test_cases
1309 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -04001310void do_ENAMETOOLONG(struct all_test_cases *tc_ptr)
plars865695b2001-08-27 22:15:12 +00001311{
subrata_modak56207ce2009-03-23 13:35:39 +00001312 int ret;
plars865695b2001-08-27 22:15:12 +00001313
subrata_modak56207ce2009-03-23 13:35:39 +00001314 if (cktcsid(tc_ptr->tcid, SYMLINK)) {
plars865695b2001-08-27 22:15:12 +00001315
subrata_modak56207ce2009-03-23 13:35:39 +00001316 TEST(symlink(tc_ptr->fn_arg[0], full_path));
1317 errno = TEST_ERRNO;
Cyril Hrubise38b9612014-06-02 17:20:57 +02001318 if ((TEST_RETURN == -1) && (errno == ENAMETOOLONG)) {
1319 if (see_if_a_symlink(full_path) == -1) {
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001320 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001321 } else {
subrata_modak56207ce2009-03-23 13:35:39 +00001322 tst_resm(TFAIL, "%s %s %d %s",
1323 "symlink(2) returned -1 when trying to create a symbolic",
1324 "link file whose name exceeded",
1325 (PATH_MAX + 1),
1326 "characters, but it created the symbolic link file");
Cyril Hrubise38b9612014-06-02 17:20:57 +02001327 }
1328 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +08001329 tst_resm(TFAIL | TERRNO,
vapiere5fce932009-08-28 14:17:14 +00001330 "Expected ENAMETOOLONG error when creating %s symbolic link file with a path exceeding %d characters",
1331 tc_ptr->fn_arg[1], (PATH_MAX + 1));
Cyril Hrubise38b9612014-06-02 17:20:57 +02001332 }
subrata_modak56207ce2009-03-23 13:35:39 +00001333 } else if (cktcsid(tc_ptr->tcid, READLINK)) {
plars865695b2001-08-27 22:15:12 +00001334
subrata_modak56207ce2009-03-23 13:35:39 +00001335 char scratch[PATH_MAX + 1];
plars865695b2001-08-27 22:15:12 +00001336
subrata_modak56207ce2009-03-23 13:35:39 +00001337 ret = readlink(full_path, scratch, strlen(full_path));
Cyril Hrubise38b9612014-06-02 17:20:57 +02001338 if ((ret == -1) && (errno == ENAMETOOLONG)) {
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001339 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001340 } else {
subrata_modak56207ce2009-03-23 13:35:39 +00001341 tst_resm(TFAIL,
1342 "Expected ENAMETOOLONG error when reading %s symbolic link file with a path exceeding %d characters: errno:%d %s",
Wanlong Gao354ebb42012-12-07 10:10:04 +08001343 tc_ptr->fn_arg[1], (PATH_MAX + 1), errno,
1344 strerror(errno));
Cyril Hrubise38b9612014-06-02 17:20:57 +02001345 }
subrata_modak56207ce2009-03-23 13:35:39 +00001346 } else
Wanlong Gao354ebb42012-12-07 10:10:04 +08001347 tst_resm(TBROK,
1348 "Unknown test case processing actions declared");
plars865695b2001-08-27 22:15:12 +00001349}
1350
1351/***********************************************************************
1352 * This routine checks for the return of EINVAL errno from requested
1353 * system call
1354 *
1355 * Argument is pointer to test_objects array of structures of type
1356 * all_test_cases
1357 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -04001358void do_EINVAL(struct all_test_cases *tc_ptr)
plars865695b2001-08-27 22:15:12 +00001359{
subrata_modak56207ce2009-03-23 13:35:39 +00001360 if (cktcsid(tc_ptr->tcid, READLINK)) {
1361 TEST(readlink(tc_ptr->fn_arg[0], test_msg, BUFMAX));
1362 errno = TEST_ERRNO;
1363 if (TEST_RETURN == -1) {
1364 if (errno == EINVAL) {
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001365 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001366 } else {
subrata_modak56207ce2009-03-23 13:35:39 +00001367 tst_resm(TFAIL,
1368 "readlink(2) ret:-1, errno:%d, : Exp errno:%d",
1369 errno, EINVAL);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001370 }
subrata_modak56207ce2009-03-23 13:35:39 +00001371 } else {
1372 tst_resm(TFAIL,
1373 "readlink(2) did not returned -1 when reading %s",
1374 "a file which is not a symbolic link file");
1375 }
1376 } else
Wanlong Gao354ebb42012-12-07 10:10:04 +08001377 tst_resm(TBROK,
1378 "Unknown test case processing actions declared");
plars865695b2001-08-27 22:15:12 +00001379}
1380
1381/***********************************************************************
1382 * This routine checks out the readlink(2) system call for a successful
1383 * invocation
1384 *
1385 * Argument is pointer to test_objects array of structures of type
1386 * all_test_cases
1387 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -04001388void do_readlink(struct all_test_cases *tc_ptr)
plars865695b2001-08-27 22:15:12 +00001389{
subrata_modak56207ce2009-03-23 13:35:39 +00001390 char scratch[PATH_MAX];
1391 int ret;
plars865695b2001-08-27 22:15:12 +00001392
subrata_modak56207ce2009-03-23 13:35:39 +00001393 ret = readlink(tc_ptr->fn_arg[1], scratch, strlen(tc_ptr->fn_arg[0]));
plars865695b2001-08-27 22:15:12 +00001394
1395 /*** the TEST macro cannot be used here for some reason ****/
1396
subrata_modak56207ce2009-03-23 13:35:39 +00001397 if (ret == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +08001398 tst_resm(TFAIL, "readlink(2) failure on %s symbolic link file",
1399 tc_ptr->fn_arg[1]);
plars865695b2001-08-27 22:15:12 +00001400
Wanlong Gao354ebb42012-12-07 10:10:04 +08001401 } else
1402 if (strncmp(tc_ptr->fn_arg[0], scratch, strlen(tc_ptr->fn_arg[0]))
1403 != 0) {
plars865695b2001-08-27 22:15:12 +00001404
subrata_modak56207ce2009-03-23 13:35:39 +00001405 /* Must null terminate scratch because readlink(2) doesn't */
plars865695b2001-08-27 22:15:12 +00001406
subrata_modak56207ce2009-03-23 13:35:39 +00001407 scratch[strlen(tc_ptr->fn_arg[0])] = '\0';
subrata_modak4bb656a2009-02-26 12:02:09 +00001408
subrata_modak56207ce2009-03-23 13:35:39 +00001409 tst_resm(TFAIL,
1410 "readlink(2) Error : Expected %s symbolic link file contents but %s actual contents were returned",
1411 tc_ptr->fn_arg[0], scratch);
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001412 } else {
vapiere5fce932009-08-28 14:17:14 +00001413 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001414 }
plars865695b2001-08-27 22:15:12 +00001415}
1416
1417/***********************************************************************
1418 * This routine checks out the stat(2) system call for a successful
1419 * invocation
1420 *
1421 * Argument is pointer to test_objects array of structures of type
1422 * all_test_cases
1423 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -04001424void do_stat(struct all_test_cases *tc_ptr)
plars865695b2001-08-27 22:15:12 +00001425{
subrata_modak56207ce2009-03-23 13:35:39 +00001426 if (statter.st_dev != asymlink.st_dev)
1427 tst_resm(TFAIL,
subrata_modak923b23f2009-11-02 13:57:16 +00001428 "stat of symbolic link reference to object device info %jd != stat of object file device info %jd",
Wanlong Gao354ebb42012-12-07 10:10:04 +08001429 (intmax_t) statter.st_dev, (intmax_t) asymlink.st_dev);
plars865695b2001-08-27 22:15:12 +00001430
subrata_modak56207ce2009-03-23 13:35:39 +00001431 else if (statter.st_mode != asymlink.st_mode)
1432 tst_resm(TFAIL,
subrata_modak923b23f2009-11-02 13:57:16 +00001433 "stat of symbolic link reference to object file permissions %jd != stat of object file permissions %jd",
Wanlong Gao354ebb42012-12-07 10:10:04 +08001434 (intmax_t) statter.st_mode,
1435 (intmax_t) asymlink.st_mode);
plars865695b2001-08-27 22:15:12 +00001436
subrata_modak56207ce2009-03-23 13:35:39 +00001437 else if (statter.st_nlink != asymlink.st_nlink)
1438 tst_resm(TFAIL,
subrata_modak923b23f2009-11-02 13:57:16 +00001439 "stat of symbolic link reference to object file link count %jd != stat of object file link count %jd",
Wanlong Gao354ebb42012-12-07 10:10:04 +08001440 (intmax_t) statter.st_nlink,
1441 (intmax_t) asymlink.st_nlink);
plars865695b2001-08-27 22:15:12 +00001442
subrata_modak56207ce2009-03-23 13:35:39 +00001443 else if (statter.st_uid != asymlink.st_uid)
1444 tst_resm(TFAIL,
subrata_modak923b23f2009-11-02 13:57:16 +00001445 "stat of symbolic link reference to object file uid %jd != stat of object file uid %jd",
Wanlong Gao354ebb42012-12-07 10:10:04 +08001446 (intmax_t) statter.st_uid, (intmax_t) asymlink.st_uid);
plars865695b2001-08-27 22:15:12 +00001447
subrata_modak56207ce2009-03-23 13:35:39 +00001448 else if (statter.st_gid != asymlink.st_gid)
1449 tst_resm(TFAIL,
subrata_modak923b23f2009-11-02 13:57:16 +00001450 "stat of symbolic link reference to object file gid %jd != stat of object file gid %jd",
Wanlong Gao354ebb42012-12-07 10:10:04 +08001451 (intmax_t) statter.st_gid, (intmax_t) asymlink.st_gid);
plars865695b2001-08-27 22:15:12 +00001452
subrata_modak56207ce2009-03-23 13:35:39 +00001453 else if (statter.st_size != asymlink.st_size)
1454 tst_resm(TFAIL,
1455 "stat of symbolic link reference to object file size %ld != stat of object file size %ld",
1456 statter.st_size, asymlink.st_size);
plars865695b2001-08-27 22:15:12 +00001457
subrata_modak56207ce2009-03-23 13:35:39 +00001458 else if (statter.st_atime != asymlink.st_atime)
1459 tst_resm(TFAIL,
1460 "stat of symbolic link reference to object access time %ld != stat of object file access time %ld",
1461 statter.st_atime, asymlink.st_atime);
plars865695b2001-08-27 22:15:12 +00001462
subrata_modak56207ce2009-03-23 13:35:39 +00001463 else if (statter.st_mtime != asymlink.st_mtime)
1464 tst_resm(TFAIL,
1465 "stat of symbolic link reference to object modify time %ld != stat of object file modify time %ld",
1466 statter.st_atime, asymlink.st_atime);
plars865695b2001-08-27 22:15:12 +00001467
subrata_modak56207ce2009-03-23 13:35:39 +00001468 else if (statter.st_ctime != asymlink.st_ctime)
1469 tst_resm(TFAIL,
1470 "stat of symbolic link reference to object change time %ld != stat of object file change time %ld",
1471 statter.st_atime, asymlink.st_atime);
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001472 else
vapiere5fce932009-08-28 14:17:14 +00001473 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
plars865695b2001-08-27 22:15:12 +00001474}
1475
1476/***********************************************************************
1477 * This routine checks out the chdir(2) system call for a successful
1478 * invocation
1479 *
1480 * Argument is pointer to test_objects array of structures of type
1481 * all_test_cases
1482 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -04001483void do_chdir(struct all_test_cases *tc_ptr)
plars865695b2001-08-27 22:15:12 +00001484{
subrata_modak56207ce2009-03-23 13:35:39 +00001485 if (mkdir(tc_ptr->fn_arg[2], MODE) == -1)
1486 tst_resm(TFAIL, "Could not create a setup directory file");
1487 else {
plars865695b2001-08-27 22:15:12 +00001488
Wanlong Gao354ebb42012-12-07 10:10:04 +08001489 sprintf(Buf, "mkdir(%s, %#o) was successful\n",
1490 tc_ptr->fn_arg[2], MODE);
subrata_modak56207ce2009-03-23 13:35:39 +00001491 strcat(Buffer, Buf);
plars865695b2001-08-27 22:15:12 +00001492
subrata_modak56207ce2009-03-23 13:35:39 +00001493 if (chdir(tc_ptr->fn_arg[1]) == -1)
1494 tst_resm(TFAIL,
1495 "%sCould not change a directory file through a %s",
Wanlong Gao354ebb42012-12-07 10:10:04 +08001496 Buffer,
1497 "symbolic link which which pointed at object");
subrata_modak56207ce2009-03-23 13:35:39 +00001498 else {
plars865695b2001-08-27 22:15:12 +00001499
subrata_modak56207ce2009-03-23 13:35:39 +00001500 char *cwd, *getcwd();
1501 char expected_location[PATH_MAX];
1502 /*
1503 * Build expected current directory position
1504 */
Garrett Cooper0ae003b2010-12-19 10:36:32 -08001505 /* FIXME (garrcoop): memory leak */
Cyril Hrubis9c31ad22014-05-14 17:15:39 +02001506 strcpy(expected_location, tst_get_tmpdir());
subrata_modak56207ce2009-03-23 13:35:39 +00001507 strcat(expected_location, "/");
1508 strcat(expected_location, tc_ptr->fn_arg[2]);
plars865695b2001-08-27 22:15:12 +00001509
Cyril Hrubise38b9612014-06-02 17:20:57 +02001510 if ((cwd = getcwd(NULL, 0)) == NULL) {
subrata_modak56207ce2009-03-23 13:35:39 +00001511 tst_resm(TFAIL, "getcwd(3) FAILURE");
Cyril Hrubise38b9612014-06-02 17:20:57 +02001512 } else if (strcmp(cwd, expected_location) == 0) {
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001513 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001514 } else {
subrata_modak56207ce2009-03-23 13:35:39 +00001515 tst_resm(TFAIL,
1516 "%s%s %s %s not equal to expected %s",
1517 Buffer,
1518 "chdir(2) returned successfully, but getcwd(3) indicated",
1519 "new current working directory location",
1520 cwd, expected_location);
1521 }
Garrett Cooper0ae003b2010-12-19 10:36:32 -08001522 /* FIXME (garrcoop): memory leak */
Cyril Hrubis9c31ad22014-05-14 17:15:39 +02001523 chdir(tst_get_tmpdir());
subrata_modak56207ce2009-03-23 13:35:39 +00001524 }
1525 rmdir(tc_ptr->fn_arg[2]);
1526 }
plars865695b2001-08-27 22:15:12 +00001527}
1528
1529/***********************************************************************
1530 * This routine checks out the link(2) system call for a successful
1531 * invocation
1532 *
1533 * Argument is pointer to test_objects array of structures of type
1534 * all_test_cases
1535 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -04001536void do_link(struct all_test_cases *tc_ptr)
plars865695b2001-08-27 22:15:12 +00001537{
subrata_modak56207ce2009-03-23 13:35:39 +00001538 struct stat stbuf;
plars865695b2001-08-27 22:15:12 +00001539
subrata_modak56207ce2009-03-23 13:35:39 +00001540 if (link(tc_ptr->fn_arg[1], "nick") == -1) {
1541 tst_resm(TFAIL, "%slink(%s, \"nick\") failed, errno: %d: %s %s",
1542 Buffer, tc_ptr->fn_arg[1], errno,
1543 "link of new file to object file via symbolic link file failed",
1544 "when expected not to");
1545 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +08001546 sprintf(Buf, "link(%s, \"nick\") was successful\n",
1547 tc_ptr->fn_arg[1]);
subrata_modak56207ce2009-03-23 13:35:39 +00001548 strcat(Buffer, Buf);
plars865695b2001-08-27 22:15:12 +00001549
Cyril Hrubise38b9612014-06-02 17:20:57 +02001550 /*
1551 * Check that links counts were properly set
1552 */
1553 if (lstat(tc_ptr->fn_arg[1], &asymlink) == -1) {
1554 tst_resm(TBROK, "lstat(%s) failed. errno: %d",
1555 tc_ptr->fn_arg[1], errno);
plars865695b2001-08-27 22:15:12 +00001556
Cyril Hrubise38b9612014-06-02 17:20:57 +02001557 } else if (lstat("nick", &statter) == -1) {
1558 tst_resm(TBROK, "lstat(nick) failed, errno:%d",
1559 errno);
1560 } else {
1561 if (statter.st_ino == asymlink.st_ino) {
1562 if ((statter.st_nlink == 2) && (asymlink.st_nlink == 2)) {
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001563 tst_resm(TEST_RESULT, "%s",
1564 msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001565 } else {
Cyril Hrubise38b9612014-06-02 17:20:57 +02001566 lstat(tc_ptr->fn_arg[2],
1567 &stbuf);
1568
1569 tst_resm(TFAIL,
1570 "%slink(%s, %s) failed to adjust link count.\n\
1571 count for nick is %d, count for %s is %d, count for %s is %d.",
1572 Buffer, tc_ptr->fn_arg[1], "nick", statter.st_nlink, tc_ptr->fn_arg[1], asymlink.st_nlink, tc_ptr->fn_arg[2],
1573 stbuf.st_nlink);
subrata_modak56207ce2009-03-23 13:35:39 +00001574 }
Cyril Hrubise38b9612014-06-02 17:20:57 +02001575 } else {
1576 tst_resm(TFAIL, "%sA lstat of %s (ino:%jd) and of\n\t\t\
1577%s (ino:%jd), does not show them being the same ino.", Buffer,
1578 tc_ptr->fn_arg[1], (intmax_t) asymlink.st_ino, "nick", (intmax_t) statter.st_ino);
subrata_modak56207ce2009-03-23 13:35:39 +00001579 }
plars865695b2001-08-27 22:15:12 +00001580 }
Cyril Hrubise38b9612014-06-02 17:20:57 +02001581
subrata_modak56207ce2009-03-23 13:35:39 +00001582 delete_files("nick", NULL);
plars865695b2001-08-27 22:15:12 +00001583 }
plars865695b2001-08-27 22:15:12 +00001584}
1585
1586/***********************************************************************
1587 * This routine checks out the unlink(2) system call for a successful
1588 * invocation
1589 *
1590 * Argument is pointer to test_objects array of structures of type
1591 * all_test_cases
1592 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -04001593void do_unlink(struct all_test_cases *tc_ptr)
plars865695b2001-08-27 22:15:12 +00001594{
subrata_modak56207ce2009-03-23 13:35:39 +00001595 if (stat(tc_ptr->fn_arg[2], &asymlink) == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +08001596 tst_resm(TBROK, "stat(2) Failure when accessing %s object file",
1597 tc_ptr->fn_arg[2]);
subrata_modak56207ce2009-03-23 13:35:39 +00001598 else if (unlink(tc_ptr->fn_arg[1]) == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +08001599 tst_resm(TFAIL,
1600 "unlink(2) failed when removing symbolic link file");
subrata_modak56207ce2009-03-23 13:35:39 +00001601 else {
1602 sprintf(Buf, "unlink(%s) was successful\n", tc_ptr->fn_arg[1]);
1603 strcat(Buffer, Buf);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001604 if (stat(tc_ptr->fn_arg[2], &statter) == -1) {
subrata_modak56207ce2009-03-23 13:35:39 +00001605 tst_resm(TFAIL, "%s %s",
1606 "unlink(2) failed because it not only removed symbolic link",
1607 "file which pointed at object file, but object file as well");
subrata_modakbdbaec52009-02-26 12:14:51 +00001608
Cyril Hrubise38b9612014-06-02 17:20:57 +02001609 } else if ((statter.st_ino == asymlink.st_ino) &&
subrata_modak56207ce2009-03-23 13:35:39 +00001610 (statter.st_dev == asymlink.st_dev) &&
Cyril Hrubise38b9612014-06-02 17:20:57 +02001611 (statter.st_size == asymlink.st_size)) {
plars865695b2001-08-27 22:15:12 +00001612
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001613 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001614 } else {
subrata_modak56207ce2009-03-23 13:35:39 +00001615 tst_resm(TFAIL, "%s%s %s %s", Buffer,
1616 "unlink(2) failed because it not only removed symbolic link",
1617 "file which pointed at object file, but it changed object",
1618 "file inode information");
Cyril Hrubise38b9612014-06-02 17:20:57 +02001619 }
subrata_modak56207ce2009-03-23 13:35:39 +00001620 }
plars865695b2001-08-27 22:15:12 +00001621
1622}
1623
1624/***********************************************************************
1625 * This routine checks out the chmod(2) system call for a successful
1626 * invocation
1627 *
1628 * Argument is pointer to test_objects array of structures of type
1629 * all_test_cases
1630 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -04001631void do_chmod(struct all_test_cases *tc_ptr)
plars865695b2001-08-27 22:15:12 +00001632{
subrata_modak56207ce2009-03-23 13:35:39 +00001633 if (stat(tc_ptr->fn_arg[2], &asymlink) == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +08001634 tst_resm(TBROK, "stat(2) Failure when accessing %s object file",
1635 tc_ptr->fn_arg[2]);
subrata_modak56207ce2009-03-23 13:35:39 +00001636 else if (chmod(tc_ptr->fn_arg[1], (MODE | MASK)) == -1)
1637 tst_resm(TFAIL, "%s%s %s", Buffer,
1638 "chmod(2) failed when changing file permission",
1639 "through symbolic link file");
1640 else {
Wanlong Gao354ebb42012-12-07 10:10:04 +08001641 sprintf(Buf, "chmod(%s, %#o) was successful\n",
1642 tc_ptr->fn_arg[1], (MODE | MASK));
subrata_modak56207ce2009-03-23 13:35:39 +00001643 strcat(Buffer, Buf);
plars865695b2001-08-27 22:15:12 +00001644
Cyril Hrubise38b9612014-06-02 17:20:57 +02001645 if (stat(tc_ptr->fn_arg[2], &statter) == -1) {
subrata_modak56207ce2009-03-23 13:35:39 +00001646 tst_resm(TBROK,
1647 "stat(2) Failure when accessing %s object file",
1648 tc_ptr->fn_arg[2]);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001649 } else if ((statter.st_mode == (MODE | MASK))
1650 && (statter.st_mode != asymlink.st_mode)) {
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001651 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001652 } else {
subrata_modak56207ce2009-03-23 13:35:39 +00001653 tst_resm(TFAIL, "%s%s %o to %o %s", Buffer,
1654 "chmod(2) failed to change object file permissions from",
Wanlong Gao354ebb42012-12-07 10:10:04 +08001655 asymlink.st_mode, (MODE | MASK),
1656 "through symbolic link file");
Cyril Hrubise38b9612014-06-02 17:20:57 +02001657 }
subrata_modak56207ce2009-03-23 13:35:39 +00001658 }
plars865695b2001-08-27 22:15:12 +00001659
1660}
1661
1662/***********************************************************************
1663 * This routine checks out the utime(2) system call for a successful
1664 * invocation
1665 *
1666 * Argument is pointer to test_objects array of structures of type
1667 * all_test_cases
1668 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -04001669void do_utime(struct all_test_cases *tc_ptr)
plars865695b2001-08-27 22:15:12 +00001670{
subrata_modak56207ce2009-03-23 13:35:39 +00001671 struct utimbuf utimes;
plars865695b2001-08-27 22:15:12 +00001672
subrata_modak56207ce2009-03-23 13:35:39 +00001673 if (stat(tc_ptr->fn_arg[2], &asymlink) == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +08001674 tst_resm(TBROK, "stat(2) Failure when accessing %s object file",
1675 tc_ptr->fn_arg[2]);
subrata_modak56207ce2009-03-23 13:35:39 +00001676 else {
1677 /* Now add a few values to access and modify times */
plars865695b2001-08-27 22:15:12 +00001678
subrata_modak56207ce2009-03-23 13:35:39 +00001679 utimes.actime = asymlink.st_atime + a_time_value;
1680 utimes.modtime = asymlink.st_mtime + a_time_value;
plars865695b2001-08-27 22:15:12 +00001681
subrata_modak56207ce2009-03-23 13:35:39 +00001682 /* Now hand off to utime(2) via symbolic link file */
plars865695b2001-08-27 22:15:12 +00001683
subrata_modak56207ce2009-03-23 13:35:39 +00001684 if (utime(tc_ptr->fn_arg[1], &utimes) == -1)
1685 tst_resm(TFAIL, "%s %s",
1686 "utime(2) failed to process object file access and modify",
1687 "time updates through symbolic link");
1688 else {
1689 /* Now verify changes were made */
plars865695b2001-08-27 22:15:12 +00001690
subrata_modak56207ce2009-03-23 13:35:39 +00001691 if (stat(tc_ptr->fn_arg[2], &statter) == -1)
1692 tst_resm(TBROK,
1693 "stat(2) Failure when accessing %s object file",
1694 tc_ptr->fn_arg[2]);
1695 else {
1696 time_t temp, diff;
plars865695b2001-08-27 22:15:12 +00001697
subrata_modak56207ce2009-03-23 13:35:39 +00001698 temp = statter.st_atime - asymlink.st_atime;
Wanlong Gao354ebb42012-12-07 10:10:04 +08001699 diff =
1700 (statter.st_mtime - asymlink.st_mtime) -
1701 temp;
subrata_modak56207ce2009-03-23 13:35:39 +00001702
Cyril Hrubise38b9612014-06-02 17:20:57 +02001703 if (!diff) {
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001704 tst_resm(TEST_RESULT, "%s",
1705 msgs[tc_ptr->pass_msg]);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001706 } else {
subrata_modak56207ce2009-03-23 13:35:39 +00001707 tst_resm(TFAIL,
subrata_modak923b23f2009-11-02 13:57:16 +00001708 "%s %s %jd greater than original times",
subrata_modak56207ce2009-03-23 13:35:39 +00001709 "utime(2) failed to change object file access and",
1710 "modify times through symbolic link to a value",
Wanlong Gao354ebb42012-12-07 10:10:04 +08001711 (intmax_t) a_time_value);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001712 }
subrata_modak56207ce2009-03-23 13:35:39 +00001713 }
1714 }
1715 }
plars865695b2001-08-27 22:15:12 +00001716}
1717
1718/***********************************************************************
1719 * This routine checks out the rename(2) system call for a successful
1720 * invocation
1721 *
1722 * Argument is pointer to test_objects array of structures of type
1723 * all_test_cases
1724 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -04001725void do_rename(struct all_test_cases *tc_ptr)
plars865695b2001-08-27 22:15:12 +00001726{
subrata_modak56207ce2009-03-23 13:35:39 +00001727 int pts_at_object = 0;
plars865695b2001-08-27 22:15:12 +00001728
subrata_modak56207ce2009-03-23 13:35:39 +00001729 if (stat(tc_ptr->fn_arg[2], &statter) != -1)
1730 pts_at_object = 1;
plars865695b2001-08-27 22:15:12 +00001731
subrata_modak56207ce2009-03-23 13:35:39 +00001732 TEST(rename(tc_ptr->fn_arg[1], A_S_FILE));
1733 errno = TEST_ERRNO;
Cyril Hrubise38b9612014-06-02 17:20:57 +02001734 if (TEST_RETURN == -1) {
subrata_modak56207ce2009-03-23 13:35:39 +00001735 tst_resm(TFAIL,
1736 "rename(3) failed to rename %s symbolic link file to %s",
1737 tc_ptr->fn_arg[2], A_S_FILE);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001738 } else if (pts_at_object) {
1739 if (ck_both(tc_ptr->fn_arg[0], A_S_FILE, tc_ptr->fn_arg[2])) {
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001740 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001741 } else {
vapiere5fce932009-08-28 14:17:14 +00001742 tst_resm(TFAIL, "%s", test_msg);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001743 }
1744 } else if (!ck_symlink(tc_ptr->fn_arg[0], A_S_FILE, NULL)) {
vapiere5fce932009-08-28 14:17:14 +00001745 tst_resm(TFAIL, "%s", test_msg);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001746 } else if (stat(tc_ptr->fn_arg[1], &asymlink) != -1) {
subrata_modak56207ce2009-03-23 13:35:39 +00001747 tst_resm(TFAIL,
1748 "rename(3) did not remove %s when renaming to %s",
1749 tc_ptr->fn_arg[1], A_S_FILE);
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001750 } else {
vapiere5fce932009-08-28 14:17:14 +00001751 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001752 }
plars865695b2001-08-27 22:15:12 +00001753}
1754
1755/***********************************************************************
1756 * This routine checks out the open(2) system call for a successful
1757 * invocation
1758 *
1759 * Argument is pointer to test_objects array of structures of type
1760 * all_test_cases
1761 ***********************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -04001762void do_open(struct all_test_cases *tc_ptr)
plars865695b2001-08-27 22:15:12 +00001763{
subrata_modak56207ce2009-03-23 13:35:39 +00001764 int fd = -1;
1765 int ret, pts_at_object = 0;
1766 char scratch[PATH_MAX];
plars865695b2001-08-27 22:15:12 +00001767
subrata_modak56207ce2009-03-23 13:35:39 +00001768 if (stat(tc_ptr->fn_arg[2], &statter) != -1)
1769 pts_at_object = 1;
plars865695b2001-08-27 22:15:12 +00001770
subrata_modak56207ce2009-03-23 13:35:39 +00001771 if (pts_at_object) {
1772 TEST(open(tc_ptr->fn_arg[1], O_RDWR));
1773 errno = TEST_ERRNO;
1774 if ((fd = TEST_RETURN) == -1) {
1775 tst_resm(TFAIL,
1776 "open(2) Failure when opening object file through symbolic link file");
1777 return;
1778 }
1779 } else {
1780 TEST(open(tc_ptr->fn_arg[1], (O_CREAT | O_RDWR), MODE));
1781 errno = TEST_ERRNO;
1782 if ((fd = TEST_RETURN) == -1) {
1783 tst_resm(TFAIL,
1784 "open(2) Failure when creating object file through symbolic link file");
1785 return;
1786 }
1787 }
1788 if ((ret = write(fd, BIG_STRING, strlen(BIG_STRING))) == -1) {
1789 tst_resm(TFAIL,
1790 "write(2) Failure to object file opened through a symbolic link file: errno:%d",
1791 errno);
1792 } else if (ret != strlen(BIG_STRING)) {
1793 tst_resm(TFAIL,
vapiere5fce932009-08-28 14:17:14 +00001794 "write(2) Failed to write %zu bytes to object file opened through a symbolic link file",
subrata_modak56207ce2009-03-23 13:35:39 +00001795 strlen(BIG_STRING));
1796 } else if (lseek(fd, 0L, 0) == -1) {
1797 tst_resm(TFAIL,
1798 "lseek(2) Failed to position to beginning of object file opened through a symbolic link file: errno = %d",
1799 errno);
1800 } else if ((ret = read(fd, scratch, strlen(BIG_STRING))) == -1) {
1801 tst_resm(TFAIL,
1802 "read(2) Failure of object file opened through a symbolic link file: errno = %d",
1803 errno);
1804 } else if (ret != strlen(BIG_STRING)) {
1805 tst_resm(TFAIL,
vapiere5fce932009-08-28 14:17:14 +00001806 "read(2) Failed to read %zu bytes to object file opened through a symbolic link file",
subrata_modak56207ce2009-03-23 13:35:39 +00001807 strlen(BIG_STRING));
1808 } else if (strncmp(BIG_STRING, scratch, strlen(BIG_STRING)) != 0) {
1809 tst_resm(TFAIL,
1810 "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",
1811 BIG_STRING, scratch);
1812 } else {
1813 /*
1814 * Close off symbolic link file to object file access
1815 */
1816 if (close(fd) == -1) {
1817 tst_resm(TFAIL,
1818 "close(2) Failure when closing object file accessed symbolic link file");
1819 }
1820 /*
1821 * Now, lets open up and read object file and compare contents
1822 */
1823 else if ((fd = open(tc_ptr->fn_arg[0], O_RDONLY)) == -1) {
1824 tst_resm(TFAIL,
1825 "open(2) Failure when opening %s file: errno:%d %s",
1826 tc_ptr->fn_arg[0], errno, strerror(errno));
1827 } else if ((ret = read(fd, scratch, strlen(BIG_STRING))) == -1) {
1828 tst_resm(TFAIL,
1829 "read(2) Failure of object file opened through a symbolic link file: errno:%d",
1830 errno);
1831 } else if (ret != strlen(BIG_STRING)) {
1832 tst_resm(TFAIL,
vapiere5fce932009-08-28 14:17:14 +00001833 "read(2) Failed to read %zu bytes to object file opened through a symbolic link file",
subrata_modak56207ce2009-03-23 13:35:39 +00001834 strlen(BIG_STRING));
Wanlong Gao354ebb42012-12-07 10:10:04 +08001835 } else if (strncmp(BIG_STRING, scratch, strlen(BIG_STRING)) !=
1836 0) {
subrata_modak56207ce2009-03-23 13:35:39 +00001837 tst_resm(TFAIL,
1838 "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",
1839 BIG_STRING, scratch);
1840 } else if (pts_at_object) {
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001841 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001842 } else { /* Insure newly created object file is pointed at */
Wanlong Gao354ebb42012-12-07 10:10:04 +08001843 if (ck_both
1844 (tc_ptr->fn_arg[0], tc_ptr->fn_arg[1],
Cyril Hrubise38b9612014-06-02 17:20:57 +02001845 tc_ptr->fn_arg[0])) {
Cyril Hrubis563a8b72014-06-10 16:10:10 +02001846 tst_resm(TEST_RESULT, "%s",
1847 msgs[tc_ptr->pass_msg]);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001848 } else {
vapiere5fce932009-08-28 14:17:14 +00001849 tst_resm(TFAIL, "%s", test_msg);
Cyril Hrubise38b9612014-06-02 17:20:57 +02001850 }
subrata_modak56207ce2009-03-23 13:35:39 +00001851 }
1852 close(fd);
1853 }
plars865695b2001-08-27 22:15:12 +00001854}
1855
1856/***************************************************************
1857 * setup() - performs all ONE TIME setup for this test.
1858 ***************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -04001859void setup(void)
plars865695b2001-08-27 22:15:12 +00001860{
Garrett Cooper2c282152010-12-16 00:55:50 -08001861
subrata_modak56207ce2009-03-23 13:35:39 +00001862 tst_sig(FORK, DEF_HANDLER, cleanup);
plars865695b2001-08-27 22:15:12 +00001863
subrata_modak56207ce2009-03-23 13:35:39 +00001864 TEST_PAUSE;
plars865695b2001-08-27 22:15:12 +00001865
subrata_modak56207ce2009-03-23 13:35:39 +00001866 /* create a temporary directory and go to it */
1867 tst_tmpdir();
plars865695b2001-08-27 22:15:12 +00001868
Garrett Cooper2c282152010-12-16 00:55:50 -08001869}
plars865695b2001-08-27 22:15:12 +00001870
1871/***************************************************************
1872 * cleanup() - performs all ONE TIME cleanup for this test at
1873 * completion or premature exit.
1874 ***************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -04001875void cleanup(void)
plars865695b2001-08-27 22:15:12 +00001876{
plars865695b2001-08-27 22:15:12 +00001877
subrata_modak56207ce2009-03-23 13:35:39 +00001878 tst_rmdir();
plars865695b2001-08-27 22:15:12 +00001879
Garrett Cooper2c282152010-12-16 00:55:50 -08001880}
plars865695b2001-08-27 22:15:12 +00001881
Mike Frysingerc57fba52014-04-09 18:56:30 -04001882void help(void)
plars865695b2001-08-27 22:15:12 +00001883{
subrata_modak56207ce2009-03-23 13:35:39 +00001884 int ind;
plars865695b2001-08-27 22:15:12 +00001885
subrata_modak56207ce2009-03-23 13:35:39 +00001886 printf(" -T id Determines which tests cases to execute:\n");
plars865695b2001-08-27 22:15:12 +00001887
subrata_modak56207ce2009-03-23 13:35:39 +00001888 for (ind = 0; ind < sizeof(all_tcses) / sizeof(struct tcses); ind++) {
1889 printf(" %s/%s - %s\n", all_tcses[ind].tcid,
1890 all_tcses[ind].syscall, all_tcses[ind].desc);
1891 }
Garrett Cooper0ae003b2010-12-19 10:36:32 -08001892}