1*49cdfc7eSAndroid Build Coastguard Worker /*
2*49cdfc7eSAndroid Build Coastguard Worker *
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) International Business Machines Corp., 2001
4*49cdfc7eSAndroid Build Coastguard Worker *
5*49cdfc7eSAndroid Build Coastguard Worker * This program is free software; you can redistribute it and/or modify
6*49cdfc7eSAndroid Build Coastguard Worker * it under the terms of the GNU General Public License as published by
7*49cdfc7eSAndroid Build Coastguard Worker * the Free Software Foundation; either version 2 of the License, or
8*49cdfc7eSAndroid Build Coastguard Worker * (at your option) any later version.
9*49cdfc7eSAndroid Build Coastguard Worker *
10*49cdfc7eSAndroid Build Coastguard Worker * This program is distributed in the hope that it will be useful,
11*49cdfc7eSAndroid Build Coastguard Worker * but WITHOUT ANY WARRANTY; without even the implied warranty of
12*49cdfc7eSAndroid Build Coastguard Worker * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13*49cdfc7eSAndroid Build Coastguard Worker * the GNU General Public License for more details.
14*49cdfc7eSAndroid Build Coastguard Worker *
15*49cdfc7eSAndroid Build Coastguard Worker * You should have received a copy of the GNU General Public License
16*49cdfc7eSAndroid Build Coastguard Worker * along with this program; if not, write to the Free Software
17*49cdfc7eSAndroid Build Coastguard Worker * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*49cdfc7eSAndroid Build Coastguard Worker */
19*49cdfc7eSAndroid Build Coastguard Worker
20*49cdfc7eSAndroid Build Coastguard Worker /*
21*49cdfc7eSAndroid Build Coastguard Worker * Test Name : symlink03
22*49cdfc7eSAndroid Build Coastguard Worker *
23*49cdfc7eSAndroid Build Coastguard Worker * Test Description :
24*49cdfc7eSAndroid Build Coastguard Worker * Verify that,
25*49cdfc7eSAndroid Build Coastguard Worker * 1) symlink(2) returns -1 and sets errno to EACCES if search/write
26*49cdfc7eSAndroid Build Coastguard Worker * permission is denied in the directory where the symbolic link is
27*49cdfc7eSAndroid Build Coastguard Worker * being created.
28*49cdfc7eSAndroid Build Coastguard Worker * 2) symlink(2) returns -1 and sets errno to EEXIST if the specified
29*49cdfc7eSAndroid Build Coastguard Worker * symbolic link already exists.
30*49cdfc7eSAndroid Build Coastguard Worker * 3) symlink(2) returns -1 and sets errno to EFAULT if the specified
31*49cdfc7eSAndroid Build Coastguard Worker * file or symbolic link points to invalid address.
32*49cdfc7eSAndroid Build Coastguard Worker * 4) symlink(2) returns -1 and sets errno to ENAMETOOLONG if the
33*49cdfc7eSAndroid Build Coastguard Worker * pathname component of symbolic link is too long (ie, > PATH_MAX).
34*49cdfc7eSAndroid Build Coastguard Worker * 5) symlink(2) returns -1 and sets errno to ENOTDIR if the directory
35*49cdfc7eSAndroid Build Coastguard Worker * component in pathname of symbolic link is not a directory.
36*49cdfc7eSAndroid Build Coastguard Worker * 6) symlink(2) returns -1 and sets errno to ENOENT if the component of
37*49cdfc7eSAndroid Build Coastguard Worker * symbolic link points to an empty string.
38*49cdfc7eSAndroid Build Coastguard Worker *
39*49cdfc7eSAndroid Build Coastguard Worker * Expected Result:
40*49cdfc7eSAndroid Build Coastguard Worker * symlink() should fail with return value -1 and set expected errno.
41*49cdfc7eSAndroid Build Coastguard Worker *
42*49cdfc7eSAndroid Build Coastguard Worker * Algorithm:
43*49cdfc7eSAndroid Build Coastguard Worker * Setup:
44*49cdfc7eSAndroid Build Coastguard Worker * Setup signal handling.
45*49cdfc7eSAndroid Build Coastguard Worker * Create temporary directory.
46*49cdfc7eSAndroid Build Coastguard Worker * Pause for SIGUSR1 if option specified.
47*49cdfc7eSAndroid Build Coastguard Worker *
48*49cdfc7eSAndroid Build Coastguard Worker * Test:
49*49cdfc7eSAndroid Build Coastguard Worker * Loop if the proper options are given.
50*49cdfc7eSAndroid Build Coastguard Worker * Execute system call
51*49cdfc7eSAndroid Build Coastguard Worker * Check return code, if system call failed (return=-1)
52*49cdfc7eSAndroid Build Coastguard Worker * if errno set == expected errno
53*49cdfc7eSAndroid Build Coastguard Worker * Issue sys call fails with expected return value and errno.
54*49cdfc7eSAndroid Build Coastguard Worker * Otherwise,
55*49cdfc7eSAndroid Build Coastguard Worker * Issue sys call fails with unexpected errno.
56*49cdfc7eSAndroid Build Coastguard Worker * Otherwise,
57*49cdfc7eSAndroid Build Coastguard Worker * Issue sys call returns unexpected value.
58*49cdfc7eSAndroid Build Coastguard Worker *
59*49cdfc7eSAndroid Build Coastguard Worker * Cleanup:
60*49cdfc7eSAndroid Build Coastguard Worker * Print errno log and/or timing stats if options given
61*49cdfc7eSAndroid Build Coastguard Worker * Delete the temporary directory(s)/file(s) created.
62*49cdfc7eSAndroid Build Coastguard Worker *
63*49cdfc7eSAndroid Build Coastguard Worker * Usage: <for command-line>
64*49cdfc7eSAndroid Build Coastguard Worker * symlink03 [-c n] [-e] [-i n] [-I x] [-p x] [-t]
65*49cdfc7eSAndroid Build Coastguard Worker * where, -c n : Run n copies concurrently.
66*49cdfc7eSAndroid Build Coastguard Worker * -e : Turn on errno logging.
67*49cdfc7eSAndroid Build Coastguard Worker * -i n : Execute test n times.
68*49cdfc7eSAndroid Build Coastguard Worker * -I x : Execute test for x seconds.
69*49cdfc7eSAndroid Build Coastguard Worker * -P x : Pause for x seconds between iterations.
70*49cdfc7eSAndroid Build Coastguard Worker * -t : Turn on syscall timing.
71*49cdfc7eSAndroid Build Coastguard Worker *
72*49cdfc7eSAndroid Build Coastguard Worker * History
73*49cdfc7eSAndroid Build Coastguard Worker * 07/2001 John George
74*49cdfc7eSAndroid Build Coastguard Worker * -Ported
75*49cdfc7eSAndroid Build Coastguard Worker *
76*49cdfc7eSAndroid Build Coastguard Worker * Restrictions:
77*49cdfc7eSAndroid Build Coastguard Worker */
78*49cdfc7eSAndroid Build Coastguard Worker
79*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
80*49cdfc7eSAndroid Build Coastguard Worker #include <sys/types.h>
81*49cdfc7eSAndroid Build Coastguard Worker #include <fcntl.h>
82*49cdfc7eSAndroid Build Coastguard Worker #include <sys/mman.h>
83*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
84*49cdfc7eSAndroid Build Coastguard Worker #include <string.h>
85*49cdfc7eSAndroid Build Coastguard Worker #include <signal.h>
86*49cdfc7eSAndroid Build Coastguard Worker #include <sys/stat.h>
87*49cdfc7eSAndroid Build Coastguard Worker #include <pwd.h>
88*49cdfc7eSAndroid Build Coastguard Worker
89*49cdfc7eSAndroid Build Coastguard Worker #include "test.h"
90*49cdfc7eSAndroid Build Coastguard Worker #include "safe_macros.h"
91*49cdfc7eSAndroid Build Coastguard Worker
92*49cdfc7eSAndroid Build Coastguard Worker #define MODE_RWX S_IRWXU | S_IRWXG | S_IRWXO
93*49cdfc7eSAndroid Build Coastguard Worker #define FILE_MODE S_IRUSR | S_IRGRP | S_IROTH
94*49cdfc7eSAndroid Build Coastguard Worker #define DIR_TEMP "testdir_1"
95*49cdfc7eSAndroid Build Coastguard Worker #define TESTFILE "testfile"
96*49cdfc7eSAndroid Build Coastguard Worker #define TEST_FILE1 "testdir_1/tfile_1"
97*49cdfc7eSAndroid Build Coastguard Worker #define SYM_FILE1 "testdir_1/sfile_1"
98*49cdfc7eSAndroid Build Coastguard Worker #define TEST_FILE2 "tfile_2"
99*49cdfc7eSAndroid Build Coastguard Worker #define SYM_FILE2 "sfile_2"
100*49cdfc7eSAndroid Build Coastguard Worker #define TEST_FILE3 "tfile_3"
101*49cdfc7eSAndroid Build Coastguard Worker #define SYM_FILE3 "t_file/sfile_3"
102*49cdfc7eSAndroid Build Coastguard Worker
103*49cdfc7eSAndroid Build Coastguard Worker char *TCID = "symlink03";
104*49cdfc7eSAndroid Build Coastguard Worker int TST_TOTAL = 1;
105*49cdfc7eSAndroid Build Coastguard Worker
106*49cdfc7eSAndroid Build Coastguard Worker int no_setup();
107*49cdfc7eSAndroid Build Coastguard Worker int setup1(); /* setup function to test symlink for EACCES */
108*49cdfc7eSAndroid Build Coastguard Worker int setup2(); /* setup function to test symlink for EEXIST */
109*49cdfc7eSAndroid Build Coastguard Worker int setup3(); /* setup function to test symlink for ENOTDIR */
110*49cdfc7eSAndroid Build Coastguard Worker int longpath_setup(); /* setup function to test chmod for ENAMETOOLONG */
111*49cdfc7eSAndroid Build Coastguard Worker
112*49cdfc7eSAndroid Build Coastguard Worker char Longpathname[PATH_MAX + 2];
113*49cdfc7eSAndroid Build Coastguard Worker char High_address_node[64];
114*49cdfc7eSAndroid Build Coastguard Worker
115*49cdfc7eSAndroid Build Coastguard Worker struct test_case_t { /* test case struct. to hold ref. test cond's */
116*49cdfc7eSAndroid Build Coastguard Worker char *file;
117*49cdfc7eSAndroid Build Coastguard Worker char *link;
118*49cdfc7eSAndroid Build Coastguard Worker char *desc;
119*49cdfc7eSAndroid Build Coastguard Worker int exp_errno;
120*49cdfc7eSAndroid Build Coastguard Worker int (*setupfunc) ();
121*49cdfc7eSAndroid Build Coastguard Worker } Test_cases[] = {
122*49cdfc7eSAndroid Build Coastguard Worker {TEST_FILE1, SYM_FILE1, "No Search permissions to process",
123*49cdfc7eSAndroid Build Coastguard Worker EACCES, setup1}, {
124*49cdfc7eSAndroid Build Coastguard Worker TEST_FILE2, SYM_FILE2, "Specified symlink already exists",
125*49cdfc7eSAndroid Build Coastguard Worker EEXIST, setup2}, {
126*49cdfc7eSAndroid Build Coastguard Worker TESTFILE, NULL, "Invalid address", EFAULT, no_setup}, {
127*49cdfc7eSAndroid Build Coastguard Worker TESTFILE, Longpathname, "Symlink path too long", ENAMETOOLONG,
128*49cdfc7eSAndroid Build Coastguard Worker longpath_setup}, {
129*49cdfc7eSAndroid Build Coastguard Worker TESTFILE, "", "Symlink Pathname is empty", ENOENT, no_setup}, {
130*49cdfc7eSAndroid Build Coastguard Worker TEST_FILE3, SYM_FILE3, "Symlink Path contains regular file",
131*49cdfc7eSAndroid Build Coastguard Worker ENOTDIR, setup3}, {
132*49cdfc7eSAndroid Build Coastguard Worker NULL, NULL, NULL, 0, no_setup}
133*49cdfc7eSAndroid Build Coastguard Worker };
134*49cdfc7eSAndroid Build Coastguard Worker
135*49cdfc7eSAndroid Build Coastguard Worker char nobody_uid[] = "nobody";
136*49cdfc7eSAndroid Build Coastguard Worker struct passwd *ltpuser;
137*49cdfc7eSAndroid Build Coastguard Worker
138*49cdfc7eSAndroid Build Coastguard Worker void setup();
139*49cdfc7eSAndroid Build Coastguard Worker void cleanup();
140*49cdfc7eSAndroid Build Coastguard Worker
main(int ac,char ** av)141*49cdfc7eSAndroid Build Coastguard Worker int main(int ac, char **av)
142*49cdfc7eSAndroid Build Coastguard Worker {
143*49cdfc7eSAndroid Build Coastguard Worker int lc;
144*49cdfc7eSAndroid Build Coastguard Worker char *test_file; /* testfile name */
145*49cdfc7eSAndroid Build Coastguard Worker char *sym_file; /* symbolic link file name */
146*49cdfc7eSAndroid Build Coastguard Worker char *test_desc; /* test specific error message */
147*49cdfc7eSAndroid Build Coastguard Worker int ind; /* counter to test different test conditions */
148*49cdfc7eSAndroid Build Coastguard Worker
149*49cdfc7eSAndroid Build Coastguard Worker tst_parse_opts(ac, av, NULL, NULL);
150*49cdfc7eSAndroid Build Coastguard Worker
151*49cdfc7eSAndroid Build Coastguard Worker /*
152*49cdfc7eSAndroid Build Coastguard Worker * Invoke setup function to call individual test setup functions
153*49cdfc7eSAndroid Build Coastguard Worker * to simulate test conditions.
154*49cdfc7eSAndroid Build Coastguard Worker */
155*49cdfc7eSAndroid Build Coastguard Worker setup();
156*49cdfc7eSAndroid Build Coastguard Worker
157*49cdfc7eSAndroid Build Coastguard Worker for (lc = 0; TEST_LOOPING(lc); lc++) {
158*49cdfc7eSAndroid Build Coastguard Worker
159*49cdfc7eSAndroid Build Coastguard Worker tst_count = 0;
160*49cdfc7eSAndroid Build Coastguard Worker
161*49cdfc7eSAndroid Build Coastguard Worker for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
162*49cdfc7eSAndroid Build Coastguard Worker test_file = Test_cases[ind].file;
163*49cdfc7eSAndroid Build Coastguard Worker sym_file = Test_cases[ind].link;
164*49cdfc7eSAndroid Build Coastguard Worker test_desc = Test_cases[ind].desc;
165*49cdfc7eSAndroid Build Coastguard Worker
166*49cdfc7eSAndroid Build Coastguard Worker /*
167*49cdfc7eSAndroid Build Coastguard Worker * Call symlink(2) to test different test conditions.
168*49cdfc7eSAndroid Build Coastguard Worker * verify that it fails with -1 return value and sets
169*49cdfc7eSAndroid Build Coastguard Worker * appropriate errno.
170*49cdfc7eSAndroid Build Coastguard Worker */
171*49cdfc7eSAndroid Build Coastguard Worker TEST(symlink(test_file, sym_file));
172*49cdfc7eSAndroid Build Coastguard Worker
173*49cdfc7eSAndroid Build Coastguard Worker if (TEST_RETURN == -1) {
174*49cdfc7eSAndroid Build Coastguard Worker /*
175*49cdfc7eSAndroid Build Coastguard Worker * Perform functional verification if
176*49cdfc7eSAndroid Build Coastguard Worker * test executed without (-f) option.
177*49cdfc7eSAndroid Build Coastguard Worker */
178*49cdfc7eSAndroid Build Coastguard Worker if (TEST_ERRNO == Test_cases[ind].exp_errno) {
179*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TPASS, "symlink() Fails, %s, "
180*49cdfc7eSAndroid Build Coastguard Worker "errno=%d", test_desc,
181*49cdfc7eSAndroid Build Coastguard Worker TEST_ERRNO);
182*49cdfc7eSAndroid Build Coastguard Worker } else {
183*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "symlink() Fails, %s, "
184*49cdfc7eSAndroid Build Coastguard Worker "errno=%d, expected errno=%d",
185*49cdfc7eSAndroid Build Coastguard Worker test_desc, TEST_ERRNO,
186*49cdfc7eSAndroid Build Coastguard Worker Test_cases[ind].exp_errno);
187*49cdfc7eSAndroid Build Coastguard Worker }
188*49cdfc7eSAndroid Build Coastguard Worker } else {
189*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "symlink() returned %ld, "
190*49cdfc7eSAndroid Build Coastguard Worker "expected -1, errno:%d", TEST_RETURN,
191*49cdfc7eSAndroid Build Coastguard Worker Test_cases[ind].exp_errno);
192*49cdfc7eSAndroid Build Coastguard Worker }
193*49cdfc7eSAndroid Build Coastguard Worker }
194*49cdfc7eSAndroid Build Coastguard Worker
195*49cdfc7eSAndroid Build Coastguard Worker tst_count++; /* incr. TEST_LOOP counter */
196*49cdfc7eSAndroid Build Coastguard Worker }
197*49cdfc7eSAndroid Build Coastguard Worker
198*49cdfc7eSAndroid Build Coastguard Worker cleanup();
199*49cdfc7eSAndroid Build Coastguard Worker tst_exit();
200*49cdfc7eSAndroid Build Coastguard Worker
201*49cdfc7eSAndroid Build Coastguard Worker }
202*49cdfc7eSAndroid Build Coastguard Worker
203*49cdfc7eSAndroid Build Coastguard Worker /*
204*49cdfc7eSAndroid Build Coastguard Worker * void
205*49cdfc7eSAndroid Build Coastguard Worker * setup() - performs all ONE TIME setup for this test.
206*49cdfc7eSAndroid Build Coastguard Worker * Create a temporary directory and change directory to it.
207*49cdfc7eSAndroid Build Coastguard Worker * Call test specific setup functions.
208*49cdfc7eSAndroid Build Coastguard Worker */
setup(void)209*49cdfc7eSAndroid Build Coastguard Worker void setup(void)
210*49cdfc7eSAndroid Build Coastguard Worker {
211*49cdfc7eSAndroid Build Coastguard Worker int ind;
212*49cdfc7eSAndroid Build Coastguard Worker
213*49cdfc7eSAndroid Build Coastguard Worker tst_require_root();
214*49cdfc7eSAndroid Build Coastguard Worker
215*49cdfc7eSAndroid Build Coastguard Worker tst_sig(NOFORK, DEF_HANDLER, cleanup);
216*49cdfc7eSAndroid Build Coastguard Worker
217*49cdfc7eSAndroid Build Coastguard Worker /* Pause if that option was specified
218*49cdfc7eSAndroid Build Coastguard Worker * TEST_PAUSE contains the code to fork the test with the -i option.
219*49cdfc7eSAndroid Build Coastguard Worker * You want to make sure you do this before you create your temporary
220*49cdfc7eSAndroid Build Coastguard Worker * directory.
221*49cdfc7eSAndroid Build Coastguard Worker */
222*49cdfc7eSAndroid Build Coastguard Worker TEST_PAUSE;
223*49cdfc7eSAndroid Build Coastguard Worker
224*49cdfc7eSAndroid Build Coastguard Worker /* Switch to nobody user for correct error code collection */
225*49cdfc7eSAndroid Build Coastguard Worker ltpuser = getpwnam(nobody_uid);
226*49cdfc7eSAndroid Build Coastguard Worker if (setuid(ltpuser->pw_uid) == -1)
227*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO | TERRNO, "setuid(%d) failed", ltpuser->pw_uid);
228*49cdfc7eSAndroid Build Coastguard Worker
229*49cdfc7eSAndroid Build Coastguard Worker tst_tmpdir();
230*49cdfc7eSAndroid Build Coastguard Worker
231*49cdfc7eSAndroid Build Coastguard Worker /* call individual setup functions */
232*49cdfc7eSAndroid Build Coastguard Worker for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
233*49cdfc7eSAndroid Build Coastguard Worker if (!Test_cases[ind].link)
234*49cdfc7eSAndroid Build Coastguard Worker Test_cases[ind].link = tst_get_bad_addr(cleanup);
235*49cdfc7eSAndroid Build Coastguard Worker Test_cases[ind].setupfunc();
236*49cdfc7eSAndroid Build Coastguard Worker }
237*49cdfc7eSAndroid Build Coastguard Worker }
238*49cdfc7eSAndroid Build Coastguard Worker
239*49cdfc7eSAndroid Build Coastguard Worker /*
240*49cdfc7eSAndroid Build Coastguard Worker * int
241*49cdfc7eSAndroid Build Coastguard Worker * no_setup() - Some test conditions for mknod(2) do not any setup.
242*49cdfc7eSAndroid Build Coastguard Worker * Hence, this function just returns 0.
243*49cdfc7eSAndroid Build Coastguard Worker * This function simply returns 0.
244*49cdfc7eSAndroid Build Coastguard Worker */
no_setup(void)245*49cdfc7eSAndroid Build Coastguard Worker int no_setup(void)
246*49cdfc7eSAndroid Build Coastguard Worker {
247*49cdfc7eSAndroid Build Coastguard Worker return 0;
248*49cdfc7eSAndroid Build Coastguard Worker }
249*49cdfc7eSAndroid Build Coastguard Worker
250*49cdfc7eSAndroid Build Coastguard Worker /*
251*49cdfc7eSAndroid Build Coastguard Worker * int
252*49cdfc7eSAndroid Build Coastguard Worker * setup1() - setup function for a test condition for which symlink(2)
253*49cdfc7eSAndroid Build Coastguard Worker * returns -1 and sets errno to EACCES.
254*49cdfc7eSAndroid Build Coastguard Worker * Create a test directory under temporary directory and create a test file
255*49cdfc7eSAndroid Build Coastguard Worker * under this directory with mode "0666" permissions.
256*49cdfc7eSAndroid Build Coastguard Worker * Modify the mode permissions on test directory such that process will not
257*49cdfc7eSAndroid Build Coastguard Worker * have search permissions on test directory.
258*49cdfc7eSAndroid Build Coastguard Worker *
259*49cdfc7eSAndroid Build Coastguard Worker * The function returns 0.
260*49cdfc7eSAndroid Build Coastguard Worker */
setup1(void)261*49cdfc7eSAndroid Build Coastguard Worker int setup1(void)
262*49cdfc7eSAndroid Build Coastguard Worker {
263*49cdfc7eSAndroid Build Coastguard Worker int fd; /* file handle for testfile */
264*49cdfc7eSAndroid Build Coastguard Worker
265*49cdfc7eSAndroid Build Coastguard Worker SAFE_MKDIR(cleanup, DIR_TEMP, MODE_RWX);
266*49cdfc7eSAndroid Build Coastguard Worker
267*49cdfc7eSAndroid Build Coastguard Worker if ((fd = open(TEST_FILE1, O_RDWR | O_CREAT, 0666)) == -1) {
268*49cdfc7eSAndroid Build Coastguard Worker tst_brkm(TBROK, cleanup,
269*49cdfc7eSAndroid Build Coastguard Worker "open(%s, O_RDWR|O_CREAT, 0666) failed, errno=%d : %s",
270*49cdfc7eSAndroid Build Coastguard Worker TEST_FILE1, errno, strerror(errno));
271*49cdfc7eSAndroid Build Coastguard Worker }
272*49cdfc7eSAndroid Build Coastguard Worker SAFE_CLOSE(cleanup, fd);
273*49cdfc7eSAndroid Build Coastguard Worker
274*49cdfc7eSAndroid Build Coastguard Worker /* Modify mode permissions on test directory */
275*49cdfc7eSAndroid Build Coastguard Worker SAFE_CHMOD(cleanup, DIR_TEMP, FILE_MODE);
276*49cdfc7eSAndroid Build Coastguard Worker return 0;
277*49cdfc7eSAndroid Build Coastguard Worker }
278*49cdfc7eSAndroid Build Coastguard Worker
279*49cdfc7eSAndroid Build Coastguard Worker /*
280*49cdfc7eSAndroid Build Coastguard Worker * int
281*49cdfc7eSAndroid Build Coastguard Worker * setup2() - EEXIST
282*49cdfc7eSAndroid Build Coastguard Worker */
setup2(void)283*49cdfc7eSAndroid Build Coastguard Worker int setup2(void)
284*49cdfc7eSAndroid Build Coastguard Worker {
285*49cdfc7eSAndroid Build Coastguard Worker int fd; /* file handle for testfile */
286*49cdfc7eSAndroid Build Coastguard Worker
287*49cdfc7eSAndroid Build Coastguard Worker if ((fd = open(TEST_FILE2, O_RDWR | O_CREAT, 0666)) == -1) {
288*49cdfc7eSAndroid Build Coastguard Worker tst_brkm(TBROK, cleanup,
289*49cdfc7eSAndroid Build Coastguard Worker "open(%s, O_RDWR|O_CREAT, 0666) failed, errno=%d : %s",
290*49cdfc7eSAndroid Build Coastguard Worker TEST_FILE1, errno, strerror(errno));
291*49cdfc7eSAndroid Build Coastguard Worker }
292*49cdfc7eSAndroid Build Coastguard Worker SAFE_CLOSE(cleanup, fd);
293*49cdfc7eSAndroid Build Coastguard Worker
294*49cdfc7eSAndroid Build Coastguard Worker SAFE_SYMLINK(cleanup, TEST_FILE2, SYM_FILE2);
295*49cdfc7eSAndroid Build Coastguard Worker return 0;
296*49cdfc7eSAndroid Build Coastguard Worker }
297*49cdfc7eSAndroid Build Coastguard Worker
298*49cdfc7eSAndroid Build Coastguard Worker /*
299*49cdfc7eSAndroid Build Coastguard Worker * int
300*49cdfc7eSAndroid Build Coastguard Worker * longpath_setup() - setup to create a node with a name length exceeding
301*49cdfc7eSAndroid Build Coastguard Worker * the MAX. length of PATH_MAX.
302*49cdfc7eSAndroid Build Coastguard Worker * This function retruns 0.
303*49cdfc7eSAndroid Build Coastguard Worker */
longpath_setup(void)304*49cdfc7eSAndroid Build Coastguard Worker int longpath_setup(void)
305*49cdfc7eSAndroid Build Coastguard Worker {
306*49cdfc7eSAndroid Build Coastguard Worker int ind; /* counter variable */
307*49cdfc7eSAndroid Build Coastguard Worker
308*49cdfc7eSAndroid Build Coastguard Worker for (ind = 0; ind <= (PATH_MAX + 1); ind++) {
309*49cdfc7eSAndroid Build Coastguard Worker Longpathname[ind] = 'a';
310*49cdfc7eSAndroid Build Coastguard Worker }
311*49cdfc7eSAndroid Build Coastguard Worker return 0;
312*49cdfc7eSAndroid Build Coastguard Worker }
313*49cdfc7eSAndroid Build Coastguard Worker
314*49cdfc7eSAndroid Build Coastguard Worker /*
315*49cdfc7eSAndroid Build Coastguard Worker * int
316*49cdfc7eSAndroid Build Coastguard Worker * setup3() - setup function for a test condition for which symlink(2)
317*49cdfc7eSAndroid Build Coastguard Worker * returns -1 and sets errno to ENOTDIR.
318*49cdfc7eSAndroid Build Coastguard Worker *
319*49cdfc7eSAndroid Build Coastguard Worker * Create a symlink file under temporary directory so that test tries to
320*49cdfc7eSAndroid Build Coastguard Worker * create symlink file "tfile_3" under "t_file" which happens to be
321*49cdfc7eSAndroid Build Coastguard Worker * another symlink file.
322*49cdfc7eSAndroid Build Coastguard Worker */
setup3(void)323*49cdfc7eSAndroid Build Coastguard Worker int setup3(void)
324*49cdfc7eSAndroid Build Coastguard Worker {
325*49cdfc7eSAndroid Build Coastguard Worker int fd; /* file handle for testfile */
326*49cdfc7eSAndroid Build Coastguard Worker
327*49cdfc7eSAndroid Build Coastguard Worker /* Creat/open a testfile and close it */
328*49cdfc7eSAndroid Build Coastguard Worker if ((fd = open("t_file", O_RDWR | O_CREAT, MODE_RWX)) == -1) {
329*49cdfc7eSAndroid Build Coastguard Worker tst_brkm(TBROK, cleanup,
330*49cdfc7eSAndroid Build Coastguard Worker "open(2) on t_file failed, errno=%d : %s",
331*49cdfc7eSAndroid Build Coastguard Worker errno, strerror(errno));
332*49cdfc7eSAndroid Build Coastguard Worker }
333*49cdfc7eSAndroid Build Coastguard Worker SAFE_CLOSE(cleanup, fd);
334*49cdfc7eSAndroid Build Coastguard Worker return 0;
335*49cdfc7eSAndroid Build Coastguard Worker }
336*49cdfc7eSAndroid Build Coastguard Worker
337*49cdfc7eSAndroid Build Coastguard Worker /*
338*49cdfc7eSAndroid Build Coastguard Worker * void
339*49cdfc7eSAndroid Build Coastguard Worker * cleanup() - performs all ONE TIME cleanup for this test at
340*49cdfc7eSAndroid Build Coastguard Worker * completion or premature exit.
341*49cdfc7eSAndroid Build Coastguard Worker * Restore the mode permissions on test directory.
342*49cdfc7eSAndroid Build Coastguard Worker * Remove the temporary directory created in the setup.
343*49cdfc7eSAndroid Build Coastguard Worker */
cleanup(void)344*49cdfc7eSAndroid Build Coastguard Worker void cleanup(void)
345*49cdfc7eSAndroid Build Coastguard Worker {
346*49cdfc7eSAndroid Build Coastguard Worker
347*49cdfc7eSAndroid Build Coastguard Worker /* Restore mode permissions on test directory created in setup2() */
348*49cdfc7eSAndroid Build Coastguard Worker SAFE_CHMOD(NULL, DIR_TEMP, MODE_RWX);
349*49cdfc7eSAndroid Build Coastguard Worker
350*49cdfc7eSAndroid Build Coastguard Worker tst_rmdir();
351*49cdfc7eSAndroid Build Coastguard Worker
352*49cdfc7eSAndroid Build Coastguard Worker }
353