1*49cdfc7eSAndroid Build Coastguard Worker /*
2*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
3*49cdfc7eSAndroid Build Coastguard Worker *
4*49cdfc7eSAndroid Build Coastguard Worker * This program is free software; you can redistribute it and/or modify it
5*49cdfc7eSAndroid Build Coastguard Worker * under the terms of version 2 of the GNU General Public License as
6*49cdfc7eSAndroid Build Coastguard Worker * published by the Free Software Foundation.
7*49cdfc7eSAndroid Build Coastguard Worker *
8*49cdfc7eSAndroid Build Coastguard Worker * This program is distributed in the hope that it would be useful, but
9*49cdfc7eSAndroid Build Coastguard Worker * WITHOUT ANY WARRANTY; without even the implied warranty of
10*49cdfc7eSAndroid Build Coastguard Worker * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11*49cdfc7eSAndroid Build Coastguard Worker *
12*49cdfc7eSAndroid Build Coastguard Worker * Further, this software is distributed without any warranty that it is
13*49cdfc7eSAndroid Build Coastguard Worker * free of the rightful claim of any third person regarding infringement
14*49cdfc7eSAndroid Build Coastguard Worker * or the like. Any license provided herein, whether implied or
15*49cdfc7eSAndroid Build Coastguard Worker * otherwise, applies only to this software file. Patent licenses, if
16*49cdfc7eSAndroid Build Coastguard Worker * any, provided herein do not apply to combinations of this program with
17*49cdfc7eSAndroid Build Coastguard Worker * other software, or any other product whatsoever.
18*49cdfc7eSAndroid Build Coastguard Worker *
19*49cdfc7eSAndroid Build Coastguard Worker * You should have received a copy of the GNU General Public License along
20*49cdfc7eSAndroid Build Coastguard Worker * with this program; if not, write the Free Software Foundation, Inc.,
21*49cdfc7eSAndroid Build Coastguard Worker * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22*49cdfc7eSAndroid Build Coastguard Worker *
23*49cdfc7eSAndroid Build Coastguard Worker * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24*49cdfc7eSAndroid Build Coastguard Worker * Mountain View, CA 94043, or:
25*49cdfc7eSAndroid Build Coastguard Worker *
26*49cdfc7eSAndroid Build Coastguard Worker * http://www.sgi.com
27*49cdfc7eSAndroid Build Coastguard Worker *
28*49cdfc7eSAndroid Build Coastguard Worker * For further information regarding this notice, see:
29*49cdfc7eSAndroid Build Coastguard Worker *
30*49cdfc7eSAndroid Build Coastguard Worker * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
31*49cdfc7eSAndroid Build Coastguard Worker */
32*49cdfc7eSAndroid Build Coastguard Worker /* $Id: symlink01.c,v 1.20 2009/11/02 13:57:19 subrata_modak Exp $ */
33*49cdfc7eSAndroid Build Coastguard Worker /*
34*49cdfc7eSAndroid Build Coastguard Worker * OS Test - Silicon Graphics, Inc.
35*49cdfc7eSAndroid Build Coastguard Worker *
36*49cdfc7eSAndroid Build Coastguard Worker * TEST IDENTIFIER : symlink01 (symlink)
37*49cdfc7eSAndroid Build Coastguard Worker * TEST TITLE : Make a Symbolic Link to a File
38*49cdfc7eSAndroid Build Coastguard Worker * PARENT DOCUMENT : symtds01
39*49cdfc7eSAndroid Build Coastguard Worker * TEST CASE TOTAL : 5
40*49cdfc7eSAndroid Build Coastguard Worker * WALL CLOCK TIME : 3
41*49cdfc7eSAndroid Build Coastguard Worker *
42*49cdfc7eSAndroid Build Coastguard Worker * TEST IDENTIFIER : readlink01 (readlink)
43*49cdfc7eSAndroid Build Coastguard Worker * TEST TITLE : Reads Value of a Symbolic Link
44*49cdfc7eSAndroid Build Coastguard Worker * PARENT DOCUMENT : symtds01
45*49cdfc7eSAndroid Build Coastguard Worker * TEST CASE TOTAL : 4
46*49cdfc7eSAndroid Build Coastguard Worker * WALL CLOCK TIME : 3
47*49cdfc7eSAndroid Build Coastguard Worker *
48*49cdfc7eSAndroid Build Coastguard Worker * TEST IDENTIFIER : stat04 (stat)
49*49cdfc7eSAndroid Build Coastguard Worker * TEST TITLE : Gets File Status Indirectly From a Symbolic Link File
50*49cdfc7eSAndroid Build Coastguard Worker * PARENT DOCUMENT : symtds01
51*49cdfc7eSAndroid Build Coastguard Worker * TEST CASE TOTAL : 3
52*49cdfc7eSAndroid Build Coastguard Worker * WALL CLOCK TIME : 3
53*49cdfc7eSAndroid Build Coastguard Worker *
54*49cdfc7eSAndroid Build Coastguard Worker * TEST IDENTIFIER : lstat01 (lstat)
55*49cdfc7eSAndroid Build Coastguard Worker * TEST TITLE : Get file Status About a Symbolic Link File
56*49cdfc7eSAndroid Build Coastguard Worker * PARENT DOCUMENT : symtds01
57*49cdfc7eSAndroid Build Coastguard Worker * TEST CASE TOTAL : 3
58*49cdfc7eSAndroid Build Coastguard Worker * WALL CLOCK TIME : 3
59*49cdfc7eSAndroid Build Coastguard Worker *
60*49cdfc7eSAndroid Build Coastguard Worker * TEST IDENTIFIER : mkdir05 (mkdir)
61*49cdfc7eSAndroid Build Coastguard Worker * TEST TITLE : Fail When Making a Directory File Indirectly From
62*49cdfc7eSAndroid Build Coastguard Worker * a Symbolic Link File
63*49cdfc7eSAndroid Build Coastguard Worker * PARENT DOCUMENT : symtds01
64*49cdfc7eSAndroid Build Coastguard Worker * TEST CASE TOTAL : 1
65*49cdfc7eSAndroid Build Coastguard Worker * WALL CLOCK TIME : 3
66*49cdfc7eSAndroid Build Coastguard Worker *
67*49cdfc7eSAndroid Build Coastguard Worker * TEST IDENTIFIER : rmdir03 (rmdir)
68*49cdfc7eSAndroid Build Coastguard Worker * TEST TITLE : Fail When Removing a Directory File Indirectly
69*49cdfc7eSAndroid Build Coastguard Worker * From a Symbolic Link File
70*49cdfc7eSAndroid Build Coastguard Worker * PARENT DOCUMENT : symtds01
71*49cdfc7eSAndroid Build Coastguard Worker * TEST CASE TOTAL : 1
72*49cdfc7eSAndroid Build Coastguard Worker * WALL CLOCK TIME : 3
73*49cdfc7eSAndroid Build Coastguard Worker *
74*49cdfc7eSAndroid Build Coastguard Worker * TEST IDENTIFIER : chdir01 (chdir)
75*49cdfc7eSAndroid Build Coastguard Worker * TEST TITLE : Changes Current Working DIrectory Location
76*49cdfc7eSAndroid Build Coastguard Worker * Indirectly From a Symbolic Link File
77*49cdfc7eSAndroid Build Coastguard Worker * PARENT DOCUMENT : symtds01
78*49cdfc7eSAndroid Build Coastguard Worker * TEST CASE TOTAL : 3
79*49cdfc7eSAndroid Build Coastguard Worker * WALL CLOCK TIME : 3
80*49cdfc7eSAndroid Build Coastguard Worker *
81*49cdfc7eSAndroid Build Coastguard Worker * TEST IDENTIFIER : link01 (link)
82*49cdfc7eSAndroid Build Coastguard Worker * TEST TITLE : Creates a Link To a File Indirectly From a
83*49cdfc7eSAndroid Build Coastguard Worker * Symbolic Link File
84*49cdfc7eSAndroid Build Coastguard Worker * PARENT DOCUMENT : symtds01
85*49cdfc7eSAndroid Build Coastguard Worker * TEST CASE TOTAL : 3
86*49cdfc7eSAndroid Build Coastguard Worker * WALL CLOCK TIME : 3
87*49cdfc7eSAndroid Build Coastguard Worker *
88*49cdfc7eSAndroid Build Coastguard Worker * TEST IDENTIFIER : unlink01 (unlink)
89*49cdfc7eSAndroid Build Coastguard Worker * TEST TITLE : Removes a Link To a File And Not Any Object File
90*49cdfc7eSAndroid Build Coastguard Worker * Which Maybe Pointed At
91*49cdfc7eSAndroid Build Coastguard Worker * PARENT DOCUMENT : symtds01
92*49cdfc7eSAndroid Build Coastguard Worker * TEST CASE TOTAL : 1
93*49cdfc7eSAndroid Build Coastguard Worker * WALL CLOCK TIME : 3
94*49cdfc7eSAndroid Build Coastguard Worker *
95*49cdfc7eSAndroid Build Coastguard Worker * TEST IDENTIFIER : chmod01 (chmod)
96*49cdfc7eSAndroid Build Coastguard Worker * TEST TITLE : Change Object File Permissions Indirectly From a
97*49cdfc7eSAndroid Build Coastguard Worker * Symbolic Link File
98*49cdfc7eSAndroid Build Coastguard Worker * PARENT DOCUMENT : symtds01
99*49cdfc7eSAndroid Build Coastguard Worker * TEST CASE TOTAL : 3
100*49cdfc7eSAndroid Build Coastguard Worker * WALL CLOCK TIME : 3
101*49cdfc7eSAndroid Build Coastguard Worker *
102*49cdfc7eSAndroid Build Coastguard Worker * TEST IDENTIFIER : utime01 (utime)
103*49cdfc7eSAndroid Build Coastguard Worker * TEST TITLE : Set File Access And Modify Object File Times
104*49cdfc7eSAndroid Build Coastguard Worker * Indirectly From a Symbolic Link File
105*49cdfc7eSAndroid Build Coastguard Worker * PARENT DOCUMENT : symtds01
106*49cdfc7eSAndroid Build Coastguard Worker * TEST CASE TOTAL : 3
107*49cdfc7eSAndroid Build Coastguard Worker * WALL CLOCK TIME : 3
108*49cdfc7eSAndroid Build Coastguard Worker *
109*49cdfc7eSAndroid Build Coastguard Worker * TEST IDENTIFIER : rename01 (rename)
110*49cdfc7eSAndroid Build Coastguard Worker * TEST TITLE : Rename a Symbolic Link File And Not Any Object
111*49cdfc7eSAndroid Build Coastguard Worker * File
112*49cdfc7eSAndroid Build Coastguard Worker * PARENT DOCUMENT : symtds01
113*49cdfc7eSAndroid Build Coastguard Worker * TEST CASE TOTAL : 3
114*49cdfc7eSAndroid Build Coastguard Worker * WALL CLOCK TIME : 3
115*49cdfc7eSAndroid Build Coastguard Worker *
116*49cdfc7eSAndroid Build Coastguard Worker * TEST IDENTIFIER : open01 (open)
117*49cdfc7eSAndroid Build Coastguard Worker * TEST TITLE : Create/Open a File For Reading Or Writing
118*49cdfc7eSAndroid Build Coastguard Worker * Indirectly From a Symbolic Link File
119*49cdfc7eSAndroid Build Coastguard Worker * PARENT DOCUMENT : symtds01
120*49cdfc7eSAndroid Build Coastguard Worker * TEST CASE TOTAL : 5
121*49cdfc7eSAndroid Build Coastguard Worker * WALL CLOCK TIME : 3
122*49cdfc7eSAndroid Build Coastguard Worker *
123*49cdfc7eSAndroid Build Coastguard Worker *
124*49cdfc7eSAndroid Build Coastguard Worker * EXECUTED BY : whom ever
125*49cdfc7eSAndroid Build Coastguard Worker * CPU TYPES : ALL
126*49cdfc7eSAndroid Build Coastguard Worker * AUTHOR : David Fenner
127*49cdfc7eSAndroid Build Coastguard Worker * CO-PILOT : Jon Hendrickson
128*49cdfc7eSAndroid Build Coastguard Worker * DATE STARTED : 07/25/90
129*49cdfc7eSAndroid Build Coastguard Worker * INITIAL RELEASE : UNICOS 6.0
130*49cdfc7eSAndroid Build Coastguard Worker *
131*49cdfc7eSAndroid Build Coastguard Worker * TEST CASES
132*49cdfc7eSAndroid Build Coastguard Worker *
133*49cdfc7eSAndroid Build Coastguard Worker * For symlink
134*49cdfc7eSAndroid Build Coastguard Worker * 1. Create symbolic link with abnormal object name path
135*49cdfc7eSAndroid Build Coastguard Worker * 2. Create symbolic link with normal object name path
136*49cdfc7eSAndroid Build Coastguard Worker * 3. Create symbolic link with path to an existing object file
137*49cdfc7eSAndroid Build Coastguard Worker * 4. Receive EEXIST error when creating an already existing symbolic link file.
138*49cdfc7eSAndroid Build Coastguard Worker * 5. Receive ENAMETOOLONG error when creating symbolic link which exceeds PATH_MAX in length
139*49cdfc7eSAndroid Build Coastguard Worker *
140*49cdfc7eSAndroid Build Coastguard Worker * For readlink
141*49cdfc7eSAndroid Build Coastguard Worker * 1. Read a symbolic link file which points at no object file
142*49cdfc7eSAndroid Build Coastguard Worker * 2. Read a symbolic link file which points at an object file
143*49cdfc7eSAndroid Build Coastguard Worker * 3. Receive ENAMETOOLONG error when reading symbolic link which exceeds PATH_MAX in length
144*49cdfc7eSAndroid Build Coastguard Worker * 4. Receive an EINVAL error when reading a file which is not a symbolic
145*49cdfc7eSAndroid Build Coastguard Worker * link file.
146*49cdfc7eSAndroid Build Coastguard Worker *
147*49cdfc7eSAndroid Build Coastguard Worker * For stat
148*49cdfc7eSAndroid Build Coastguard Worker * 1. Get object file status through symbolic link file
149*49cdfc7eSAndroid Build Coastguard Worker * 2. Receive ENOENT error when accessing non-existent object file through symbolic link file
150*49cdfc7eSAndroid Build Coastguard Worker * 3. Receive ELOOP error when nesting of symbolic links exceed maximum
151*49cdfc7eSAndroid Build Coastguard Worker *
152*49cdfc7eSAndroid Build Coastguard Worker * For lstat
153*49cdfc7eSAndroid Build Coastguard Worker * 1. Get symbolic link file status when pointing at no object file
154*49cdfc7eSAndroid Build Coastguard Worker * 2. Get symbolic link file status when pointing at an object file
155*49cdfc7eSAndroid Build Coastguard Worker * 3. Get object file status when argument is not a symbolic link
156*49cdfc7eSAndroid Build Coastguard Worker * file.
157*49cdfc7eSAndroid Build Coastguard Worker *
158*49cdfc7eSAndroid Build Coastguard Worker * For mkdir
159*49cdfc7eSAndroid Build Coastguard Worker * 1. Receive EEXIST error when creating a directory through a symbolic link file
160*49cdfc7eSAndroid Build Coastguard Worker *
161*49cdfc7eSAndroid Build Coastguard Worker * For rmdir
162*49cdfc7eSAndroid Build Coastguard Worker * 1. Receive ENOTDIR error when removing an existing directory through a symbolic link file
163*49cdfc7eSAndroid Build Coastguard Worker *
164*49cdfc7eSAndroid Build Coastguard Worker * For chdir
165*49cdfc7eSAndroid Build Coastguard Worker * 1. Change current working directory through a symbolic link file
166*49cdfc7eSAndroid Build Coastguard Worker * 2. Receive ENOENT error when accessing non-existent directory through symbolic link file
167*49cdfc7eSAndroid Build Coastguard Worker * 3. Receive ELOOP error when nesting of symbolic links exceed maximum
168*49cdfc7eSAndroid Build Coastguard Worker *
169*49cdfc7eSAndroid Build Coastguard Worker * For link
170*49cdfc7eSAndroid Build Coastguard Worker * 1. Link an object file to a new file through symbolic link file
171*49cdfc7eSAndroid Build Coastguard Worker * 2. Receive ENOENT error when accessing non-existent object file through symbolic link file
172*49cdfc7eSAndroid Build Coastguard Worker * 3. Receive ELOOP error when nesting of symbolic links exceed maximum
173*49cdfc7eSAndroid Build Coastguard Worker *
174*49cdfc7eSAndroid Build Coastguard Worker * For unlink
175*49cdfc7eSAndroid Build Coastguard Worker * 1. Delete a symbolic link file and not the object file which it points at
176*49cdfc7eSAndroid Build Coastguard Worker *
177*49cdfc7eSAndroid Build Coastguard Worker * For chmod
178*49cdfc7eSAndroid Build Coastguard Worker * 1. Change file permissions of object file through a symbolic link file
179*49cdfc7eSAndroid Build Coastguard Worker * 2. Receive ENOENT error when accessing non-existent directory through symbolic link file
180*49cdfc7eSAndroid Build Coastguard Worker * 3. Receive ELOOP error when nesting of symbolic links exceed maximum
181*49cdfc7eSAndroid Build Coastguard Worker *
182*49cdfc7eSAndroid Build Coastguard Worker * For utime
183*49cdfc7eSAndroid Build Coastguard Worker * 1. Change inode times of object file through a symbolic link file
184*49cdfc7eSAndroid Build Coastguard Worker * 2. Receive ENOENT error when accessing non-existent directory through symbolic link file
185*49cdfc7eSAndroid Build Coastguard Worker * 3. Receive ELOOP error when nesting of symbolic links exceed maximum
186*49cdfc7eSAndroid Build Coastguard Worker *
187*49cdfc7eSAndroid Build Coastguard Worker * For rename
188*49cdfc7eSAndroid Build Coastguard Worker * 1. Rename a symbolic link file which points at no object file
189*49cdfc7eSAndroid Build Coastguard Worker * 2. Rename a symbolic link file which points at an object file without any object file alterations.
190*49cdfc7eSAndroid Build Coastguard Worker * 3. Receive EXDEV when trying to rename a symbolic link file to an address outside of current file system
191*49cdfc7eSAndroid Build Coastguard Worker *
192*49cdfc7eSAndroid Build Coastguard Worker * For open
193*49cdfc7eSAndroid Build Coastguard Worker * 1. Create an object file through a symbolic link file
194*49cdfc7eSAndroid Build Coastguard Worker * 2. Open an object file through a symbolic link file
195*49cdfc7eSAndroid Build Coastguard Worker * 3. Receive EEXIST error when exclusively creating an object file through a symbolic link file
196*49cdfc7eSAndroid Build Coastguard Worker * 4. Receive ENOENT error when accessing non-existent object file through symbolic link file
197*49cdfc7eSAndroid Build Coastguard Worker * 5. Receive ELOOP error when nesting of symbolic links exceed maximum
198*49cdfc7eSAndroid Build Coastguard Worker *
199*49cdfc7eSAndroid Build Coastguard Worker * ENVIRONMENTAL NEEDS
200*49cdfc7eSAndroid Build Coastguard Worker * None
201*49cdfc7eSAndroid Build Coastguard Worker *
202*49cdfc7eSAndroid Build Coastguard Worker * DETAILED DESCRIPTION
203*49cdfc7eSAndroid Build Coastguard Worker *
204*49cdfc7eSAndroid Build Coastguard Worker * Self-documenting code so see below
205*49cdfc7eSAndroid Build Coastguard Worker */
206*49cdfc7eSAndroid Build Coastguard Worker
207*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
208*49cdfc7eSAndroid Build Coastguard Worker #include <signal.h>
209*49cdfc7eSAndroid Build Coastguard Worker #include <string.h>
210*49cdfc7eSAndroid Build Coastguard Worker #include <fcntl.h> /* open(2) system call */
211*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
212*49cdfc7eSAndroid Build Coastguard Worker #include <sys/types.h>
213*49cdfc7eSAndroid Build Coastguard Worker #include <utime.h> /* utime(2) system call */
214*49cdfc7eSAndroid Build Coastguard Worker #include <sys/param.h>
215*49cdfc7eSAndroid Build Coastguard Worker #include <sys/stat.h> /* stat(2) and lstat(2) system calls */
216*49cdfc7eSAndroid Build Coastguard Worker #include <stdint.h>
217*49cdfc7eSAndroid Build Coastguard Worker #include <unistd.h>
218*49cdfc7eSAndroid Build Coastguard Worker
219*49cdfc7eSAndroid Build Coastguard Worker #include "test.h"
220*49cdfc7eSAndroid Build Coastguard Worker
221*49cdfc7eSAndroid Build Coastguard Worker void setup(void);
222*49cdfc7eSAndroid Build Coastguard Worker void cleanup(void);
223*49cdfc7eSAndroid Build Coastguard Worker void help(void);
224*49cdfc7eSAndroid Build Coastguard Worker void delete_files(char *path1, char *path2);
225*49cdfc7eSAndroid Build Coastguard Worker struct all_test_cases;
226*49cdfc7eSAndroid Build Coastguard Worker void do_EEXIST(struct all_test_cases *tc_ptr);
227*49cdfc7eSAndroid Build Coastguard Worker void do_ENOENT(struct all_test_cases *tc_ptr);
228*49cdfc7eSAndroid Build Coastguard Worker void do_ELOOP(struct all_test_cases *tc_ptr);
229*49cdfc7eSAndroid Build Coastguard Worker void do_ENOTDIR(struct all_test_cases *tc_ptr);
230*49cdfc7eSAndroid Build Coastguard Worker void do_EXDEV(struct all_test_cases *tc_ptr);
231*49cdfc7eSAndroid Build Coastguard Worker void do_ENAMETOOLONG(struct all_test_cases *tc_ptr);
232*49cdfc7eSAndroid Build Coastguard Worker void do_EINVAL(struct all_test_cases *tc_ptr);
233*49cdfc7eSAndroid Build Coastguard Worker void do_readlink(struct all_test_cases *tc_ptr);
234*49cdfc7eSAndroid Build Coastguard Worker void do_stat(struct all_test_cases *tc_ptr);
235*49cdfc7eSAndroid Build Coastguard Worker void do_chdir(struct all_test_cases *tc_ptr);
236*49cdfc7eSAndroid Build Coastguard Worker void do_link(struct all_test_cases *tc_ptr);
237*49cdfc7eSAndroid Build Coastguard Worker void do_unlink(struct all_test_cases *tc_ptr);
238*49cdfc7eSAndroid Build Coastguard Worker void do_chmod(struct all_test_cases *tc_ptr);
239*49cdfc7eSAndroid Build Coastguard Worker void do_utime(struct all_test_cases *tc_ptr);
240*49cdfc7eSAndroid Build Coastguard Worker void do_rename(struct all_test_cases *tc_ptr);
241*49cdfc7eSAndroid Build Coastguard Worker void do_open(struct all_test_cases *tc_ptr);
242*49cdfc7eSAndroid Build Coastguard Worker struct tcses;
243*49cdfc7eSAndroid Build Coastguard Worker int do_syscalltests(struct tcses *tcs);
244*49cdfc7eSAndroid Build Coastguard Worker struct tcses *get_tcs_info(char *ptr);
245*49cdfc7eSAndroid Build Coastguard Worker
246*49cdfc7eSAndroid Build Coastguard Worker #define S_FILE "symbolic" /* Name of symbolic link file */
247*49cdfc7eSAndroid Build Coastguard Worker #define O_FILE "object" /* Name of object file */
248*49cdfc7eSAndroid Build Coastguard Worker #define A_S_FILE "asymbolic" /* Another name for a symbolic link file */
249*49cdfc7eSAndroid Build Coastguard Worker #define Y_A_S_FILE "/NiCkEr" /* Yet another symbolic link file */
250*49cdfc7eSAndroid Build Coastguard Worker #define BIG_STRING "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
251*49cdfc7eSAndroid Build Coastguard Worker
252*49cdfc7eSAndroid Build Coastguard Worker #define DEFAULT_TCID "symlink01"
253*49cdfc7eSAndroid Build Coastguard Worker
254*49cdfc7eSAndroid Build Coastguard Worker #define SYMLINK "symlink01"
255*49cdfc7eSAndroid Build Coastguard Worker #define READLINK "readlink01"
256*49cdfc7eSAndroid Build Coastguard Worker #define STAT "stat04"
257*49cdfc7eSAndroid Build Coastguard Worker #define STAT_64 "stat04_64"
258*49cdfc7eSAndroid Build Coastguard Worker #define LSTAT "lstat01"
259*49cdfc7eSAndroid Build Coastguard Worker #define LSTAT_64 "lstat01_64"
260*49cdfc7eSAndroid Build Coastguard Worker #define MKDIR "mkdir05"
261*49cdfc7eSAndroid Build Coastguard Worker #define RMDIR "rmdir03"
262*49cdfc7eSAndroid Build Coastguard Worker #define CHDIR "chdir01"
263*49cdfc7eSAndroid Build Coastguard Worker #define LINK "link01"
264*49cdfc7eSAndroid Build Coastguard Worker #define UNLINK "unlink01"
265*49cdfc7eSAndroid Build Coastguard Worker #define CHMOD "chmod01"
266*49cdfc7eSAndroid Build Coastguard Worker #define UTIME "utime01"
267*49cdfc7eSAndroid Build Coastguard Worker #define RENAME "rename01"
268*49cdfc7eSAndroid Build Coastguard Worker #define OPEN "open01"
269*49cdfc7eSAndroid Build Coastguard Worker
270*49cdfc7eSAndroid Build Coastguard Worker #define cktcsid(s1,s2) (!strcmp(s1,s2))
271*49cdfc7eSAndroid Build Coastguard Worker #define BUFMAX 512
272*49cdfc7eSAndroid Build Coastguard Worker #define MODE 0700
273*49cdfc7eSAndroid Build Coastguard Worker #define MASK 0100777 /* A regular file with r,w,x for all mask */
274*49cdfc7eSAndroid Build Coastguard Worker
275*49cdfc7eSAndroid Build Coastguard Worker /*
276*49cdfc7eSAndroid Build Coastguard Worker * Lets be optimistic and only define messages for passing test cases
277*49cdfc7eSAndroid Build Coastguard Worker */
278*49cdfc7eSAndroid Build Coastguard Worker const char *msgs[] = {
279*49cdfc7eSAndroid Build Coastguard Worker "Creation of symbolic link file to no object file is ok",
280*49cdfc7eSAndroid Build Coastguard Worker "Creation of symbolic link file and object file via symbolic link is ok",
281*49cdfc7eSAndroid Build Coastguard Worker "Creating an existing symbolic link file error is caught",
282*49cdfc7eSAndroid Build Coastguard Worker "Creating a symbolic link which exceeds maximum pathname error is caught",
283*49cdfc7eSAndroid Build Coastguard Worker "Reading of symbolic link file contents checks out ok",
284*49cdfc7eSAndroid Build Coastguard Worker "Reading a symbolic link which exceeds maximum pathname error is caught",
285*49cdfc7eSAndroid Build Coastguard Worker "Getting stat info about object file through symbolic link file is ok",
286*49cdfc7eSAndroid Build Coastguard Worker "Stat(2) error when accessing non-existent object through symbolic link is caught",
287*49cdfc7eSAndroid Build Coastguard Worker "lstat(2) of symbolic link file which points to no object file is ok",
288*49cdfc7eSAndroid Build Coastguard Worker "lstat(2) of symbolic link file which points at an object file is ok",
289*49cdfc7eSAndroid Build Coastguard Worker "mkdir(2) of object file through symbolic link file failed as expected",
290*49cdfc7eSAndroid Build Coastguard Worker "rmdir(2) of object file through symbolic link file failed as expected",
291*49cdfc7eSAndroid Build Coastguard Worker "chdir(2) to object file location through symbolic link file is ok",
292*49cdfc7eSAndroid Build Coastguard Worker "chdir(2) to non-existent object file location through symbolic link file failed as expected",
293*49cdfc7eSAndroid Build Coastguard Worker "link(2) to a symbolic link, which is pointing to an existing object file worked - file created and link count adjusted",
294*49cdfc7eSAndroid Build Coastguard Worker "link(2) to a symbolic link, which is pointing to a non-existing object file worked ok - file created and link count adjusted.",
295*49cdfc7eSAndroid Build Coastguard Worker "unlink(2) of symbolic link file with no object file removal is ok",
296*49cdfc7eSAndroid Build Coastguard Worker "chmod(2) of object file permissions through symbolic link file is ok",
297*49cdfc7eSAndroid Build Coastguard Worker "chmod(2) error when accessing non-existent object through symbolic link is caught",
298*49cdfc7eSAndroid Build Coastguard Worker "utime(2) change of object file access and modify times through symbolic link file is ok",
299*49cdfc7eSAndroid Build Coastguard Worker "utime(2) error when accessing non-existent object through symbolic link is caught",
300*49cdfc7eSAndroid Build Coastguard Worker "rename(3) of symbolic link file name which points at no object file is ok",
301*49cdfc7eSAndroid Build Coastguard Worker "rename(3) of symbolic link file name which points at object file is ok",
302*49cdfc7eSAndroid Build Coastguard Worker "rename(3) error of symbolic link file name across file systems is caught",
303*49cdfc7eSAndroid Build Coastguard Worker "open(2) with (O_CREAT | O_RDWR) to create object file through symbolic link file and all writes, reads, and lseeks are ok",
304*49cdfc7eSAndroid Build Coastguard Worker "open(2) with O_RDWR of existing object file through symbolic link file and all writes, reads, and lseeks are ok",
305*49cdfc7eSAndroid Build Coastguard Worker "open(2) with (O_CREAT | O_EXCL) error is caught when creating object file through symbolic link file",
306*49cdfc7eSAndroid Build Coastguard Worker "open(2) error with O_RDWR is caught when processing symbolic link file which points at no object file",
307*49cdfc7eSAndroid Build Coastguard Worker "Nested symbolic link access condition caught. ELOOP is returned",
308*49cdfc7eSAndroid Build Coastguard Worker "Reading a nonsymbolic link file error condition is caught. EINVAL is returned",
309*49cdfc7eSAndroid Build Coastguard Worker "lstat(2) of object file returns object file inode information",
310*49cdfc7eSAndroid Build Coastguard Worker "NULL"
311*49cdfc7eSAndroid Build Coastguard Worker };
312*49cdfc7eSAndroid Build Coastguard Worker
313*49cdfc7eSAndroid Build Coastguard Worker /*
314*49cdfc7eSAndroid Build Coastguard Worker * Define test object setup and validation functions
315*49cdfc7eSAndroid Build Coastguard Worker */
316*49cdfc7eSAndroid Build Coastguard Worker int creat_both(char *path1, char *path2, char *path3);
317*49cdfc7eSAndroid Build Coastguard Worker int creat_symlink(char *path1, char *path2, char *_path3);
318*49cdfc7eSAndroid Build Coastguard Worker int creat_path_max(char *path1, char *path2, char *path3);
319*49cdfc7eSAndroid Build Coastguard Worker int ck_symlink(char *path1, char *path2, char *path3);
320*49cdfc7eSAndroid Build Coastguard Worker int creat_object(char *path1, char *_path2, char *_path3);
321*49cdfc7eSAndroid Build Coastguard Worker int ck_object(char *path1, char *path2, char *path3);
322*49cdfc7eSAndroid Build Coastguard Worker int ck_both(char *path1, char *path2, char *path3);
323*49cdfc7eSAndroid Build Coastguard Worker int ck_path_max(char *path1, char *path2, char *path3);
324*49cdfc7eSAndroid Build Coastguard Worker
325*49cdfc7eSAndroid Build Coastguard Worker /*
326*49cdfc7eSAndroid Build Coastguard Worker * Define test cases
327*49cdfc7eSAndroid Build Coastguard Worker */
328*49cdfc7eSAndroid Build Coastguard Worker struct all_test_cases {
329*49cdfc7eSAndroid Build Coastguard Worker char *tcid;
330*49cdfc7eSAndroid Build Coastguard Worker int test_fail;
331*49cdfc7eSAndroid Build Coastguard Worker int errno_val;
332*49cdfc7eSAndroid Build Coastguard Worker int pass_msg;
333*49cdfc7eSAndroid Build Coastguard Worker int (*test_setup) (char *path1, char *path2, char *path3);
334*49cdfc7eSAndroid Build Coastguard Worker int (*ck_test) (char *path1, char *path2, char *path3);
335*49cdfc7eSAndroid Build Coastguard Worker char *fn_arg[3];
336*49cdfc7eSAndroid Build Coastguard Worker
337*49cdfc7eSAndroid Build Coastguard Worker } test_objects[] = {
338*49cdfc7eSAndroid Build Coastguard Worker {
339*49cdfc7eSAndroid Build Coastguard Worker SYMLINK, 0, 0, 0, creat_symlink, ck_symlink, {
340*49cdfc7eSAndroid Build Coastguard Worker "%bc+eFhi!k", S_FILE, NULL}}, {
341*49cdfc7eSAndroid Build Coastguard Worker SYMLINK, 0, 0, 0, creat_symlink, ck_symlink, {
342*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, NULL}}, {
343*49cdfc7eSAndroid Build Coastguard Worker SYMLINK, 0, 0, 1, creat_both, ck_both, {
344*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, O_FILE}}, {
345*49cdfc7eSAndroid Build Coastguard Worker SYMLINK, 1, EEXIST, 2, creat_symlink, ck_symlink, {
346*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, NULL}}, {
347*49cdfc7eSAndroid Build Coastguard Worker SYMLINK, 1, ENAMETOOLONG, 3, creat_path_max, ck_path_max, {
348*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, NULL}}, {
349*49cdfc7eSAndroid Build Coastguard Worker READLINK, 0, 0, 4, creat_symlink, ck_symlink, {
350*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, NULL}}, {
351*49cdfc7eSAndroid Build Coastguard Worker READLINK, 0, 0, 4, creat_both, ck_both, {
352*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, O_FILE}}, {
353*49cdfc7eSAndroid Build Coastguard Worker READLINK, 1, ENAMETOOLONG, 5, creat_path_max, ck_path_max, {
354*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, NULL}}, {
355*49cdfc7eSAndroid Build Coastguard Worker READLINK, 1, EINVAL, 29, creat_object, ck_object, {
356*49cdfc7eSAndroid Build Coastguard Worker O_FILE, NULL, NULL}}, {
357*49cdfc7eSAndroid Build Coastguard Worker STAT, 0, 0, 6, creat_both, ck_both, {
358*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, O_FILE}},
359*49cdfc7eSAndroid Build Coastguard Worker /* 10 */
360*49cdfc7eSAndroid Build Coastguard Worker {
361*49cdfc7eSAndroid Build Coastguard Worker STAT, 1, ENOENT, 7, creat_symlink, ck_symlink, {
362*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, NULL}}, {
363*49cdfc7eSAndroid Build Coastguard Worker STAT, 1, ELOOP, 28, creat_symlink, ck_symlink, {
364*49cdfc7eSAndroid Build Coastguard Worker S_FILE, S_FILE, NULL}}, {
365*49cdfc7eSAndroid Build Coastguard Worker STAT_64, 0, 0, 6, creat_both, ck_both, {
366*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, O_FILE}}, {
367*49cdfc7eSAndroid Build Coastguard Worker STAT_64, 1, ENOENT, 7, creat_symlink, ck_symlink, {
368*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, NULL}}, {
369*49cdfc7eSAndroid Build Coastguard Worker STAT_64, 1, ELOOP, 28, creat_symlink, ck_symlink, {
370*49cdfc7eSAndroid Build Coastguard Worker S_FILE, S_FILE, NULL}}, {
371*49cdfc7eSAndroid Build Coastguard Worker LSTAT, 0, 0, 8, creat_symlink, ck_symlink, {
372*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, NULL}}, {
373*49cdfc7eSAndroid Build Coastguard Worker LSTAT, 0, 0, 9, creat_both, ck_both, {
374*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, O_FILE}}, {
375*49cdfc7eSAndroid Build Coastguard Worker LSTAT, 0, 0, 30, creat_object, ck_object, {
376*49cdfc7eSAndroid Build Coastguard Worker O_FILE, NULL, NULL}}, {
377*49cdfc7eSAndroid Build Coastguard Worker LSTAT_64, 0, 0, 8, creat_symlink, ck_symlink, {
378*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, NULL}}, {
379*49cdfc7eSAndroid Build Coastguard Worker LSTAT_64, 0, 0, 9, creat_both, ck_both, {
380*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, O_FILE}},
381*49cdfc7eSAndroid Build Coastguard Worker /* 20 */
382*49cdfc7eSAndroid Build Coastguard Worker {
383*49cdfc7eSAndroid Build Coastguard Worker LSTAT_64, 0, 0, 30, creat_object, ck_object, {
384*49cdfc7eSAndroid Build Coastguard Worker O_FILE, NULL, NULL}}, {
385*49cdfc7eSAndroid Build Coastguard Worker MKDIR, 1, EEXIST, 10, creat_symlink, ck_symlink, {
386*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, NULL}}, {
387*49cdfc7eSAndroid Build Coastguard Worker RMDIR, 1, ENOTDIR, 11, creat_symlink, ck_symlink, {
388*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, NULL}}, {
389*49cdfc7eSAndroid Build Coastguard Worker CHDIR, 0, 0, 12, creat_symlink, ck_symlink, {
390*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, O_FILE}}, {
391*49cdfc7eSAndroid Build Coastguard Worker CHDIR, 1, ENOENT, 13, creat_symlink, ck_symlink, {
392*49cdfc7eSAndroid Build Coastguard Worker "%bc+eFhi!k", S_FILE, NULL}}, {
393*49cdfc7eSAndroid Build Coastguard Worker CHDIR, 1, ELOOP, 28, creat_symlink, ck_symlink, {
394*49cdfc7eSAndroid Build Coastguard Worker S_FILE, S_FILE, NULL}}, {
395*49cdfc7eSAndroid Build Coastguard Worker LINK, 0, 0, 14, creat_both, ck_both, {
396*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, O_FILE}}, {
397*49cdfc7eSAndroid Build Coastguard Worker LINK, 0, 0, 15, creat_symlink, ck_symlink, {
398*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, NULL}},
399*49cdfc7eSAndroid Build Coastguard Worker /* The following link test case is invalid - leaving it defined so */
400*49cdfc7eSAndroid Build Coastguard Worker /* I don't have to change all the entries in the all_tcses array after link */
401*49cdfc7eSAndroid Build Coastguard Worker /* It has been disabled at the moment. */
402*49cdfc7eSAndroid Build Coastguard Worker {
403*49cdfc7eSAndroid Build Coastguard Worker LINK, 1, -1, -1, creat_symlink, ck_symlink, {
404*49cdfc7eSAndroid Build Coastguard Worker NULL, NULL, NULL}}, {
405*49cdfc7eSAndroid Build Coastguard Worker UNLINK, 0, 0, 16, creat_both, ck_both, {
406*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, O_FILE}},
407*49cdfc7eSAndroid Build Coastguard Worker /* 30 */
408*49cdfc7eSAndroid Build Coastguard Worker {
409*49cdfc7eSAndroid Build Coastguard Worker CHMOD, 0, 0, 17, creat_both, ck_both, {
410*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, O_FILE}}, {
411*49cdfc7eSAndroid Build Coastguard Worker CHMOD, 1, ENOENT, 18, creat_symlink, ck_symlink, {
412*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, NULL}}, {
413*49cdfc7eSAndroid Build Coastguard Worker CHMOD, 1, ELOOP, 28, creat_symlink, ck_symlink, {
414*49cdfc7eSAndroid Build Coastguard Worker S_FILE, S_FILE, NULL}}, {
415*49cdfc7eSAndroid Build Coastguard Worker UTIME, 0, 0, 19, creat_both, ck_both, {
416*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, O_FILE}}, {
417*49cdfc7eSAndroid Build Coastguard Worker UTIME, 1, ENOENT, 20, creat_symlink, ck_symlink, {
418*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, NULL}}, {
419*49cdfc7eSAndroid Build Coastguard Worker UTIME, 1, ELOOP, 28, creat_symlink, ck_symlink, {
420*49cdfc7eSAndroid Build Coastguard Worker S_FILE, S_FILE, NULL}}, {
421*49cdfc7eSAndroid Build Coastguard Worker RENAME, 0, 0, 21, creat_symlink, ck_symlink, {
422*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, NULL}}, {
423*49cdfc7eSAndroid Build Coastguard Worker RENAME, 0, 0, 22, creat_both, ck_both, {
424*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, O_FILE}},
425*49cdfc7eSAndroid Build Coastguard Worker /* The following rename test makes assumption that the link and target */
426*49cdfc7eSAndroid Build Coastguard Worker /* files are located in different filesystems, which is incorrect. */
427*49cdfc7eSAndroid Build Coastguard Worker /* It has been disabled at the moment. */
428*49cdfc7eSAndroid Build Coastguard Worker {
429*49cdfc7eSAndroid Build Coastguard Worker RENAME, 1, EXDEV, 23, creat_both, ck_both, {
430*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, O_FILE}}, {
431*49cdfc7eSAndroid Build Coastguard Worker OPEN, 0, 0, 24, creat_symlink, ck_symlink, {
432*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, NULL}},
433*49cdfc7eSAndroid Build Coastguard Worker /* 40 */
434*49cdfc7eSAndroid Build Coastguard Worker {
435*49cdfc7eSAndroid Build Coastguard Worker OPEN, 0, 0, 25, creat_both, ck_both, {
436*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, O_FILE}}, {
437*49cdfc7eSAndroid Build Coastguard Worker OPEN, 1, EEXIST, 26, creat_symlink, ck_symlink, {
438*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, O_FILE}}, {
439*49cdfc7eSAndroid Build Coastguard Worker OPEN, 1, ENOENT, 27, creat_symlink, ck_symlink, {
440*49cdfc7eSAndroid Build Coastguard Worker O_FILE, S_FILE, NULL}}, {
441*49cdfc7eSAndroid Build Coastguard Worker OPEN, 1, ELOOP, 28, creat_symlink, ck_symlink, {
442*49cdfc7eSAndroid Build Coastguard Worker S_FILE, S_FILE, NULL}}
443*49cdfc7eSAndroid Build Coastguard Worker };
444*49cdfc7eSAndroid Build Coastguard Worker
445*49cdfc7eSAndroid Build Coastguard Worker /*
446*49cdfc7eSAndroid Build Coastguard Worker * Define tcses
447*49cdfc7eSAndroid Build Coastguard Worker */
448*49cdfc7eSAndroid Build Coastguard Worker struct tcses {
449*49cdfc7eSAndroid Build Coastguard Worker char *tcid;
450*49cdfc7eSAndroid Build Coastguard Worker char *syscall;
451*49cdfc7eSAndroid Build Coastguard Worker int test_cases; /* number of entries in test_objects array */
452*49cdfc7eSAndroid Build Coastguard Worker struct all_test_cases *tc_ptr;
453*49cdfc7eSAndroid Build Coastguard Worker char *desc;
454*49cdfc7eSAndroid Build Coastguard Worker } all_tcses[] = {
455*49cdfc7eSAndroid Build Coastguard Worker
456*49cdfc7eSAndroid Build Coastguard Worker {
457*49cdfc7eSAndroid Build Coastguard Worker SYMLINK, "symlink", 5, &test_objects[0],
458*49cdfc7eSAndroid Build Coastguard Worker "Make a Symbolic Link to a File"}, {
459*49cdfc7eSAndroid Build Coastguard Worker READLINK, "readlink", 4, &test_objects[5],
460*49cdfc7eSAndroid Build Coastguard Worker "Reads Value of a Symbolic Link"}, {
461*49cdfc7eSAndroid Build Coastguard Worker STAT, "stat", 3, &test_objects[9],
462*49cdfc7eSAndroid Build Coastguard Worker "Gets File Status Indirectly From a Symbolic Link file"}, {
463*49cdfc7eSAndroid Build Coastguard Worker STAT_64, "stat64", 3, &test_objects[12],
464*49cdfc7eSAndroid Build Coastguard Worker "Gets File Status Indirectly From a Symbolic Link file"}, {
465*49cdfc7eSAndroid Build Coastguard Worker LSTAT, "lstat", 3, &test_objects[15],
466*49cdfc7eSAndroid Build Coastguard Worker "Get file Status About a Symbolic Link File"}, {
467*49cdfc7eSAndroid Build Coastguard Worker LSTAT_64, "lstat64", 3, &test_objects[18],
468*49cdfc7eSAndroid Build Coastguard Worker "Get file Status About a Symbolic Link File"}, {
469*49cdfc7eSAndroid Build Coastguard Worker MKDIR, "mkdir", 1, &test_objects[21],
470*49cdfc7eSAndroid Build Coastguard Worker "Fail When Making a Directory File Indirectly from a symlink"},
471*49cdfc7eSAndroid Build Coastguard Worker {
472*49cdfc7eSAndroid Build Coastguard Worker RMDIR, "rmdir", 1, &test_objects[22],
473*49cdfc7eSAndroid Build Coastguard Worker "Fail When Removing a Directory File Indirectly from a symlink"},
474*49cdfc7eSAndroid Build Coastguard Worker {
475*49cdfc7eSAndroid Build Coastguard Worker CHDIR, "chdir", 3, &test_objects[23],
476*49cdfc7eSAndroid Build Coastguard Worker "Changes CWD Location Indirectly from a symlink"}, {
477*49cdfc7eSAndroid Build Coastguard Worker LINK, "link", 2, &test_objects[26],
478*49cdfc7eSAndroid Build Coastguard Worker "Creates a Link To a File Indirectly From a Symbolic"}, {
479*49cdfc7eSAndroid Build Coastguard Worker UNLINK, "unlink", 1, &test_objects[29],
480*49cdfc7eSAndroid Build Coastguard Worker "Removes a Link To a File but not the Object File"}, {
481*49cdfc7eSAndroid Build Coastguard Worker CHMOD, "chmod", 3, &test_objects[30],
482*49cdfc7eSAndroid Build Coastguard Worker "Change Object File Permissions Indirectly From a Symbolic"},
483*49cdfc7eSAndroid Build Coastguard Worker {
484*49cdfc7eSAndroid Build Coastguard Worker UTIME, "utime", 3, &test_objects[33],
485*49cdfc7eSAndroid Build Coastguard Worker "Set File Access And Modify Object File Times via symlink"},
486*49cdfc7eSAndroid Build Coastguard Worker {
487*49cdfc7eSAndroid Build Coastguard Worker RENAME, "rename", 2, &test_objects[36],
488*49cdfc7eSAndroid Build Coastguard Worker "Rename a Symbolic Link File And Not Any Object file"}, {
489*49cdfc7eSAndroid Build Coastguard Worker OPEN, "open", 5, &test_objects[39],
490*49cdfc7eSAndroid Build Coastguard Worker "Create/Open a File For Reading Or Writing via symlink"},};
491*49cdfc7eSAndroid Build Coastguard Worker
492*49cdfc7eSAndroid Build Coastguard Worker /*
493*49cdfc7eSAndroid Build Coastguard Worker * Define GLOBAL variables
494*49cdfc7eSAndroid Build Coastguard Worker */
495*49cdfc7eSAndroid Build Coastguard Worker
496*49cdfc7eSAndroid Build Coastguard Worker int TST_TOTAL;
497*49cdfc7eSAndroid Build Coastguard Worker int TEST_RESULT;
498*49cdfc7eSAndroid Build Coastguard Worker time_t a_time_value = 100;
499*49cdfc7eSAndroid Build Coastguard Worker char *TCID;
500*49cdfc7eSAndroid Build Coastguard Worker char *Selectedtests = NULL; /* Name (tcid) of selected test cases */
501*49cdfc7eSAndroid Build Coastguard Worker char test_msg[BUFMAX];
502*49cdfc7eSAndroid Build Coastguard Worker char full_path[PATH_MAX + 1 + 1]; /* Add one for '\0' and another to exceed the PATH_MAX limit, see creat_path_max() */
503*49cdfc7eSAndroid Build Coastguard Worker
504*49cdfc7eSAndroid Build Coastguard Worker struct stat asymlink, statter;
505*49cdfc7eSAndroid Build Coastguard Worker char Buffer[1024];
506*49cdfc7eSAndroid Build Coastguard Worker char Buf[1024];
507*49cdfc7eSAndroid Build Coastguard Worker
508*49cdfc7eSAndroid Build Coastguard Worker char *Tcid = NULL;
509*49cdfc7eSAndroid Build Coastguard Worker
510*49cdfc7eSAndroid Build Coastguard Worker option_t Options[] = {
511*49cdfc7eSAndroid Build Coastguard Worker {"T:", NULL, &Tcid}, /* -T tcid option */
512*49cdfc7eSAndroid Build Coastguard Worker {NULL, NULL, NULL}
513*49cdfc7eSAndroid Build Coastguard Worker };
514*49cdfc7eSAndroid Build Coastguard Worker
515*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
516*49cdfc7eSAndroid Build Coastguard Worker * MAIN
517*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
main(int argc,char * argv[])518*49cdfc7eSAndroid Build Coastguard Worker int main(int argc, char *argv[])
519*49cdfc7eSAndroid Build Coastguard Worker {
520*49cdfc7eSAndroid Build Coastguard Worker struct tcses *tcs_ptr;
521*49cdfc7eSAndroid Build Coastguard Worker int lc;
522*49cdfc7eSAndroid Build Coastguard Worker
523*49cdfc7eSAndroid Build Coastguard Worker tst_parse_opts(argc, argv, Options, &help);
524*49cdfc7eSAndroid Build Coastguard Worker
525*49cdfc7eSAndroid Build Coastguard Worker /*
526*49cdfc7eSAndroid Build Coastguard Worker * If the -T option was used, use that TCID or use the default
527*49cdfc7eSAndroid Build Coastguard Worker */
528*49cdfc7eSAndroid Build Coastguard Worker if (Tcid != NULL) {
529*49cdfc7eSAndroid Build Coastguard Worker TCID = Tcid;
530*49cdfc7eSAndroid Build Coastguard Worker Selectedtests = Tcid;
531*49cdfc7eSAndroid Build Coastguard Worker
532*49cdfc7eSAndroid Build Coastguard Worker }
533*49cdfc7eSAndroid Build Coastguard Worker #ifndef ALL
534*49cdfc7eSAndroid Build Coastguard Worker else {
535*49cdfc7eSAndroid Build Coastguard Worker TCID = DEFAULT_TCID;
536*49cdfc7eSAndroid Build Coastguard Worker Selectedtests = DEFAULT_TCID;
537*49cdfc7eSAndroid Build Coastguard Worker }
538*49cdfc7eSAndroid Build Coastguard Worker #endif
539*49cdfc7eSAndroid Build Coastguard Worker
540*49cdfc7eSAndroid Build Coastguard Worker /*
541*49cdfc7eSAndroid Build Coastguard Worker * Get test case specification information and assign TST_TOTAL
542*49cdfc7eSAndroid Build Coastguard Worker */
543*49cdfc7eSAndroid Build Coastguard Worker if ((tcs_ptr = get_tcs_info(Selectedtests)) == NULL) {
544*49cdfc7eSAndroid Build Coastguard Worker TST_TOTAL = 1;
545*49cdfc7eSAndroid Build Coastguard Worker tst_brkm(TBROK, cleanup,
546*49cdfc7eSAndroid Build Coastguard Worker "Unknown symbolic link test case specification executed");
547*49cdfc7eSAndroid Build Coastguard Worker }
548*49cdfc7eSAndroid Build Coastguard Worker
549*49cdfc7eSAndroid Build Coastguard Worker /***************************************************************
550*49cdfc7eSAndroid Build Coastguard Worker * perform global setup for test
551*49cdfc7eSAndroid Build Coastguard Worker ***************************************************************/
552*49cdfc7eSAndroid Build Coastguard Worker
553*49cdfc7eSAndroid Build Coastguard Worker setup();
554*49cdfc7eSAndroid Build Coastguard Worker
555*49cdfc7eSAndroid Build Coastguard Worker /***************************************************************
556*49cdfc7eSAndroid Build Coastguard Worker * check looping state if -c option given
557*49cdfc7eSAndroid Build Coastguard Worker ***************************************************************/
558*49cdfc7eSAndroid Build Coastguard Worker for (lc = 0; TEST_LOOPING(lc); lc++) {
559*49cdfc7eSAndroid Build Coastguard Worker
560*49cdfc7eSAndroid Build Coastguard Worker tst_count = 0;
561*49cdfc7eSAndroid Build Coastguard Worker
562*49cdfc7eSAndroid Build Coastguard Worker /*
563*49cdfc7eSAndroid Build Coastguard Worker * Execute tcs testing function and all defined test cases
564*49cdfc7eSAndroid Build Coastguard Worker */
565*49cdfc7eSAndroid Build Coastguard Worker do_syscalltests(tcs_ptr);
566*49cdfc7eSAndroid Build Coastguard Worker
567*49cdfc7eSAndroid Build Coastguard Worker }
568*49cdfc7eSAndroid Build Coastguard Worker
569*49cdfc7eSAndroid Build Coastguard Worker /*
570*49cdfc7eSAndroid Build Coastguard Worker * End appropriately
571*49cdfc7eSAndroid Build Coastguard Worker */
572*49cdfc7eSAndroid Build Coastguard Worker cleanup();
573*49cdfc7eSAndroid Build Coastguard Worker tst_exit();
574*49cdfc7eSAndroid Build Coastguard Worker
575*49cdfc7eSAndroid Build Coastguard Worker }
576*49cdfc7eSAndroid Build Coastguard Worker
577*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
578*49cdfc7eSAndroid Build Coastguard Worker * This function maps the name of the process to a test case specification
579*49cdfc7eSAndroid Build Coastguard Worker * defined in the all_tcses array of tcses structures. Either a pointer
580*49cdfc7eSAndroid Build Coastguard Worker * to the mapped test case specification information is returned or a
581*49cdfc7eSAndroid Build Coastguard Worker * null pointer.
582*49cdfc7eSAndroid Build Coastguard Worker *
583*49cdfc7eSAndroid Build Coastguard Worker * Argument is path to program name.
584*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
get_tcs_info(char * ptr)585*49cdfc7eSAndroid Build Coastguard Worker struct tcses *get_tcs_info(char *ptr)
586*49cdfc7eSAndroid Build Coastguard Worker {
587*49cdfc7eSAndroid Build Coastguard Worker int ctr;
588*49cdfc7eSAndroid Build Coastguard Worker struct tcses *tcs_ptr;
589*49cdfc7eSAndroid Build Coastguard Worker
590*49cdfc7eSAndroid Build Coastguard Worker #if ALL
591*49cdfc7eSAndroid Build Coastguard Worker if (ptr == NULL) {
592*49cdfc7eSAndroid Build Coastguard Worker
593*49cdfc7eSAndroid Build Coastguard Worker TST_TOTAL = 0;
594*49cdfc7eSAndroid Build Coastguard Worker for (ctr = 1; ctr < sizeof(all_tcses) / sizeof(struct tcses);
595*49cdfc7eSAndroid Build Coastguard Worker ctr++)
596*49cdfc7eSAndroid Build Coastguard Worker TST_TOTAL += all_tcses[ctr].test_cases;
597*49cdfc7eSAndroid Build Coastguard Worker return all_tcses;
598*49cdfc7eSAndroid Build Coastguard Worker }
599*49cdfc7eSAndroid Build Coastguard Worker #endif
600*49cdfc7eSAndroid Build Coastguard Worker
601*49cdfc7eSAndroid Build Coastguard Worker for (ctr = 0; ctr < (int)(sizeof(all_tcses) / sizeof(struct tcses)); ctr++) {
602*49cdfc7eSAndroid Build Coastguard Worker if (strcmp(ptr, all_tcses[ctr].tcid) == 0 ||
603*49cdfc7eSAndroid Build Coastguard Worker strcmp(ptr, all_tcses[ctr].syscall) == 0) {
604*49cdfc7eSAndroid Build Coastguard Worker tcs_ptr = &all_tcses[ctr];
605*49cdfc7eSAndroid Build Coastguard Worker TCID = all_tcses[ctr].tcid;
606*49cdfc7eSAndroid Build Coastguard Worker TST_TOTAL = tcs_ptr->test_cases;
607*49cdfc7eSAndroid Build Coastguard Worker return (tcs_ptr);
608*49cdfc7eSAndroid Build Coastguard Worker }
609*49cdfc7eSAndroid Build Coastguard Worker
610*49cdfc7eSAndroid Build Coastguard Worker }
611*49cdfc7eSAndroid Build Coastguard Worker return NULL;
612*49cdfc7eSAndroid Build Coastguard Worker }
613*49cdfc7eSAndroid Build Coastguard Worker
614*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
615*49cdfc7eSAndroid Build Coastguard Worker * Determines if what path points at is a symbolic link file
616*49cdfc7eSAndroid Build Coastguard Worker *
617*49cdfc7eSAndroid Build Coastguard Worker * Argument is path to symbolic link file.
618*49cdfc7eSAndroid Build Coastguard Worker *
619*49cdfc7eSAndroid Build Coastguard Worker * Return status is one if a symbolic link file. Zero if not a symbolic
620*49cdfc7eSAndroid Build Coastguard Worker * link file and a minus one if the path doesn't point at a file.
621*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
see_if_a_symlink(char * path)622*49cdfc7eSAndroid Build Coastguard Worker static int see_if_a_symlink(char *path)
623*49cdfc7eSAndroid Build Coastguard Worker {
624*49cdfc7eSAndroid Build Coastguard Worker if (lstat(path, &asymlink) < 0)
625*49cdfc7eSAndroid Build Coastguard Worker return (-1);
626*49cdfc7eSAndroid Build Coastguard Worker
627*49cdfc7eSAndroid Build Coastguard Worker if ((asymlink.st_mode & S_IFMT) == S_IFLNK)
628*49cdfc7eSAndroid Build Coastguard Worker return 1;
629*49cdfc7eSAndroid Build Coastguard Worker else
630*49cdfc7eSAndroid Build Coastguard Worker return 0;
631*49cdfc7eSAndroid Build Coastguard Worker }
632*49cdfc7eSAndroid Build Coastguard Worker
633*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
634*49cdfc7eSAndroid Build Coastguard Worker * This function performs without any hesitation, file(s) deletions
635*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
delete_files(char * path1,char * path2)636*49cdfc7eSAndroid Build Coastguard Worker void delete_files(char *path1, char *path2)
637*49cdfc7eSAndroid Build Coastguard Worker {
638*49cdfc7eSAndroid Build Coastguard Worker unlink(path1);
639*49cdfc7eSAndroid Build Coastguard Worker unlink(path2);
640*49cdfc7eSAndroid Build Coastguard Worker }
641*49cdfc7eSAndroid Build Coastguard Worker
642*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
643*49cdfc7eSAndroid Build Coastguard Worker *
644*49cdfc7eSAndroid Build Coastguard Worker * This routine creates a symbolic link file.
645*49cdfc7eSAndroid Build Coastguard Worker *
646*49cdfc7eSAndroid Build Coastguard Worker * Argument one is symbolic link pathname to point at.
647*49cdfc7eSAndroid Build Coastguard Worker * Argument two is name of symbolic link file.
648*49cdfc7eSAndroid Build Coastguard Worker *
649*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
creat_symlink(char * path1,char * path2,char * _path3)650*49cdfc7eSAndroid Build Coastguard Worker int creat_symlink(char *path1, char *path2, char *_path3)
651*49cdfc7eSAndroid Build Coastguard Worker {
652*49cdfc7eSAndroid Build Coastguard Worker TEST(symlink(path1, path2));
653*49cdfc7eSAndroid Build Coastguard Worker errno = TEST_ERRNO;
654*49cdfc7eSAndroid Build Coastguard Worker if (TEST_RETURN == -1) {
655*49cdfc7eSAndroid Build Coastguard Worker TEST_RESULT = TBROK;
656*49cdfc7eSAndroid Build Coastguard Worker sprintf(test_msg,
657*49cdfc7eSAndroid Build Coastguard Worker "symlink(2) Failure when creating setup %s object file: errno:%d %s",
658*49cdfc7eSAndroid Build Coastguard Worker path1, errno, strerror(errno));
659*49cdfc7eSAndroid Build Coastguard Worker return 0;
660*49cdfc7eSAndroid Build Coastguard Worker } else {
661*49cdfc7eSAndroid Build Coastguard Worker sprintf(Buf, "symlink(%s, %s) was successful.\n", path1, path2);
662*49cdfc7eSAndroid Build Coastguard Worker strcat(Buffer, Buf);
663*49cdfc7eSAndroid Build Coastguard Worker #if DEBUG
664*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TPASS, "symlink(%s, %s) was successful.", path1, path2);
665*49cdfc7eSAndroid Build Coastguard Worker #endif
666*49cdfc7eSAndroid Build Coastguard Worker }
667*49cdfc7eSAndroid Build Coastguard Worker return 1;
668*49cdfc7eSAndroid Build Coastguard Worker }
669*49cdfc7eSAndroid Build Coastguard Worker #define creat_symlink(p1, p2) creat_symlink(p1, p2, NULL)
670*49cdfc7eSAndroid Build Coastguard Worker
671*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
672*49cdfc7eSAndroid Build Coastguard Worker *
673*49cdfc7eSAndroid Build Coastguard Worker * This routine creates a regular file.
674*49cdfc7eSAndroid Build Coastguard Worker *
675*49cdfc7eSAndroid Build Coastguard Worker * Argument one is a pathname
676*49cdfc7eSAndroid Build Coastguard Worker *
677*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
creat_object(char * path1,char * _path2,char * _path3)678*49cdfc7eSAndroid Build Coastguard Worker int creat_object(char *path1, char *_path2, char *_path3)
679*49cdfc7eSAndroid Build Coastguard Worker {
680*49cdfc7eSAndroid Build Coastguard Worker int fd;
681*49cdfc7eSAndroid Build Coastguard Worker if ((fd = creat(path1, MODE)) == -1) {
682*49cdfc7eSAndroid Build Coastguard Worker TEST_RESULT = TBROK;
683*49cdfc7eSAndroid Build Coastguard Worker sprintf(test_msg,
684*49cdfc7eSAndroid Build Coastguard Worker "creat(2) Failure when creating setup %s object file: errno:%d %s",
685*49cdfc7eSAndroid Build Coastguard Worker path1, errno, strerror(errno));
686*49cdfc7eSAndroid Build Coastguard Worker return 0;
687*49cdfc7eSAndroid Build Coastguard Worker } else {
688*49cdfc7eSAndroid Build Coastguard Worker sprintf(Buf, "creat(%s, %#o) was successful.\n", path1, MODE);
689*49cdfc7eSAndroid Build Coastguard Worker strcat(Buffer, Buf);
690*49cdfc7eSAndroid Build Coastguard Worker #if DEBUG
691*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TPASS, "creat(%s, %#o) was successful.", path1, MODE);
692*49cdfc7eSAndroid Build Coastguard Worker #endif
693*49cdfc7eSAndroid Build Coastguard Worker }
694*49cdfc7eSAndroid Build Coastguard Worker if (close(fd) == -1) {
695*49cdfc7eSAndroid Build Coastguard Worker TEST_RESULT = TBROK;
696*49cdfc7eSAndroid Build Coastguard Worker sprintf(test_msg,
697*49cdfc7eSAndroid Build Coastguard Worker "close(2) Failure when closing setup %s object file: errno:%d %s",
698*49cdfc7eSAndroid Build Coastguard Worker path1, errno, strerror(errno));
699*49cdfc7eSAndroid Build Coastguard Worker return 0;
700*49cdfc7eSAndroid Build Coastguard Worker }
701*49cdfc7eSAndroid Build Coastguard Worker return 1;
702*49cdfc7eSAndroid Build Coastguard Worker }
703*49cdfc7eSAndroid Build Coastguard Worker #define creat_object(p1) creat_object(p1, NULL, NULL)
704*49cdfc7eSAndroid Build Coastguard Worker
705*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
706*49cdfc7eSAndroid Build Coastguard Worker *
707*49cdfc7eSAndroid Build Coastguard Worker * This routine creates a symbolic link file and a regular file.
708*49cdfc7eSAndroid Build Coastguard Worker *
709*49cdfc7eSAndroid Build Coastguard Worker * Argument one is a pathname of object file
710*49cdfc7eSAndroid Build Coastguard Worker * Argument two is symbolic link file name
711*49cdfc7eSAndroid Build Coastguard Worker * Argument three is regular file name
712*49cdfc7eSAndroid Build Coastguard Worker *
713*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
creat_both(char * path1,char * path2,char * path3)714*49cdfc7eSAndroid Build Coastguard Worker int creat_both(char *path1, char *path2, char *path3)
715*49cdfc7eSAndroid Build Coastguard Worker {
716*49cdfc7eSAndroid Build Coastguard Worker if (creat_symlink(path1, path2) == -1)
717*49cdfc7eSAndroid Build Coastguard Worker return 0;
718*49cdfc7eSAndroid Build Coastguard Worker else if (creat_object(path3) == -1)
719*49cdfc7eSAndroid Build Coastguard Worker return 0;
720*49cdfc7eSAndroid Build Coastguard Worker return 1;
721*49cdfc7eSAndroid Build Coastguard Worker }
722*49cdfc7eSAndroid Build Coastguard Worker
723*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
724*49cdfc7eSAndroid Build Coastguard Worker *
725*49cdfc7eSAndroid Build Coastguard Worker * This routine checks if symbolic link file is a symbolic link file.
726*49cdfc7eSAndroid Build Coastguard Worker *
727*49cdfc7eSAndroid Build Coastguard Worker * Argument one is a pathname of object file
728*49cdfc7eSAndroid Build Coastguard Worker * Argument two is symbolic link file name
729*49cdfc7eSAndroid Build Coastguard Worker * Argument three is regular file name
730*49cdfc7eSAndroid Build Coastguard Worker *
731*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
ck_symlink(char * path1,char * path2,char * path3)732*49cdfc7eSAndroid Build Coastguard Worker int ck_symlink(char *path1, char *path2, char *path3)
733*49cdfc7eSAndroid Build Coastguard Worker {
734*49cdfc7eSAndroid Build Coastguard Worker int ret;
735*49cdfc7eSAndroid Build Coastguard Worker
736*49cdfc7eSAndroid Build Coastguard Worker if ((ret = see_if_a_symlink(path2)) == -1) {
737*49cdfc7eSAndroid Build Coastguard Worker TEST_RESULT = TBROK;
738*49cdfc7eSAndroid Build Coastguard Worker sprintf(test_msg,
739*49cdfc7eSAndroid Build Coastguard Worker "lstat(2) Failure when accessing %s symbolic link file which should contain %s path to %s file ",
740*49cdfc7eSAndroid Build Coastguard Worker path2, path1, path3);
741*49cdfc7eSAndroid Build Coastguard Worker return 0;
742*49cdfc7eSAndroid Build Coastguard Worker } else if (ret == 0) {
743*49cdfc7eSAndroid Build Coastguard Worker TEST_RESULT = TBROK;
744*49cdfc7eSAndroid Build Coastguard Worker sprintf(test_msg,
745*49cdfc7eSAndroid Build Coastguard Worker "%s is not a symbolic link file which contains %s path to %s file",
746*49cdfc7eSAndroid Build Coastguard Worker path2, path1, path3);
747*49cdfc7eSAndroid Build Coastguard Worker return 0;
748*49cdfc7eSAndroid Build Coastguard Worker }
749*49cdfc7eSAndroid Build Coastguard Worker return 1;
750*49cdfc7eSAndroid Build Coastguard Worker }
751*49cdfc7eSAndroid Build Coastguard Worker
752*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
753*49cdfc7eSAndroid Build Coastguard Worker *
754*49cdfc7eSAndroid Build Coastguard Worker * This routine checks if symbolic link file points at object file.
755*49cdfc7eSAndroid Build Coastguard Worker *
756*49cdfc7eSAndroid Build Coastguard Worker * Argument one is a pathname of object file
757*49cdfc7eSAndroid Build Coastguard Worker * Argument two is symbolic link file name
758*49cdfc7eSAndroid Build Coastguard Worker * Argument three is regular file name
759*49cdfc7eSAndroid Build Coastguard Worker *
760*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
ck_both(char * path1,char * path2,char * path3)761*49cdfc7eSAndroid Build Coastguard Worker int ck_both(char *path1, char *path2, char *path3)
762*49cdfc7eSAndroid Build Coastguard Worker {
763*49cdfc7eSAndroid Build Coastguard Worker if (ck_symlink(path1, path2, path3) == 0)
764*49cdfc7eSAndroid Build Coastguard Worker return 0;
765*49cdfc7eSAndroid Build Coastguard Worker else if ((stat(path3, &statter) == -1) && (errno == ENOENT)) {
766*49cdfc7eSAndroid Build Coastguard Worker TEST_RESULT = TBROK;
767*49cdfc7eSAndroid Build Coastguard Worker sprintf(test_msg,
768*49cdfc7eSAndroid Build Coastguard Worker "stat(2) Failure when accessing %s object file ",
769*49cdfc7eSAndroid Build Coastguard Worker path3);
770*49cdfc7eSAndroid Build Coastguard Worker return 0;
771*49cdfc7eSAndroid Build Coastguard Worker } else if ((stat(path2, &asymlink) == -1) && (errno == ENOENT)) {
772*49cdfc7eSAndroid Build Coastguard Worker TEST_RESULT = TBROK;
773*49cdfc7eSAndroid Build Coastguard Worker sprintf(test_msg,
774*49cdfc7eSAndroid Build Coastguard Worker "stat(2) Failure when accessing %s symbolic link file ",
775*49cdfc7eSAndroid Build Coastguard Worker path2);
776*49cdfc7eSAndroid Build Coastguard Worker return 0;
777*49cdfc7eSAndroid Build Coastguard Worker } else if (statter.st_ino != asymlink.st_ino) {
778*49cdfc7eSAndroid Build Coastguard Worker TEST_RESULT = TBROK;
779*49cdfc7eSAndroid Build Coastguard Worker sprintf(test_msg,
780*49cdfc7eSAndroid Build Coastguard Worker "stat(2) Failure when accessing %s object file through %s symbolic link file ",
781*49cdfc7eSAndroid Build Coastguard Worker path3, path2);
782*49cdfc7eSAndroid Build Coastguard Worker return 0;
783*49cdfc7eSAndroid Build Coastguard Worker }
784*49cdfc7eSAndroid Build Coastguard Worker return 1;
785*49cdfc7eSAndroid Build Coastguard Worker
786*49cdfc7eSAndroid Build Coastguard Worker }
787*49cdfc7eSAndroid Build Coastguard Worker
788*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
789*49cdfc7eSAndroid Build Coastguard Worker * This routine populates full_path with a pathname whose length exceeds
790*49cdfc7eSAndroid Build Coastguard Worker * the PATH_MAX define value in param.h
791*49cdfc7eSAndroid Build Coastguard Worker *
792*49cdfc7eSAndroid Build Coastguard Worker * Argument one is a pathname of object file
793*49cdfc7eSAndroid Build Coastguard Worker * Argument two is symbolic link file name
794*49cdfc7eSAndroid Build Coastguard Worker * Argument three is regular file name
795*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
creat_path_max(char * path1,char * path2,char * path3)796*49cdfc7eSAndroid Build Coastguard Worker int creat_path_max(char *path1, char *path2, char *path3)
797*49cdfc7eSAndroid Build Coastguard Worker {
798*49cdfc7eSAndroid Build Coastguard Worker int ctr, to_go, size, whole_chunks;
799*49cdfc7eSAndroid Build Coastguard Worker char *cwd;
800*49cdfc7eSAndroid Build Coastguard Worker
801*49cdfc7eSAndroid Build Coastguard Worker if ((cwd = getcwd(NULL, 0)) == NULL) {
802*49cdfc7eSAndroid Build Coastguard Worker TEST_RESULT = TBROK;
803*49cdfc7eSAndroid Build Coastguard Worker sprintf(test_msg,
804*49cdfc7eSAndroid Build Coastguard Worker "getcwd(3) Failure in setup of %s %s %s test case object elements",
805*49cdfc7eSAndroid Build Coastguard Worker path1, path2, path3);
806*49cdfc7eSAndroid Build Coastguard Worker return 0;
807*49cdfc7eSAndroid Build Coastguard Worker }
808*49cdfc7eSAndroid Build Coastguard Worker cwd = getcwd(NULL, 0);
809*49cdfc7eSAndroid Build Coastguard Worker size = strlen(cwd);
810*49cdfc7eSAndroid Build Coastguard Worker
811*49cdfc7eSAndroid Build Coastguard Worker to_go = PATH_MAX - size;
812*49cdfc7eSAndroid Build Coastguard Worker size = strlen(path1);
813*49cdfc7eSAndroid Build Coastguard Worker whole_chunks = to_go / size;
814*49cdfc7eSAndroid Build Coastguard Worker strcpy(full_path, cwd);
815*49cdfc7eSAndroid Build Coastguard Worker for (ctr = 0; ctr < whole_chunks; ctr++) {
816*49cdfc7eSAndroid Build Coastguard Worker strcat(full_path, path1);
817*49cdfc7eSAndroid Build Coastguard Worker }
818*49cdfc7eSAndroid Build Coastguard Worker size = strlen(full_path);
819*49cdfc7eSAndroid Build Coastguard Worker to_go = PATH_MAX - size;
820*49cdfc7eSAndroid Build Coastguard Worker strcat(full_path, "/");
821*49cdfc7eSAndroid Build Coastguard Worker for (ctr = 0; ctr < to_go; ctr++)
822*49cdfc7eSAndroid Build Coastguard Worker strcat(full_path, "Z");
823*49cdfc7eSAndroid Build Coastguard Worker
824*49cdfc7eSAndroid Build Coastguard Worker return 1;
825*49cdfc7eSAndroid Build Coastguard Worker }
826*49cdfc7eSAndroid Build Coastguard Worker
827*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
828*49cdfc7eSAndroid Build Coastguard Worker * This routine checks that full_path's length exceeds the PATH_MAX
829*49cdfc7eSAndroid Build Coastguard Worker * define value in param.h
830*49cdfc7eSAndroid Build Coastguard Worker *
831*49cdfc7eSAndroid Build Coastguard Worker * Argument one is a pathname of object file
832*49cdfc7eSAndroid Build Coastguard Worker * Argument two is symbolic link file name
833*49cdfc7eSAndroid Build Coastguard Worker * Argument three is regular file name
834*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
ck_path_max(char * path1,char * path2,char * path3)835*49cdfc7eSAndroid Build Coastguard Worker int ck_path_max(char *path1, char *path2, char *path3)
836*49cdfc7eSAndroid Build Coastguard Worker {
837*49cdfc7eSAndroid Build Coastguard Worker if (strlen(full_path) == (PATH_MAX + 1))
838*49cdfc7eSAndroid Build Coastguard Worker return 1;
839*49cdfc7eSAndroid Build Coastguard Worker else {
840*49cdfc7eSAndroid Build Coastguard Worker TEST_RESULT = TBROK;
841*49cdfc7eSAndroid Build Coastguard Worker sprintf(test_msg, "%s %d %s %s %s %s",
842*49cdfc7eSAndroid Build Coastguard Worker "full_path character array length was not",
843*49cdfc7eSAndroid Build Coastguard Worker (PATH_MAX + 1),
844*49cdfc7eSAndroid Build Coastguard Worker "characters long for test case object elements", path1,
845*49cdfc7eSAndroid Build Coastguard Worker path2, path3);
846*49cdfc7eSAndroid Build Coastguard Worker return 0;
847*49cdfc7eSAndroid Build Coastguard Worker }
848*49cdfc7eSAndroid Build Coastguard Worker }
849*49cdfc7eSAndroid Build Coastguard Worker
850*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
851*49cdfc7eSAndroid Build Coastguard Worker * This routine checks if the stat(2) and lstat(2) calls return the same
852*49cdfc7eSAndroid Build Coastguard Worker * information when the path is not a symbolic link file
853*49cdfc7eSAndroid Build Coastguard Worker *
854*49cdfc7eSAndroid Build Coastguard Worker * Argument one is a pathname of object file
855*49cdfc7eSAndroid Build Coastguard Worker * Argument two is symbolic link file name
856*49cdfc7eSAndroid Build Coastguard Worker * Argument three is regular file name
857*49cdfc7eSAndroid Build Coastguard Worker *
858*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
ck_object(char * path1,char * path2,char * path3)859*49cdfc7eSAndroid Build Coastguard Worker int ck_object(char *path1, char *path2, char *path3)
860*49cdfc7eSAndroid Build Coastguard Worker {
861*49cdfc7eSAndroid Build Coastguard Worker int ret;
862*49cdfc7eSAndroid Build Coastguard Worker
863*49cdfc7eSAndroid Build Coastguard Worker if ((ret = see_if_a_symlink(path1)) < 0) {
864*49cdfc7eSAndroid Build Coastguard Worker TEST_RESULT = TFAIL;
865*49cdfc7eSAndroid Build Coastguard Worker sprintf(test_msg,
866*49cdfc7eSAndroid Build Coastguard Worker "lstat(2) failed to return inode information for a regular object file");
867*49cdfc7eSAndroid Build Coastguard Worker return 0;
868*49cdfc7eSAndroid Build Coastguard Worker } else if (ret == 1) {
869*49cdfc7eSAndroid Build Coastguard Worker TEST_RESULT = TFAIL;
870*49cdfc7eSAndroid Build Coastguard Worker sprintf(test_msg,
871*49cdfc7eSAndroid Build Coastguard Worker "lstat(2) detected a regular object file as a symbolic link file");
872*49cdfc7eSAndroid Build Coastguard Worker return 0;
873*49cdfc7eSAndroid Build Coastguard Worker } else if (stat(path1, &statter) == -1) {
874*49cdfc7eSAndroid Build Coastguard Worker TEST_RESULT = TBROK;
875*49cdfc7eSAndroid Build Coastguard Worker sprintf(test_msg,
876*49cdfc7eSAndroid Build Coastguard Worker "stat(2) failed to return inode information for a regular object file");
877*49cdfc7eSAndroid Build Coastguard Worker return 0;
878*49cdfc7eSAndroid Build Coastguard Worker } else if (memcmp((char *)&statter, (char *)&asymlink, sizeof(statter))
879*49cdfc7eSAndroid Build Coastguard Worker != 0) {
880*49cdfc7eSAndroid Build Coastguard Worker TEST_RESULT = TFAIL;
881*49cdfc7eSAndroid Build Coastguard Worker sprintf(test_msg,
882*49cdfc7eSAndroid Build Coastguard Worker "lstat(2) and stat(2) do not return same inode information for an object file");
883*49cdfc7eSAndroid Build Coastguard Worker return 0;
884*49cdfc7eSAndroid Build Coastguard Worker
885*49cdfc7eSAndroid Build Coastguard Worker }
886*49cdfc7eSAndroid Build Coastguard Worker return 1;
887*49cdfc7eSAndroid Build Coastguard Worker }
888*49cdfc7eSAndroid Build Coastguard Worker
889*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
890*49cdfc7eSAndroid Build Coastguard Worker * Main test case processing function
891*49cdfc7eSAndroid Build Coastguard Worker *
892*49cdfc7eSAndroid Build Coastguard Worker * Argument is a ptr into the all_tcses array of structures of type tcses
893*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
do_syscalltests(struct tcses * tcs)894*49cdfc7eSAndroid Build Coastguard Worker int do_syscalltests(struct tcses *tcs)
895*49cdfc7eSAndroid Build Coastguard Worker {
896*49cdfc7eSAndroid Build Coastguard Worker int ctr, ret;
897*49cdfc7eSAndroid Build Coastguard Worker struct all_test_cases *tc_ptr;
898*49cdfc7eSAndroid Build Coastguard Worker
899*49cdfc7eSAndroid Build Coastguard Worker /*
900*49cdfc7eSAndroid Build Coastguard Worker * loop through desired number of test cases
901*49cdfc7eSAndroid Build Coastguard Worker */
902*49cdfc7eSAndroid Build Coastguard Worker for (ctr = 0, tc_ptr = tcs->tc_ptr; ctr < TST_TOTAL; ctr++, tc_ptr++) {
903*49cdfc7eSAndroid Build Coastguard Worker
904*49cdfc7eSAndroid Build Coastguard Worker Buffer[0] = '\0';
905*49cdfc7eSAndroid Build Coastguard Worker
906*49cdfc7eSAndroid Build Coastguard Worker /*
907*49cdfc7eSAndroid Build Coastguard Worker * If running all test cases for all tcid, set the TCID if needed.
908*49cdfc7eSAndroid Build Coastguard Worker */
909*49cdfc7eSAndroid Build Coastguard Worker if (Selectedtests == NULL) {
910*49cdfc7eSAndroid Build Coastguard Worker if (strcmp(tcs->tcid, tc_ptr->tcid) != 0) {
911*49cdfc7eSAndroid Build Coastguard Worker TCID = tc_ptr->tcid;
912*49cdfc7eSAndroid Build Coastguard Worker tst_count = 0;
913*49cdfc7eSAndroid Build Coastguard Worker }
914*49cdfc7eSAndroid Build Coastguard Worker }
915*49cdfc7eSAndroid Build Coastguard Worker /*
916*49cdfc7eSAndroid Build Coastguard Worker * Insure that we are executing the correct tcs test case
917*49cdfc7eSAndroid Build Coastguard Worker */
918*49cdfc7eSAndroid Build Coastguard Worker if (strcmp(tcs->tcid, tc_ptr->tcid) != 0) {
919*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TBROK,
920*49cdfc7eSAndroid Build Coastguard Worker "%s TCID attempted to execute %s %d %d test case",
921*49cdfc7eSAndroid Build Coastguard Worker tcs->tcid, tc_ptr->tcid, tc_ptr->test_fail,
922*49cdfc7eSAndroid Build Coastguard Worker tc_ptr->errno_val);
923*49cdfc7eSAndroid Build Coastguard Worker continue;
924*49cdfc7eSAndroid Build Coastguard Worker }
925*49cdfc7eSAndroid Build Coastguard Worker TEST_RESULT = TPASS;
926*49cdfc7eSAndroid Build Coastguard Worker delete_files(S_FILE, O_FILE);
927*49cdfc7eSAndroid Build Coastguard Worker /*
928*49cdfc7eSAndroid Build Coastguard Worker * Perform test case setup
929*49cdfc7eSAndroid Build Coastguard Worker */
930*49cdfc7eSAndroid Build Coastguard Worker ret =
931*49cdfc7eSAndroid Build Coastguard Worker (tc_ptr->test_setup) (tc_ptr->fn_arg[0], tc_ptr->fn_arg[1],
932*49cdfc7eSAndroid Build Coastguard Worker tc_ptr->fn_arg[2]);
933*49cdfc7eSAndroid Build Coastguard Worker
934*49cdfc7eSAndroid Build Coastguard Worker /* If an expected error, try it out */
935*49cdfc7eSAndroid Build Coastguard Worker
936*49cdfc7eSAndroid Build Coastguard Worker if (tc_ptr->test_fail) {
937*49cdfc7eSAndroid Build Coastguard Worker /*
938*49cdfc7eSAndroid Build Coastguard Worker * Try to perform test verification function
939*49cdfc7eSAndroid Build Coastguard Worker */
940*49cdfc7eSAndroid Build Coastguard Worker if (!(tc_ptr->ck_test)
941*49cdfc7eSAndroid Build Coastguard Worker (tc_ptr->fn_arg[0], tc_ptr->fn_arg[1],
942*49cdfc7eSAndroid Build Coastguard Worker tc_ptr->fn_arg[2]))
943*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", test_msg);
944*49cdfc7eSAndroid Build Coastguard Worker else if (tc_ptr->errno_val == EEXIST)
945*49cdfc7eSAndroid Build Coastguard Worker do_EEXIST(tc_ptr);
946*49cdfc7eSAndroid Build Coastguard Worker else if (tc_ptr->errno_val == ENOENT)
947*49cdfc7eSAndroid Build Coastguard Worker do_ENOENT(tc_ptr);
948*49cdfc7eSAndroid Build Coastguard Worker else if (tc_ptr->errno_val == ELOOP)
949*49cdfc7eSAndroid Build Coastguard Worker do_ELOOP(tc_ptr);
950*49cdfc7eSAndroid Build Coastguard Worker else if (tc_ptr->errno_val == ENOTDIR)
951*49cdfc7eSAndroid Build Coastguard Worker do_ENOTDIR(tc_ptr);
952*49cdfc7eSAndroid Build Coastguard Worker else if (tc_ptr->errno_val == EXDEV)
953*49cdfc7eSAndroid Build Coastguard Worker do_EXDEV(tc_ptr);
954*49cdfc7eSAndroid Build Coastguard Worker else if (tc_ptr->errno_val == ENAMETOOLONG)
955*49cdfc7eSAndroid Build Coastguard Worker do_ENAMETOOLONG(tc_ptr);
956*49cdfc7eSAndroid Build Coastguard Worker else if (tc_ptr->errno_val == EINVAL)
957*49cdfc7eSAndroid Build Coastguard Worker do_EINVAL(tc_ptr);
958*49cdfc7eSAndroid Build Coastguard Worker else
959*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TBROK, "Test Case Declaration Error");
960*49cdfc7eSAndroid Build Coastguard Worker } else if (ret == 1) { /* No setup function error */
961*49cdfc7eSAndroid Build Coastguard Worker
962*49cdfc7eSAndroid Build Coastguard Worker if (tc_ptr->errno_val != 0)
963*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TBROK, "Test Case Declaration Error");
964*49cdfc7eSAndroid Build Coastguard Worker else {
965*49cdfc7eSAndroid Build Coastguard Worker /*
966*49cdfc7eSAndroid Build Coastguard Worker * Perform test verification function
967*49cdfc7eSAndroid Build Coastguard Worker */
968*49cdfc7eSAndroid Build Coastguard Worker ret =
969*49cdfc7eSAndroid Build Coastguard Worker (tc_ptr->ck_test) (tc_ptr->fn_arg[0],
970*49cdfc7eSAndroid Build Coastguard Worker tc_ptr->fn_arg[1],
971*49cdfc7eSAndroid Build Coastguard Worker tc_ptr->fn_arg[2]);
972*49cdfc7eSAndroid Build Coastguard Worker
973*49cdfc7eSAndroid Build Coastguard Worker /* Perform requested symbolic link system call test */
974*49cdfc7eSAndroid Build Coastguard Worker
975*49cdfc7eSAndroid Build Coastguard Worker if ((cktcsid(tc_ptr->tcid, SYMLINK)) ||
976*49cdfc7eSAndroid Build Coastguard Worker (cktcsid(tc_ptr->tcid, LSTAT)) ||
977*49cdfc7eSAndroid Build Coastguard Worker (cktcsid(tc_ptr->tcid, LSTAT_64))) {
978*49cdfc7eSAndroid Build Coastguard Worker if (ret == 1)
979*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s",
980*49cdfc7eSAndroid Build Coastguard Worker msgs[tc_ptr->
981*49cdfc7eSAndroid Build Coastguard Worker pass_msg]);
982*49cdfc7eSAndroid Build Coastguard Worker else
983*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s",
984*49cdfc7eSAndroid Build Coastguard Worker test_msg);
985*49cdfc7eSAndroid Build Coastguard Worker } else if (ret == 0)
986*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", test_msg);
987*49cdfc7eSAndroid Build Coastguard Worker else if (cktcsid(tc_ptr->tcid, READLINK))
988*49cdfc7eSAndroid Build Coastguard Worker do_readlink(tc_ptr);
989*49cdfc7eSAndroid Build Coastguard Worker else if (cktcsid(tc_ptr->tcid, STAT))
990*49cdfc7eSAndroid Build Coastguard Worker do_stat(tc_ptr);
991*49cdfc7eSAndroid Build Coastguard Worker else if (cktcsid(tc_ptr->tcid, STAT_64))
992*49cdfc7eSAndroid Build Coastguard Worker do_stat(tc_ptr);
993*49cdfc7eSAndroid Build Coastguard Worker else if (cktcsid(tc_ptr->tcid, CHDIR))
994*49cdfc7eSAndroid Build Coastguard Worker do_chdir(tc_ptr);
995*49cdfc7eSAndroid Build Coastguard Worker else if (cktcsid(tc_ptr->tcid, LINK))
996*49cdfc7eSAndroid Build Coastguard Worker do_link(tc_ptr);
997*49cdfc7eSAndroid Build Coastguard Worker else if (cktcsid(tc_ptr->tcid, UNLINK))
998*49cdfc7eSAndroid Build Coastguard Worker do_unlink(tc_ptr);
999*49cdfc7eSAndroid Build Coastguard Worker else if (cktcsid(tc_ptr->tcid, CHMOD))
1000*49cdfc7eSAndroid Build Coastguard Worker do_chmod(tc_ptr);
1001*49cdfc7eSAndroid Build Coastguard Worker else if (cktcsid(tc_ptr->tcid, UTIME))
1002*49cdfc7eSAndroid Build Coastguard Worker do_utime(tc_ptr);
1003*49cdfc7eSAndroid Build Coastguard Worker else if (cktcsid(tc_ptr->tcid, RENAME))
1004*49cdfc7eSAndroid Build Coastguard Worker do_rename(tc_ptr);
1005*49cdfc7eSAndroid Build Coastguard Worker else if (cktcsid(tc_ptr->tcid, OPEN))
1006*49cdfc7eSAndroid Build Coastguard Worker do_open(tc_ptr);
1007*49cdfc7eSAndroid Build Coastguard Worker else
1008*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TBROK,
1009*49cdfc7eSAndroid Build Coastguard Worker "Unknown test case processing actions declared");
1010*49cdfc7eSAndroid Build Coastguard Worker }
1011*49cdfc7eSAndroid Build Coastguard Worker } else
1012*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TBROK, "Test Case Declaration Error");
1013*49cdfc7eSAndroid Build Coastguard Worker }
1014*49cdfc7eSAndroid Build Coastguard Worker return 0;
1015*49cdfc7eSAndroid Build Coastguard Worker }
1016*49cdfc7eSAndroid Build Coastguard Worker
1017*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
1018*49cdfc7eSAndroid Build Coastguard Worker * This routine checks for the return of EEXIST errno from requested
1019*49cdfc7eSAndroid Build Coastguard Worker * system call
1020*49cdfc7eSAndroid Build Coastguard Worker *
1021*49cdfc7eSAndroid Build Coastguard Worker * Argument is pointer to test_objects array of structures of type
1022*49cdfc7eSAndroid Build Coastguard Worker * all_test_cases
1023*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
do_EEXIST(struct all_test_cases * tc_ptr)1024*49cdfc7eSAndroid Build Coastguard Worker void do_EEXIST(struct all_test_cases *tc_ptr)
1025*49cdfc7eSAndroid Build Coastguard Worker {
1026*49cdfc7eSAndroid Build Coastguard Worker if (cktcsid(tc_ptr->tcid, SYMLINK)) {
1027*49cdfc7eSAndroid Build Coastguard Worker
1028*49cdfc7eSAndroid Build Coastguard Worker TEST(symlink(tc_ptr->fn_arg[0], tc_ptr->fn_arg[1]));
1029*49cdfc7eSAndroid Build Coastguard Worker errno = TEST_ERRNO;
1030*49cdfc7eSAndroid Build Coastguard Worker if ((TEST_RETURN == -1) && (errno == EEXIST))
1031*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TPASS, "%s", msgs[tc_ptr->pass_msg]);
1032*49cdfc7eSAndroid Build Coastguard Worker else
1033*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s %s",
1034*49cdfc7eSAndroid Build Coastguard Worker "Expected EEXIST error when creating a symbolic link file",
1035*49cdfc7eSAndroid Build Coastguard Worker "which already existed");
1036*49cdfc7eSAndroid Build Coastguard Worker } else if (cktcsid(tc_ptr->tcid, MKDIR)) {
1037*49cdfc7eSAndroid Build Coastguard Worker
1038*49cdfc7eSAndroid Build Coastguard Worker TEST(mkdir(tc_ptr->fn_arg[1], MODE));
1039*49cdfc7eSAndroid Build Coastguard Worker errno = TEST_ERRNO;
1040*49cdfc7eSAndroid Build Coastguard Worker if ((TEST_RETURN == -1) && (errno == EEXIST)) {
1041*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1042*49cdfc7eSAndroid Build Coastguard Worker } else {
1043*49cdfc7eSAndroid Build Coastguard Worker
1044*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s %s",
1045*49cdfc7eSAndroid Build Coastguard Worker "Expected EEXIST error when creating a directory by a symbolic",
1046*49cdfc7eSAndroid Build Coastguard Worker "link file which pointed at no object file");
1047*49cdfc7eSAndroid Build Coastguard Worker rmdir(tc_ptr->fn_arg[1]);
1048*49cdfc7eSAndroid Build Coastguard Worker }
1049*49cdfc7eSAndroid Build Coastguard Worker } else if (cktcsid(tc_ptr->tcid, OPEN)) {
1050*49cdfc7eSAndroid Build Coastguard Worker
1051*49cdfc7eSAndroid Build Coastguard Worker TEST(open(tc_ptr->fn_arg[1], (O_EXCL | O_CREAT), 0666));
1052*49cdfc7eSAndroid Build Coastguard Worker errno = TEST_ERRNO;
1053*49cdfc7eSAndroid Build Coastguard Worker if ((TEST_RETURN == -1) && (errno == EEXIST)) {
1054*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1055*49cdfc7eSAndroid Build Coastguard Worker } else {
1056*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s %s errno:%d %s",
1057*49cdfc7eSAndroid Build Coastguard Worker "Expected EEXIST error for exclusively opening an object file",
1058*49cdfc7eSAndroid Build Coastguard Worker "through a symbolic link file was not received:",
1059*49cdfc7eSAndroid Build Coastguard Worker errno, strerror(errno));
1060*49cdfc7eSAndroid Build Coastguard Worker }
1061*49cdfc7eSAndroid Build Coastguard Worker } else
1062*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TBROK,
1063*49cdfc7eSAndroid Build Coastguard Worker "Unknown test case processing actions declared");
1064*49cdfc7eSAndroid Build Coastguard Worker }
1065*49cdfc7eSAndroid Build Coastguard Worker
1066*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
1067*49cdfc7eSAndroid Build Coastguard Worker * This routine checks for the return of ENOENT errno from requested
1068*49cdfc7eSAndroid Build Coastguard Worker * system call
1069*49cdfc7eSAndroid Build Coastguard Worker *
1070*49cdfc7eSAndroid Build Coastguard Worker * Argument is pointer to test_objects array of structures of type
1071*49cdfc7eSAndroid Build Coastguard Worker * all_test_cases
1072*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
do_ENOENT(struct all_test_cases * tc_ptr)1073*49cdfc7eSAndroid Build Coastguard Worker void do_ENOENT(struct all_test_cases *tc_ptr)
1074*49cdfc7eSAndroid Build Coastguard Worker {
1075*49cdfc7eSAndroid Build Coastguard Worker if ((cktcsid(tc_ptr->tcid, STAT)) || (cktcsid(tc_ptr->tcid, STAT_64))) {
1076*49cdfc7eSAndroid Build Coastguard Worker
1077*49cdfc7eSAndroid Build Coastguard Worker if ((stat(tc_ptr->fn_arg[1], &asymlink) == -1)
1078*49cdfc7eSAndroid Build Coastguard Worker && (errno == ENOENT)) {
1079*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1080*49cdfc7eSAndroid Build Coastguard Worker } else {
1081*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s %s errno:%d %s",
1082*49cdfc7eSAndroid Build Coastguard Worker "Expected ENOENT error for stating a non-existent directory",
1083*49cdfc7eSAndroid Build Coastguard Worker "through a symbolic link file was not received:",
1084*49cdfc7eSAndroid Build Coastguard Worker errno, strerror(errno));
1085*49cdfc7eSAndroid Build Coastguard Worker }
1086*49cdfc7eSAndroid Build Coastguard Worker } else if (cktcsid(tc_ptr->tcid, CHDIR)) {
1087*49cdfc7eSAndroid Build Coastguard Worker if ((chdir(tc_ptr->fn_arg[1]) == -1) && (errno == ENOENT)) {
1088*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1089*49cdfc7eSAndroid Build Coastguard Worker } else {
1090*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s %s errno:%d %s",
1091*49cdfc7eSAndroid Build Coastguard Worker "Expected ENOENT error for changing to a non-existent",
1092*49cdfc7eSAndroid Build Coastguard Worker "directory through a symbolic link file was not received:",
1093*49cdfc7eSAndroid Build Coastguard Worker errno, strerror(errno));
1094*49cdfc7eSAndroid Build Coastguard Worker /* FIXME (garrcoop): memory leak */
1095*49cdfc7eSAndroid Build Coastguard Worker chdir(tst_get_tmpdir());
1096*49cdfc7eSAndroid Build Coastguard Worker }
1097*49cdfc7eSAndroid Build Coastguard Worker } else if (cktcsid(tc_ptr->tcid, LINK)) {
1098*49cdfc7eSAndroid Build Coastguard Worker
1099*49cdfc7eSAndroid Build Coastguard Worker if ((link(tc_ptr->fn_arg[1], "nick") == -1)
1100*49cdfc7eSAndroid Build Coastguard Worker && (errno == ENOENT)) {
1101*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1102*49cdfc7eSAndroid Build Coastguard Worker } else {
1103*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s %s errno:%d %s",
1104*49cdfc7eSAndroid Build Coastguard Worker "Expected ENOENT error condition when link(2) a symbolic",
1105*49cdfc7eSAndroid Build Coastguard Worker "link which pointed at no object:", errno,
1106*49cdfc7eSAndroid Build Coastguard Worker strerror(errno));
1107*49cdfc7eSAndroid Build Coastguard Worker delete_files("nick", NULL);
1108*49cdfc7eSAndroid Build Coastguard Worker }
1109*49cdfc7eSAndroid Build Coastguard Worker } else if (cktcsid(tc_ptr->tcid, CHMOD)) {
1110*49cdfc7eSAndroid Build Coastguard Worker
1111*49cdfc7eSAndroid Build Coastguard Worker if ((chmod(tc_ptr->fn_arg[1], MODE) == -1) && (errno == ENOENT)) {
1112*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1113*49cdfc7eSAndroid Build Coastguard Worker } else {
1114*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s %s errno:%d %s",
1115*49cdfc7eSAndroid Build Coastguard Worker "Expected ENOENT error condition when chmod(2) a symbolic",
1116*49cdfc7eSAndroid Build Coastguard Worker "link which pointed at no object,", errno,
1117*49cdfc7eSAndroid Build Coastguard Worker strerror(errno));
1118*49cdfc7eSAndroid Build Coastguard Worker }
1119*49cdfc7eSAndroid Build Coastguard Worker } else if (cktcsid(tc_ptr->tcid, UTIME)) {
1120*49cdfc7eSAndroid Build Coastguard Worker
1121*49cdfc7eSAndroid Build Coastguard Worker if ((utime(tc_ptr->fn_arg[1], NULL) == -1) && (errno == ENOENT)) {
1122*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1123*49cdfc7eSAndroid Build Coastguard Worker } else {
1124*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s %s errno:%d %s",
1125*49cdfc7eSAndroid Build Coastguard Worker "Expected ENOENT error condition when utime(2) a symbolic",
1126*49cdfc7eSAndroid Build Coastguard Worker "link which pointed at no object:", errno,
1127*49cdfc7eSAndroid Build Coastguard Worker strerror(errno));
1128*49cdfc7eSAndroid Build Coastguard Worker }
1129*49cdfc7eSAndroid Build Coastguard Worker } else if (cktcsid(tc_ptr->tcid, OPEN)) {
1130*49cdfc7eSAndroid Build Coastguard Worker
1131*49cdfc7eSAndroid Build Coastguard Worker if ((open(tc_ptr->fn_arg[1], O_RDWR) == -1)
1132*49cdfc7eSAndroid Build Coastguard Worker && (errno == ENOENT)) {
1133*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1134*49cdfc7eSAndroid Build Coastguard Worker } else {
1135*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s %s errno:%d %s",
1136*49cdfc7eSAndroid Build Coastguard Worker "Expected ENOENT error for opening a non-existent object",
1137*49cdfc7eSAndroid Build Coastguard Worker " file through a symbolic link file was not received,",
1138*49cdfc7eSAndroid Build Coastguard Worker errno, strerror(errno));
1139*49cdfc7eSAndroid Build Coastguard Worker }
1140*49cdfc7eSAndroid Build Coastguard Worker } else
1141*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TBROK,
1142*49cdfc7eSAndroid Build Coastguard Worker "Unknown test case processing actions declared");
1143*49cdfc7eSAndroid Build Coastguard Worker }
1144*49cdfc7eSAndroid Build Coastguard Worker
1145*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
1146*49cdfc7eSAndroid Build Coastguard Worker * This routine checks for the return of ELOOP errno from requested
1147*49cdfc7eSAndroid Build Coastguard Worker * system call
1148*49cdfc7eSAndroid Build Coastguard Worker *
1149*49cdfc7eSAndroid Build Coastguard Worker * Argument is pointer to test_objects array of structures of type
1150*49cdfc7eSAndroid Build Coastguard Worker * all_test_cases
1151*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
do_ELOOP(struct all_test_cases * tc_ptr)1152*49cdfc7eSAndroid Build Coastguard Worker void do_ELOOP(struct all_test_cases *tc_ptr)
1153*49cdfc7eSAndroid Build Coastguard Worker {
1154*49cdfc7eSAndroid Build Coastguard Worker if ((cktcsid(tc_ptr->tcid, STAT)) || (cktcsid(tc_ptr->tcid, STAT_64))) {
1155*49cdfc7eSAndroid Build Coastguard Worker
1156*49cdfc7eSAndroid Build Coastguard Worker TEST(stat(tc_ptr->fn_arg[1], &asymlink));
1157*49cdfc7eSAndroid Build Coastguard Worker errno = TEST_ERRNO;
1158*49cdfc7eSAndroid Build Coastguard Worker if ((TEST_RETURN == -1) && (errno == ELOOP)) {
1159*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1160*49cdfc7eSAndroid Build Coastguard Worker } else {
1161*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s errno:%d %s",
1162*49cdfc7eSAndroid Build Coastguard Worker "Expected ELOOP errno from stat(2) (nested symb link),",
1163*49cdfc7eSAndroid Build Coastguard Worker errno, strerror(errno));
1164*49cdfc7eSAndroid Build Coastguard Worker }
1165*49cdfc7eSAndroid Build Coastguard Worker } else if (cktcsid(tc_ptr->tcid, CHDIR)) {
1166*49cdfc7eSAndroid Build Coastguard Worker
1167*49cdfc7eSAndroid Build Coastguard Worker TEST(chdir(tc_ptr->fn_arg[1]));
1168*49cdfc7eSAndroid Build Coastguard Worker errno = TEST_ERRNO;
1169*49cdfc7eSAndroid Build Coastguard Worker if ((TEST_RETURN == -1) && (errno == ELOOP)) {
1170*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1171*49cdfc7eSAndroid Build Coastguard Worker } else {
1172*49cdfc7eSAndroid Build Coastguard Worker
1173*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s errno:%d %s",
1174*49cdfc7eSAndroid Build Coastguard Worker "Expected ELOOP error condition when chdir(2) a nested symbolic link:",
1175*49cdfc7eSAndroid Build Coastguard Worker errno, strerror(errno));
1176*49cdfc7eSAndroid Build Coastguard Worker /* FIXME (garrcoop): memory leak */
1177*49cdfc7eSAndroid Build Coastguard Worker chdir(tst_get_tmpdir());
1178*49cdfc7eSAndroid Build Coastguard Worker }
1179*49cdfc7eSAndroid Build Coastguard Worker } else if (cktcsid(tc_ptr->tcid, LINK)) {
1180*49cdfc7eSAndroid Build Coastguard Worker
1181*49cdfc7eSAndroid Build Coastguard Worker TEST(link(tc_ptr->fn_arg[1], O_FILE));
1182*49cdfc7eSAndroid Build Coastguard Worker errno = TEST_ERRNO;
1183*49cdfc7eSAndroid Build Coastguard Worker if ((TEST_RETURN == -1) && (errno == ELOOP)) {
1184*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1185*49cdfc7eSAndroid Build Coastguard Worker } else {
1186*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s errno:%d %s",
1187*49cdfc7eSAndroid Build Coastguard Worker "Expected ELOOP error condition when link(2) a nested symbolic link:",
1188*49cdfc7eSAndroid Build Coastguard Worker errno, strerror(errno));
1189*49cdfc7eSAndroid Build Coastguard Worker }
1190*49cdfc7eSAndroid Build Coastguard Worker } else if (cktcsid(tc_ptr->tcid, CHMOD)) {
1191*49cdfc7eSAndroid Build Coastguard Worker
1192*49cdfc7eSAndroid Build Coastguard Worker TEST(chmod(tc_ptr->fn_arg[1], MODE));
1193*49cdfc7eSAndroid Build Coastguard Worker errno = TEST_ERRNO;
1194*49cdfc7eSAndroid Build Coastguard Worker if ((TEST_RETURN == -1) && (errno == ELOOP)) {
1195*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1196*49cdfc7eSAndroid Build Coastguard Worker } else {
1197*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s errno:%d %s",
1198*49cdfc7eSAndroid Build Coastguard Worker "Expected ELOOP error condition when chmod(2) a nested symbolic link:",
1199*49cdfc7eSAndroid Build Coastguard Worker errno, strerror(errno));
1200*49cdfc7eSAndroid Build Coastguard Worker }
1201*49cdfc7eSAndroid Build Coastguard Worker return;
1202*49cdfc7eSAndroid Build Coastguard Worker } else if (cktcsid(tc_ptr->tcid, UTIME)) {
1203*49cdfc7eSAndroid Build Coastguard Worker
1204*49cdfc7eSAndroid Build Coastguard Worker TEST(utime(tc_ptr->fn_arg[1], NULL));
1205*49cdfc7eSAndroid Build Coastguard Worker errno = TEST_ERRNO;
1206*49cdfc7eSAndroid Build Coastguard Worker
1207*49cdfc7eSAndroid Build Coastguard Worker if ((TEST_RETURN == -1) && (errno == ELOOP)) {
1208*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1209*49cdfc7eSAndroid Build Coastguard Worker } else {
1210*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s errno:%d %s",
1211*49cdfc7eSAndroid Build Coastguard Worker "Expected ELOOP error condition when utime(2) a nested symbolic link:",
1212*49cdfc7eSAndroid Build Coastguard Worker errno, strerror(errno));
1213*49cdfc7eSAndroid Build Coastguard Worker }
1214*49cdfc7eSAndroid Build Coastguard Worker } else if (cktcsid(tc_ptr->tcid, OPEN)) {
1215*49cdfc7eSAndroid Build Coastguard Worker
1216*49cdfc7eSAndroid Build Coastguard Worker int fd;
1217*49cdfc7eSAndroid Build Coastguard Worker TEST(open(tc_ptr->fn_arg[1], O_CREAT, 0666));
1218*49cdfc7eSAndroid Build Coastguard Worker fd = TEST_RETURN;
1219*49cdfc7eSAndroid Build Coastguard Worker errno = TEST_ERRNO;
1220*49cdfc7eSAndroid Build Coastguard Worker if ((fd == -1) && (errno == ELOOP)) {
1221*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1222*49cdfc7eSAndroid Build Coastguard Worker } else {
1223*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s errno:%d %s",
1224*49cdfc7eSAndroid Build Coastguard Worker "Expected ELOOP error condition when open(2) a nested symbolic link:",
1225*49cdfc7eSAndroid Build Coastguard Worker errno, strerror(errno));
1226*49cdfc7eSAndroid Build Coastguard Worker }
1227*49cdfc7eSAndroid Build Coastguard Worker } else
1228*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TBROK,
1229*49cdfc7eSAndroid Build Coastguard Worker "Unknown test case processing actions declared");
1230*49cdfc7eSAndroid Build Coastguard Worker }
1231*49cdfc7eSAndroid Build Coastguard Worker
1232*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
1233*49cdfc7eSAndroid Build Coastguard Worker * This routine checks for the return of ENOTDIR errno from requested
1234*49cdfc7eSAndroid Build Coastguard Worker * system call
1235*49cdfc7eSAndroid Build Coastguard Worker *
1236*49cdfc7eSAndroid Build Coastguard Worker * Argument is pointer to test_objects array of structures of type
1237*49cdfc7eSAndroid Build Coastguard Worker * all_test_cases
1238*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
do_ENOTDIR(struct all_test_cases * tc_ptr)1239*49cdfc7eSAndroid Build Coastguard Worker void do_ENOTDIR(struct all_test_cases *tc_ptr)
1240*49cdfc7eSAndroid Build Coastguard Worker {
1241*49cdfc7eSAndroid Build Coastguard Worker if (cktcsid(tc_ptr->tcid, RMDIR)) {
1242*49cdfc7eSAndroid Build Coastguard Worker
1243*49cdfc7eSAndroid Build Coastguard Worker TEST(mkdir(tc_ptr->fn_arg[0], MODE));
1244*49cdfc7eSAndroid Build Coastguard Worker errno = TEST_ERRNO;
1245*49cdfc7eSAndroid Build Coastguard Worker if (TEST_RETURN == -1)
1246*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TBROK, "mkdir(2) Failure when creating %s",
1247*49cdfc7eSAndroid Build Coastguard Worker tc_ptr->fn_arg[0]);
1248*49cdfc7eSAndroid Build Coastguard Worker else if ((rmdir(tc_ptr->fn_arg[1]) == -1) && (errno == ENOTDIR)) {
1249*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1250*49cdfc7eSAndroid Build Coastguard Worker rmdir(tc_ptr->fn_arg[0]);
1251*49cdfc7eSAndroid Build Coastguard Worker } else {
1252*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s %s errno:%d %s",
1253*49cdfc7eSAndroid Build Coastguard Worker "Expected ENOTDIR error for removing a non-existent",
1254*49cdfc7eSAndroid Build Coastguard Worker "directory through a symbolic link file was not received,",
1255*49cdfc7eSAndroid Build Coastguard Worker errno, strerror(errno));
1256*49cdfc7eSAndroid Build Coastguard Worker }
1257*49cdfc7eSAndroid Build Coastguard Worker } else
1258*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TBROK,
1259*49cdfc7eSAndroid Build Coastguard Worker "Unknown test case processing actions declared");
1260*49cdfc7eSAndroid Build Coastguard Worker }
1261*49cdfc7eSAndroid Build Coastguard Worker
1262*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
1263*49cdfc7eSAndroid Build Coastguard Worker * This routine checks for the return of EXDEV errno from requested
1264*49cdfc7eSAndroid Build Coastguard Worker * system call
1265*49cdfc7eSAndroid Build Coastguard Worker *
1266*49cdfc7eSAndroid Build Coastguard Worker * Argument is pointer to test_objects array of structures of type
1267*49cdfc7eSAndroid Build Coastguard Worker * all_test_cases
1268*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
do_EXDEV(struct all_test_cases * tc_ptr)1269*49cdfc7eSAndroid Build Coastguard Worker void do_EXDEV(struct all_test_cases *tc_ptr)
1270*49cdfc7eSAndroid Build Coastguard Worker {
1271*49cdfc7eSAndroid Build Coastguard Worker if (cktcsid(tc_ptr->tcid, RENAME)) {
1272*49cdfc7eSAndroid Build Coastguard Worker
1273*49cdfc7eSAndroid Build Coastguard Worker TEST(rename(tc_ptr->fn_arg[1], Y_A_S_FILE));
1274*49cdfc7eSAndroid Build Coastguard Worker errno = TEST_ERRNO;
1275*49cdfc7eSAndroid Build Coastguard Worker if ((TEST_RETURN == -1) && (errno == EXDEV)) {
1276*49cdfc7eSAndroid Build Coastguard Worker if (see_if_a_symlink(Y_A_S_FILE) == -1) {
1277*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1278*49cdfc7eSAndroid Build Coastguard Worker } else {
1279*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1280*49cdfc7eSAndroid Build Coastguard Worker "%s %s %s file outside of current file system",
1281*49cdfc7eSAndroid Build Coastguard Worker "rename(3) returned -1 when trying to move symbolic link file",
1282*49cdfc7eSAndroid Build Coastguard Worker "outside of current file system, but created",
1283*49cdfc7eSAndroid Build Coastguard Worker Y_A_S_FILE);
1284*49cdfc7eSAndroid Build Coastguard Worker }
1285*49cdfc7eSAndroid Build Coastguard Worker } else {
1286*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s %s errno:%d %s",
1287*49cdfc7eSAndroid Build Coastguard Worker "Expected EXDEV error for renaming an existing symbolic",
1288*49cdfc7eSAndroid Build Coastguard Worker "link file to a location outside of existing file system,",
1289*49cdfc7eSAndroid Build Coastguard Worker errno, strerror(errno));
1290*49cdfc7eSAndroid Build Coastguard Worker delete_files("/NiCkEr", NULL);
1291*49cdfc7eSAndroid Build Coastguard Worker }
1292*49cdfc7eSAndroid Build Coastguard Worker } else
1293*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TBROK,
1294*49cdfc7eSAndroid Build Coastguard Worker "Unknown test case processing actions declared");
1295*49cdfc7eSAndroid Build Coastguard Worker }
1296*49cdfc7eSAndroid Build Coastguard Worker
1297*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
1298*49cdfc7eSAndroid Build Coastguard Worker * This routine checks for the return of ENAMETOOLONG errno from requested
1299*49cdfc7eSAndroid Build Coastguard Worker * system call
1300*49cdfc7eSAndroid Build Coastguard Worker *
1301*49cdfc7eSAndroid Build Coastguard Worker * Argument is pointer to test_objects array of structures of type
1302*49cdfc7eSAndroid Build Coastguard Worker * all_test_cases
1303*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
do_ENAMETOOLONG(struct all_test_cases * tc_ptr)1304*49cdfc7eSAndroid Build Coastguard Worker void do_ENAMETOOLONG(struct all_test_cases *tc_ptr)
1305*49cdfc7eSAndroid Build Coastguard Worker {
1306*49cdfc7eSAndroid Build Coastguard Worker int ret;
1307*49cdfc7eSAndroid Build Coastguard Worker
1308*49cdfc7eSAndroid Build Coastguard Worker if (cktcsid(tc_ptr->tcid, SYMLINK)) {
1309*49cdfc7eSAndroid Build Coastguard Worker
1310*49cdfc7eSAndroid Build Coastguard Worker TEST(symlink(tc_ptr->fn_arg[0], full_path));
1311*49cdfc7eSAndroid Build Coastguard Worker errno = TEST_ERRNO;
1312*49cdfc7eSAndroid Build Coastguard Worker if ((TEST_RETURN == -1) && (errno == ENAMETOOLONG)) {
1313*49cdfc7eSAndroid Build Coastguard Worker if (see_if_a_symlink(full_path) == -1) {
1314*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1315*49cdfc7eSAndroid Build Coastguard Worker } else {
1316*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s %s %d %s",
1317*49cdfc7eSAndroid Build Coastguard Worker "symlink(2) returned -1 when trying to create a symbolic",
1318*49cdfc7eSAndroid Build Coastguard Worker "link file whose name exceeded",
1319*49cdfc7eSAndroid Build Coastguard Worker (PATH_MAX + 1),
1320*49cdfc7eSAndroid Build Coastguard Worker "characters, but it created the symbolic link file");
1321*49cdfc7eSAndroid Build Coastguard Worker }
1322*49cdfc7eSAndroid Build Coastguard Worker } else {
1323*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL | TERRNO,
1324*49cdfc7eSAndroid Build Coastguard Worker "Expected ENAMETOOLONG error when creating %s symbolic link file with a path exceeding %d characters",
1325*49cdfc7eSAndroid Build Coastguard Worker tc_ptr->fn_arg[1], (PATH_MAX + 1));
1326*49cdfc7eSAndroid Build Coastguard Worker }
1327*49cdfc7eSAndroid Build Coastguard Worker } else if (cktcsid(tc_ptr->tcid, READLINK)) {
1328*49cdfc7eSAndroid Build Coastguard Worker
1329*49cdfc7eSAndroid Build Coastguard Worker char scratch[PATH_MAX + 1];
1330*49cdfc7eSAndroid Build Coastguard Worker
1331*49cdfc7eSAndroid Build Coastguard Worker ret = readlink(full_path, scratch, strlen(full_path));
1332*49cdfc7eSAndroid Build Coastguard Worker if ((ret == -1) && (errno == ENAMETOOLONG)) {
1333*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1334*49cdfc7eSAndroid Build Coastguard Worker } else {
1335*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1336*49cdfc7eSAndroid Build Coastguard Worker "Expected ENAMETOOLONG error when reading %s symbolic link file with a path exceeding %d characters: errno:%d %s",
1337*49cdfc7eSAndroid Build Coastguard Worker tc_ptr->fn_arg[1], (PATH_MAX + 1), errno,
1338*49cdfc7eSAndroid Build Coastguard Worker strerror(errno));
1339*49cdfc7eSAndroid Build Coastguard Worker }
1340*49cdfc7eSAndroid Build Coastguard Worker } else
1341*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TBROK,
1342*49cdfc7eSAndroid Build Coastguard Worker "Unknown test case processing actions declared");
1343*49cdfc7eSAndroid Build Coastguard Worker }
1344*49cdfc7eSAndroid Build Coastguard Worker
1345*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
1346*49cdfc7eSAndroid Build Coastguard Worker * This routine checks for the return of EINVAL errno from requested
1347*49cdfc7eSAndroid Build Coastguard Worker * system call
1348*49cdfc7eSAndroid Build Coastguard Worker *
1349*49cdfc7eSAndroid Build Coastguard Worker * Argument is pointer to test_objects array of structures of type
1350*49cdfc7eSAndroid Build Coastguard Worker * all_test_cases
1351*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
do_EINVAL(struct all_test_cases * tc_ptr)1352*49cdfc7eSAndroid Build Coastguard Worker void do_EINVAL(struct all_test_cases *tc_ptr)
1353*49cdfc7eSAndroid Build Coastguard Worker {
1354*49cdfc7eSAndroid Build Coastguard Worker if (cktcsid(tc_ptr->tcid, READLINK)) {
1355*49cdfc7eSAndroid Build Coastguard Worker TEST(readlink(tc_ptr->fn_arg[0], test_msg, BUFMAX));
1356*49cdfc7eSAndroid Build Coastguard Worker errno = TEST_ERRNO;
1357*49cdfc7eSAndroid Build Coastguard Worker if (TEST_RETURN == -1) {
1358*49cdfc7eSAndroid Build Coastguard Worker if (errno == EINVAL) {
1359*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1360*49cdfc7eSAndroid Build Coastguard Worker } else {
1361*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1362*49cdfc7eSAndroid Build Coastguard Worker "readlink(2) ret:-1, errno:%d, : Exp errno:%d",
1363*49cdfc7eSAndroid Build Coastguard Worker errno, EINVAL);
1364*49cdfc7eSAndroid Build Coastguard Worker }
1365*49cdfc7eSAndroid Build Coastguard Worker } else {
1366*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1367*49cdfc7eSAndroid Build Coastguard Worker "readlink(2) did not returned -1 when reading %s",
1368*49cdfc7eSAndroid Build Coastguard Worker "a file which is not a symbolic link file");
1369*49cdfc7eSAndroid Build Coastguard Worker }
1370*49cdfc7eSAndroid Build Coastguard Worker } else
1371*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TBROK,
1372*49cdfc7eSAndroid Build Coastguard Worker "Unknown test case processing actions declared");
1373*49cdfc7eSAndroid Build Coastguard Worker }
1374*49cdfc7eSAndroid Build Coastguard Worker
1375*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
1376*49cdfc7eSAndroid Build Coastguard Worker * This routine checks out the readlink(2) system call for a successful
1377*49cdfc7eSAndroid Build Coastguard Worker * invocation
1378*49cdfc7eSAndroid Build Coastguard Worker *
1379*49cdfc7eSAndroid Build Coastguard Worker * Argument is pointer to test_objects array of structures of type
1380*49cdfc7eSAndroid Build Coastguard Worker * all_test_cases
1381*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
do_readlink(struct all_test_cases * tc_ptr)1382*49cdfc7eSAndroid Build Coastguard Worker void do_readlink(struct all_test_cases *tc_ptr)
1383*49cdfc7eSAndroid Build Coastguard Worker {
1384*49cdfc7eSAndroid Build Coastguard Worker char scratch[PATH_MAX];
1385*49cdfc7eSAndroid Build Coastguard Worker int ret;
1386*49cdfc7eSAndroid Build Coastguard Worker
1387*49cdfc7eSAndroid Build Coastguard Worker ret = readlink(tc_ptr->fn_arg[1], scratch, strlen(tc_ptr->fn_arg[0]));
1388*49cdfc7eSAndroid Build Coastguard Worker
1389*49cdfc7eSAndroid Build Coastguard Worker /*** the TEST macro cannot be used here for some reason ****/
1390*49cdfc7eSAndroid Build Coastguard Worker
1391*49cdfc7eSAndroid Build Coastguard Worker if (ret == -1) {
1392*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "readlink(2) failure on %s symbolic link file",
1393*49cdfc7eSAndroid Build Coastguard Worker tc_ptr->fn_arg[1]);
1394*49cdfc7eSAndroid Build Coastguard Worker
1395*49cdfc7eSAndroid Build Coastguard Worker } else
1396*49cdfc7eSAndroid Build Coastguard Worker if (strncmp(tc_ptr->fn_arg[0], scratch, strlen(tc_ptr->fn_arg[0]))
1397*49cdfc7eSAndroid Build Coastguard Worker != 0) {
1398*49cdfc7eSAndroid Build Coastguard Worker
1399*49cdfc7eSAndroid Build Coastguard Worker /* Must null terminate scratch because readlink(2) doesn't */
1400*49cdfc7eSAndroid Build Coastguard Worker
1401*49cdfc7eSAndroid Build Coastguard Worker scratch[strlen(tc_ptr->fn_arg[0])] = '\0';
1402*49cdfc7eSAndroid Build Coastguard Worker
1403*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1404*49cdfc7eSAndroid Build Coastguard Worker "readlink(2) Error : Expected %s symbolic link file contents but %s actual contents were returned",
1405*49cdfc7eSAndroid Build Coastguard Worker tc_ptr->fn_arg[0], scratch);
1406*49cdfc7eSAndroid Build Coastguard Worker } else {
1407*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1408*49cdfc7eSAndroid Build Coastguard Worker }
1409*49cdfc7eSAndroid Build Coastguard Worker }
1410*49cdfc7eSAndroid Build Coastguard Worker
1411*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
1412*49cdfc7eSAndroid Build Coastguard Worker * This routine checks out the stat(2) system call for a successful
1413*49cdfc7eSAndroid Build Coastguard Worker * invocation
1414*49cdfc7eSAndroid Build Coastguard Worker *
1415*49cdfc7eSAndroid Build Coastguard Worker * Argument is pointer to test_objects array of structures of type
1416*49cdfc7eSAndroid Build Coastguard Worker * all_test_cases
1417*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
do_stat(struct all_test_cases * tc_ptr)1418*49cdfc7eSAndroid Build Coastguard Worker void do_stat(struct all_test_cases *tc_ptr)
1419*49cdfc7eSAndroid Build Coastguard Worker {
1420*49cdfc7eSAndroid Build Coastguard Worker if (statter.st_dev != asymlink.st_dev)
1421*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1422*49cdfc7eSAndroid Build Coastguard Worker "stat of symbolic link reference to object device info %jd != stat of object file device info %jd",
1423*49cdfc7eSAndroid Build Coastguard Worker (intmax_t) statter.st_dev, (intmax_t) asymlink.st_dev);
1424*49cdfc7eSAndroid Build Coastguard Worker
1425*49cdfc7eSAndroid Build Coastguard Worker else if (statter.st_mode != asymlink.st_mode)
1426*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1427*49cdfc7eSAndroid Build Coastguard Worker "stat of symbolic link reference to object file permissions %jd != stat of object file permissions %jd",
1428*49cdfc7eSAndroid Build Coastguard Worker (intmax_t) statter.st_mode,
1429*49cdfc7eSAndroid Build Coastguard Worker (intmax_t) asymlink.st_mode);
1430*49cdfc7eSAndroid Build Coastguard Worker
1431*49cdfc7eSAndroid Build Coastguard Worker else if (statter.st_nlink != asymlink.st_nlink)
1432*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1433*49cdfc7eSAndroid Build Coastguard Worker "stat of symbolic link reference to object file link count %jd != stat of object file link count %jd",
1434*49cdfc7eSAndroid Build Coastguard Worker (intmax_t) statter.st_nlink,
1435*49cdfc7eSAndroid Build Coastguard Worker (intmax_t) asymlink.st_nlink);
1436*49cdfc7eSAndroid Build Coastguard Worker
1437*49cdfc7eSAndroid Build Coastguard Worker else if (statter.st_uid != asymlink.st_uid)
1438*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1439*49cdfc7eSAndroid Build Coastguard Worker "stat of symbolic link reference to object file uid %jd != stat of object file uid %jd",
1440*49cdfc7eSAndroid Build Coastguard Worker (intmax_t) statter.st_uid, (intmax_t) asymlink.st_uid);
1441*49cdfc7eSAndroid Build Coastguard Worker
1442*49cdfc7eSAndroid Build Coastguard Worker else if (statter.st_gid != asymlink.st_gid)
1443*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1444*49cdfc7eSAndroid Build Coastguard Worker "stat of symbolic link reference to object file gid %jd != stat of object file gid %jd",
1445*49cdfc7eSAndroid Build Coastguard Worker (intmax_t) statter.st_gid, (intmax_t) asymlink.st_gid);
1446*49cdfc7eSAndroid Build Coastguard Worker
1447*49cdfc7eSAndroid Build Coastguard Worker else if (statter.st_size != asymlink.st_size)
1448*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1449*49cdfc7eSAndroid Build Coastguard Worker "stat of symbolic link reference to object file size %ld != stat of object file size %ld",
1450*49cdfc7eSAndroid Build Coastguard Worker statter.st_size, asymlink.st_size);
1451*49cdfc7eSAndroid Build Coastguard Worker
1452*49cdfc7eSAndroid Build Coastguard Worker else if (statter.st_atime != asymlink.st_atime)
1453*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1454*49cdfc7eSAndroid Build Coastguard Worker "stat of symbolic link reference to object access time %ld != stat of object file access time %ld",
1455*49cdfc7eSAndroid Build Coastguard Worker statter.st_atime, asymlink.st_atime);
1456*49cdfc7eSAndroid Build Coastguard Worker
1457*49cdfc7eSAndroid Build Coastguard Worker else if (statter.st_mtime != asymlink.st_mtime)
1458*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1459*49cdfc7eSAndroid Build Coastguard Worker "stat of symbolic link reference to object modify time %ld != stat of object file modify time %ld",
1460*49cdfc7eSAndroid Build Coastguard Worker statter.st_atime, asymlink.st_atime);
1461*49cdfc7eSAndroid Build Coastguard Worker
1462*49cdfc7eSAndroid Build Coastguard Worker else if (statter.st_ctime != asymlink.st_ctime)
1463*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1464*49cdfc7eSAndroid Build Coastguard Worker "stat of symbolic link reference to object change time %ld != stat of object file change time %ld",
1465*49cdfc7eSAndroid Build Coastguard Worker statter.st_atime, asymlink.st_atime);
1466*49cdfc7eSAndroid Build Coastguard Worker else
1467*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1468*49cdfc7eSAndroid Build Coastguard Worker }
1469*49cdfc7eSAndroid Build Coastguard Worker
1470*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
1471*49cdfc7eSAndroid Build Coastguard Worker * This routine checks out the chdir(2) system call for a successful
1472*49cdfc7eSAndroid Build Coastguard Worker * invocation
1473*49cdfc7eSAndroid Build Coastguard Worker *
1474*49cdfc7eSAndroid Build Coastguard Worker * Argument is pointer to test_objects array of structures of type
1475*49cdfc7eSAndroid Build Coastguard Worker * all_test_cases
1476*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
do_chdir(struct all_test_cases * tc_ptr)1477*49cdfc7eSAndroid Build Coastguard Worker void do_chdir(struct all_test_cases *tc_ptr)
1478*49cdfc7eSAndroid Build Coastguard Worker {
1479*49cdfc7eSAndroid Build Coastguard Worker if (mkdir(tc_ptr->fn_arg[2], MODE) == -1)
1480*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "Could not create a setup directory file");
1481*49cdfc7eSAndroid Build Coastguard Worker else {
1482*49cdfc7eSAndroid Build Coastguard Worker
1483*49cdfc7eSAndroid Build Coastguard Worker sprintf(Buf, "mkdir(%s, %#o) was successful\n",
1484*49cdfc7eSAndroid Build Coastguard Worker tc_ptr->fn_arg[2], MODE);
1485*49cdfc7eSAndroid Build Coastguard Worker strcat(Buffer, Buf);
1486*49cdfc7eSAndroid Build Coastguard Worker
1487*49cdfc7eSAndroid Build Coastguard Worker if (chdir(tc_ptr->fn_arg[1]) == -1)
1488*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1489*49cdfc7eSAndroid Build Coastguard Worker "%sCould not change a directory file through a %s",
1490*49cdfc7eSAndroid Build Coastguard Worker Buffer,
1491*49cdfc7eSAndroid Build Coastguard Worker "symbolic link which which pointed at object");
1492*49cdfc7eSAndroid Build Coastguard Worker else {
1493*49cdfc7eSAndroid Build Coastguard Worker
1494*49cdfc7eSAndroid Build Coastguard Worker char *cwd;
1495*49cdfc7eSAndroid Build Coastguard Worker char expected_location[PATH_MAX];
1496*49cdfc7eSAndroid Build Coastguard Worker /*
1497*49cdfc7eSAndroid Build Coastguard Worker * Build expected current directory position
1498*49cdfc7eSAndroid Build Coastguard Worker */
1499*49cdfc7eSAndroid Build Coastguard Worker /* FIXME (garrcoop): memory leak */
1500*49cdfc7eSAndroid Build Coastguard Worker strcpy(expected_location, tst_get_tmpdir());
1501*49cdfc7eSAndroid Build Coastguard Worker strcat(expected_location, "/");
1502*49cdfc7eSAndroid Build Coastguard Worker strcat(expected_location, tc_ptr->fn_arg[2]);
1503*49cdfc7eSAndroid Build Coastguard Worker
1504*49cdfc7eSAndroid Build Coastguard Worker if ((cwd = getcwd(NULL, 0)) == NULL) {
1505*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "getcwd(3) FAILURE");
1506*49cdfc7eSAndroid Build Coastguard Worker } else if (strcmp(cwd, expected_location) == 0) {
1507*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1508*49cdfc7eSAndroid Build Coastguard Worker } else {
1509*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1510*49cdfc7eSAndroid Build Coastguard Worker "%s%s %s %s not equal to expected %s",
1511*49cdfc7eSAndroid Build Coastguard Worker Buffer,
1512*49cdfc7eSAndroid Build Coastguard Worker "chdir(2) returned successfully, but getcwd(3) indicated",
1513*49cdfc7eSAndroid Build Coastguard Worker "new current working directory location",
1514*49cdfc7eSAndroid Build Coastguard Worker cwd, expected_location);
1515*49cdfc7eSAndroid Build Coastguard Worker }
1516*49cdfc7eSAndroid Build Coastguard Worker /* FIXME (garrcoop): memory leak */
1517*49cdfc7eSAndroid Build Coastguard Worker chdir(tst_get_tmpdir());
1518*49cdfc7eSAndroid Build Coastguard Worker }
1519*49cdfc7eSAndroid Build Coastguard Worker rmdir(tc_ptr->fn_arg[2]);
1520*49cdfc7eSAndroid Build Coastguard Worker }
1521*49cdfc7eSAndroid Build Coastguard Worker }
1522*49cdfc7eSAndroid Build Coastguard Worker
1523*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
1524*49cdfc7eSAndroid Build Coastguard Worker * This routine checks out the link(2) system call for a successful
1525*49cdfc7eSAndroid Build Coastguard Worker * invocation
1526*49cdfc7eSAndroid Build Coastguard Worker *
1527*49cdfc7eSAndroid Build Coastguard Worker * Argument is pointer to test_objects array of structures of type
1528*49cdfc7eSAndroid Build Coastguard Worker * all_test_cases
1529*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
do_link(struct all_test_cases * tc_ptr)1530*49cdfc7eSAndroid Build Coastguard Worker void do_link(struct all_test_cases *tc_ptr)
1531*49cdfc7eSAndroid Build Coastguard Worker {
1532*49cdfc7eSAndroid Build Coastguard Worker struct stat stbuf;
1533*49cdfc7eSAndroid Build Coastguard Worker
1534*49cdfc7eSAndroid Build Coastguard Worker if (link(tc_ptr->fn_arg[1], "nick") == -1) {
1535*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%slink(%s, \"nick\") failed, errno: %d: %s %s",
1536*49cdfc7eSAndroid Build Coastguard Worker Buffer, tc_ptr->fn_arg[1], errno,
1537*49cdfc7eSAndroid Build Coastguard Worker "link of new file to object file via symbolic link file failed",
1538*49cdfc7eSAndroid Build Coastguard Worker "when expected not to");
1539*49cdfc7eSAndroid Build Coastguard Worker } else {
1540*49cdfc7eSAndroid Build Coastguard Worker sprintf(Buf, "link(%s, \"nick\") was successful\n",
1541*49cdfc7eSAndroid Build Coastguard Worker tc_ptr->fn_arg[1]);
1542*49cdfc7eSAndroid Build Coastguard Worker strcat(Buffer, Buf);
1543*49cdfc7eSAndroid Build Coastguard Worker
1544*49cdfc7eSAndroid Build Coastguard Worker /*
1545*49cdfc7eSAndroid Build Coastguard Worker * Check that links counts were properly set
1546*49cdfc7eSAndroid Build Coastguard Worker */
1547*49cdfc7eSAndroid Build Coastguard Worker if (lstat(tc_ptr->fn_arg[1], &asymlink) == -1) {
1548*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TBROK, "lstat(%s) failed. errno: %d",
1549*49cdfc7eSAndroid Build Coastguard Worker tc_ptr->fn_arg[1], errno);
1550*49cdfc7eSAndroid Build Coastguard Worker
1551*49cdfc7eSAndroid Build Coastguard Worker } else if (lstat("nick", &statter) == -1) {
1552*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TBROK, "lstat(nick) failed, errno:%d",
1553*49cdfc7eSAndroid Build Coastguard Worker errno);
1554*49cdfc7eSAndroid Build Coastguard Worker } else {
1555*49cdfc7eSAndroid Build Coastguard Worker if (statter.st_ino == asymlink.st_ino) {
1556*49cdfc7eSAndroid Build Coastguard Worker if ((statter.st_nlink == 2) && (asymlink.st_nlink == 2)) {
1557*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s",
1558*49cdfc7eSAndroid Build Coastguard Worker msgs[tc_ptr->pass_msg]);
1559*49cdfc7eSAndroid Build Coastguard Worker } else {
1560*49cdfc7eSAndroid Build Coastguard Worker lstat(tc_ptr->fn_arg[2],
1561*49cdfc7eSAndroid Build Coastguard Worker &stbuf);
1562*49cdfc7eSAndroid Build Coastguard Worker
1563*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1564*49cdfc7eSAndroid Build Coastguard Worker "%slink(%s, %s) failed to adjust link count.\n\
1565*49cdfc7eSAndroid Build Coastguard Worker count for nick is %d, count for %s is %d, count for %s is %d.",
1566*49cdfc7eSAndroid Build Coastguard Worker Buffer, tc_ptr->fn_arg[1], "nick", statter.st_nlink, tc_ptr->fn_arg[1], asymlink.st_nlink, tc_ptr->fn_arg[2],
1567*49cdfc7eSAndroid Build Coastguard Worker stbuf.st_nlink);
1568*49cdfc7eSAndroid Build Coastguard Worker }
1569*49cdfc7eSAndroid Build Coastguard Worker } else {
1570*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%sA lstat of %s (ino:%jd) and of\n\t\t\
1571*49cdfc7eSAndroid Build Coastguard Worker %s (ino:%jd), does not show them being the same ino.", Buffer,
1572*49cdfc7eSAndroid Build Coastguard Worker tc_ptr->fn_arg[1], (intmax_t) asymlink.st_ino, "nick", (intmax_t) statter.st_ino);
1573*49cdfc7eSAndroid Build Coastguard Worker }
1574*49cdfc7eSAndroid Build Coastguard Worker }
1575*49cdfc7eSAndroid Build Coastguard Worker
1576*49cdfc7eSAndroid Build Coastguard Worker delete_files("nick", NULL);
1577*49cdfc7eSAndroid Build Coastguard Worker }
1578*49cdfc7eSAndroid Build Coastguard Worker }
1579*49cdfc7eSAndroid Build Coastguard Worker
1580*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
1581*49cdfc7eSAndroid Build Coastguard Worker * This routine checks out the unlink(2) system call for a successful
1582*49cdfc7eSAndroid Build Coastguard Worker * invocation
1583*49cdfc7eSAndroid Build Coastguard Worker *
1584*49cdfc7eSAndroid Build Coastguard Worker * Argument is pointer to test_objects array of structures of type
1585*49cdfc7eSAndroid Build Coastguard Worker * all_test_cases
1586*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
do_unlink(struct all_test_cases * tc_ptr)1587*49cdfc7eSAndroid Build Coastguard Worker void do_unlink(struct all_test_cases *tc_ptr)
1588*49cdfc7eSAndroid Build Coastguard Worker {
1589*49cdfc7eSAndroid Build Coastguard Worker if (stat(tc_ptr->fn_arg[2], &asymlink) == -1)
1590*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TBROK, "stat(2) Failure when accessing %s object file",
1591*49cdfc7eSAndroid Build Coastguard Worker tc_ptr->fn_arg[2]);
1592*49cdfc7eSAndroid Build Coastguard Worker else if (unlink(tc_ptr->fn_arg[1]) == -1)
1593*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1594*49cdfc7eSAndroid Build Coastguard Worker "unlink(2) failed when removing symbolic link file");
1595*49cdfc7eSAndroid Build Coastguard Worker else {
1596*49cdfc7eSAndroid Build Coastguard Worker sprintf(Buf, "unlink(%s) was successful\n", tc_ptr->fn_arg[1]);
1597*49cdfc7eSAndroid Build Coastguard Worker strcat(Buffer, Buf);
1598*49cdfc7eSAndroid Build Coastguard Worker if (stat(tc_ptr->fn_arg[2], &statter) == -1) {
1599*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s %s",
1600*49cdfc7eSAndroid Build Coastguard Worker "unlink(2) failed because it not only removed symbolic link",
1601*49cdfc7eSAndroid Build Coastguard Worker "file which pointed at object file, but object file as well");
1602*49cdfc7eSAndroid Build Coastguard Worker
1603*49cdfc7eSAndroid Build Coastguard Worker } else if ((statter.st_ino == asymlink.st_ino) &&
1604*49cdfc7eSAndroid Build Coastguard Worker (statter.st_dev == asymlink.st_dev) &&
1605*49cdfc7eSAndroid Build Coastguard Worker (statter.st_size == asymlink.st_size)) {
1606*49cdfc7eSAndroid Build Coastguard Worker
1607*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1608*49cdfc7eSAndroid Build Coastguard Worker } else {
1609*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s%s %s %s", Buffer,
1610*49cdfc7eSAndroid Build Coastguard Worker "unlink(2) failed because it not only removed symbolic link",
1611*49cdfc7eSAndroid Build Coastguard Worker "file which pointed at object file, but it changed object",
1612*49cdfc7eSAndroid Build Coastguard Worker "file inode information");
1613*49cdfc7eSAndroid Build Coastguard Worker }
1614*49cdfc7eSAndroid Build Coastguard Worker }
1615*49cdfc7eSAndroid Build Coastguard Worker
1616*49cdfc7eSAndroid Build Coastguard Worker }
1617*49cdfc7eSAndroid Build Coastguard Worker
1618*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
1619*49cdfc7eSAndroid Build Coastguard Worker * This routine checks out the chmod(2) system call for a successful
1620*49cdfc7eSAndroid Build Coastguard Worker * invocation
1621*49cdfc7eSAndroid Build Coastguard Worker *
1622*49cdfc7eSAndroid Build Coastguard Worker * Argument is pointer to test_objects array of structures of type
1623*49cdfc7eSAndroid Build Coastguard Worker * all_test_cases
1624*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
do_chmod(struct all_test_cases * tc_ptr)1625*49cdfc7eSAndroid Build Coastguard Worker void do_chmod(struct all_test_cases *tc_ptr)
1626*49cdfc7eSAndroid Build Coastguard Worker {
1627*49cdfc7eSAndroid Build Coastguard Worker if (stat(tc_ptr->fn_arg[2], &asymlink) == -1)
1628*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TBROK, "stat(2) Failure when accessing %s object file",
1629*49cdfc7eSAndroid Build Coastguard Worker tc_ptr->fn_arg[2]);
1630*49cdfc7eSAndroid Build Coastguard Worker else if (chmod(tc_ptr->fn_arg[1], (MODE | MASK)) == -1)
1631*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s%s %s", Buffer,
1632*49cdfc7eSAndroid Build Coastguard Worker "chmod(2) failed when changing file permission",
1633*49cdfc7eSAndroid Build Coastguard Worker "through symbolic link file");
1634*49cdfc7eSAndroid Build Coastguard Worker else {
1635*49cdfc7eSAndroid Build Coastguard Worker sprintf(Buf, "chmod(%s, %#o) was successful\n",
1636*49cdfc7eSAndroid Build Coastguard Worker tc_ptr->fn_arg[1], (MODE | MASK));
1637*49cdfc7eSAndroid Build Coastguard Worker strcat(Buffer, Buf);
1638*49cdfc7eSAndroid Build Coastguard Worker
1639*49cdfc7eSAndroid Build Coastguard Worker if (stat(tc_ptr->fn_arg[2], &statter) == -1) {
1640*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TBROK,
1641*49cdfc7eSAndroid Build Coastguard Worker "stat(2) Failure when accessing %s object file",
1642*49cdfc7eSAndroid Build Coastguard Worker tc_ptr->fn_arg[2]);
1643*49cdfc7eSAndroid Build Coastguard Worker } else if ((statter.st_mode == (MODE | MASK))
1644*49cdfc7eSAndroid Build Coastguard Worker && (statter.st_mode != asymlink.st_mode)) {
1645*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1646*49cdfc7eSAndroid Build Coastguard Worker } else {
1647*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s%s %o to %o %s", Buffer,
1648*49cdfc7eSAndroid Build Coastguard Worker "chmod(2) failed to change object file permissions from",
1649*49cdfc7eSAndroid Build Coastguard Worker asymlink.st_mode, (MODE | MASK),
1650*49cdfc7eSAndroid Build Coastguard Worker "through symbolic link file");
1651*49cdfc7eSAndroid Build Coastguard Worker }
1652*49cdfc7eSAndroid Build Coastguard Worker }
1653*49cdfc7eSAndroid Build Coastguard Worker
1654*49cdfc7eSAndroid Build Coastguard Worker }
1655*49cdfc7eSAndroid Build Coastguard Worker
1656*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
1657*49cdfc7eSAndroid Build Coastguard Worker * This routine checks out the utime(2) system call for a successful
1658*49cdfc7eSAndroid Build Coastguard Worker * invocation
1659*49cdfc7eSAndroid Build Coastguard Worker *
1660*49cdfc7eSAndroid Build Coastguard Worker * Argument is pointer to test_objects array of structures of type
1661*49cdfc7eSAndroid Build Coastguard Worker * all_test_cases
1662*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
do_utime(struct all_test_cases * tc_ptr)1663*49cdfc7eSAndroid Build Coastguard Worker void do_utime(struct all_test_cases *tc_ptr)
1664*49cdfc7eSAndroid Build Coastguard Worker {
1665*49cdfc7eSAndroid Build Coastguard Worker struct utimbuf utimes;
1666*49cdfc7eSAndroid Build Coastguard Worker
1667*49cdfc7eSAndroid Build Coastguard Worker if (stat(tc_ptr->fn_arg[2], &asymlink) == -1)
1668*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TBROK, "stat(2) Failure when accessing %s object file",
1669*49cdfc7eSAndroid Build Coastguard Worker tc_ptr->fn_arg[2]);
1670*49cdfc7eSAndroid Build Coastguard Worker else {
1671*49cdfc7eSAndroid Build Coastguard Worker /* Now add a few values to access and modify times */
1672*49cdfc7eSAndroid Build Coastguard Worker
1673*49cdfc7eSAndroid Build Coastguard Worker utimes.actime = asymlink.st_atime + a_time_value;
1674*49cdfc7eSAndroid Build Coastguard Worker utimes.modtime = asymlink.st_mtime + a_time_value;
1675*49cdfc7eSAndroid Build Coastguard Worker
1676*49cdfc7eSAndroid Build Coastguard Worker /* Now hand off to utime(2) via symbolic link file */
1677*49cdfc7eSAndroid Build Coastguard Worker
1678*49cdfc7eSAndroid Build Coastguard Worker if (utime(tc_ptr->fn_arg[1], &utimes) == -1)
1679*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s %s",
1680*49cdfc7eSAndroid Build Coastguard Worker "utime(2) failed to process object file access and modify",
1681*49cdfc7eSAndroid Build Coastguard Worker "time updates through symbolic link");
1682*49cdfc7eSAndroid Build Coastguard Worker else {
1683*49cdfc7eSAndroid Build Coastguard Worker /* Now verify changes were made */
1684*49cdfc7eSAndroid Build Coastguard Worker
1685*49cdfc7eSAndroid Build Coastguard Worker if (stat(tc_ptr->fn_arg[2], &statter) == -1)
1686*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TBROK,
1687*49cdfc7eSAndroid Build Coastguard Worker "stat(2) Failure when accessing %s object file",
1688*49cdfc7eSAndroid Build Coastguard Worker tc_ptr->fn_arg[2]);
1689*49cdfc7eSAndroid Build Coastguard Worker else {
1690*49cdfc7eSAndroid Build Coastguard Worker time_t temp, diff;
1691*49cdfc7eSAndroid Build Coastguard Worker
1692*49cdfc7eSAndroid Build Coastguard Worker temp = statter.st_atime - asymlink.st_atime;
1693*49cdfc7eSAndroid Build Coastguard Worker diff =
1694*49cdfc7eSAndroid Build Coastguard Worker (statter.st_mtime - asymlink.st_mtime) -
1695*49cdfc7eSAndroid Build Coastguard Worker temp;
1696*49cdfc7eSAndroid Build Coastguard Worker
1697*49cdfc7eSAndroid Build Coastguard Worker if (!diff) {
1698*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s",
1699*49cdfc7eSAndroid Build Coastguard Worker msgs[tc_ptr->pass_msg]);
1700*49cdfc7eSAndroid Build Coastguard Worker } else {
1701*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1702*49cdfc7eSAndroid Build Coastguard Worker "%s %s %jd greater than original times",
1703*49cdfc7eSAndroid Build Coastguard Worker "utime(2) failed to change object file access and",
1704*49cdfc7eSAndroid Build Coastguard Worker "modify times through symbolic link to a value",
1705*49cdfc7eSAndroid Build Coastguard Worker (intmax_t) a_time_value);
1706*49cdfc7eSAndroid Build Coastguard Worker }
1707*49cdfc7eSAndroid Build Coastguard Worker }
1708*49cdfc7eSAndroid Build Coastguard Worker }
1709*49cdfc7eSAndroid Build Coastguard Worker }
1710*49cdfc7eSAndroid Build Coastguard Worker }
1711*49cdfc7eSAndroid Build Coastguard Worker
1712*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
1713*49cdfc7eSAndroid Build Coastguard Worker * This routine checks out the rename(2) system call for a successful
1714*49cdfc7eSAndroid Build Coastguard Worker * invocation
1715*49cdfc7eSAndroid Build Coastguard Worker *
1716*49cdfc7eSAndroid Build Coastguard Worker * Argument is pointer to test_objects array of structures of type
1717*49cdfc7eSAndroid Build Coastguard Worker * all_test_cases
1718*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
do_rename(struct all_test_cases * tc_ptr)1719*49cdfc7eSAndroid Build Coastguard Worker void do_rename(struct all_test_cases *tc_ptr)
1720*49cdfc7eSAndroid Build Coastguard Worker {
1721*49cdfc7eSAndroid Build Coastguard Worker int pts_at_object = 0;
1722*49cdfc7eSAndroid Build Coastguard Worker
1723*49cdfc7eSAndroid Build Coastguard Worker if (stat(tc_ptr->fn_arg[2], &statter) != -1)
1724*49cdfc7eSAndroid Build Coastguard Worker pts_at_object = 1;
1725*49cdfc7eSAndroid Build Coastguard Worker
1726*49cdfc7eSAndroid Build Coastguard Worker TEST(rename(tc_ptr->fn_arg[1], A_S_FILE));
1727*49cdfc7eSAndroid Build Coastguard Worker errno = TEST_ERRNO;
1728*49cdfc7eSAndroid Build Coastguard Worker if (TEST_RETURN == -1) {
1729*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1730*49cdfc7eSAndroid Build Coastguard Worker "rename(3) failed to rename %s symbolic link file to %s",
1731*49cdfc7eSAndroid Build Coastguard Worker tc_ptr->fn_arg[2], A_S_FILE);
1732*49cdfc7eSAndroid Build Coastguard Worker } else if (pts_at_object) {
1733*49cdfc7eSAndroid Build Coastguard Worker if (ck_both(tc_ptr->fn_arg[0], A_S_FILE, tc_ptr->fn_arg[2])) {
1734*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1735*49cdfc7eSAndroid Build Coastguard Worker } else {
1736*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s", test_msg);
1737*49cdfc7eSAndroid Build Coastguard Worker }
1738*49cdfc7eSAndroid Build Coastguard Worker } else if (!ck_symlink(tc_ptr->fn_arg[0], A_S_FILE, NULL)) {
1739*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s", test_msg);
1740*49cdfc7eSAndroid Build Coastguard Worker } else if (stat(tc_ptr->fn_arg[1], &asymlink) != -1) {
1741*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1742*49cdfc7eSAndroid Build Coastguard Worker "rename(3) did not remove %s when renaming to %s",
1743*49cdfc7eSAndroid Build Coastguard Worker tc_ptr->fn_arg[1], A_S_FILE);
1744*49cdfc7eSAndroid Build Coastguard Worker } else {
1745*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1746*49cdfc7eSAndroid Build Coastguard Worker }
1747*49cdfc7eSAndroid Build Coastguard Worker }
1748*49cdfc7eSAndroid Build Coastguard Worker
1749*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
1750*49cdfc7eSAndroid Build Coastguard Worker * This routine checks out the open(2) system call for a successful
1751*49cdfc7eSAndroid Build Coastguard Worker * invocation
1752*49cdfc7eSAndroid Build Coastguard Worker *
1753*49cdfc7eSAndroid Build Coastguard Worker * Argument is pointer to test_objects array of structures of type
1754*49cdfc7eSAndroid Build Coastguard Worker * all_test_cases
1755*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
do_open(struct all_test_cases * tc_ptr)1756*49cdfc7eSAndroid Build Coastguard Worker void do_open(struct all_test_cases *tc_ptr)
1757*49cdfc7eSAndroid Build Coastguard Worker {
1758*49cdfc7eSAndroid Build Coastguard Worker int fd = -1;
1759*49cdfc7eSAndroid Build Coastguard Worker int ret, pts_at_object = 0;
1760*49cdfc7eSAndroid Build Coastguard Worker char scratch[PATH_MAX];
1761*49cdfc7eSAndroid Build Coastguard Worker
1762*49cdfc7eSAndroid Build Coastguard Worker if (stat(tc_ptr->fn_arg[2], &statter) != -1)
1763*49cdfc7eSAndroid Build Coastguard Worker pts_at_object = 1;
1764*49cdfc7eSAndroid Build Coastguard Worker
1765*49cdfc7eSAndroid Build Coastguard Worker if (pts_at_object) {
1766*49cdfc7eSAndroid Build Coastguard Worker TEST(open(tc_ptr->fn_arg[1], O_RDWR));
1767*49cdfc7eSAndroid Build Coastguard Worker errno = TEST_ERRNO;
1768*49cdfc7eSAndroid Build Coastguard Worker if ((fd = TEST_RETURN) == -1) {
1769*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1770*49cdfc7eSAndroid Build Coastguard Worker "open(2) Failure when opening object file through symbolic link file");
1771*49cdfc7eSAndroid Build Coastguard Worker return;
1772*49cdfc7eSAndroid Build Coastguard Worker }
1773*49cdfc7eSAndroid Build Coastguard Worker } else {
1774*49cdfc7eSAndroid Build Coastguard Worker TEST(open(tc_ptr->fn_arg[1], (O_CREAT | O_RDWR), MODE));
1775*49cdfc7eSAndroid Build Coastguard Worker errno = TEST_ERRNO;
1776*49cdfc7eSAndroid Build Coastguard Worker if ((fd = TEST_RETURN) == -1) {
1777*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1778*49cdfc7eSAndroid Build Coastguard Worker "open(2) Failure when creating object file through symbolic link file");
1779*49cdfc7eSAndroid Build Coastguard Worker return;
1780*49cdfc7eSAndroid Build Coastguard Worker }
1781*49cdfc7eSAndroid Build Coastguard Worker }
1782*49cdfc7eSAndroid Build Coastguard Worker if ((ret = write(fd, BIG_STRING, strlen(BIG_STRING))) == -1) {
1783*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1784*49cdfc7eSAndroid Build Coastguard Worker "write(2) Failure to object file opened through a symbolic link file: errno:%d",
1785*49cdfc7eSAndroid Build Coastguard Worker errno);
1786*49cdfc7eSAndroid Build Coastguard Worker } else if (ret != strlen(BIG_STRING)) {
1787*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1788*49cdfc7eSAndroid Build Coastguard Worker "write(2) Failed to write %zu bytes to object file opened through a symbolic link file",
1789*49cdfc7eSAndroid Build Coastguard Worker strlen(BIG_STRING));
1790*49cdfc7eSAndroid Build Coastguard Worker } else if (lseek(fd, 0L, 0) == -1) {
1791*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1792*49cdfc7eSAndroid Build Coastguard Worker "lseek(2) Failed to position to beginning of object file opened through a symbolic link file: errno = %d",
1793*49cdfc7eSAndroid Build Coastguard Worker errno);
1794*49cdfc7eSAndroid Build Coastguard Worker } else if ((ret = read(fd, scratch, strlen(BIG_STRING))) == -1) {
1795*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1796*49cdfc7eSAndroid Build Coastguard Worker "read(2) Failure of object file opened through a symbolic link file: errno = %d",
1797*49cdfc7eSAndroid Build Coastguard Worker errno);
1798*49cdfc7eSAndroid Build Coastguard Worker } else if (ret != strlen(BIG_STRING)) {
1799*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1800*49cdfc7eSAndroid Build Coastguard Worker "read(2) Failed to read %zu bytes to object file opened through a symbolic link file",
1801*49cdfc7eSAndroid Build Coastguard Worker strlen(BIG_STRING));
1802*49cdfc7eSAndroid Build Coastguard Worker } else if (strncmp(BIG_STRING, scratch, strlen(BIG_STRING)) != 0) {
1803*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1804*49cdfc7eSAndroid Build Coastguard Worker "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",
1805*49cdfc7eSAndroid Build Coastguard Worker BIG_STRING, scratch);
1806*49cdfc7eSAndroid Build Coastguard Worker } else {
1807*49cdfc7eSAndroid Build Coastguard Worker /*
1808*49cdfc7eSAndroid Build Coastguard Worker * Close off symbolic link file to object file access
1809*49cdfc7eSAndroid Build Coastguard Worker */
1810*49cdfc7eSAndroid Build Coastguard Worker if (close(fd) == -1) {
1811*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1812*49cdfc7eSAndroid Build Coastguard Worker "close(2) Failure when closing object file accessed symbolic link file");
1813*49cdfc7eSAndroid Build Coastguard Worker }
1814*49cdfc7eSAndroid Build Coastguard Worker /*
1815*49cdfc7eSAndroid Build Coastguard Worker * Now, lets open up and read object file and compare contents
1816*49cdfc7eSAndroid Build Coastguard Worker */
1817*49cdfc7eSAndroid Build Coastguard Worker else if ((fd = open(tc_ptr->fn_arg[0], O_RDONLY)) == -1) {
1818*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1819*49cdfc7eSAndroid Build Coastguard Worker "open(2) Failure when opening %s file: errno:%d %s",
1820*49cdfc7eSAndroid Build Coastguard Worker tc_ptr->fn_arg[0], errno, strerror(errno));
1821*49cdfc7eSAndroid Build Coastguard Worker } else if ((ret = read(fd, scratch, strlen(BIG_STRING))) == -1) {
1822*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1823*49cdfc7eSAndroid Build Coastguard Worker "read(2) Failure of object file opened through a symbolic link file: errno:%d",
1824*49cdfc7eSAndroid Build Coastguard Worker errno);
1825*49cdfc7eSAndroid Build Coastguard Worker } else if (ret != strlen(BIG_STRING)) {
1826*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1827*49cdfc7eSAndroid Build Coastguard Worker "read(2) Failed to read %zu bytes to object file opened through a symbolic link file",
1828*49cdfc7eSAndroid Build Coastguard Worker strlen(BIG_STRING));
1829*49cdfc7eSAndroid Build Coastguard Worker } else if (strncmp(BIG_STRING, scratch, strlen(BIG_STRING)) !=
1830*49cdfc7eSAndroid Build Coastguard Worker 0) {
1831*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
1832*49cdfc7eSAndroid Build Coastguard Worker "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",
1833*49cdfc7eSAndroid Build Coastguard Worker BIG_STRING, scratch);
1834*49cdfc7eSAndroid Build Coastguard Worker } else if (pts_at_object) {
1835*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]);
1836*49cdfc7eSAndroid Build Coastguard Worker } else { /* Insure newly created object file is pointed at */
1837*49cdfc7eSAndroid Build Coastguard Worker if (ck_both
1838*49cdfc7eSAndroid Build Coastguard Worker (tc_ptr->fn_arg[0], tc_ptr->fn_arg[1],
1839*49cdfc7eSAndroid Build Coastguard Worker tc_ptr->fn_arg[0])) {
1840*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TEST_RESULT, "%s",
1841*49cdfc7eSAndroid Build Coastguard Worker msgs[tc_ptr->pass_msg]);
1842*49cdfc7eSAndroid Build Coastguard Worker } else {
1843*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s", test_msg);
1844*49cdfc7eSAndroid Build Coastguard Worker }
1845*49cdfc7eSAndroid Build Coastguard Worker }
1846*49cdfc7eSAndroid Build Coastguard Worker close(fd);
1847*49cdfc7eSAndroid Build Coastguard Worker }
1848*49cdfc7eSAndroid Build Coastguard Worker }
1849*49cdfc7eSAndroid Build Coastguard Worker
1850*49cdfc7eSAndroid Build Coastguard Worker /***************************************************************
1851*49cdfc7eSAndroid Build Coastguard Worker * setup() - performs all ONE TIME setup for this test.
1852*49cdfc7eSAndroid Build Coastguard Worker ***************************************************************/
setup(void)1853*49cdfc7eSAndroid Build Coastguard Worker void setup(void)
1854*49cdfc7eSAndroid Build Coastguard Worker {
1855*49cdfc7eSAndroid Build Coastguard Worker
1856*49cdfc7eSAndroid Build Coastguard Worker tst_sig(FORK, DEF_HANDLER, cleanup);
1857*49cdfc7eSAndroid Build Coastguard Worker
1858*49cdfc7eSAndroid Build Coastguard Worker TEST_PAUSE;
1859*49cdfc7eSAndroid Build Coastguard Worker
1860*49cdfc7eSAndroid Build Coastguard Worker /* create a temporary directory and go to it */
1861*49cdfc7eSAndroid Build Coastguard Worker tst_tmpdir();
1862*49cdfc7eSAndroid Build Coastguard Worker
1863*49cdfc7eSAndroid Build Coastguard Worker }
1864*49cdfc7eSAndroid Build Coastguard Worker
1865*49cdfc7eSAndroid Build Coastguard Worker /***************************************************************
1866*49cdfc7eSAndroid Build Coastguard Worker * cleanup() - performs all ONE TIME cleanup for this test at
1867*49cdfc7eSAndroid Build Coastguard Worker * completion or premature exit.
1868*49cdfc7eSAndroid Build Coastguard Worker ***************************************************************/
cleanup(void)1869*49cdfc7eSAndroid Build Coastguard Worker void cleanup(void)
1870*49cdfc7eSAndroid Build Coastguard Worker {
1871*49cdfc7eSAndroid Build Coastguard Worker
1872*49cdfc7eSAndroid Build Coastguard Worker tst_rmdir();
1873*49cdfc7eSAndroid Build Coastguard Worker
1874*49cdfc7eSAndroid Build Coastguard Worker }
1875*49cdfc7eSAndroid Build Coastguard Worker
help(void)1876*49cdfc7eSAndroid Build Coastguard Worker void help(void)
1877*49cdfc7eSAndroid Build Coastguard Worker {
1878*49cdfc7eSAndroid Build Coastguard Worker unsigned int ind;
1879*49cdfc7eSAndroid Build Coastguard Worker
1880*49cdfc7eSAndroid Build Coastguard Worker printf(" -T id Determines which tests cases to execute:\n");
1881*49cdfc7eSAndroid Build Coastguard Worker
1882*49cdfc7eSAndroid Build Coastguard Worker for (ind = 0; ind < sizeof(all_tcses) / sizeof(struct tcses); ind++) {
1883*49cdfc7eSAndroid Build Coastguard Worker printf(" %s/%s - %s\n", all_tcses[ind].tcid,
1884*49cdfc7eSAndroid Build Coastguard Worker all_tcses[ind].syscall, all_tcses[ind].desc);
1885*49cdfc7eSAndroid Build Coastguard Worker }
1886*49cdfc7eSAndroid Build Coastguard Worker }
1887