1*49cdfc7eSAndroid Build Coastguard Worker /*
2*49cdfc7eSAndroid Build Coastguard Worker *
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) International Business Machines Corp., 2002
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 /* 10/31/2002 Port to LTP [email protected] */
21*49cdfc7eSAndroid Build Coastguard Worker /* 06/30/2001 Port to Linux [email protected] */
22*49cdfc7eSAndroid Build Coastguard Worker
23*49cdfc7eSAndroid Build Coastguard Worker /*
24*49cdfc7eSAndroid Build Coastguard Worker * NAME
25*49cdfc7eSAndroid Build Coastguard Worker * tools64.c - Supporting functions for nftw64.c
26*49cdfc7eSAndroid Build Coastguard Worker */
27*49cdfc7eSAndroid Build Coastguard Worker
28*49cdfc7eSAndroid Build Coastguard Worker #include "nftw64.h"
29*49cdfc7eSAndroid Build Coastguard Worker
30*49cdfc7eSAndroid Build Coastguard Worker extern pathdata pathdat[];
31*49cdfc7eSAndroid Build Coastguard Worker extern struct list mnem[];
32*49cdfc7eSAndroid Build Coastguard Worker extern char ebuf[ERR_BUF_SIZ];
33*49cdfc7eSAndroid Build Coastguard Worker extern int npathdats, ngoods, nbads, nmnem;
34*49cdfc7eSAndroid Build Coastguard Worker void fail_exit(void);
35*49cdfc7eSAndroid Build Coastguard Worker extern FILE *temp;
36*49cdfc7eSAndroid Build Coastguard Worker /*
37*49cdfc7eSAndroid Build Coastguard Worker * Function: void cleanup_function(void)
38*49cdfc7eSAndroid Build Coastguard Worker *
39*49cdfc7eSAndroid Build Coastguard Worker * Description:
40*49cdfc7eSAndroid Build Coastguard Worker * Cleans the residues$
41*49cdfc7eSAndroid Build Coastguard Worker *
42*49cdfc7eSAndroid Build Coastguard Worker * Returns :
43*49cdfc7eSAndroid Build Coastguard Worker * Nothing
44*49cdfc7eSAndroid Build Coastguard Worker */
45*49cdfc7eSAndroid Build Coastguard Worker
cleanup_function(void)46*49cdfc7eSAndroid Build Coastguard Worker void cleanup_function(void)
47*49cdfc7eSAndroid Build Coastguard Worker {
48*49cdfc7eSAndroid Build Coastguard Worker chmod("./tmp/data/d333", (mode_t) S_IRWXU | S_IRWXG | S_IRWXO);
49*49cdfc7eSAndroid Build Coastguard Worker chmod("./tmp/data/d666", (mode_t) S_IRWXU | S_IRWXG | S_IRWXO);
50*49cdfc7eSAndroid Build Coastguard Worker chmod("./tmp/data/dirg/dir_right.1", (mode_t) S_IRWXU | S_IRWXG |
51*49cdfc7eSAndroid Build Coastguard Worker S_IRWXO);
52*49cdfc7eSAndroid Build Coastguard Worker system("rm -rf ./tmp");
53*49cdfc7eSAndroid Build Coastguard Worker wait(NULL);
54*49cdfc7eSAndroid Build Coastguard Worker }
55*49cdfc7eSAndroid Build Coastguard Worker
56*49cdfc7eSAndroid Build Coastguard Worker /*
57*49cdfc7eSAndroid Build Coastguard Worker * Function: void setup_path(void)
58*49cdfc7eSAndroid Build Coastguard Worker *
59*49cdfc7eSAndroid Build Coastguard Worker * Description:
60*49cdfc7eSAndroid Build Coastguard Worker * Setup the environment to run the nftw64.c
61*49cdfc7eSAndroid Build Coastguard Worker *
62*49cdfc7eSAndroid Build Coastguard Worker * Returns :
63*49cdfc7eSAndroid Build Coastguard Worker * Nothing
64*49cdfc7eSAndroid Build Coastguard Worker */
65*49cdfc7eSAndroid Build Coastguard Worker
setup_path(void)66*49cdfc7eSAndroid Build Coastguard Worker void setup_path(void)
67*49cdfc7eSAndroid Build Coastguard Worker {
68*49cdfc7eSAndroid Build Coastguard Worker int i, fd;
69*49cdfc7eSAndroid Build Coastguard Worker temp = stderr;
70*49cdfc7eSAndroid Build Coastguard Worker
71*49cdfc7eSAndroid Build Coastguard Worker if (mkdir("./tmp", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1) {
72*49cdfc7eSAndroid Build Coastguard Worker sprintf(ebuf, "Can't mkdir ./tmp");
73*49cdfc7eSAndroid Build Coastguard Worker perror(ebuf);
74*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp, "ERROR: setup_path function failed\n");
75*49cdfc7eSAndroid Build Coastguard Worker fail_exit();
76*49cdfc7eSAndroid Build Coastguard Worker }
77*49cdfc7eSAndroid Build Coastguard Worker for (i = 0; i < npathdats; i++) {
78*49cdfc7eSAndroid Build Coastguard Worker if (pathdat[i].type == DIR) {
79*49cdfc7eSAndroid Build Coastguard Worker if (mkdir(pathdat[i].name, pathdat[i].mode) == -1) {
80*49cdfc7eSAndroid Build Coastguard Worker sprintf(ebuf, "Can't mkdir %s %d",
81*49cdfc7eSAndroid Build Coastguard Worker pathdat[i].name, i);
82*49cdfc7eSAndroid Build Coastguard Worker perror(ebuf);
83*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp,
84*49cdfc7eSAndroid Build Coastguard Worker "ERROR: setup_path function failed\n");
85*49cdfc7eSAndroid Build Coastguard Worker cleanup_function();
86*49cdfc7eSAndroid Build Coastguard Worker fail_exit();
87*49cdfc7eSAndroid Build Coastguard Worker }
88*49cdfc7eSAndroid Build Coastguard Worker } else if (pathdat[i].type == SYM) {
89*49cdfc7eSAndroid Build Coastguard Worker if (symlink(pathdat[i].contents, pathdat[i].name) == -1) {
90*49cdfc7eSAndroid Build Coastguard Worker sprintf(ebuf, "Can't symlink %s ",
91*49cdfc7eSAndroid Build Coastguard Worker pathdat[i].name);
92*49cdfc7eSAndroid Build Coastguard Worker perror(ebuf);
93*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp,
94*49cdfc7eSAndroid Build Coastguard Worker "ERROR: setup_path function failed\n");
95*49cdfc7eSAndroid Build Coastguard Worker cleanup_function();
96*49cdfc7eSAndroid Build Coastguard Worker fail_exit();
97*49cdfc7eSAndroid Build Coastguard Worker }
98*49cdfc7eSAndroid Build Coastguard Worker } else {
99*49cdfc7eSAndroid Build Coastguard Worker if ((fd = open(pathdat[i].name, O_WRONLY | O_CREAT,
100*49cdfc7eSAndroid Build Coastguard Worker pathdat[i].mode)) == -1) {
101*49cdfc7eSAndroid Build Coastguard Worker sprintf(ebuf, "Can't open %s", pathdat[i].name);
102*49cdfc7eSAndroid Build Coastguard Worker perror(ebuf);
103*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp,
104*49cdfc7eSAndroid Build Coastguard Worker "ERROR: setup_path function failed\n");
105*49cdfc7eSAndroid Build Coastguard Worker cleanup_function();
106*49cdfc7eSAndroid Build Coastguard Worker fail_exit();
107*49cdfc7eSAndroid Build Coastguard Worker }
108*49cdfc7eSAndroid Build Coastguard Worker if (write(fd, pathdat[i].contents,
109*49cdfc7eSAndroid Build Coastguard Worker strlen(pathdat[i].contents)) == -1) {
110*49cdfc7eSAndroid Build Coastguard Worker perror("Can't write");
111*49cdfc7eSAndroid Build Coastguard Worker close(fd);
112*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp,
113*49cdfc7eSAndroid Build Coastguard Worker "ERROR: setup_path function failed\n");
114*49cdfc7eSAndroid Build Coastguard Worker cleanup_function();
115*49cdfc7eSAndroid Build Coastguard Worker fail_exit();
116*49cdfc7eSAndroid Build Coastguard Worker }
117*49cdfc7eSAndroid Build Coastguard Worker close(fd);
118*49cdfc7eSAndroid Build Coastguard Worker }
119*49cdfc7eSAndroid Build Coastguard Worker }
120*49cdfc7eSAndroid Build Coastguard Worker
121*49cdfc7eSAndroid Build Coastguard Worker if (chmod("./tmp/data/d333", (mode_t) S_IWUSR | S_IXUSR | S_IWGRP |
122*49cdfc7eSAndroid Build Coastguard Worker S_IXGRP | S_IWOTH | S_IXOTH) == -1) {
123*49cdfc7eSAndroid Build Coastguard Worker sprintf(ebuf, "Can't chmod %s ", "./tmp/data/d333");
124*49cdfc7eSAndroid Build Coastguard Worker perror(ebuf);
125*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp, "ERROR: setup_path function failed\n");
126*49cdfc7eSAndroid Build Coastguard Worker cleanup_function();
127*49cdfc7eSAndroid Build Coastguard Worker fail_exit();
128*49cdfc7eSAndroid Build Coastguard Worker }
129*49cdfc7eSAndroid Build Coastguard Worker if (chmod("./tmp/data/d666", (mode_t) S_IRUSR | S_IWUSR | S_IRGRP |
130*49cdfc7eSAndroid Build Coastguard Worker S_IWGRP | S_IROTH | S_IWOTH) == -1) {
131*49cdfc7eSAndroid Build Coastguard Worker sprintf(ebuf, "Can't chmod %s ", "./tmp/data/d666");
132*49cdfc7eSAndroid Build Coastguard Worker perror(ebuf);
133*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp, "ERROR: setup_path function failed\n");
134*49cdfc7eSAndroid Build Coastguard Worker cleanup_function();
135*49cdfc7eSAndroid Build Coastguard Worker fail_exit();
136*49cdfc7eSAndroid Build Coastguard Worker }
137*49cdfc7eSAndroid Build Coastguard Worker if (chmod("./tmp/data/dirg/dir_right.1", (mode_t) S_IWUSR | S_IXUSR |
138*49cdfc7eSAndroid Build Coastguard Worker S_IWGRP | S_IXGRP | S_IWOTH | S_IXOTH) == -1) {
139*49cdfc7eSAndroid Build Coastguard Worker sprintf(ebuf, "Can't chmod %s ", "./tmp/data/dirg/dir_right.1");
140*49cdfc7eSAndroid Build Coastguard Worker perror(ebuf);
141*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp, "ERROR: setup_path function failed\n");
142*49cdfc7eSAndroid Build Coastguard Worker cleanup_function();
143*49cdfc7eSAndroid Build Coastguard Worker fail_exit();
144*49cdfc7eSAndroid Build Coastguard Worker }
145*49cdfc7eSAndroid Build Coastguard Worker }
146*49cdfc7eSAndroid Build Coastguard Worker
147*49cdfc7eSAndroid Build Coastguard Worker /*
148*49cdfc7eSAndroid Build Coastguard Worker * Function: int nftw64_fn(const char, const struct stat64, int, struct FTW )
149*49cdfc7eSAndroid Build Coastguard Worker *
150*49cdfc7eSAndroid Build Coastguard Worker * Description:
151*49cdfc7eSAndroid Build Coastguard Worker * Dummy function for errno tests
152*49cdfc7eSAndroid Build Coastguard Worker *
153*49cdfc7eSAndroid Build Coastguard Worker * Returns :
154*49cdfc7eSAndroid Build Coastguard Worker * 0
155*49cdfc7eSAndroid Build Coastguard Worker */
156*49cdfc7eSAndroid Build Coastguard Worker
157*49cdfc7eSAndroid Build Coastguard Worker int
nftw64_fn(const char * path,const struct stat64 * st,int ival,struct FTW * FTWS)158*49cdfc7eSAndroid Build Coastguard Worker nftw64_fn(const char *path, const struct stat64 *st, int ival, struct FTW *FTWS)
159*49cdfc7eSAndroid Build Coastguard Worker {
160*49cdfc7eSAndroid Build Coastguard Worker return (0);
161*49cdfc7eSAndroid Build Coastguard Worker }
162*49cdfc7eSAndroid Build Coastguard Worker
163*49cdfc7eSAndroid Build Coastguard Worker /*
164*49cdfc7eSAndroid Build Coastguard Worker * Function: int callback(char *)
165*49cdfc7eSAndroid Build Coastguard Worker *
166*49cdfc7eSAndroid Build Coastguard Worker * Description:
167*49cdfc7eSAndroid Build Coastguard Worker * Dummy function for errno tests
168*49cdfc7eSAndroid Build Coastguard Worker *
169*49cdfc7eSAndroid Build Coastguard Worker * Returns :
170*49cdfc7eSAndroid Build Coastguard Worker * nftw64()
171*49cdfc7eSAndroid Build Coastguard Worker */
172*49cdfc7eSAndroid Build Coastguard Worker
callback(const char * path)173*49cdfc7eSAndroid Build Coastguard Worker int callback(const char *path)
174*49cdfc7eSAndroid Build Coastguard Worker {
175*49cdfc7eSAndroid Build Coastguard Worker return nftw64(path, nftw64_fn, 10, FTW_MOUNT);
176*49cdfc7eSAndroid Build Coastguard Worker }
177*49cdfc7eSAndroid Build Coastguard Worker
178*49cdfc7eSAndroid Build Coastguard Worker /*
179*49cdfc7eSAndroid Build Coastguard Worker * Function: char * ftw_mnemonic(int)
180*49cdfc7eSAndroid Build Coastguard Worker *
181*49cdfc7eSAndroid Build Coastguard Worker * Description:
182*49cdfc7eSAndroid Build Coastguard Worker * Conversion function for printing
183*49cdfc7eSAndroid Build Coastguard Worker *
184*49cdfc7eSAndroid Build Coastguard Worker * Returns:
185*49cdfc7eSAndroid Build Coastguard Worker * String for printing
186*49cdfc7eSAndroid Build Coastguard Worker */
187*49cdfc7eSAndroid Build Coastguard Worker
ftw_mnemonic(int x)188*49cdfc7eSAndroid Build Coastguard Worker char *ftw_mnemonic(int x)
189*49cdfc7eSAndroid Build Coastguard Worker {
190*49cdfc7eSAndroid Build Coastguard Worker static char s[STRLEN];
191*49cdfc7eSAndroid Build Coastguard Worker int i;
192*49cdfc7eSAndroid Build Coastguard Worker
193*49cdfc7eSAndroid Build Coastguard Worker for (i = 0; i < nmnem; i++)
194*49cdfc7eSAndroid Build Coastguard Worker if (x == mnem[i].i)
195*49cdfc7eSAndroid Build Coastguard Worker return (mnem[i].s);
196*49cdfc7eSAndroid Build Coastguard Worker
197*49cdfc7eSAndroid Build Coastguard Worker sprintf(s, "Unknown value for third argument to fn(): %d\n", x);
198*49cdfc7eSAndroid Build Coastguard Worker return (s);
199*49cdfc7eSAndroid Build Coastguard Worker }
200*49cdfc7eSAndroid Build Coastguard Worker
201*49cdfc7eSAndroid Build Coastguard Worker /*
202*49cdfc7eSAndroid Build Coastguard Worker * Function: int getbase(char *)
203*49cdfc7eSAndroid Build Coastguard Worker *
204*49cdfc7eSAndroid Build Coastguard Worker * Description:
205*49cdfc7eSAndroid Build Coastguard Worker * Find basename
206*49cdfc7eSAndroid Build Coastguard Worker *
207*49cdfc7eSAndroid Build Coastguard Worker * Returns:
208*49cdfc7eSAndroid Build Coastguard Worker * Position of filename in path
209*49cdfc7eSAndroid Build Coastguard Worker */
210*49cdfc7eSAndroid Build Coastguard Worker
getbase(const char * s)211*49cdfc7eSAndroid Build Coastguard Worker int getbase(const char *s)
212*49cdfc7eSAndroid Build Coastguard Worker {
213*49cdfc7eSAndroid Build Coastguard Worker int i, last = 0;
214*49cdfc7eSAndroid Build Coastguard Worker
215*49cdfc7eSAndroid Build Coastguard Worker for (i = 0; *s != '\0'; s++, i++)
216*49cdfc7eSAndroid Build Coastguard Worker if (*s == '/')
217*49cdfc7eSAndroid Build Coastguard Worker last = i;
218*49cdfc7eSAndroid Build Coastguard Worker return (last ? last + 1 : 0);
219*49cdfc7eSAndroid Build Coastguard Worker }
220*49cdfc7eSAndroid Build Coastguard Worker
221*49cdfc7eSAndroid Build Coastguard Worker /*
222*49cdfc7eSAndroid Build Coastguard Worker * Function: int getlev( char *);
223*49cdfc7eSAndroid Build Coastguard Worker *
224*49cdfc7eSAndroid Build Coastguard Worker * Description:
225*49cdfc7eSAndroid Build Coastguard Worker * Find level
226*49cdfc7eSAndroid Build Coastguard Worker *
227*49cdfc7eSAndroid Build Coastguard Worker * Returns:
228*49cdfc7eSAndroid Build Coastguard Worker * Number of /'s in path
229*49cdfc7eSAndroid Build Coastguard Worker */
230*49cdfc7eSAndroid Build Coastguard Worker
getlev(const char * s)231*49cdfc7eSAndroid Build Coastguard Worker int getlev(const char *s)
232*49cdfc7eSAndroid Build Coastguard Worker {
233*49cdfc7eSAndroid Build Coastguard Worker int i;
234*49cdfc7eSAndroid Build Coastguard Worker for (i = 0; *s != '\0'; s++)
235*49cdfc7eSAndroid Build Coastguard Worker if (*s == '/')
236*49cdfc7eSAndroid Build Coastguard Worker i++;
237*49cdfc7eSAndroid Build Coastguard Worker return (i);
238*49cdfc7eSAndroid Build Coastguard Worker }
239*49cdfc7eSAndroid Build Coastguard Worker
240*49cdfc7eSAndroid Build Coastguard Worker /*
241*49cdfc7eSAndroid Build Coastguard Worker * Function: void doinfo(char *);
242*49cdfc7eSAndroid Build Coastguard Worker *
243*49cdfc7eSAndroid Build Coastguard Worker * Description:
244*49cdfc7eSAndroid Build Coastguard Worker * print the file being visited
245*49cdfc7eSAndroid Build Coastguard Worker *
246*49cdfc7eSAndroid Build Coastguard Worker * Returns:
247*49cdfc7eSAndroid Build Coastguard Worker * Nothing
248*49cdfc7eSAndroid Build Coastguard Worker */
249*49cdfc7eSAndroid Build Coastguard Worker
do_info(const char * path_name)250*49cdfc7eSAndroid Build Coastguard Worker void do_info(const char *path_name)
251*49cdfc7eSAndroid Build Coastguard Worker {
252*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
253*49cdfc7eSAndroid Build Coastguard Worker temp = stderr;
254*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp, "INFO: Call to fn() at %s\n", path_name);
255*49cdfc7eSAndroid Build Coastguard Worker #endif
256*49cdfc7eSAndroid Build Coastguard Worker }
257*49cdfc7eSAndroid Build Coastguard Worker
258*49cdfc7eSAndroid Build Coastguard Worker /** LTP Port **/
259*49cdfc7eSAndroid Build Coastguard Worker
260*49cdfc7eSAndroid Build Coastguard Worker /*
261*49cdfc7eSAndroid Build Coastguard Worker * fail_exit()
262*49cdfc7eSAndroid Build Coastguard Worker *
263*49cdfc7eSAndroid Build Coastguard Worker * Exit on failure
264*49cdfc7eSAndroid Build Coastguard Worker */
fail_exit(void)265*49cdfc7eSAndroid Build Coastguard Worker void fail_exit(void)
266*49cdfc7eSAndroid Build Coastguard Worker {
267*49cdfc7eSAndroid Build Coastguard Worker tst_brkm(TFAIL, NULL, "Test failed");
268*49cdfc7eSAndroid Build Coastguard Worker }
269*49cdfc7eSAndroid Build Coastguard Worker
270*49cdfc7eSAndroid Build Coastguard Worker /**************/
271