blob: 34f4a0342ecd3dd445b083586b6dd5af8afd0538 [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
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, 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"
219#include "usctest.h"
220
221void setup();
222void cleanup();
223void help();
224void delete_files();
225void do_EEXIST();
226void do_ENOENT();
227void do_ELOOP();
228void do_ENOTDIR();
229void do_EXDEV();
230void do_ENAMETOOLONG();
231void do_EINVAL();
232void do_readlink();
233void do_stat();
234void do_chdir();
235void do_link();
236void do_unlink();
237void do_chmod();
238void do_utime();
239void do_rename();
240void do_open();
241
subrata_modak56207ce2009-03-23 13:35:39 +0000242#define S_FILE "symbolic" /* Name of symbolic link file */
243#define O_FILE "object" /* Name of object file */
244#define A_S_FILE "asymbolic" /* Another name for a symbolic link file */
245#define Y_A_S_FILE "/NiCkEr" /* Yet another symbolic link file */
plars865695b2001-08-27 22:15:12 +0000246#define BIG_STRING "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
247
248#define DEFAULT_TCID "symlink01"
249
250#define SYMLINK "symlink01"
251#define READLINK "readlink01"
252#define STAT "stat04"
subrata_modakcc378eb2008-12-18 05:46:04 +0000253#define STAT_64 "stat04_64"
plars865695b2001-08-27 22:15:12 +0000254#define LSTAT "lstat01"
subrata_modakcc378eb2008-12-18 05:46:04 +0000255#define LSTAT_64 "lstat01_64"
plars865695b2001-08-27 22:15:12 +0000256#define MKDIR "mkdir05"
257#define RMDIR "rmdir03"
258#define CHDIR "chdir01"
259#define LINK "link01"
260#define UNLINK "unlink01"
261#define CHMOD "chmod01"
262#define UTIME "utime01"
263#define RENAME "rename01"
264#define OPEN "open01"
265
266#define cktcsid(s1,s2) (!strcmp(s1,s2))
267#define BUFMAX 512
268#define MODE 0700
subrata_modak56207ce2009-03-23 13:35:39 +0000269#define MASK 0100777 /* A regular file with r,w,x for all mask */
plars865695b2001-08-27 22:15:12 +0000270
271/*
272 * Lets be optimistic and only define messages for passing test cases
273 */
274char *msgs[] = {
subrata_modak56207ce2009-03-23 13:35:39 +0000275 "Creation of symbolic link file to no object file is ok",
276 "Creation of symbolic link file and object file via symbolic link is ok",
277 "Creating an existing symbolic link file error is caught",
278 "Creating a symbolic link which exceeds maximum pathname error is caught",
279 "Reading of symbolic link file contents checks out ok",
280 "Reading a symbolic link which exceeds maximum pathname error is caught",
281 "Getting stat info about object file through symbolic link file is ok",
282 "Stat(2) error when accessing non-existent object through symbolic link is caught",
283 "lstat(2) of symbolic link file which points to no object file is ok",
284 "lstat(2) of symbolic link file which points at an object file is ok",
285 "mkdir(2) of object file through symbolic link file failed as expected",
286 "rmdir(2) of object file through symbolic link file failed as expected",
287 "chdir(2) to object file location through symbolic link file is ok",
288 "chdir(2) to non-existent object file location through symbolic link file failed as expected",
289 "link(2) to a symbolic link, which is pointing to an existing object file worked - file created and link count adjusted",
290 "link(2) to a symbolic link, which is pointing to a non-existing object file worked ok - file created and link count adjusted.",
291 "unlink(2) of symbolic link file with no object file removal is ok",
292 "chmod(2) of object file permissions through symbolic link file is ok",
293 "chmod(2) error when accessing non-existent object through symbolic link is caught",
294 "utime(2) change of object file access and modify times through symbolic link file is ok",
295 "utime(2) error when accessing non-existent object through symbolic link is caught",
296 "rename(3) of symbolic link file name which points at no object file is ok",
297 "rename(3) of symbolic link file name which points at object file is ok",
298 "rename(3) error of symbolic link file name across file systems is caught",
299 "open(2) with (O_CREAT | O_RDWR) to create object file through symbolic link file and all writes, reads, and lseeks are ok",
300 "open(2) with O_RDWR of existing object file through symbolic link file and all writes, reads, and lseeks are ok",
301 "open(2) with (O_CREAT | O_EXCL) error is caught when creating object file through symbolic link file",
302 "open(2) error with O_RDWR is caught when processing symbolic link file which points at no object file",
303 "Nested symbolic link access condition caught. ELOOP is returned",
304 "Reading a nonsymbolic link file error condition is caught. EINVAL is returned",
305 "lstat(2) of object file returns object file inode information",
306 "NULL"
plars865695b2001-08-27 22:15:12 +0000307};
308
309/*
310 * Define test object setup and validation functions
311 */
312int creat_both(), creat_symlink(), creat_path_max(), ck_symlink(),
subrata_modak56207ce2009-03-23 13:35:39 +0000313creat_object(), ck_object(), ck_both(), ck_path_max();
plars865695b2001-08-27 22:15:12 +0000314
315/*
316 * Define test cases
317 */
subrata_modak56207ce2009-03-23 13:35:39 +0000318struct all_test_cases {
319 char *tcid;
320 int test_fail;
321 int errno_val;
322 int pass_msg;
323 int (*test_setup) ();
324 int (*ck_test) ();
325 char *fn_arg[3];
326
plars865695b2001-08-27 22:15:12 +0000327} test_objects[] = {
subrata_modak56207ce2009-03-23 13:35:39 +0000328 {
329 SYMLINK, 0, 0, 0, creat_symlink, ck_symlink, { "%bc+eFhi!k", S_FILE, NULL}}, {
330 SYMLINK, 0, 0, 0, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, {
331 SYMLINK, 0, 0, 1, creat_both, ck_both, { O_FILE, S_FILE, O_FILE}}, {
332 SYMLINK, 1, EEXIST, 2, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, {
333 SYMLINK, 1, ENAMETOOLONG, 3, creat_path_max, ck_path_max, { O_FILE, S_FILE, NULL}}, {
334 READLINK, 0, 0, 4, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, {
335 READLINK, 0, 0, 4, creat_both, ck_both, { O_FILE, S_FILE, O_FILE}}, {
336 READLINK, 1, ENAMETOOLONG, 5, creat_path_max, ck_path_max, { O_FILE, S_FILE, NULL}}, {
337 READLINK, 1, EINVAL, 29, creat_object, ck_object, { O_FILE, NULL, NULL}}, {
338 STAT, 0, 0, 6, creat_both, ck_both, { O_FILE, S_FILE, O_FILE}},
339 /* 10 */
340 {
341 STAT, 1, ENOENT, 7, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, {
342 STAT, 1, ELOOP, 28, creat_symlink, ck_symlink, { S_FILE, S_FILE, NULL}}, {
343 STAT_64, 0, 0, 6, creat_both, ck_both, { O_FILE, S_FILE, O_FILE}}, {
344 STAT_64, 1, ENOENT, 7, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, {
345 STAT_64, 1, ELOOP, 28, creat_symlink, ck_symlink, { S_FILE, S_FILE, NULL}}, {
346 LSTAT, 0, 0, 8, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, {
347 LSTAT, 0, 0, 9, creat_both, ck_both, { O_FILE, S_FILE, O_FILE}}, {
348 LSTAT, 0, 0, 30, creat_object, ck_object, { O_FILE, NULL, NULL}}, {
349 LSTAT_64, 0, 0, 8, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, {
350 LSTAT_64, 0, 0, 9, creat_both, ck_both, { O_FILE, S_FILE, O_FILE}},
351 /* 20 */
352 {
353 LSTAT_64, 0, 0, 30, creat_object, ck_object, { O_FILE, NULL, NULL}}, {
354 MKDIR, 1, EEXIST, 10, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, {
355 RMDIR, 1, ENOTDIR, 11, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, {
356 CHDIR, 0, 0, 12, creat_symlink, ck_symlink, { O_FILE, S_FILE, O_FILE}}, {
357 CHDIR, 1, ENOENT, 13, creat_symlink, ck_symlink, { "%bc+eFhi!k", S_FILE, NULL}}, {
358 CHDIR, 1, ELOOP, 28, creat_symlink, ck_symlink, { S_FILE, S_FILE, NULL}}, {
359 LINK, 0, 0, 14, creat_both, ck_both, { O_FILE, S_FILE, O_FILE}}, {
360 LINK, 0, 0, 15, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}},
361 /* The following link test case is invalid - leaving it defined so */
362 /* I don't have to change all the entries in the all_tcses array after link */
363 /* It has been disabled at the moment. */
364 {
365 LINK, 1, -1, -1, creat_symlink, ck_symlink, { NULL, NULL, NULL}}, {
366 UNLINK, 0, 0, 16, creat_both, ck_both, { O_FILE, S_FILE, O_FILE}},
367 /* 30 */
368 {
369 CHMOD, 0, 0, 17, creat_both, ck_both, { O_FILE, S_FILE, O_FILE}}, {
370 CHMOD, 1, ENOENT, 18, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, {
371 CHMOD, 1, ELOOP, 28, creat_symlink, ck_symlink, { S_FILE, S_FILE, NULL}}, {
372 UTIME, 0, 0, 19, creat_both, ck_both, { O_FILE, S_FILE, O_FILE}}, {
373 UTIME, 1, ENOENT, 20, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, {
374 UTIME, 1, ELOOP, 28, creat_symlink, ck_symlink, { S_FILE, S_FILE, NULL}}, {
375 RENAME, 0, 0, 21, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, {
376 RENAME, 0, 0, 22, creat_both, ck_both, { O_FILE, S_FILE, O_FILE}},
377 /* The following rename test makes assumption that the link and target */
378 /* files are located in different filesystems, which is incorrect. */
379 /* It has been disabled at the moment. */
380 {
381 RENAME, 1, EXDEV, 23, creat_both, ck_both, { O_FILE, S_FILE, O_FILE}}, {
382 OPEN, 0, 0, 24, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}},
383 /* 40 */
384 {
385 OPEN, 0, 0, 25, creat_both, ck_both, { O_FILE, S_FILE, O_FILE}}, {
386 OPEN, 1, EEXIST, 26, creat_symlink, ck_symlink, { O_FILE, S_FILE, O_FILE}}, {
387 OPEN, 1, ENOENT, 27, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, {
388 OPEN, 1, ELOOP, 28, creat_symlink, ck_symlink, { S_FILE, S_FILE, NULL}}
plars865695b2001-08-27 22:15:12 +0000389};
390
391/*
392 * Define tcses
393 */
subrata_modak56207ce2009-03-23 13:35:39 +0000394struct tcses {
395 char *tcid;
396 char *syscall;
397 int test_cases; /* number of entries in test_objects array */
398 struct all_test_cases *tc_ptr;
399 char *desc;
plars865695b2001-08-27 22:15:12 +0000400} all_tcses[] = {
401
subrata_modak56207ce2009-03-23 13:35:39 +0000402 {
403 SYMLINK, "symlink", 5, &test_objects[0], "Make a Symbolic Link to a File"}, {
404 READLINK, "readlink", 4, &test_objects[5], "Reads Value of a Symbolic Link"}, {
405 STAT, "stat", 3, &test_objects[9],
406 "Gets File Status Indirectly From a Symbolic Link file"}, {
407 STAT_64, "stat64", 3, &test_objects[12],
408 "Gets File Status Indirectly From a Symbolic Link file"}, {
409 LSTAT, "lstat", 3, &test_objects[15], "Get file Status About a Symbolic Link File"}, {
410 LSTAT_64, "lstat64", 3, &test_objects[18],
411 "Get file Status About a Symbolic Link File"}, {
412 MKDIR, "mkdir", 1, &test_objects[21],
413 "Fail When Making a Directory File Indirectly from a symlink"}, {
414 RMDIR, "rmdir", 1, &test_objects[22],
415 "Fail When Removing a Directory File Indirectly from a symlink"}, {
416 CHDIR, "chdir", 3, &test_objects[23],
417 "Changes CWD Location Indirectly from a symlink"}, {
418 LINK, "link", 2, &test_objects[26],
419 "Creates a Link To a File Indirectly From a Symbolic"}, {
420 UNLINK, "unlink", 1, &test_objects[29],
421 "Removes a Link To a File but not the Object File"}, {
422 CHMOD, "chmod", 3, &test_objects[30],
423 "Change Object File Permissions Indirectly From a Symbolic"}, {
424 UTIME, "utime", 3, &test_objects[33],
425 "Set File Access And Modify Object File Times via symlink"}, {
426 RENAME, "rename", 2, &test_objects[36],
427 "Rename a Symbolic Link File And Not Any Object file"}, {
428OPEN, "open", 5, &test_objects[39],
429 "Create/Open a File For Reading Or Writing via symlink"},};
plars865695b2001-08-27 22:15:12 +0000430
431/*
432 * Define GLOBAL variables
433 */
434
435int TST_TOTAL;
436int TEST_RESULT;
437time_t a_time_value = 100;
subrata_modak56207ce2009-03-23 13:35:39 +0000438char *TCID;
439char *Selectedtests = NULL; /* Name (tcid) of selected test cases */
plars865695b2001-08-27 22:15:12 +0000440char test_msg[BUFMAX];
subrata_modak56207ce2009-03-23 13:35:39 +0000441char 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 +0000442extern int Tst_count;
443extern char *TESTDIR;
mridgef7298c72005-12-05 19:14:37 +0000444/*extern char *strrchr();*/
plars865695b2001-08-27 22:15:12 +0000445
446struct stat asymlink, statter;
447char Buffer[1024];
448char Buf[1024];
449
450char *Tcid = NULL;
451
452option_t Options[] = {
subrata_modak56207ce2009-03-23 13:35:39 +0000453 {"T:", NULL, &Tcid}, /* -T tcid option */
454 {NULL, NULL, NULL}
plars865695b2001-08-27 22:15:12 +0000455};
456
457/***********************************************************************
458 * MAIN
459 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000460int main(int argc, char *argv[])
plars865695b2001-08-27 22:15:12 +0000461{
subrata_modak56207ce2009-03-23 13:35:39 +0000462 struct tcses *tcs_ptr, *get_tcs_info();
463 int do_syscalltests();
464 void cleanup();
465 int lc; /* loop counter */
466 char *msg; /* message returned from parse_opts */
plars865695b2001-08-27 22:15:12 +0000467
468 /***************************************************************
469 * parse standard options, and exit if there is an error
470 ***************************************************************/
Garrett Cooper45e285d2010-11-22 12:19:25 -0800471 if ((msg = parse_opts(argc, argv, Options, &help)) != NULL) {
subrata_modak56207ce2009-03-23 13:35:39 +0000472 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Cooper2c282152010-12-16 00:55:50 -0800473
subrata_modak56207ce2009-03-23 13:35:39 +0000474 }
plars865695b2001-08-27 22:15:12 +0000475
subrata_modak56207ce2009-03-23 13:35:39 +0000476 /*
477 * If the -T option was used, use that TCID or use the default
478 */
479 if (Tcid != NULL) {
480 TCID = Tcid;
481 Selectedtests = Tcid;
plars865695b2001-08-27 22:15:12 +0000482
subrata_modak56207ce2009-03-23 13:35:39 +0000483 }
plars865695b2001-08-27 22:15:12 +0000484#ifndef ALL
subrata_modak56207ce2009-03-23 13:35:39 +0000485 else {
486 TCID = DEFAULT_TCID;
487 Selectedtests = DEFAULT_TCID;
488 }
plars865695b2001-08-27 22:15:12 +0000489#endif
490
subrata_modak56207ce2009-03-23 13:35:39 +0000491 /*
492 * Get test case specification information and assign TST_TOTAL
493 */
494 if ((tcs_ptr = get_tcs_info(Selectedtests)) == NULL) {
495 TST_TOTAL = 1;
496 tst_brkm(TBROK, cleanup, "Unknown symbolic link test case specification executed");
497 }
plars865695b2001-08-27 22:15:12 +0000498
499 /***************************************************************
500 * perform global setup for test
501 ***************************************************************/
502
subrata_modak56207ce2009-03-23 13:35:39 +0000503 setup();
plars865695b2001-08-27 22:15:12 +0000504
505 /***************************************************************
506 * check looping state if -c option given
507 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000508 for (lc = 0; TEST_LOOPING(lc); lc++) {
plars865695b2001-08-27 22:15:12 +0000509
subrata_modak56207ce2009-03-23 13:35:39 +0000510 Tst_count = 0;
plars865695b2001-08-27 22:15:12 +0000511
subrata_modak56207ce2009-03-23 13:35:39 +0000512 /*
513 * Execute tcs testing function and all defined test cases
514 */
515 do_syscalltests(tcs_ptr);
plars865695b2001-08-27 22:15:12 +0000516
Garrett Cooper2c282152010-12-16 00:55:50 -0800517 }
plars865695b2001-08-27 22:15:12 +0000518
subrata_modak56207ce2009-03-23 13:35:39 +0000519 /*
520 * End appropriately
521 */
522 cleanup();
plars865695b2001-08-27 22:15:12 +0000523
plars865695b2001-08-27 22:15:12 +0000524}
525
526/***********************************************************************
527 * This function maps the name of the process to a test case specification
528 * defined in the all_tcses array of tcses structures. Either a pointer
529 * to the mapped test case specification information is returned or a
530 * null pointer.
531 *
532 * Argument is path to program name.
533 ***********************************************************************/
534struct tcses *get_tcs_info(ptr)
535char *ptr;
536{
subrata_modak56207ce2009-03-23 13:35:39 +0000537 int ctr;
538 struct tcses *tcs_ptr;
plars865695b2001-08-27 22:15:12 +0000539
540#if ALL
subrata_modak56207ce2009-03-23 13:35:39 +0000541 if (ptr == NULL) {
plars865695b2001-08-27 22:15:12 +0000542
subrata_modak56207ce2009-03-23 13:35:39 +0000543 TST_TOTAL = 0;
544 for (ctr = 1; ctr < sizeof(all_tcses) / sizeof(struct tcses); ctr++)
545 TST_TOTAL += all_tcses[ctr].test_cases;
546 return all_tcses;
547 }
plars865695b2001-08-27 22:15:12 +0000548#endif
549
subrata_modak56207ce2009-03-23 13:35:39 +0000550 for (ctr = 0; ctr < (sizeof(all_tcses) / sizeof(struct tcses)); ctr++) {
551 if (strcmp(ptr, all_tcses[ctr].tcid) == 0 ||
552 strcmp(ptr, all_tcses[ctr].syscall) == 0) {
553 tcs_ptr = &all_tcses[ctr];
554 TCID = all_tcses[ctr].tcid;
555 TST_TOTAL = tcs_ptr->test_cases;
556 return (tcs_ptr);
557 }
558
559 }
560 return NULL;
plars865695b2001-08-27 22:15:12 +0000561}
562
563/***********************************************************************
564 * Determines if what path points at is a symbolic link file
565 *
566 * Argument is path to symbolic link file.
567 *
568 * Return status is one if a symbolic link file. Zero if not a symbolic
569 * link file and a minus one if the path doesn't point at a file.
570 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000571int see_if_a_symlink(path)
plars865695b2001-08-27 22:15:12 +0000572char *path;
573{
subrata_modak56207ce2009-03-23 13:35:39 +0000574 if (lstat(path, &asymlink) < 0)
575 return (-1);
plars865695b2001-08-27 22:15:12 +0000576
subrata_modak56207ce2009-03-23 13:35:39 +0000577 if ((asymlink.st_mode & S_IFMT) == S_IFLNK)
578 return 1;
579 else
580 return 0;
plars865695b2001-08-27 22:15:12 +0000581}
582
583/***********************************************************************
584 * This function performs without any hesitation, file(s) deletions
585 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000586void delete_files(path1, path2)
plars865695b2001-08-27 22:15:12 +0000587char *path1, *path2;
588{
subrata_modak56207ce2009-03-23 13:35:39 +0000589 unlink(path1);
590 unlink(path2);
plars865695b2001-08-27 22:15:12 +0000591}
592
593/***********************************************************************
594 *
595 * This routine creates a symbolic link file.
596 *
597 * Argument one is symbolic link pathname to point at.
598 * Argument two is name of symbolic link file.
599 *
600 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000601int creat_symlink(path1, path2)
plars865695b2001-08-27 22:15:12 +0000602char *path1, *path2;
603{
subrata_modak56207ce2009-03-23 13:35:39 +0000604 TEST(symlink(path1, path2));
605 errno = TEST_ERRNO;
606 if (TEST_RETURN == -1) {
607 TEST_RESULT = TBROK;
608 sprintf(test_msg,
609 "symlink(2) Failure when creating setup %s object file: errno:%d %s",
610 path1, errno, strerror(errno));
611 return 0;
612 } else {
613 sprintf(Buf, "symlink(%s, %s) was succesful.\n", path1, path2);
614 strcat(Buffer, Buf);
plars865695b2001-08-27 22:15:12 +0000615#if DEBUG
subrata_modak56207ce2009-03-23 13:35:39 +0000616 tst_resm(TPASS, "symlink(%s, %s) was succesful.", path1, path2);
plars865695b2001-08-27 22:15:12 +0000617#endif
subrata_modak56207ce2009-03-23 13:35:39 +0000618 }
619 return 1;
plars865695b2001-08-27 22:15:12 +0000620}
621
622/***********************************************************************
623 *
624 * This routine creates a regular file.
625 *
626 * Argument one is a pathname
627 *
628 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000629int creat_object(path1)
plars865695b2001-08-27 22:15:12 +0000630char *path1;
631{
subrata_modak56207ce2009-03-23 13:35:39 +0000632 int fd;
633 if ((fd = creat(path1, MODE)) == -1) {
634 TEST_RESULT = TBROK;
635 sprintf(test_msg,
636 "creat(2) Failure when creating setup %s object file: errno:%d %s",
637 path1, errno, strerror(errno));
638 return 0;
639 } else {
640 sprintf(Buf, "creat(%s, %#o) was succesful.\n", path1, MODE);
641 strcat(Buffer, Buf);
plars865695b2001-08-27 22:15:12 +0000642#if DEBUG
subrata_modak56207ce2009-03-23 13:35:39 +0000643 tst_resm(TPASS, "creat(%s, %#o) was succesful.", path1, MODE);
plars865695b2001-08-27 22:15:12 +0000644#endif
subrata_modak56207ce2009-03-23 13:35:39 +0000645 }
646 if (close(fd) == -1) {
647 TEST_RESULT = TBROK;
648 sprintf(test_msg,
649 "close(2) Failure when closing setup %s object file: errno:%d %s",
650 path1, errno, strerror(errno));
651 return 0;
652 }
653 return 1;
plars865695b2001-08-27 22:15:12 +0000654}
655
656/***********************************************************************
657 *
658 * This routine creates a symbolic link file and a regular file.
659 *
660 * Argument one is a pathname of object file
661 * Argument two is symbolic link file name
662 * Argument three is regular file name
663 *
664 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000665int creat_both(path1, path2, path3)
plars865695b2001-08-27 22:15:12 +0000666char *path1, *path2, *path3;
667{
subrata_modak56207ce2009-03-23 13:35:39 +0000668 if (creat_symlink(path1, path2) == -1)
669 return 0;
670 else if (creat_object(path3) == -1)
671 return 0;
672 return 1;
plars865695b2001-08-27 22:15:12 +0000673}
674
675/***********************************************************************
676 *
677 * This routine checks if symbolic link file is a symbolic link file.
678 *
679 * Argument one is a pathname of object file
680 * Argument two is symbolic link file name
681 * Argument three is regular file name
682 *
683 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000684int ck_symlink(path1, path2, path3)
plars865695b2001-08-27 22:15:12 +0000685char *path1, *path2, *path3;
686{
subrata_modak56207ce2009-03-23 13:35:39 +0000687 int ret;
plars865695b2001-08-27 22:15:12 +0000688
subrata_modak56207ce2009-03-23 13:35:39 +0000689 if ((ret = see_if_a_symlink(path2)) == -1) {
690 TEST_RESULT = TBROK;
691 sprintf(test_msg,
692 "lstat(2) Failure when accessing %s symbolic link file which should contain %s path to %s file ",
693 path2, path1, path3);
694 return 0;
695 } else if (ret == 0) {
696 TEST_RESULT = TBROK;
697 sprintf(test_msg,
698 "%s is not a symbolic link file which contains %s path to %s file",
699 path2, path1, path3);
700 return 0;
701 }
702 return 1;
plars865695b2001-08-27 22:15:12 +0000703}
704
705/***********************************************************************
706 *
707 * This routine checks if symbolic link file points at object file.
708 *
709 * Argument one is a pathname of object file
710 * Argument two is symbolic link file name
711 * Argument three is regular file name
712 *
713 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000714int ck_both(path1, path2, path3)
plars865695b2001-08-27 22:15:12 +0000715char *path1, *path2, *path3;
716{
subrata_modak56207ce2009-03-23 13:35:39 +0000717 if (ck_symlink(path1, path2, path3) == 0)
718 return 0;
719 else if ((stat(path3, &statter) == -1) && (errno == ENOENT)) {
720 TEST_RESULT = TBROK;
721 sprintf(test_msg, "stat(2) Failure when accessing %s object file ", path3);
722 return 0;
723 } else if ((stat(path2, &asymlink) == -1) && (errno == ENOENT)) {
724 TEST_RESULT = TBROK;
725 sprintf(test_msg, "stat(2) Failure when accessing %s symbolic link file ", path2);
726 return 0;
727 } else if (statter.st_ino != asymlink.st_ino) {
728 TEST_RESULT = TBROK;
729 sprintf(test_msg,
730 "stat(2) Failure when accessing %s object file through %s symbolic link file ",
731 path3, path2);
732 return 0;
733 }
734 return 1;
735
plars865695b2001-08-27 22:15:12 +0000736}
737
738/***********************************************************************
739 * This routine populates full_path with a pathname whose length exceeds
740 * the PATH_MAX define value in param.h
741 *
742 * Argument one is a pathname of object file
743 * Argument two is symbolic link file name
744 * Argument three is regular file name
745 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000746int creat_path_max(path1, path2, path3)
plars865695b2001-08-27 22:15:12 +0000747char *path1, *path2, *path3;
748{
subrata_modak56207ce2009-03-23 13:35:39 +0000749 int ctr, to_go, size, whole_chunks;
750 char *cwd, *getcwd();
plars865695b2001-08-27 22:15:12 +0000751
Garrett Cooper45e285d2010-11-22 12:19:25 -0800752 if ((cwd = getcwd(NULL, 0)) == NULL) {
subrata_modak56207ce2009-03-23 13:35:39 +0000753 TEST_RESULT = TBROK;
754 sprintf(test_msg,
755 "getcwd(3) Failure in setup of %s %s %s test case object elements",
756 path1, path2, path3);
757 return 0;
758 }
Garrett Cooper45e285d2010-11-22 12:19:25 -0800759 cwd = getcwd(NULL, 0);
subrata_modak56207ce2009-03-23 13:35:39 +0000760 size = strlen(cwd);
plars865695b2001-08-27 22:15:12 +0000761
subrata_modak56207ce2009-03-23 13:35:39 +0000762 to_go = PATH_MAX - size;
763 size = strlen(path1);
764 whole_chunks = to_go / size;
765 strcpy(full_path, cwd);
766 for (ctr = 0; ctr < whole_chunks; ctr++) {
767 strcat(full_path, path1);
768 }
769 size = strlen(full_path);
770 to_go = PATH_MAX - size;
771 strcat(full_path, "/");
772 for (ctr = 0; ctr < to_go; ctr++)
773 strcat(full_path, "Z");
plars865695b2001-08-27 22:15:12 +0000774
subrata_modak56207ce2009-03-23 13:35:39 +0000775 return 1;
plars865695b2001-08-27 22:15:12 +0000776}
777
778/***********************************************************************
779 * This routine checks that full_path's length exceeds the PATH_MAX
780 * define value in param.h
781 *
782 * Argument one is a pathname of object file
783 * Argument two is symbolic link file name
784 * Argument three is regular file name
785 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000786int ck_path_max(path1, path2, path3)
plars865695b2001-08-27 22:15:12 +0000787char *path1, *path2, *path3;
788{
subrata_modak56207ce2009-03-23 13:35:39 +0000789 if (strlen(full_path) == (PATH_MAX + 1))
790 return 1;
791 else {
792 TEST_RESULT = TBROK;
793 sprintf(test_msg, "%s %d %s %s %s %s",
794 "full_path character array length was not",
795 (PATH_MAX + 1),
796 "characters long for test case object elements", path1, path2, path3);
797 return 0;
798 }
plars865695b2001-08-27 22:15:12 +0000799}
800
801/***********************************************************************
802 * This routine checks if the stat(2) and lstat(2) calls return the same
803 * information when the path is not a symbolic link file
804 *
805 * Argument one is a pathname of object file
806 * Argument two is symbolic link file name
807 * Argument three is regular file name
808 *
809 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000810int ck_object(path1, path2, path3)
plars865695b2001-08-27 22:15:12 +0000811char *path1, *path2, *path3;
812{
subrata_modak56207ce2009-03-23 13:35:39 +0000813 int ret;
plars865695b2001-08-27 22:15:12 +0000814
subrata_modak56207ce2009-03-23 13:35:39 +0000815 if ((ret = see_if_a_symlink(path1)) < 0) {
816 TEST_RESULT = TFAIL;
817 sprintf(test_msg,
818 "lstat(2) failed to return inode information for a regular object file");
819 return 0;
820 } else if (ret == 1) {
821 TEST_RESULT = TFAIL;
822 sprintf(test_msg,
823 "lstat(2) detected a regular object file as a symbolic link file");
824 return 0;
825 } else if (stat(path1, &statter) == -1) {
826 TEST_RESULT = TBROK;
827 sprintf(test_msg,
828 "stat(2) failed to return inode information for a regular object file");
829 return 0;
830 } else if (memcmp((char *)&statter, (char *)&asymlink, sizeof(statter))
831 != 0) {
832 TEST_RESULT = TFAIL;
833 sprintf(test_msg,
834 "lstat(2) and stat(2) do not return same inode information for an object file");
835 return 0;
836
837 }
838 return 1;
plars865695b2001-08-27 22:15:12 +0000839}
840
841/***********************************************************************
842 * Main test case processing function
843 *
844 * Argument is a ptr into the all_tcses array of structures of type tcses
845 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000846int do_syscalltests(tcs)
plars865695b2001-08-27 22:15:12 +0000847struct tcses *tcs;
848{
subrata_modak56207ce2009-03-23 13:35:39 +0000849 int ctr, ret;
850 struct all_test_cases *tc_ptr;
plars865695b2001-08-27 22:15:12 +0000851
subrata_modak56207ce2009-03-23 13:35:39 +0000852 /*
853 * loop through desired number of test cases
854 */
855 for (ctr = 0, tc_ptr = tcs->tc_ptr; ctr < TST_TOTAL; ctr++, tc_ptr++) {
plars865695b2001-08-27 22:15:12 +0000856
subrata_modak56207ce2009-03-23 13:35:39 +0000857 Buffer[0] = '\0';
plars865695b2001-08-27 22:15:12 +0000858
subrata_modak56207ce2009-03-23 13:35:39 +0000859 /*
860 * If running all test cases for all tcid, set the TCID if needed.
861 */
862 if (Selectedtests == NULL) {
863 if (strcmp(tcs->tcid, tc_ptr->tcid) != 0) {
864 TCID = tc_ptr->tcid;
865 Tst_count = 0;
866 }
867 }
868 /*
869 * Insure that we are executing the correct tcs test case
870 */
871 if (strcmp(tcs->tcid, tc_ptr->tcid) != 0) {
872 tst_resm(TBROK,
873 "%s TCID attempted to execute %s %d %d test case",
874 tcs->tcid, tc_ptr->tcid, tc_ptr->test_fail, tc_ptr->errno_val);
875 continue;
876 }
877 TEST_RESULT = TPASS;
878 delete_files(S_FILE, O_FILE);
879 /*
880 * Perform test case setup
881 */
882 ret =
883 (tc_ptr->test_setup) (tc_ptr->fn_arg[0], tc_ptr->fn_arg[1],
884 tc_ptr->fn_arg[2], tc_ptr->errno_val);
plars865695b2001-08-27 22:15:12 +0000885
subrata_modak56207ce2009-03-23 13:35:39 +0000886 /* If an expected error, try it out */
plars865695b2001-08-27 22:15:12 +0000887
subrata_modak56207ce2009-03-23 13:35:39 +0000888 if (tc_ptr->test_fail) {
889 /*
890 * Try to perform test verification function
891 */
892 if (!(tc_ptr->ck_test)
893 (tc_ptr->fn_arg[0], tc_ptr->fn_arg[1],
894 tc_ptr->fn_arg[2], tc_ptr->errno_val))
vapiere5fce932009-08-28 14:17:14 +0000895 tst_resm(TEST_RESULT, "%s", test_msg);
subrata_modak56207ce2009-03-23 13:35:39 +0000896 else if (tc_ptr->errno_val == EEXIST)
897 do_EEXIST(tc_ptr);
898 else if (tc_ptr->errno_val == ENOENT)
899 do_ENOENT(tc_ptr);
900 else if (tc_ptr->errno_val == ELOOP)
901 do_ELOOP(tc_ptr);
902 else if (tc_ptr->errno_val == ENOTDIR)
903 do_ENOTDIR(tc_ptr);
904 else if (tc_ptr->errno_val == EXDEV)
905 do_EXDEV(tc_ptr);
906 else if (tc_ptr->errno_val == ENAMETOOLONG)
907 do_ENAMETOOLONG(tc_ptr);
908 else if (tc_ptr->errno_val == EINVAL)
909 do_EINVAL(tc_ptr);
910 else
911 tst_resm(TBROK, "Test Case Declaration Error");
912 } else if (ret == 1) { /* No setup function error */
subrata_modak4bb656a2009-02-26 12:02:09 +0000913
subrata_modak56207ce2009-03-23 13:35:39 +0000914 if (tc_ptr->errno_val != 0)
915 tst_resm(TBROK, "Test Case Declaration Error");
916 else {
917 /*
918 * Perform test verification function
919 */
920 ret =
921 (tc_ptr->ck_test) (tc_ptr->fn_arg[0],
922 tc_ptr->fn_arg[1],
923 tc_ptr->fn_arg[2], tc_ptr->errno_val);
plars865695b2001-08-27 22:15:12 +0000924
subrata_modak56207ce2009-03-23 13:35:39 +0000925 /* Perform requested symbolic link system call test */
plars865695b2001-08-27 22:15:12 +0000926
subrata_modak56207ce2009-03-23 13:35:39 +0000927 if ((cktcsid(tc_ptr->tcid, SYMLINK)) ||
928 (cktcsid(tc_ptr->tcid, LSTAT)) ||
929 (cktcsid(tc_ptr->tcid, LSTAT_64))) {
930 if (ret == 1)
vapiere5fce932009-08-28 14:17:14 +0000931 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +0000932 else
vapiere5fce932009-08-28 14:17:14 +0000933 tst_resm(TEST_RESULT, "%s", test_msg);
subrata_modak56207ce2009-03-23 13:35:39 +0000934 } else if (ret == 0)
vapiere5fce932009-08-28 14:17:14 +0000935 tst_resm(TEST_RESULT, "%s", test_msg);
subrata_modak56207ce2009-03-23 13:35:39 +0000936 else if (cktcsid(tc_ptr->tcid, READLINK))
937 do_readlink(tc_ptr);
938 else if (cktcsid(tc_ptr->tcid, STAT))
939 do_stat(tc_ptr);
940 else if (cktcsid(tc_ptr->tcid, STAT_64))
941 do_stat(tc_ptr);
942 else if (cktcsid(tc_ptr->tcid, CHDIR))
943 do_chdir(tc_ptr);
944 else if (cktcsid(tc_ptr->tcid, LINK))
945 do_link(tc_ptr);
946 else if (cktcsid(tc_ptr->tcid, UNLINK))
947 do_unlink(tc_ptr);
948 else if (cktcsid(tc_ptr->tcid, CHMOD))
949 do_chmod(tc_ptr);
950 else if (cktcsid(tc_ptr->tcid, UTIME))
951 do_utime(tc_ptr);
952 else if (cktcsid(tc_ptr->tcid, RENAME))
953 do_rename(tc_ptr);
954 else if (cktcsid(tc_ptr->tcid, OPEN))
955 do_open(tc_ptr);
956 else
957 tst_resm(TBROK,
958 "Unknown test case processing actions declared");
959 }
960 } else
961 tst_resm(TBROK, "Test Case Declaration Error");
962 }
963 return 0;
plars865695b2001-08-27 22:15:12 +0000964}
965
966/***********************************************************************
967 * This routine checks for the return of EEXIST errno from requested
968 * system call
969 *
970 * Argument is pointer to test_objects array of structures of type
971 * all_test_cases
972 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000973void do_EEXIST(tc_ptr)
plars865695b2001-08-27 22:15:12 +0000974struct all_test_cases *tc_ptr;
975{
subrata_modak56207ce2009-03-23 13:35:39 +0000976 if (cktcsid(tc_ptr->tcid, SYMLINK)) {
plars865695b2001-08-27 22:15:12 +0000977
subrata_modak56207ce2009-03-23 13:35:39 +0000978 TEST(symlink(tc_ptr->fn_arg[0], tc_ptr->fn_arg[1]));
979 errno = TEST_ERRNO;
980 if ((TEST_RETURN == -1) && (errno == EEXIST))
981 if (STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +0000982 tst_resm(TPASS, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +0000983 else
984 Tst_count++;
985 else
986 tst_resm(TFAIL, "%s %s",
987 "Expected EEXIST error when creating a symbolic link file",
988 "which already existed");
989 } else if (cktcsid(tc_ptr->tcid, MKDIR)) {
plars865695b2001-08-27 22:15:12 +0000990
subrata_modak56207ce2009-03-23 13:35:39 +0000991 TEST(mkdir(tc_ptr->fn_arg[1], MODE));
992 errno = TEST_ERRNO;
993 if ((TEST_RETURN == -1) && (errno == EEXIST))
994 if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +0000995 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +0000996 else
997 Tst_count++;
998 else {
plars865695b2001-08-27 22:15:12 +0000999
subrata_modak56207ce2009-03-23 13:35:39 +00001000 tst_resm(TFAIL, "%s %s",
1001 "Expected EEXIST error when creating a directory by a symbolic",
1002 "link file which pointed at no object file");
1003 rmdir(tc_ptr->fn_arg[1]);
1004 }
1005 } else if (cktcsid(tc_ptr->tcid, OPEN)) {
plars865695b2001-08-27 22:15:12 +00001006
subrata_modak56207ce2009-03-23 13:35:39 +00001007 TEST(open(tc_ptr->fn_arg[1], (O_EXCL | O_CREAT), 0666));
1008 errno = TEST_ERRNO;
1009 if ((TEST_RETURN == -1) && (errno == EEXIST))
1010 if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001011 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001012 else
1013 Tst_count++;
1014 else
1015 tst_resm(TFAIL, "%s %s errno:%d %s",
1016 "Expected EEXIST error for exclusively opening an object file",
1017 "through a symbolic link file was not received:",
1018 errno, strerror(errno));
1019 } else
1020 tst_resm(TBROK, "Unknown test case processing actions declared");
plars865695b2001-08-27 22:15:12 +00001021}
1022
1023/***********************************************************************
1024 * This routine checks for the return of ENOENT errno from requested
1025 * system call
1026 *
1027 * Argument is pointer to test_objects array of structures of type
1028 * all_test_cases
1029 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +00001030void do_ENOENT(tc_ptr)
plars865695b2001-08-27 22:15:12 +00001031struct all_test_cases *tc_ptr;
1032{
subrata_modak56207ce2009-03-23 13:35:39 +00001033 if ((cktcsid(tc_ptr->tcid, STAT)) || (cktcsid(tc_ptr->tcid, STAT_64))) {
plars865695b2001-08-27 22:15:12 +00001034
subrata_modak56207ce2009-03-23 13:35:39 +00001035 if ((stat(tc_ptr->fn_arg[1], &asymlink) == -1)
1036 && (errno == ENOENT))
1037 if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001038 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001039 else
1040 Tst_count++;
1041 else
1042 tst_resm(TFAIL, "%s %s errno:%d %s",
1043 "Expected ENOENT error for stating a non-existent directory",
1044 "through a symbolic link file was not received:",
1045 errno, strerror(errno));
1046 } else if (cktcsid(tc_ptr->tcid, CHDIR)) {
1047 if ((chdir(tc_ptr->fn_arg[1]) == -1) && (errno == ENOENT))
1048 if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001049 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001050 else
1051 Tst_count++;
1052 else {
1053 tst_resm(TFAIL, "%s %s errno:%d %s",
1054 "Expected ENOENT error for changing to a non-existent",
1055 "directory through a symbolic link file was not received:",
1056 errno, strerror(errno));
1057 chdir(TESTDIR);
1058 }
1059 } else if (cktcsid(tc_ptr->tcid, LINK)) {
plars865695b2001-08-27 22:15:12 +00001060
subrata_modak56207ce2009-03-23 13:35:39 +00001061 if ((link(tc_ptr->fn_arg[1], "nick") == -1)
1062 && (errno == ENOENT))
1063 if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001064 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001065 else
1066 Tst_count++;
1067 else {
1068 tst_resm(TFAIL, "%s %s errno:%d %s",
1069 "Expected ENOENT error condition when link(2) a symbolic",
1070 "link which pointed at no object:", errno, strerror(errno));
1071 delete_files("nick", NULL);
1072 }
1073 } else if (cktcsid(tc_ptr->tcid, CHMOD)) {
plars865695b2001-08-27 22:15:12 +00001074
subrata_modak56207ce2009-03-23 13:35:39 +00001075 if ((chmod(tc_ptr->fn_arg[1], MODE) == -1) && (errno == ENOENT))
1076 if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001077 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001078 else
1079 Tst_count++;
1080 else
1081 tst_resm(TFAIL, "%s %s errno:%d %s",
1082 "Expected ENOENT error condition when chmod(2) a symbolic",
1083 "link which pointed at no object,", errno, strerror(errno));
1084 } else if (cktcsid(tc_ptr->tcid, UTIME)) {
plars865695b2001-08-27 22:15:12 +00001085
subrata_modak56207ce2009-03-23 13:35:39 +00001086 if ((utime(tc_ptr->fn_arg[1], NULL) == -1) && (errno == ENOENT))
1087 if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001088 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001089 else
1090 Tst_count++;
1091 else
1092 tst_resm(TFAIL, "%s %s errno:%d %s",
1093 "Expected ENOENT error condition when utime(2) a symbolic",
1094 "link which pointed at no object:", errno, strerror(errno));
1095 } else if (cktcsid(tc_ptr->tcid, OPEN)) {
plars865695b2001-08-27 22:15:12 +00001096
subrata_modak56207ce2009-03-23 13:35:39 +00001097 if ((open(tc_ptr->fn_arg[1], O_RDWR) == -1)
1098 && (errno == ENOENT))
1099 if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001100 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001101 else
1102 Tst_count++;
1103 else
1104 tst_resm(TFAIL, "%s %s errno:%d %s",
1105 "Expected ENOENT error for opening a non-existent object",
1106 " file through a symbolic link file was not received,",
1107 errno, strerror(errno));
1108 } else
1109 tst_resm(TBROK, "Unknown test case processing actions declared");
plars865695b2001-08-27 22:15:12 +00001110}
1111
1112/***********************************************************************
1113 * This routine checks for the return of ELOOP errno from requested
1114 * system call
1115 *
1116 * Argument is pointer to test_objects array of structures of type
1117 * all_test_cases
1118 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +00001119void do_ELOOP(tc_ptr)
plars865695b2001-08-27 22:15:12 +00001120struct all_test_cases *tc_ptr;
1121{
subrata_modak56207ce2009-03-23 13:35:39 +00001122 if ((cktcsid(tc_ptr->tcid, STAT)) || (cktcsid(tc_ptr->tcid, STAT_64))) {
plars865695b2001-08-27 22:15:12 +00001123
subrata_modak56207ce2009-03-23 13:35:39 +00001124 TEST(stat(tc_ptr->fn_arg[1], &asymlink));
1125 errno = TEST_ERRNO;
1126 if ((TEST_RETURN == -1) && (errno == ELOOP))
1127 if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001128 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001129 else
1130 Tst_count++;
1131 else if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
1132 tst_resm(TEST_RESULT, "%s errno:%d %s",
1133 "Expected ELOOP errno from stat(2) (nested symb link),",
1134 errno, strerror(errno));
1135 else
1136 Tst_count++;
1137 } else if (cktcsid(tc_ptr->tcid, CHDIR)) {
plars865695b2001-08-27 22:15:12 +00001138
subrata_modak56207ce2009-03-23 13:35:39 +00001139 TEST(chdir(tc_ptr->fn_arg[1]));
1140 errno = TEST_ERRNO;
1141 if ((TEST_RETURN == -1) && (errno == ELOOP))
1142 if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001143 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001144 else
1145 Tst_count++;
1146 else {
plars865695b2001-08-27 22:15:12 +00001147
subrata_modak56207ce2009-03-23 13:35:39 +00001148 tst_resm(TFAIL, "%s errno:%d %s",
1149 "Expected ELOOP error condition when chdir(2) a nested symbolic link:",
1150 errno, strerror(errno));
1151 chdir(TESTDIR);
1152 }
1153 } else if (cktcsid(tc_ptr->tcid, LINK)) {
plars865695b2001-08-27 22:15:12 +00001154
subrata_modak56207ce2009-03-23 13:35:39 +00001155 TEST(link(tc_ptr->fn_arg[1], O_FILE));
1156 errno = TEST_ERRNO;
1157 if ((TEST_RETURN == -1) && (errno == ELOOP))
1158 if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001159 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001160 else
1161 Tst_count++;
1162 else
1163 tst_resm(TFAIL, "%s errno:%d %s",
1164 "Expected ELOOP error condition when link(2) a nested symbolic link:",
1165 errno, strerror(errno));
1166 } else if (cktcsid(tc_ptr->tcid, CHMOD)) {
plars865695b2001-08-27 22:15:12 +00001167
subrata_modak56207ce2009-03-23 13:35:39 +00001168 TEST(chmod(tc_ptr->fn_arg[1], MODE));
1169 errno = TEST_ERRNO;
1170 if ((TEST_RETURN == -1) && (errno == ELOOP))
1171 if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001172 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001173 else
1174 Tst_count++;
1175 else
1176 tst_resm(TFAIL, "%s errno:%d %s",
1177 "Expected ELOOP error condition when chmod(2) a nested symbolic link:",
1178 errno, strerror(errno));
1179 return;
1180 } else if (cktcsid(tc_ptr->tcid, UTIME)) {
plars865695b2001-08-27 22:15:12 +00001181
subrata_modak56207ce2009-03-23 13:35:39 +00001182 TEST(utime(tc_ptr->fn_arg[1], NULL));
1183 errno = TEST_ERRNO;
plars865695b2001-08-27 22:15:12 +00001184
subrata_modak56207ce2009-03-23 13:35:39 +00001185 if ((TEST_RETURN == -1) && (errno == ELOOP))
1186 if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001187 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001188 else
1189 Tst_count++;
1190 else
1191 tst_resm(TFAIL, "%s errno:%d %s",
1192 "Expected ELOOP error condition when utime(2) a nested symbolic link:",
1193 errno, strerror(errno));
1194 } else if (cktcsid(tc_ptr->tcid, OPEN)) {
plars865695b2001-08-27 22:15:12 +00001195
subrata_modak56207ce2009-03-23 13:35:39 +00001196 int fd;
1197 TEST(open(tc_ptr->fn_arg[1], O_CREAT, 0666));
1198 fd = TEST_RETURN;
1199 errno = TEST_ERRNO;
1200 if ((fd == -1) && (errno == ELOOP))
1201 if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001202 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001203 else
1204 Tst_count++;
1205 else
1206 tst_resm(TFAIL, "%s errno:%d %s",
1207 "Expected ELOOP error condition when open(2) a nested symbolic link:",
1208 errno, strerror(errno));
1209 } else
1210 tst_resm(TBROK, "Unknown test case processing actions declared");
plars865695b2001-08-27 22:15:12 +00001211}
1212
1213/***********************************************************************
1214 * This routine checks for the return of ENOTDIR errno from requested
1215 * system call
1216 *
1217 * Argument is pointer to test_objects array of structures of type
1218 * all_test_cases
1219 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +00001220void do_ENOTDIR(tc_ptr)
plars865695b2001-08-27 22:15:12 +00001221struct all_test_cases *tc_ptr;
1222{
subrata_modak56207ce2009-03-23 13:35:39 +00001223 if (cktcsid(tc_ptr->tcid, RMDIR)) {
plars865695b2001-08-27 22:15:12 +00001224
subrata_modak56207ce2009-03-23 13:35:39 +00001225 TEST(mkdir(tc_ptr->fn_arg[0], MODE));
1226 errno = TEST_ERRNO;
1227 if (TEST_RETURN == -1)
1228 tst_resm(TBROK, "mkdir(2) Failure when creating %s", tc_ptr->fn_arg[0]);
1229 else if ((rmdir(tc_ptr->fn_arg[1]) == -1) && (errno == ENOTDIR)) {
plars865695b2001-08-27 22:15:12 +00001230
subrata_modak56207ce2009-03-23 13:35:39 +00001231 if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001232 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001233 else
1234 Tst_count++;
1235 rmdir(tc_ptr->fn_arg[0]);
1236 } else
1237 tst_resm(TFAIL, "%s %s errno:%d %s",
1238 "Expected ENOTDIR error for removing a non-existent",
1239 "directory through a symbolic link file was not received,",
1240 errno, strerror(errno));
1241 } else
1242 tst_resm(TBROK, "Unknown test case processing actions declared");
plars865695b2001-08-27 22:15:12 +00001243}
1244
1245/***********************************************************************
1246 * This routine checks for the return of EXDEV errno from requested
1247 * system call
1248 *
1249 * Argument is pointer to test_objects array of structures of type
1250 * all_test_cases
1251 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +00001252void do_EXDEV(tc_ptr)
plars865695b2001-08-27 22:15:12 +00001253struct all_test_cases *tc_ptr;
1254{
subrata_modak56207ce2009-03-23 13:35:39 +00001255 if (cktcsid(tc_ptr->tcid, RENAME)) {
plars865695b2001-08-27 22:15:12 +00001256
subrata_modak56207ce2009-03-23 13:35:39 +00001257 TEST(rename(tc_ptr->fn_arg[1], Y_A_S_FILE));
1258 errno = TEST_ERRNO;
1259 if ((TEST_RETURN == -1) && (errno == EXDEV)) {
1260 if (see_if_a_symlink(Y_A_S_FILE) == -1)
1261 if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001262 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001263 else
1264 Tst_count++;
1265 else
1266 tst_resm(TFAIL,
1267 "%s %s %s file outside of current file system",
1268 "rename(3) returned -1 when trying to move symbolic link file",
1269 "outside of current file system, but created", Y_A_S_FILE);
1270 } else {
1271 tst_resm(TFAIL, "%s %s errno:%d %s",
1272 "Expected EXDEV error for renaming an existing symbolic",
1273 "link file to a location outside of existing file system,",
1274 errno, strerror(errno));
1275 delete_files("/NiCkEr", NULL);
1276 }
1277 } else
1278 tst_resm(TBROK, "Unknown test case processing actions declared");
plars865695b2001-08-27 22:15:12 +00001279}
1280
1281/***********************************************************************
1282 * This routine checks for the return of ENAMETOOLONG errno from requested
1283 * system call
1284 *
1285 * Argument is pointer to test_objects array of structures of type
1286 * all_test_cases
1287 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +00001288void do_ENAMETOOLONG(tc_ptr)
plars865695b2001-08-27 22:15:12 +00001289struct all_test_cases *tc_ptr;
1290{
subrata_modak56207ce2009-03-23 13:35:39 +00001291 int ret;
plars865695b2001-08-27 22:15:12 +00001292
subrata_modak56207ce2009-03-23 13:35:39 +00001293 if (cktcsid(tc_ptr->tcid, SYMLINK)) {
plars865695b2001-08-27 22:15:12 +00001294
subrata_modak56207ce2009-03-23 13:35:39 +00001295 TEST(symlink(tc_ptr->fn_arg[0], full_path));
1296 errno = TEST_ERRNO;
1297 if ((TEST_RETURN == -1) && (errno == ENAMETOOLONG))
1298 if (see_if_a_symlink(full_path) == -1)
1299 if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001300 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001301 else
1302 Tst_count++;
1303 else
1304 tst_resm(TFAIL, "%s %s %d %s",
1305 "symlink(2) returned -1 when trying to create a symbolic",
1306 "link file whose name exceeded",
1307 (PATH_MAX + 1),
1308 "characters, but it created the symbolic link file");
1309 else
vapiere5fce932009-08-28 14:17:14 +00001310 tst_resm(TFAIL|TERRNO,
1311 "Expected ENAMETOOLONG error when creating %s symbolic link file with a path exceeding %d characters",
1312 tc_ptr->fn_arg[1], (PATH_MAX + 1));
subrata_modak56207ce2009-03-23 13:35:39 +00001313 } else if (cktcsid(tc_ptr->tcid, READLINK)) {
plars865695b2001-08-27 22:15:12 +00001314
subrata_modak56207ce2009-03-23 13:35:39 +00001315 char scratch[PATH_MAX + 1];
plars865695b2001-08-27 22:15:12 +00001316
subrata_modak56207ce2009-03-23 13:35:39 +00001317 ret = readlink(full_path, scratch, strlen(full_path));
1318 if ((ret == -1) && (errno == ENAMETOOLONG))
1319 if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001320 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001321 else
1322 Tst_count++;
1323 else
1324 tst_resm(TFAIL,
1325 "Expected ENAMETOOLONG error when reading %s symbolic link file with a path exceeding %d characters: errno:%d %s",
1326 tc_ptr->fn_arg[1], (PATH_MAX + 1), errno, strerror(errno));
1327 } else
1328 tst_resm(TBROK, "Unknown test case processing actions declared");
plars865695b2001-08-27 22:15:12 +00001329}
1330
1331/***********************************************************************
1332 * This routine checks for the return of EINVAL errno from requested
1333 * system call
1334 *
1335 * Argument is pointer to test_objects array of structures of type
1336 * all_test_cases
1337 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +00001338void do_EINVAL(tc_ptr)
plars865695b2001-08-27 22:15:12 +00001339struct all_test_cases *tc_ptr;
1340{
subrata_modak56207ce2009-03-23 13:35:39 +00001341 if (cktcsid(tc_ptr->tcid, READLINK)) {
1342 TEST(readlink(tc_ptr->fn_arg[0], test_msg, BUFMAX));
1343 errno = TEST_ERRNO;
1344 if (TEST_RETURN == -1) {
1345 if (errno == EINVAL) {
1346 if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001347 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001348 else
1349 Tst_count++;
1350 } else
1351 tst_resm(TFAIL,
1352 "readlink(2) ret:-1, errno:%d, : Exp errno:%d",
1353 errno, EINVAL);
1354 } else {
1355 tst_resm(TFAIL,
1356 "readlink(2) did not returned -1 when reading %s",
1357 "a file which is not a symbolic link file");
1358 }
1359 } else
1360 tst_resm(TBROK, "Unknown test case processing actions declared");
plars865695b2001-08-27 22:15:12 +00001361}
1362
1363/***********************************************************************
1364 * This routine checks out the readlink(2) system call for a successful
1365 * invocation
1366 *
1367 * Argument is pointer to test_objects array of structures of type
1368 * all_test_cases
1369 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +00001370void do_readlink(tc_ptr)
plars865695b2001-08-27 22:15:12 +00001371struct all_test_cases *tc_ptr;
1372{
subrata_modak56207ce2009-03-23 13:35:39 +00001373 char scratch[PATH_MAX];
1374 int ret;
plars865695b2001-08-27 22:15:12 +00001375
subrata_modak56207ce2009-03-23 13:35:39 +00001376 ret = readlink(tc_ptr->fn_arg[1], scratch, strlen(tc_ptr->fn_arg[0]));
plars865695b2001-08-27 22:15:12 +00001377
1378 /*** the TEST macro cannot be used here for some reason ****/
1379
subrata_modak56207ce2009-03-23 13:35:39 +00001380 if (ret == -1) {
1381 tst_resm(TFAIL, "readlink(2) failure on %s symbolic link file", tc_ptr->fn_arg[1]);
plars865695b2001-08-27 22:15:12 +00001382
subrata_modak56207ce2009-03-23 13:35:39 +00001383 } else if (strncmp(tc_ptr->fn_arg[0], scratch, strlen(tc_ptr->fn_arg[0])) != 0) {
plars865695b2001-08-27 22:15:12 +00001384
subrata_modak56207ce2009-03-23 13:35:39 +00001385 /* Must null terminate scratch because readlink(2) doesn't */
plars865695b2001-08-27 22:15:12 +00001386
subrata_modak56207ce2009-03-23 13:35:39 +00001387 scratch[strlen(tc_ptr->fn_arg[0])] = '\0';
subrata_modak4bb656a2009-02-26 12:02:09 +00001388
subrata_modak56207ce2009-03-23 13:35:39 +00001389 tst_resm(TFAIL,
1390 "readlink(2) Error : Expected %s symbolic link file contents but %s actual contents were returned",
1391 tc_ptr->fn_arg[0], scratch);
1392 } else if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001393 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001394 else
1395 Tst_count++;
plars865695b2001-08-27 22:15:12 +00001396}
1397
1398/***********************************************************************
1399 * This routine checks out the stat(2) system call for a successful
1400 * invocation
1401 *
1402 * Argument is pointer to test_objects array of structures of type
1403 * all_test_cases
1404 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +00001405void do_stat(tc_ptr)
plars865695b2001-08-27 22:15:12 +00001406struct all_test_cases *tc_ptr;
1407{
subrata_modak56207ce2009-03-23 13:35:39 +00001408 if (statter.st_dev != asymlink.st_dev)
1409 tst_resm(TFAIL,
subrata_modak923b23f2009-11-02 13:57:16 +00001410 "stat of symbolic link reference to object device info %jd != stat of object file device info %jd",
1411 (intmax_t)statter.st_dev, (intmax_t)asymlink.st_dev);
plars865695b2001-08-27 22:15:12 +00001412
subrata_modak56207ce2009-03-23 13:35:39 +00001413 else if (statter.st_mode != asymlink.st_mode)
1414 tst_resm(TFAIL,
subrata_modak923b23f2009-11-02 13:57:16 +00001415 "stat of symbolic link reference to object file permissions %jd != stat of object file permissions %jd",
1416 (intmax_t)statter.st_mode, (intmax_t)asymlink.st_mode);
plars865695b2001-08-27 22:15:12 +00001417
subrata_modak56207ce2009-03-23 13:35:39 +00001418 else if (statter.st_nlink != asymlink.st_nlink)
1419 tst_resm(TFAIL,
subrata_modak923b23f2009-11-02 13:57:16 +00001420 "stat of symbolic link reference to object file link count %jd != stat of object file link count %jd",
1421 (intmax_t)statter.st_nlink, (intmax_t)asymlink.st_nlink);
plars865695b2001-08-27 22:15:12 +00001422
subrata_modak56207ce2009-03-23 13:35:39 +00001423 else if (statter.st_uid != asymlink.st_uid)
1424 tst_resm(TFAIL,
subrata_modak923b23f2009-11-02 13:57:16 +00001425 "stat of symbolic link reference to object file uid %jd != stat of object file uid %jd",
1426 (intmax_t)statter.st_uid, (intmax_t)asymlink.st_uid);
plars865695b2001-08-27 22:15:12 +00001427
subrata_modak56207ce2009-03-23 13:35:39 +00001428 else if (statter.st_gid != asymlink.st_gid)
1429 tst_resm(TFAIL,
subrata_modak923b23f2009-11-02 13:57:16 +00001430 "stat of symbolic link reference to object file gid %jd != stat of object file gid %jd",
1431 (intmax_t)statter.st_gid, (intmax_t)asymlink.st_gid);
plars865695b2001-08-27 22:15:12 +00001432
subrata_modak56207ce2009-03-23 13:35:39 +00001433 else if (statter.st_size != asymlink.st_size)
1434 tst_resm(TFAIL,
1435 "stat of symbolic link reference to object file size %ld != stat of object file size %ld",
1436 statter.st_size, asymlink.st_size);
plars865695b2001-08-27 22:15:12 +00001437
subrata_modak56207ce2009-03-23 13:35:39 +00001438 else if (statter.st_atime != asymlink.st_atime)
1439 tst_resm(TFAIL,
1440 "stat of symbolic link reference to object access time %ld != stat of object file access time %ld",
1441 statter.st_atime, asymlink.st_atime);
plars865695b2001-08-27 22:15:12 +00001442
subrata_modak56207ce2009-03-23 13:35:39 +00001443 else if (statter.st_mtime != asymlink.st_mtime)
1444 tst_resm(TFAIL,
1445 "stat of symbolic link reference to object modify time %ld != stat of object file modify time %ld",
1446 statter.st_atime, asymlink.st_atime);
plars865695b2001-08-27 22:15:12 +00001447
subrata_modak56207ce2009-03-23 13:35:39 +00001448 else if (statter.st_ctime != asymlink.st_ctime)
1449 tst_resm(TFAIL,
1450 "stat of symbolic link reference to object change time %ld != stat of object file change time %ld",
1451 statter.st_atime, asymlink.st_atime);
1452 else if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001453 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001454 else
1455 Tst_count++;
plars865695b2001-08-27 22:15:12 +00001456}
1457
1458/***********************************************************************
1459 * This routine checks out the chdir(2) system call for a successful
1460 * invocation
1461 *
1462 * Argument is pointer to test_objects array of structures of type
1463 * all_test_cases
1464 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +00001465void do_chdir(tc_ptr)
plars865695b2001-08-27 22:15:12 +00001466struct all_test_cases *tc_ptr;
1467{
subrata_modak56207ce2009-03-23 13:35:39 +00001468 if (mkdir(tc_ptr->fn_arg[2], MODE) == -1)
1469 tst_resm(TFAIL, "Could not create a setup directory file");
1470 else {
plars865695b2001-08-27 22:15:12 +00001471
subrata_modak56207ce2009-03-23 13:35:39 +00001472 sprintf(Buf, "mkdir(%s, %#o) was successful\n", tc_ptr->fn_arg[2], MODE);
1473 strcat(Buffer, Buf);
plars865695b2001-08-27 22:15:12 +00001474
subrata_modak56207ce2009-03-23 13:35:39 +00001475 if (chdir(tc_ptr->fn_arg[1]) == -1)
1476 tst_resm(TFAIL,
1477 "%sCould not change a directory file through a %s",
1478 Buffer, "symbolic link which which pointed at object");
1479 else {
plars865695b2001-08-27 22:15:12 +00001480
subrata_modak56207ce2009-03-23 13:35:39 +00001481 char *cwd, *getcwd();
1482 char expected_location[PATH_MAX];
1483 /*
1484 * Build expected current directory position
1485 */
1486 strcpy(expected_location, TESTDIR);
1487 strcat(expected_location, "/");
1488 strcat(expected_location, tc_ptr->fn_arg[2]);
plars865695b2001-08-27 22:15:12 +00001489
Garrett Cooper45e285d2010-11-22 12:19:25 -08001490 if ((cwd = getcwd(NULL, 0)) == NULL)
subrata_modak56207ce2009-03-23 13:35:39 +00001491 tst_resm(TFAIL, "getcwd(3) FAILURE");
1492 else if (strcmp(cwd, expected_location) == 0)
1493 if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001494 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001495 else
1496 Tst_count++;
1497 else {
1498 tst_resm(TFAIL,
1499 "%s%s %s %s not equal to expected %s",
1500 Buffer,
1501 "chdir(2) returned successfully, but getcwd(3) indicated",
1502 "new current working directory location",
1503 cwd, expected_location);
1504 }
1505 chdir(TESTDIR);
1506 }
1507 rmdir(tc_ptr->fn_arg[2]);
1508 }
plars865695b2001-08-27 22:15:12 +00001509}
1510
1511/***********************************************************************
1512 * This routine checks out the link(2) system call for a successful
1513 * invocation
1514 *
1515 * Argument is pointer to test_objects array of structures of type
1516 * all_test_cases
1517 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +00001518void do_link(tc_ptr)
plars865695b2001-08-27 22:15:12 +00001519struct all_test_cases *tc_ptr;
1520{
subrata_modak56207ce2009-03-23 13:35:39 +00001521 struct stat stbuf;
plars865695b2001-08-27 22:15:12 +00001522
subrata_modak56207ce2009-03-23 13:35:39 +00001523 if (link(tc_ptr->fn_arg[1], "nick") == -1) {
1524 tst_resm(TFAIL, "%slink(%s, \"nick\") failed, errno: %d: %s %s",
1525 Buffer, tc_ptr->fn_arg[1], errno,
1526 "link of new file to object file via symbolic link file failed",
1527 "when expected not to");
1528 } else {
1529 sprintf(Buf, "link(%s, \"nick\") was successful\n", tc_ptr->fn_arg[1]);
1530 strcat(Buffer, Buf);
plars865695b2001-08-27 22:15:12 +00001531
subrata_modak56207ce2009-03-23 13:35:39 +00001532 if (STD_FUNCTIONAL_TEST) {
1533 /*
1534 * Check that links counts were properly set
1535 */
1536 if (lstat(tc_ptr->fn_arg[1], &asymlink) == -1) {
1537 tst_resm(TBROK, "lstat(%s) failed. errno: %d",
1538 tc_ptr->fn_arg[1], errno);
plars865695b2001-08-27 22:15:12 +00001539
subrata_modak56207ce2009-03-23 13:35:39 +00001540 } else if (lstat("nick", &statter) == -1) {
1541 tst_resm(TBROK, "lstat(nick) failed, errno:%d", errno);
1542 } else {
1543 if (statter.st_ino == asymlink.st_ino) {
1544 if ((statter.st_nlink == 2)
1545 && (asymlink.st_nlink == 2)) {
1546 if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001547 tst_resm(TEST_RESULT, "%s",
subrata_modak56207ce2009-03-23 13:35:39 +00001548 msgs[tc_ptr->pass_msg]);
1549 else
1550 Tst_count++;
1551 } else {
1552 lstat(tc_ptr->fn_arg[2], &stbuf);
plars865695b2001-08-27 22:15:12 +00001553
subrata_modak56207ce2009-03-23 13:35:39 +00001554 tst_resm(TFAIL,
1555 "%slink(%s, %s) failed to adjust link count.\n\
plars865695b2001-08-27 22:15:12 +00001556 count for nick is %d, count for %s is %d, count for %s is %d.",
subrata_modak56207ce2009-03-23 13:35:39 +00001557 Buffer, tc_ptr->fn_arg[1], "nick", statter.st_nlink, tc_ptr->fn_arg[1], asymlink.st_nlink, tc_ptr->fn_arg[2],
1558 stbuf.st_nlink);
1559 }
1560 } else {
subrata_modak923b23f2009-11-02 13:57:16 +00001561 tst_resm(TFAIL, "%sA lstat of %s (ino:%jd) and of\n\t\t\
1562%s (ino:%jd), does not show them being the same ino.", Buffer, tc_ptr->fn_arg[1], (intmax_t)asymlink.st_ino, "nick", (intmax_t)statter.st_ino);
subrata_modak56207ce2009-03-23 13:35:39 +00001563 }
1564 }
plars865695b2001-08-27 22:15:12 +00001565 }
subrata_modak56207ce2009-03-23 13:35:39 +00001566 delete_files("nick", NULL);
plars865695b2001-08-27 22:15:12 +00001567 }
plars865695b2001-08-27 22:15:12 +00001568}
1569
1570/***********************************************************************
1571 * This routine checks out the unlink(2) system call for a successful
1572 * invocation
1573 *
1574 * Argument is pointer to test_objects array of structures of type
1575 * all_test_cases
1576 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +00001577void do_unlink(tc_ptr)
plars865695b2001-08-27 22:15:12 +00001578struct all_test_cases *tc_ptr;
1579{
subrata_modak56207ce2009-03-23 13:35:39 +00001580 if (stat(tc_ptr->fn_arg[2], &asymlink) == -1)
1581 tst_resm(TBROK, "stat(2) Failure when accessing %s object file", tc_ptr->fn_arg[2]);
1582 else if (unlink(tc_ptr->fn_arg[1]) == -1)
1583 tst_resm(TFAIL, "unlink(2) failed when removing symbolic link file");
1584 else {
1585 sprintf(Buf, "unlink(%s) was successful\n", tc_ptr->fn_arg[1]);
1586 strcat(Buffer, Buf);
1587 if (stat(tc_ptr->fn_arg[2], &statter) == -1)
1588 tst_resm(TFAIL, "%s %s",
1589 "unlink(2) failed because it not only removed symbolic link",
1590 "file which pointed at object file, but object file as well");
subrata_modakbdbaec52009-02-26 12:14:51 +00001591
subrata_modak56207ce2009-03-23 13:35:39 +00001592 else if ((statter.st_ino == asymlink.st_ino) &&
1593 (statter.st_dev == asymlink.st_dev) &&
1594 (statter.st_size == asymlink.st_size))
plars865695b2001-08-27 22:15:12 +00001595
subrata_modak56207ce2009-03-23 13:35:39 +00001596 if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001597 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001598 else
1599 Tst_count++;
1600 else
1601 tst_resm(TFAIL, "%s%s %s %s", Buffer,
1602 "unlink(2) failed because it not only removed symbolic link",
1603 "file which pointed at object file, but it changed object",
1604 "file inode information");
1605 }
plars865695b2001-08-27 22:15:12 +00001606
1607}
1608
1609/***********************************************************************
1610 * This routine checks out the chmod(2) system call for a successful
1611 * invocation
1612 *
1613 * Argument is pointer to test_objects array of structures of type
1614 * all_test_cases
1615 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +00001616void do_chmod(tc_ptr)
plars865695b2001-08-27 22:15:12 +00001617struct all_test_cases *tc_ptr;
1618{
subrata_modak56207ce2009-03-23 13:35:39 +00001619 if (stat(tc_ptr->fn_arg[2], &asymlink) == -1)
1620 tst_resm(TBROK, "stat(2) Failure when accessing %s object file", tc_ptr->fn_arg[2]);
1621 else if (chmod(tc_ptr->fn_arg[1], (MODE | MASK)) == -1)
1622 tst_resm(TFAIL, "%s%s %s", Buffer,
1623 "chmod(2) failed when changing file permission",
1624 "through symbolic link file");
1625 else {
1626 sprintf(Buf, "chmod(%s, %#o) was successful\n", tc_ptr->fn_arg[1], (MODE | MASK));
1627 strcat(Buffer, Buf);
plars865695b2001-08-27 22:15:12 +00001628
subrata_modak56207ce2009-03-23 13:35:39 +00001629 if (stat(tc_ptr->fn_arg[2], &statter) == -1)
1630 tst_resm(TBROK,
1631 "stat(2) Failure when accessing %s object file",
1632 tc_ptr->fn_arg[2]);
1633 else if ((statter.st_mode == (MODE | MASK))
1634 && (statter.st_mode != asymlink.st_mode))
1635 if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001636 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001637 else
1638 Tst_count++;
1639 else
1640 tst_resm(TFAIL, "%s%s %o to %o %s", Buffer,
1641 "chmod(2) failed to change object file permissions from",
1642 asymlink.st_mode, (MODE | MASK), "through symbolic link file");
1643 }
plars865695b2001-08-27 22:15:12 +00001644
1645}
1646
1647/***********************************************************************
1648 * This routine checks out the utime(2) system call for a successful
1649 * invocation
1650 *
1651 * Argument is pointer to test_objects array of structures of type
1652 * all_test_cases
1653 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +00001654void do_utime(tc_ptr)
plars865695b2001-08-27 22:15:12 +00001655struct all_test_cases *tc_ptr;
1656{
subrata_modak56207ce2009-03-23 13:35:39 +00001657 struct utimbuf utimes;
plars865695b2001-08-27 22:15:12 +00001658
subrata_modak56207ce2009-03-23 13:35:39 +00001659 if (stat(tc_ptr->fn_arg[2], &asymlink) == -1)
1660 tst_resm(TBROK, "stat(2) Failure when accessing %s object file", tc_ptr->fn_arg[2]);
1661 else {
1662 /* Now add a few values to access and modify times */
plars865695b2001-08-27 22:15:12 +00001663
subrata_modak56207ce2009-03-23 13:35:39 +00001664 utimes.actime = asymlink.st_atime + a_time_value;
1665 utimes.modtime = asymlink.st_mtime + a_time_value;
plars865695b2001-08-27 22:15:12 +00001666
subrata_modak56207ce2009-03-23 13:35:39 +00001667 /* Now hand off to utime(2) via symbolic link file */
plars865695b2001-08-27 22:15:12 +00001668
subrata_modak56207ce2009-03-23 13:35:39 +00001669 if (utime(tc_ptr->fn_arg[1], &utimes) == -1)
1670 tst_resm(TFAIL, "%s %s",
1671 "utime(2) failed to process object file access and modify",
1672 "time updates through symbolic link");
1673 else {
1674 /* Now verify changes were made */
plars865695b2001-08-27 22:15:12 +00001675
subrata_modak56207ce2009-03-23 13:35:39 +00001676 if (stat(tc_ptr->fn_arg[2], &statter) == -1)
1677 tst_resm(TBROK,
1678 "stat(2) Failure when accessing %s object file",
1679 tc_ptr->fn_arg[2]);
1680 else {
1681 time_t temp, diff;
plars865695b2001-08-27 22:15:12 +00001682
subrata_modak56207ce2009-03-23 13:35:39 +00001683 temp = statter.st_atime - asymlink.st_atime;
1684 diff = (statter.st_mtime - asymlink.st_mtime) - temp;
1685
1686 if (!diff)
1687 if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001688 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001689 else
1690 Tst_count++;
1691 else
1692 tst_resm(TFAIL,
subrata_modak923b23f2009-11-02 13:57:16 +00001693 "%s %s %jd greater than original times",
subrata_modak56207ce2009-03-23 13:35:39 +00001694 "utime(2) failed to change object file access and",
1695 "modify times through symbolic link to a value",
subrata_modak923b23f2009-11-02 13:57:16 +00001696 (intmax_t)a_time_value);
subrata_modak56207ce2009-03-23 13:35:39 +00001697 }
1698 }
1699 }
plars865695b2001-08-27 22:15:12 +00001700}
1701
1702/***********************************************************************
1703 * This routine checks out the rename(2) system call for a successful
1704 * invocation
1705 *
1706 * Argument is pointer to test_objects array of structures of type
1707 * all_test_cases
1708 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +00001709void do_rename(tc_ptr)
plars865695b2001-08-27 22:15:12 +00001710struct all_test_cases *tc_ptr;
1711{
subrata_modak56207ce2009-03-23 13:35:39 +00001712 int pts_at_object = 0;
plars865695b2001-08-27 22:15:12 +00001713
subrata_modak56207ce2009-03-23 13:35:39 +00001714 if (stat(tc_ptr->fn_arg[2], &statter) != -1)
1715 pts_at_object = 1;
plars865695b2001-08-27 22:15:12 +00001716
subrata_modak56207ce2009-03-23 13:35:39 +00001717 TEST(rename(tc_ptr->fn_arg[1], A_S_FILE));
1718 errno = TEST_ERRNO;
1719 if (TEST_RETURN == -1)
1720 tst_resm(TFAIL,
1721 "rename(3) failed to rename %s symbolic link file to %s",
1722 tc_ptr->fn_arg[2], A_S_FILE);
1723 else if (pts_at_object)
1724 if (ck_both(tc_ptr->fn_arg[0], A_S_FILE, tc_ptr->fn_arg[2]))
1725 if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001726 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001727 else
1728 Tst_count++;
1729 else
vapiere5fce932009-08-28 14:17:14 +00001730 tst_resm(TFAIL, "%s", test_msg);
subrata_modak56207ce2009-03-23 13:35:39 +00001731 else if (!ck_symlink(tc_ptr->fn_arg[0], A_S_FILE, NULL))
vapiere5fce932009-08-28 14:17:14 +00001732 tst_resm(TFAIL, "%s", test_msg);
subrata_modak56207ce2009-03-23 13:35:39 +00001733 else if (stat(tc_ptr->fn_arg[1], &asymlink) != -1)
1734 tst_resm(TFAIL,
1735 "rename(3) did not remove %s when renaming to %s",
1736 tc_ptr->fn_arg[1], A_S_FILE);
1737 else if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001738 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001739 else
plars865695b2001-08-27 22:15:12 +00001740 Tst_count++;
plars865695b2001-08-27 22:15:12 +00001741}
1742
1743/***********************************************************************
1744 * This routine checks out the open(2) system call for a successful
1745 * invocation
1746 *
1747 * Argument is pointer to test_objects array of structures of type
1748 * all_test_cases
1749 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +00001750void do_open(tc_ptr)
plars865695b2001-08-27 22:15:12 +00001751struct all_test_cases *tc_ptr;
1752{
subrata_modak56207ce2009-03-23 13:35:39 +00001753 int fd = -1;
1754 int ret, pts_at_object = 0;
1755 char scratch[PATH_MAX];
plars865695b2001-08-27 22:15:12 +00001756
subrata_modak56207ce2009-03-23 13:35:39 +00001757 if (stat(tc_ptr->fn_arg[2], &statter) != -1)
1758 pts_at_object = 1;
plars865695b2001-08-27 22:15:12 +00001759
subrata_modak56207ce2009-03-23 13:35:39 +00001760 if (pts_at_object) {
1761 TEST(open(tc_ptr->fn_arg[1], O_RDWR));
1762 errno = TEST_ERRNO;
1763 if ((fd = TEST_RETURN) == -1) {
1764 tst_resm(TFAIL,
1765 "open(2) Failure when opening object file through symbolic link file");
1766 return;
1767 }
1768 } else {
1769 TEST(open(tc_ptr->fn_arg[1], (O_CREAT | O_RDWR), MODE));
1770 errno = TEST_ERRNO;
1771 if ((fd = TEST_RETURN) == -1) {
1772 tst_resm(TFAIL,
1773 "open(2) Failure when creating object file through symbolic link file");
1774 return;
1775 }
1776 }
1777 if ((ret = write(fd, BIG_STRING, strlen(BIG_STRING))) == -1) {
1778 tst_resm(TFAIL,
1779 "write(2) Failure to object file opened through a symbolic link file: errno:%d",
1780 errno);
1781 } else if (ret != strlen(BIG_STRING)) {
1782 tst_resm(TFAIL,
vapiere5fce932009-08-28 14:17:14 +00001783 "write(2) Failed to write %zu bytes to object file opened through a symbolic link file",
subrata_modak56207ce2009-03-23 13:35:39 +00001784 strlen(BIG_STRING));
1785 } else if (lseek(fd, 0L, 0) == -1) {
1786 tst_resm(TFAIL,
1787 "lseek(2) Failed to position to beginning of object file opened through a symbolic link file: errno = %d",
1788 errno);
1789 } else if ((ret = read(fd, scratch, strlen(BIG_STRING))) == -1) {
1790 tst_resm(TFAIL,
1791 "read(2) Failure of object file opened through a symbolic link file: errno = %d",
1792 errno);
1793 } else if (ret != strlen(BIG_STRING)) {
1794 tst_resm(TFAIL,
vapiere5fce932009-08-28 14:17:14 +00001795 "read(2) Failed to read %zu bytes to object file opened through a symbolic link file",
subrata_modak56207ce2009-03-23 13:35:39 +00001796 strlen(BIG_STRING));
1797 } else if (strncmp(BIG_STRING, scratch, strlen(BIG_STRING)) != 0) {
1798 tst_resm(TFAIL,
1799 "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",
1800 BIG_STRING, scratch);
1801 } else {
1802 /*
1803 * Close off symbolic link file to object file access
1804 */
1805 if (close(fd) == -1) {
1806 tst_resm(TFAIL,
1807 "close(2) Failure when closing object file accessed symbolic link file");
1808 }
1809 /*
1810 * Now, lets open up and read object file and compare contents
1811 */
1812 else if ((fd = open(tc_ptr->fn_arg[0], O_RDONLY)) == -1) {
1813 tst_resm(TFAIL,
1814 "open(2) Failure when opening %s file: errno:%d %s",
1815 tc_ptr->fn_arg[0], errno, strerror(errno));
1816 } else if ((ret = read(fd, scratch, strlen(BIG_STRING))) == -1) {
1817 tst_resm(TFAIL,
1818 "read(2) Failure of object file opened through a symbolic link file: errno:%d",
1819 errno);
1820 } else if (ret != strlen(BIG_STRING)) {
1821 tst_resm(TFAIL,
vapiere5fce932009-08-28 14:17:14 +00001822 "read(2) Failed to read %zu bytes to object file opened through a symbolic link file",
subrata_modak56207ce2009-03-23 13:35:39 +00001823 strlen(BIG_STRING));
1824 } else if (strncmp(BIG_STRING, scratch, strlen(BIG_STRING)) != 0) {
1825 tst_resm(TFAIL,
1826 "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",
1827 BIG_STRING, scratch);
1828 } else if (pts_at_object) {
1829 if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001830 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001831 else
1832 Tst_count++;
1833 } else { /* Insure newly created object file is pointed at */
1834 if (ck_both(tc_ptr->fn_arg[0], tc_ptr->fn_arg[1], tc_ptr->fn_arg[0]))
1835 if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST)
vapiere5fce932009-08-28 14:17:14 +00001836 tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
subrata_modak56207ce2009-03-23 13:35:39 +00001837 else
1838 Tst_count++;
1839 else
vapiere5fce932009-08-28 14:17:14 +00001840 tst_resm(TFAIL, "%s", test_msg);
subrata_modak56207ce2009-03-23 13:35:39 +00001841 }
1842 close(fd);
1843 }
plars865695b2001-08-27 22:15:12 +00001844}
1845
1846/***************************************************************
1847 * setup() - performs all ONE TIME setup for this test.
1848 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +00001849void setup()
plars865695b2001-08-27 22:15:12 +00001850{
Garrett Cooper2c282152010-12-16 00:55:50 -08001851
subrata_modak56207ce2009-03-23 13:35:39 +00001852 tst_sig(FORK, DEF_HANDLER, cleanup);
plars865695b2001-08-27 22:15:12 +00001853
subrata_modak56207ce2009-03-23 13:35:39 +00001854 TEST_PAUSE;
plars865695b2001-08-27 22:15:12 +00001855
subrata_modak56207ce2009-03-23 13:35:39 +00001856 /* create a temporary directory and go to it */
1857 tst_tmpdir();
plars865695b2001-08-27 22:15:12 +00001858
Garrett Cooper2c282152010-12-16 00:55:50 -08001859}
plars865695b2001-08-27 22:15:12 +00001860
1861/***************************************************************
1862 * cleanup() - performs all ONE TIME cleanup for this test at
1863 * completion or premature exit.
1864 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +00001865void cleanup()
plars865695b2001-08-27 22:15:12 +00001866{
subrata_modak56207ce2009-03-23 13:35:39 +00001867 /*
1868 * print timing stats if that option was specified.
1869 */
1870 TEST_CLEANUP;
plars865695b2001-08-27 22:15:12 +00001871
subrata_modak56207ce2009-03-23 13:35:39 +00001872 tst_rmdir();
plars865695b2001-08-27 22:15:12 +00001873
Garrett Cooper2c282152010-12-16 00:55:50 -08001874}
plars865695b2001-08-27 22:15:12 +00001875
plars865695b2001-08-27 22:15:12 +00001876void help()
1877{
subrata_modak56207ce2009-03-23 13:35:39 +00001878 int ind;
plars865695b2001-08-27 22:15:12 +00001879
subrata_modak56207ce2009-03-23 13:35:39 +00001880 printf(" -T id Determines which tests cases to execute:\n");
plars865695b2001-08-27 22:15:12 +00001881
subrata_modak56207ce2009-03-23 13:35:39 +00001882 for (ind = 0; ind < sizeof(all_tcses) / sizeof(struct tcses); ind++) {
1883 printf(" %s/%s - %s\n", all_tcses[ind].tcid,
1884 all_tcses[ind].syscall, all_tcses[ind].desc);
1885 }
Garrett Cooper2c282152010-12-16 00:55:50 -08001886}