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 /* inode1.c */
24*49cdfc7eSAndroid Build Coastguard Worker /*======================================================================
25*49cdfc7eSAndroid Build Coastguard Worker =================== TESTPLAN SEGMENT ===================
26*49cdfc7eSAndroid Build Coastguard Worker CALLS: mkdir, stat, open
27*49cdfc7eSAndroid Build Coastguard Worker
28*49cdfc7eSAndroid Build Coastguard Worker run using TERM mode
29*49cdfc7eSAndroid Build Coastguard Worker
30*49cdfc7eSAndroid Build Coastguard Worker >KEYS: < file system management I/O
31*49cdfc7eSAndroid Build Coastguard Worker >WHAT: < Do the system's file system management and I/O functions work
32*49cdfc7eSAndroid Build Coastguard Worker < correctly?
33*49cdfc7eSAndroid Build Coastguard Worker >HOW: < Construct a directory tree, create files in it, and verify
34*49cdfc7eSAndroid Build Coastguard Worker < that this was done as expected.
35*49cdfc7eSAndroid Build Coastguard Worker >BUGS: <
36*49cdfc7eSAndroid Build Coastguard Worker ======================================================================*/
37*49cdfc7eSAndroid Build Coastguard Worker /* modified by dale 25-Jul-84 */
38*49cdfc7eSAndroid Build Coastguard Worker
39*49cdfc7eSAndroid Build Coastguard Worker /************************************************/
40*49cdfc7eSAndroid Build Coastguard Worker #define PATH_STRING_LENGTH 100
41*49cdfc7eSAndroid Build Coastguard Worker #define NAME_LENGTH 8
42*49cdfc7eSAndroid Build Coastguard Worker #define MAX_PATH_STRING_LENGTH (PATH_STRING_LENGTH - NAME_LENGTH)
43*49cdfc7eSAndroid Build Coastguard Worker #define MAX_DEPTH 3
44*49cdfc7eSAndroid Build Coastguard Worker #define MAX_BREADTH 3
45*49cdfc7eSAndroid Build Coastguard Worker #define FILE_LENGTH 100
46*49cdfc7eSAndroid Build Coastguard Worker #define DIRECTORY_MODE 00777
47*49cdfc7eSAndroid Build Coastguard Worker #define FILE_MODE 00777
48*49cdfc7eSAndroid Build Coastguard Worker
49*49cdfc7eSAndroid Build Coastguard Worker /* #define PRINT define to get list while running */
50*49cdfc7eSAndroid Build Coastguard Worker
51*49cdfc7eSAndroid Build Coastguard Worker #define TRUE 1
52*49cdfc7eSAndroid Build Coastguard Worker #define FALSE 0
53*49cdfc7eSAndroid Build Coastguard Worker #define READ 0
54*49cdfc7eSAndroid Build Coastguard Worker #define WRITE 1
55*49cdfc7eSAndroid Build Coastguard Worker
56*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
57*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
58*49cdfc7eSAndroid Build Coastguard Worker #include <sys/types.h>
59*49cdfc7eSAndroid Build Coastguard Worker #include <sys/stat.h>
60*49cdfc7eSAndroid Build Coastguard Worker #include <fcntl.h>
61*49cdfc7eSAndroid Build Coastguard Worker #include <signal.h>
62*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
63*49cdfc7eSAndroid Build Coastguard Worker
64*49cdfc7eSAndroid Build Coastguard Worker /** LTP Port **/
65*49cdfc7eSAndroid Build Coastguard Worker #include "test.h"
66*49cdfc7eSAndroid Build Coastguard Worker
67*49cdfc7eSAndroid Build Coastguard Worker void blexit(void);
68*49cdfc7eSAndroid Build Coastguard Worker void blenter(void);
69*49cdfc7eSAndroid Build Coastguard Worker void setup(void);
70*49cdfc7eSAndroid Build Coastguard Worker void fail_exit(void);
71*49cdfc7eSAndroid Build Coastguard Worker void anyfail(void);
72*49cdfc7eSAndroid Build Coastguard Worker void ok_exit(void);
73*49cdfc7eSAndroid Build Coastguard Worker
74*49cdfc7eSAndroid Build Coastguard Worker #define FAILED 0
75*49cdfc7eSAndroid Build Coastguard Worker #define PASSED 1
76*49cdfc7eSAndroid Build Coastguard Worker
77*49cdfc7eSAndroid Build Coastguard Worker int local_flag = PASSED;
78*49cdfc7eSAndroid Build Coastguard Worker int block_number;
79*49cdfc7eSAndroid Build Coastguard Worker FILE *temp;
80*49cdfc7eSAndroid Build Coastguard Worker
81*49cdfc7eSAndroid Build Coastguard Worker char *TCID = "inode01"; /* Test program identifier. */
82*49cdfc7eSAndroid Build Coastguard Worker int TST_TOTAL = 2; /* Total number of test cases. */
83*49cdfc7eSAndroid Build Coastguard Worker /**************/
84*49cdfc7eSAndroid Build Coastguard Worker
85*49cdfc7eSAndroid Build Coastguard Worker #ifdef LINUX
86*49cdfc7eSAndroid Build Coastguard Worker #include <string.h>
87*49cdfc7eSAndroid Build Coastguard Worker #endif
88*49cdfc7eSAndroid Build Coastguard Worker
89*49cdfc7eSAndroid Build Coastguard Worker char name[NAME_LENGTH + 1];
90*49cdfc7eSAndroid Build Coastguard Worker char path_string[PATH_STRING_LENGTH + 1];
91*49cdfc7eSAndroid Build Coastguard Worker char read_string[PATH_STRING_LENGTH + 1];
92*49cdfc7eSAndroid Build Coastguard Worker char write_string[PATH_STRING_LENGTH + 1];
93*49cdfc7eSAndroid Build Coastguard Worker char rm_string[200];
94*49cdfc7eSAndroid Build Coastguard Worker
95*49cdfc7eSAndroid Build Coastguard Worker FILE *list_stream = NULL;
96*49cdfc7eSAndroid Build Coastguard Worker int file_id;
97*49cdfc7eSAndroid Build Coastguard Worker int list_id;
98*49cdfc7eSAndroid Build Coastguard Worker
99*49cdfc7eSAndroid Build Coastguard Worker int increment_name(), get_next_name(), mode(), escrivez();
100*49cdfc7eSAndroid Build Coastguard Worker
main(void)101*49cdfc7eSAndroid Build Coastguard Worker int main(void)
102*49cdfc7eSAndroid Build Coastguard Worker {
103*49cdfc7eSAndroid Build Coastguard Worker char root[16]; //as pids can get much longer
104*49cdfc7eSAndroid Build Coastguard Worker int gen_ret_val, ch_ret_val, level;
105*49cdfc7eSAndroid Build Coastguard Worker int ret_val;
106*49cdfc7eSAndroid Build Coastguard Worker int generate(), check();
107*49cdfc7eSAndroid Build Coastguard Worker char path_list_string[PATH_STRING_LENGTH + 1];
108*49cdfc7eSAndroid Build Coastguard Worker int status;
109*49cdfc7eSAndroid Build Coastguard Worker int len;
110*49cdfc7eSAndroid Build Coastguard Worker int term();
111*49cdfc7eSAndroid Build Coastguard Worker int snp_ret;
112*49cdfc7eSAndroid Build Coastguard Worker
113*49cdfc7eSAndroid Build Coastguard Worker strcpy(path_string, "inode");
114*49cdfc7eSAndroid Build Coastguard Worker sprintf(root, "A%d", getpid());
115*49cdfc7eSAndroid Build Coastguard Worker strcat(path_string, root);
116*49cdfc7eSAndroid Build Coastguard Worker
117*49cdfc7eSAndroid Build Coastguard Worker strcpy(rm_string, "rm -rf ");
118*49cdfc7eSAndroid Build Coastguard Worker strcat(rm_string, path_string);
119*49cdfc7eSAndroid Build Coastguard Worker
120*49cdfc7eSAndroid Build Coastguard Worker setup();
121*49cdfc7eSAndroid Build Coastguard Worker
122*49cdfc7eSAndroid Build Coastguard Worker if (signal(SIGTERM, (void (*)())term) == SIG_ERR) {
123*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp, "\tSIGTERM signal set failed!, errno=%d\n",
124*49cdfc7eSAndroid Build Coastguard Worker errno);
125*49cdfc7eSAndroid Build Coastguard Worker fail_exit();
126*49cdfc7eSAndroid Build Coastguard Worker }
127*49cdfc7eSAndroid Build Coastguard Worker
128*49cdfc7eSAndroid Build Coastguard Worker blenter();
129*49cdfc7eSAndroid Build Coastguard Worker
130*49cdfc7eSAndroid Build Coastguard Worker /********************************/
131*49cdfc7eSAndroid Build Coastguard Worker /* */
132*49cdfc7eSAndroid Build Coastguard Worker /* make the root directory for */
133*49cdfc7eSAndroid Build Coastguard Worker /* the tree */
134*49cdfc7eSAndroid Build Coastguard Worker /* */
135*49cdfc7eSAndroid Build Coastguard Worker /********************************/
136*49cdfc7eSAndroid Build Coastguard Worker
137*49cdfc7eSAndroid Build Coastguard Worker ret_val = mkdir(path_string, DIRECTORY_MODE);
138*49cdfc7eSAndroid Build Coastguard Worker
139*49cdfc7eSAndroid Build Coastguard Worker if (ret_val == -1) {
140*49cdfc7eSAndroid Build Coastguard Worker perror("mkdir error");
141*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp, "\tcreating directory '%s'\n", path_string);
142*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp, "\t\n%s Impossible to create directory %s\n",
143*49cdfc7eSAndroid Build Coastguard Worker root, path_string);
144*49cdfc7eSAndroid Build Coastguard Worker fail_exit();
145*49cdfc7eSAndroid Build Coastguard Worker }
146*49cdfc7eSAndroid Build Coastguard Worker #ifdef PRINT
147*49cdfc7eSAndroid Build Coastguard Worker printf("\n%s\n", path_string);
148*49cdfc7eSAndroid Build Coastguard Worker #endif
149*49cdfc7eSAndroid Build Coastguard Worker
150*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
151*49cdfc7eSAndroid Build Coastguard Worker /* */
152*49cdfc7eSAndroid Build Coastguard Worker /* create the "path_list" file, in */
153*49cdfc7eSAndroid Build Coastguard Worker /* which the list of generated paths */
154*49cdfc7eSAndroid Build Coastguard Worker /* will be stored so that they later */
155*49cdfc7eSAndroid Build Coastguard Worker /* may be checked */
156*49cdfc7eSAndroid Build Coastguard Worker /* */
157*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
158*49cdfc7eSAndroid Build Coastguard Worker
159*49cdfc7eSAndroid Build Coastguard Worker snp_ret = snprintf(path_list_string, sizeof(path_list_string),
160*49cdfc7eSAndroid Build Coastguard Worker "%s/path_list", path_string);
161*49cdfc7eSAndroid Build Coastguard Worker if (snp_ret < 0 || snp_ret >= sizeof(path_list_string)) {
162*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TBROK, "snprintf(path_list_string,..) returned %d",
163*49cdfc7eSAndroid Build Coastguard Worker snp_ret);
164*49cdfc7eSAndroid Build Coastguard Worker fail_exit();
165*49cdfc7eSAndroid Build Coastguard Worker }
166*49cdfc7eSAndroid Build Coastguard Worker list_id = creat(path_list_string, FILE_MODE);
167*49cdfc7eSAndroid Build Coastguard Worker if (list_id == -1) {
168*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp,
169*49cdfc7eSAndroid Build Coastguard Worker "\t\n%s The path_list file cannot be created, errno=%d \n",
170*49cdfc7eSAndroid Build Coastguard Worker root, errno);
171*49cdfc7eSAndroid Build Coastguard Worker fail_exit();
172*49cdfc7eSAndroid Build Coastguard Worker }
173*49cdfc7eSAndroid Build Coastguard Worker
174*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
175*49cdfc7eSAndroid Build Coastguard Worker /* */
176*49cdfc7eSAndroid Build Coastguard Worker /* and store its name in path_list */
177*49cdfc7eSAndroid Build Coastguard Worker /* */
178*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
179*49cdfc7eSAndroid Build Coastguard Worker
180*49cdfc7eSAndroid Build Coastguard Worker strcpy(write_string, path_string);
181*49cdfc7eSAndroid Build Coastguard Worker len = strlen(write_string);
182*49cdfc7eSAndroid Build Coastguard Worker write_string[len++] = 'D';
183*49cdfc7eSAndroid Build Coastguard Worker write_string[len] = '\0';
184*49cdfc7eSAndroid Build Coastguard Worker escrivez(write_string);
185*49cdfc7eSAndroid Build Coastguard Worker
186*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
187*49cdfc7eSAndroid Build Coastguard Worker /* */
188*49cdfc7eSAndroid Build Coastguard Worker /* generate the directory-file tree */
189*49cdfc7eSAndroid Build Coastguard Worker /* */
190*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
191*49cdfc7eSAndroid Build Coastguard Worker
192*49cdfc7eSAndroid Build Coastguard Worker level = 0;
193*49cdfc7eSAndroid Build Coastguard Worker
194*49cdfc7eSAndroid Build Coastguard Worker #ifdef PRINT
195*49cdfc7eSAndroid Build Coastguard Worker printf("\n\t%s\n\n", "GENERATING:");
196*49cdfc7eSAndroid Build Coastguard Worker #endif
197*49cdfc7eSAndroid Build Coastguard Worker
198*49cdfc7eSAndroid Build Coastguard Worker gen_ret_val = generate(path_string, level);
199*49cdfc7eSAndroid Build Coastguard Worker
200*49cdfc7eSAndroid Build Coastguard Worker if (gen_ret_val) {
201*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp,
202*49cdfc7eSAndroid Build Coastguard Worker "Failure occured in generate routine, return value %d\n",
203*49cdfc7eSAndroid Build Coastguard Worker gen_ret_val);
204*49cdfc7eSAndroid Build Coastguard Worker local_flag = FAILED;
205*49cdfc7eSAndroid Build Coastguard Worker }
206*49cdfc7eSAndroid Build Coastguard Worker
207*49cdfc7eSAndroid Build Coastguard Worker blexit();
208*49cdfc7eSAndroid Build Coastguard Worker blenter();
209*49cdfc7eSAndroid Build Coastguard Worker
210*49cdfc7eSAndroid Build Coastguard Worker close(list_id);
211*49cdfc7eSAndroid Build Coastguard Worker list_id = open(path_list_string, READ);
212*49cdfc7eSAndroid Build Coastguard Worker if (list_id == -1) {
213*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp,
214*49cdfc7eSAndroid Build Coastguard Worker "\t\n%s The path_list file cannot be opened for reading, errno=%d\n",
215*49cdfc7eSAndroid Build Coastguard Worker root, errno);
216*49cdfc7eSAndroid Build Coastguard Worker fail_exit();
217*49cdfc7eSAndroid Build Coastguard Worker }
218*49cdfc7eSAndroid Build Coastguard Worker list_stream = fdopen(list_id, "r");
219*49cdfc7eSAndroid Build Coastguard Worker
220*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
221*49cdfc7eSAndroid Build Coastguard Worker /* */
222*49cdfc7eSAndroid Build Coastguard Worker /* check the directory-file tree */
223*49cdfc7eSAndroid Build Coastguard Worker /* for correctness */
224*49cdfc7eSAndroid Build Coastguard Worker /* */
225*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
226*49cdfc7eSAndroid Build Coastguard Worker
227*49cdfc7eSAndroid Build Coastguard Worker #ifdef PRINT
228*49cdfc7eSAndroid Build Coastguard Worker printf("\n\t%s\n\n", "CHECKING:");
229*49cdfc7eSAndroid Build Coastguard Worker #endif
230*49cdfc7eSAndroid Build Coastguard Worker
231*49cdfc7eSAndroid Build Coastguard Worker ch_ret_val = check();
232*49cdfc7eSAndroid Build Coastguard Worker
233*49cdfc7eSAndroid Build Coastguard Worker if (ch_ret_val) {
234*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp,
235*49cdfc7eSAndroid Build Coastguard Worker "Failure occured in check routine, return value %d\n",
236*49cdfc7eSAndroid Build Coastguard Worker ch_ret_val);
237*49cdfc7eSAndroid Build Coastguard Worker local_flag = FAILED;
238*49cdfc7eSAndroid Build Coastguard Worker }
239*49cdfc7eSAndroid Build Coastguard Worker
240*49cdfc7eSAndroid Build Coastguard Worker status = fclose(list_stream);
241*49cdfc7eSAndroid Build Coastguard Worker if (status != 0) {
242*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp,
243*49cdfc7eSAndroid Build Coastguard Worker "Failed to close list_stream: ret=%d errno=%d (%s)\n",
244*49cdfc7eSAndroid Build Coastguard Worker status, errno, strerror(errno));
245*49cdfc7eSAndroid Build Coastguard Worker local_flag = FAILED;
246*49cdfc7eSAndroid Build Coastguard Worker }
247*49cdfc7eSAndroid Build Coastguard Worker
248*49cdfc7eSAndroid Build Coastguard Worker blexit();
249*49cdfc7eSAndroid Build Coastguard Worker
250*49cdfc7eSAndroid Build Coastguard Worker /*
251*49cdfc7eSAndroid Build Coastguard Worker * Now fork and exec a system call to remove the directory.
252*49cdfc7eSAndroid Build Coastguard Worker */
253*49cdfc7eSAndroid Build Coastguard Worker
254*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
255*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp, "\nClean up:\trm string = %s\n", rm_string);
256*49cdfc7eSAndroid Build Coastguard Worker #endif
257*49cdfc7eSAndroid Build Coastguard Worker fflush(stdout);
258*49cdfc7eSAndroid Build Coastguard Worker fflush(temp);
259*49cdfc7eSAndroid Build Coastguard Worker
260*49cdfc7eSAndroid Build Coastguard Worker status = system(rm_string);
261*49cdfc7eSAndroid Build Coastguard Worker
262*49cdfc7eSAndroid Build Coastguard Worker if (status) {
263*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp, "Caution-``%s'' may have failed\n", rm_string);
264*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp, "rm command exit status = %d\n", status);
265*49cdfc7eSAndroid Build Coastguard Worker }
266*49cdfc7eSAndroid Build Coastguard Worker
267*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
268*49cdfc7eSAndroid Build Coastguard Worker /* */
269*49cdfc7eSAndroid Build Coastguard Worker /* .....and exit main */
270*49cdfc7eSAndroid Build Coastguard Worker /* */
271*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
272*49cdfc7eSAndroid Build Coastguard Worker
273*49cdfc7eSAndroid Build Coastguard Worker anyfail();
274*49cdfc7eSAndroid Build Coastguard Worker /***** NOT REACHED ******/
275*49cdfc7eSAndroid Build Coastguard Worker tst_exit();
276*49cdfc7eSAndroid Build Coastguard Worker }
277*49cdfc7eSAndroid Build Coastguard Worker
generate(char * string,int level)278*49cdfc7eSAndroid Build Coastguard Worker int generate(char *string, int level)
279*49cdfc7eSAndroid Build Coastguard Worker
280*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
281*49cdfc7eSAndroid Build Coastguard Worker /* */
282*49cdfc7eSAndroid Build Coastguard Worker /* generate recursively a tree of */
283*49cdfc7eSAndroid Build Coastguard Worker /* directories and files: within */
284*49cdfc7eSAndroid Build Coastguard Worker /* created directory, an alternating */
285*49cdfc7eSAndroid Build Coastguard Worker /* series of files and directories */
286*49cdfc7eSAndroid Build Coastguard Worker /* are constructed---until tree */
287*49cdfc7eSAndroid Build Coastguard Worker /* breadth and depth limits are */
288*49cdfc7eSAndroid Build Coastguard Worker /* reached or an error occurs */
289*49cdfc7eSAndroid Build Coastguard Worker /* */
290*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
291*49cdfc7eSAndroid Build Coastguard Worker /***************************/
292*49cdfc7eSAndroid Build Coastguard Worker /* string[] */
293*49cdfc7eSAndroid Build Coastguard Worker /* the directory path */
294*49cdfc7eSAndroid Build Coastguard Worker /* string below which a */
295*49cdfc7eSAndroid Build Coastguard Worker /* tree is generated */
296*49cdfc7eSAndroid Build Coastguard Worker /* */
297*49cdfc7eSAndroid Build Coastguard Worker /***************************/
298*49cdfc7eSAndroid Build Coastguard Worker
299*49cdfc7eSAndroid Build Coastguard Worker /***************************/
300*49cdfc7eSAndroid Build Coastguard Worker /* level */
301*49cdfc7eSAndroid Build Coastguard Worker /* the tree depth variable */
302*49cdfc7eSAndroid Build Coastguard Worker /* */
303*49cdfc7eSAndroid Build Coastguard Worker /***************************/
304*49cdfc7eSAndroid Build Coastguard Worker {
305*49cdfc7eSAndroid Build Coastguard Worker int switch_flag;
306*49cdfc7eSAndroid Build Coastguard Worker int ret_val = 0;
307*49cdfc7eSAndroid Build Coastguard Worker int new_ret_val, len, ret_len;
308*49cdfc7eSAndroid Build Coastguard Worker char new_string[PATH_STRING_LENGTH + 1];
309*49cdfc7eSAndroid Build Coastguard Worker int new_level;
310*49cdfc7eSAndroid Build Coastguard Worker int i, j; /* iteration counters */
311*49cdfc7eSAndroid Build Coastguard Worker int snp_ret;
312*49cdfc7eSAndroid Build Coastguard Worker
313*49cdfc7eSAndroid Build Coastguard Worker switch_flag = level & TRUE;
314*49cdfc7eSAndroid Build Coastguard Worker if (strlen(string) >= MAX_PATH_STRING_LENGTH) {
315*49cdfc7eSAndroid Build Coastguard Worker
316*49cdfc7eSAndroid Build Coastguard Worker /********************************/
317*49cdfc7eSAndroid Build Coastguard Worker /* */
318*49cdfc7eSAndroid Build Coastguard Worker /* Maximum path name length */
319*49cdfc7eSAndroid Build Coastguard Worker /* reached */
320*49cdfc7eSAndroid Build Coastguard Worker /* */
321*49cdfc7eSAndroid Build Coastguard Worker /********************************/
322*49cdfc7eSAndroid Build Coastguard Worker
323*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp, "\tMaximum path_name length reached.\n");
324*49cdfc7eSAndroid Build Coastguard Worker return (-1);
325*49cdfc7eSAndroid Build Coastguard Worker } else if (level < MAX_DEPTH) {
326*49cdfc7eSAndroid Build Coastguard Worker for (i = 0; i <= MAX_BREADTH; i++) {
327*49cdfc7eSAndroid Build Coastguard Worker get_next_name();
328*49cdfc7eSAndroid Build Coastguard Worker snp_ret = snprintf(new_string, sizeof(new_string),
329*49cdfc7eSAndroid Build Coastguard Worker "%s/%s", string, name);
330*49cdfc7eSAndroid Build Coastguard Worker if (snp_ret < 0 || snp_ret >= sizeof(new_string)) {
331*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TBROK, "snprintf(new_string,..) "
332*49cdfc7eSAndroid Build Coastguard Worker "returned %d", snp_ret);
333*49cdfc7eSAndroid Build Coastguard Worker fail_exit();
334*49cdfc7eSAndroid Build Coastguard Worker }
335*49cdfc7eSAndroid Build Coastguard Worker
336*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
337*49cdfc7eSAndroid Build Coastguard Worker /* */
338*49cdfc7eSAndroid Build Coastguard Worker /* switch between creating files */
339*49cdfc7eSAndroid Build Coastguard Worker /* and making directories */
340*49cdfc7eSAndroid Build Coastguard Worker /* */
341*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
342*49cdfc7eSAndroid Build Coastguard Worker
343*49cdfc7eSAndroid Build Coastguard Worker if (switch_flag) {
344*49cdfc7eSAndroid Build Coastguard Worker switch_flag = FALSE;
345*49cdfc7eSAndroid Build Coastguard Worker
346*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
347*49cdfc7eSAndroid Build Coastguard Worker /* */
348*49cdfc7eSAndroid Build Coastguard Worker /* create a new file */
349*49cdfc7eSAndroid Build Coastguard Worker /* */
350*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
351*49cdfc7eSAndroid Build Coastguard Worker
352*49cdfc7eSAndroid Build Coastguard Worker file_id = creat(new_string, FILE_MODE);
353*49cdfc7eSAndroid Build Coastguard Worker if (file_id == -1) {
354*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp,
355*49cdfc7eSAndroid Build Coastguard Worker "\tImpossible to create file %s, errno=%d\n",
356*49cdfc7eSAndroid Build Coastguard Worker new_string, errno);
357*49cdfc7eSAndroid Build Coastguard Worker return (-2);
358*49cdfc7eSAndroid Build Coastguard Worker }
359*49cdfc7eSAndroid Build Coastguard Worker #ifdef PRINT
360*49cdfc7eSAndroid Build Coastguard Worker printf("%d %s F\n", level, new_string);
361*49cdfc7eSAndroid Build Coastguard Worker #endif
362*49cdfc7eSAndroid Build Coastguard Worker
363*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
364*49cdfc7eSAndroid Build Coastguard Worker /* */
365*49cdfc7eSAndroid Build Coastguard Worker /* write to it */
366*49cdfc7eSAndroid Build Coastguard Worker /* */
367*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
368*49cdfc7eSAndroid Build Coastguard Worker
369*49cdfc7eSAndroid Build Coastguard Worker len = strlen(new_string);
370*49cdfc7eSAndroid Build Coastguard Worker for (j = 1; j <= FILE_LENGTH; j++) {
371*49cdfc7eSAndroid Build Coastguard Worker ret_len =
372*49cdfc7eSAndroid Build Coastguard Worker write(file_id, new_string, len);
373*49cdfc7eSAndroid Build Coastguard Worker if (ret_len != len) {
374*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp,
375*49cdfc7eSAndroid Build Coastguard Worker "\tUnsuccessful write to file %s, expected return of %d, got %d, errno=%d\n",
376*49cdfc7eSAndroid Build Coastguard Worker new_string, len,
377*49cdfc7eSAndroid Build Coastguard Worker ret_len, errno);
378*49cdfc7eSAndroid Build Coastguard Worker return (-3);
379*49cdfc7eSAndroid Build Coastguard Worker }
380*49cdfc7eSAndroid Build Coastguard Worker }
381*49cdfc7eSAndroid Build Coastguard Worker close(file_id);
382*49cdfc7eSAndroid Build Coastguard Worker
383*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
384*49cdfc7eSAndroid Build Coastguard Worker /* */
385*49cdfc7eSAndroid Build Coastguard Worker /* and store its name in path_list */
386*49cdfc7eSAndroid Build Coastguard Worker /* */
387*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
388*49cdfc7eSAndroid Build Coastguard Worker
389*49cdfc7eSAndroid Build Coastguard Worker strcpy(write_string, new_string);
390*49cdfc7eSAndroid Build Coastguard Worker len = strlen(write_string);
391*49cdfc7eSAndroid Build Coastguard Worker write_string[len++] = 'F';
392*49cdfc7eSAndroid Build Coastguard Worker write_string[len] = '\0';
393*49cdfc7eSAndroid Build Coastguard Worker escrivez(write_string);
394*49cdfc7eSAndroid Build Coastguard Worker } else {
395*49cdfc7eSAndroid Build Coastguard Worker switch_flag = TRUE;
396*49cdfc7eSAndroid Build Coastguard Worker
397*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
398*49cdfc7eSAndroid Build Coastguard Worker /* */
399*49cdfc7eSAndroid Build Coastguard Worker /* or make a directory */
400*49cdfc7eSAndroid Build Coastguard Worker /* */
401*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
402*49cdfc7eSAndroid Build Coastguard Worker
403*49cdfc7eSAndroid Build Coastguard Worker ret_val = mkdir(new_string, DIRECTORY_MODE);
404*49cdfc7eSAndroid Build Coastguard Worker
405*49cdfc7eSAndroid Build Coastguard Worker if (ret_val != 0) {
406*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp,
407*49cdfc7eSAndroid Build Coastguard Worker "\tImpossible to create directory %s, errno=%d\n",
408*49cdfc7eSAndroid Build Coastguard Worker new_string, errno);
409*49cdfc7eSAndroid Build Coastguard Worker return (-5);
410*49cdfc7eSAndroid Build Coastguard Worker }
411*49cdfc7eSAndroid Build Coastguard Worker #ifdef PRINT
412*49cdfc7eSAndroid Build Coastguard Worker printf("%d %s D\n", level, new_string);
413*49cdfc7eSAndroid Build Coastguard Worker #endif
414*49cdfc7eSAndroid Build Coastguard Worker
415*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
416*49cdfc7eSAndroid Build Coastguard Worker /* */
417*49cdfc7eSAndroid Build Coastguard Worker /* store its name in path_list */
418*49cdfc7eSAndroid Build Coastguard Worker /* */
419*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
420*49cdfc7eSAndroid Build Coastguard Worker
421*49cdfc7eSAndroid Build Coastguard Worker strcpy(write_string, new_string);
422*49cdfc7eSAndroid Build Coastguard Worker len = strlen(write_string);
423*49cdfc7eSAndroid Build Coastguard Worker write_string[len++] = 'D';
424*49cdfc7eSAndroid Build Coastguard Worker write_string[len] = '\0';
425*49cdfc7eSAndroid Build Coastguard Worker escrivez(write_string);
426*49cdfc7eSAndroid Build Coastguard Worker
427*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
428*49cdfc7eSAndroid Build Coastguard Worker /* */
429*49cdfc7eSAndroid Build Coastguard Worker /* and generate a new level */
430*49cdfc7eSAndroid Build Coastguard Worker /* */
431*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
432*49cdfc7eSAndroid Build Coastguard Worker
433*49cdfc7eSAndroid Build Coastguard Worker new_level = level + 1;
434*49cdfc7eSAndroid Build Coastguard Worker new_ret_val = generate(new_string, new_level);
435*49cdfc7eSAndroid Build Coastguard Worker if (new_ret_val < ret_val)
436*49cdfc7eSAndroid Build Coastguard Worker ret_val = new_ret_val;
437*49cdfc7eSAndroid Build Coastguard Worker }
438*49cdfc7eSAndroid Build Coastguard Worker }
439*49cdfc7eSAndroid Build Coastguard Worker
440*49cdfc7eSAndroid Build Coastguard Worker /********************************/
441*49cdfc7eSAndroid Build Coastguard Worker /* */
442*49cdfc7eSAndroid Build Coastguard Worker /* Maximum breadth reached */
443*49cdfc7eSAndroid Build Coastguard Worker /* */
444*49cdfc7eSAndroid Build Coastguard Worker /********************************/
445*49cdfc7eSAndroid Build Coastguard Worker
446*49cdfc7eSAndroid Build Coastguard Worker return (ret_val);
447*49cdfc7eSAndroid Build Coastguard Worker } else
448*49cdfc7eSAndroid Build Coastguard Worker /********************************/
449*49cdfc7eSAndroid Build Coastguard Worker /* */
450*49cdfc7eSAndroid Build Coastguard Worker /* Maximum depth reached */
451*49cdfc7eSAndroid Build Coastguard Worker /* */
452*49cdfc7eSAndroid Build Coastguard Worker /********************************/
453*49cdfc7eSAndroid Build Coastguard Worker return 0;
454*49cdfc7eSAndroid Build Coastguard Worker }
455*49cdfc7eSAndroid Build Coastguard Worker
check(void)456*49cdfc7eSAndroid Build Coastguard Worker int check(void)
457*49cdfc7eSAndroid Build Coastguard Worker
458*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
459*49cdfc7eSAndroid Build Coastguard Worker /* */
460*49cdfc7eSAndroid Build Coastguard Worker /* check for file and directory */
461*49cdfc7eSAndroid Build Coastguard Worker /* correctness by reading records */
462*49cdfc7eSAndroid Build Coastguard Worker /* from the path_list and attempting */
463*49cdfc7eSAndroid Build Coastguard Worker /* to determine if the corresponding */
464*49cdfc7eSAndroid Build Coastguard Worker /* files or directories are as */
465*49cdfc7eSAndroid Build Coastguard Worker /* created */
466*49cdfc7eSAndroid Build Coastguard Worker /* */
467*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
468*49cdfc7eSAndroid Build Coastguard Worker {
469*49cdfc7eSAndroid Build Coastguard Worker int len, path_mode, val, ret_len, j;
470*49cdfc7eSAndroid Build Coastguard Worker
471*49cdfc7eSAndroid Build Coastguard Worker for (;;) {
472*49cdfc7eSAndroid Build Coastguard Worker
473*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
474*49cdfc7eSAndroid Build Coastguard Worker /* */
475*49cdfc7eSAndroid Build Coastguard Worker /* read a path string from path_list */
476*49cdfc7eSAndroid Build Coastguard Worker /* */
477*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
478*49cdfc7eSAndroid Build Coastguard Worker
479*49cdfc7eSAndroid Build Coastguard Worker if (fscanf(list_stream, "%s", path_string) == EOF) {
480*49cdfc7eSAndroid Build Coastguard Worker
481*49cdfc7eSAndroid Build Coastguard Worker #ifdef PRINT
482*49cdfc7eSAndroid Build Coastguard Worker printf("\nEnd of path_list file reached \n");
483*49cdfc7eSAndroid Build Coastguard Worker #endif
484*49cdfc7eSAndroid Build Coastguard Worker
485*49cdfc7eSAndroid Build Coastguard Worker return 0;
486*49cdfc7eSAndroid Build Coastguard Worker }
487*49cdfc7eSAndroid Build Coastguard Worker #ifdef PRINT
488*49cdfc7eSAndroid Build Coastguard Worker printf("%s\n", path_string);
489*49cdfc7eSAndroid Build Coastguard Worker #endif
490*49cdfc7eSAndroid Build Coastguard Worker
491*49cdfc7eSAndroid Build Coastguard Worker len = strlen(path_string);
492*49cdfc7eSAndroid Build Coastguard Worker len--;
493*49cdfc7eSAndroid Build Coastguard Worker if (path_string[len] == 'F') {
494*49cdfc7eSAndroid Build Coastguard Worker
495*49cdfc7eSAndroid Build Coastguard Worker /********************************/
496*49cdfc7eSAndroid Build Coastguard Worker /* */
497*49cdfc7eSAndroid Build Coastguard Worker /* this should be a file */
498*49cdfc7eSAndroid Build Coastguard Worker /* */
499*49cdfc7eSAndroid Build Coastguard Worker /********************************/
500*49cdfc7eSAndroid Build Coastguard Worker
501*49cdfc7eSAndroid Build Coastguard Worker path_string[len] = '\0';
502*49cdfc7eSAndroid Build Coastguard Worker file_id = open(path_string, READ);
503*49cdfc7eSAndroid Build Coastguard Worker if (file_id <= 0) {
504*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp,
505*49cdfc7eSAndroid Build Coastguard Worker "\tImpossible to open file %s, errno=%d\n",
506*49cdfc7eSAndroid Build Coastguard Worker path_string, errno);
507*49cdfc7eSAndroid Build Coastguard Worker return (-1);
508*49cdfc7eSAndroid Build Coastguard Worker }
509*49cdfc7eSAndroid Build Coastguard Worker
510*49cdfc7eSAndroid Build Coastguard Worker else {
511*49cdfc7eSAndroid Build Coastguard Worker /********************************/
512*49cdfc7eSAndroid Build Coastguard Worker /* */
513*49cdfc7eSAndroid Build Coastguard Worker /* check its contents */
514*49cdfc7eSAndroid Build Coastguard Worker /* */
515*49cdfc7eSAndroid Build Coastguard Worker /********************************/
516*49cdfc7eSAndroid Build Coastguard Worker
517*49cdfc7eSAndroid Build Coastguard Worker len = strlen(path_string);
518*49cdfc7eSAndroid Build Coastguard Worker for (j = 1; j <= FILE_LENGTH; j++) {
519*49cdfc7eSAndroid Build Coastguard Worker ret_len =
520*49cdfc7eSAndroid Build Coastguard Worker read(file_id, read_string, len);
521*49cdfc7eSAndroid Build Coastguard Worker if (len != ret_len) {
522*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp,
523*49cdfc7eSAndroid Build Coastguard Worker "\tFile read error for file %s, expected return of %d, got %d, errno=%d\n",
524*49cdfc7eSAndroid Build Coastguard Worker path_string, len,
525*49cdfc7eSAndroid Build Coastguard Worker ret_len, errno);
526*49cdfc7eSAndroid Build Coastguard Worker return (-3);
527*49cdfc7eSAndroid Build Coastguard Worker }
528*49cdfc7eSAndroid Build Coastguard Worker read_string[len] = '\0';
529*49cdfc7eSAndroid Build Coastguard Worker val = strcmp(read_string, path_string);
530*49cdfc7eSAndroid Build Coastguard Worker if (val != 0) {
531*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp,
532*49cdfc7eSAndroid Build Coastguard Worker "\tContents of file %s are different than expected: %s\n",
533*49cdfc7eSAndroid Build Coastguard Worker path_string,
534*49cdfc7eSAndroid Build Coastguard Worker read_string);
535*49cdfc7eSAndroid Build Coastguard Worker return (-4);
536*49cdfc7eSAndroid Build Coastguard Worker }
537*49cdfc7eSAndroid Build Coastguard Worker }
538*49cdfc7eSAndroid Build Coastguard Worker close(file_id);
539*49cdfc7eSAndroid Build Coastguard Worker } /* else for */
540*49cdfc7eSAndroid Build Coastguard Worker if (ret_len <= 0) {
541*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp, "\tImpossible to read file %s\n",
542*49cdfc7eSAndroid Build Coastguard Worker path_string);
543*49cdfc7eSAndroid Build Coastguard Worker return (-2);
544*49cdfc7eSAndroid Build Coastguard Worker }
545*49cdfc7eSAndroid Build Coastguard Worker } else {
546*49cdfc7eSAndroid Build Coastguard Worker
547*49cdfc7eSAndroid Build Coastguard Worker /********************************/
548*49cdfc7eSAndroid Build Coastguard Worker /* */
549*49cdfc7eSAndroid Build Coastguard Worker /* otherwise.......... */
550*49cdfc7eSAndroid Build Coastguard Worker /* it should be a directory */
551*49cdfc7eSAndroid Build Coastguard Worker /* */
552*49cdfc7eSAndroid Build Coastguard Worker /********************************/
553*49cdfc7eSAndroid Build Coastguard Worker
554*49cdfc7eSAndroid Build Coastguard Worker path_string[len] = '\0';
555*49cdfc7eSAndroid Build Coastguard Worker path_mode = mode(path_string);
556*49cdfc7eSAndroid Build Coastguard Worker if (path_mode == -1) {
557*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp,
558*49cdfc7eSAndroid Build Coastguard Worker "\tPreviously created directory path %s was not open\n",
559*49cdfc7eSAndroid Build Coastguard Worker path_string);
560*49cdfc7eSAndroid Build Coastguard Worker return (-4);
561*49cdfc7eSAndroid Build Coastguard Worker }
562*49cdfc7eSAndroid Build Coastguard Worker if ((040000 & path_mode) != 040000) {
563*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp,
564*49cdfc7eSAndroid Build Coastguard Worker "\tPath %s was not recognized to be a directory\n",
565*49cdfc7eSAndroid Build Coastguard Worker path_string);
566*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp, "\tIts mode is %o\n", path_mode);
567*49cdfc7eSAndroid Build Coastguard Worker return (-5);
568*49cdfc7eSAndroid Build Coastguard Worker }
569*49cdfc7eSAndroid Build Coastguard Worker }
570*49cdfc7eSAndroid Build Coastguard Worker } /* while */
571*49cdfc7eSAndroid Build Coastguard Worker }
572*49cdfc7eSAndroid Build Coastguard Worker
get_next_name(void)573*49cdfc7eSAndroid Build Coastguard Worker int get_next_name(void)
574*49cdfc7eSAndroid Build Coastguard Worker
575*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
576*49cdfc7eSAndroid Build Coastguard Worker /* */
577*49cdfc7eSAndroid Build Coastguard Worker /* get the next---in a dictionary */
578*49cdfc7eSAndroid Build Coastguard Worker /* sense---file or directory name */
579*49cdfc7eSAndroid Build Coastguard Worker /* */
580*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
581*49cdfc7eSAndroid Build Coastguard Worker {
582*49cdfc7eSAndroid Build Coastguard Worker static int k;
583*49cdfc7eSAndroid Build Coastguard Worker int i;
584*49cdfc7eSAndroid Build Coastguard Worker int last_position;
585*49cdfc7eSAndroid Build Coastguard Worker
586*49cdfc7eSAndroid Build Coastguard Worker last_position = NAME_LENGTH - 1;
587*49cdfc7eSAndroid Build Coastguard Worker if (k == 0) {
588*49cdfc7eSAndroid Build Coastguard Worker
589*49cdfc7eSAndroid Build Coastguard Worker /************************/
590*49cdfc7eSAndroid Build Coastguard Worker /* */
591*49cdfc7eSAndroid Build Coastguard Worker /* initialize name */
592*49cdfc7eSAndroid Build Coastguard Worker /* */
593*49cdfc7eSAndroid Build Coastguard Worker /************************/
594*49cdfc7eSAndroid Build Coastguard Worker
595*49cdfc7eSAndroid Build Coastguard Worker for (i = 0; i < NAME_LENGTH; i++)
596*49cdfc7eSAndroid Build Coastguard Worker name[i] = 'a';
597*49cdfc7eSAndroid Build Coastguard Worker name[NAME_LENGTH] = '\0';
598*49cdfc7eSAndroid Build Coastguard Worker k++;
599*49cdfc7eSAndroid Build Coastguard Worker }
600*49cdfc7eSAndroid Build Coastguard Worker /********************************/
601*49cdfc7eSAndroid Build Coastguard Worker /* */
602*49cdfc7eSAndroid Build Coastguard Worker else
603*49cdfc7eSAndroid Build Coastguard Worker increment_name(last_position); /* i.e., beginning at the last */
604*49cdfc7eSAndroid Build Coastguard Worker /* position */
605*49cdfc7eSAndroid Build Coastguard Worker /* */
606*49cdfc7eSAndroid Build Coastguard Worker /********************************/
607*49cdfc7eSAndroid Build Coastguard Worker return 0;
608*49cdfc7eSAndroid Build Coastguard Worker }
609*49cdfc7eSAndroid Build Coastguard Worker
increment_name(int position)610*49cdfc7eSAndroid Build Coastguard Worker int increment_name(int position)
611*49cdfc7eSAndroid Build Coastguard Worker
612*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
613*49cdfc7eSAndroid Build Coastguard Worker /* */
614*49cdfc7eSAndroid Build Coastguard Worker /* recursively revise the letters in */
615*49cdfc7eSAndroid Build Coastguard Worker /* a name to get the lexiographically */
616*49cdfc7eSAndroid Build Coastguard Worker /* next name */
617*49cdfc7eSAndroid Build Coastguard Worker /* */
618*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
619*49cdfc7eSAndroid Build Coastguard Worker {
620*49cdfc7eSAndroid Build Coastguard Worker int next_position;
621*49cdfc7eSAndroid Build Coastguard Worker
622*49cdfc7eSAndroid Build Coastguard Worker if (name[position] == 'z')
623*49cdfc7eSAndroid Build Coastguard Worker if (position == 0) {
624*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp,
625*49cdfc7eSAndroid Build Coastguard Worker "\tERROR: There are no more available names\n");
626*49cdfc7eSAndroid Build Coastguard Worker fail_exit();
627*49cdfc7eSAndroid Build Coastguard Worker } else {
628*49cdfc7eSAndroid Build Coastguard Worker name[position] = 'a'; /**********************/
629*49cdfc7eSAndroid Build Coastguard Worker next_position = --position; /* */
630*49cdfc7eSAndroid Build Coastguard Worker increment_name(next_position); /* increment the */
631*49cdfc7eSAndroid Build Coastguard Worker /* previous letter */
632*49cdfc7eSAndroid Build Coastguard Worker /* */
633*49cdfc7eSAndroid Build Coastguard Worker /**********************/
634*49cdfc7eSAndroid Build Coastguard Worker }
635*49cdfc7eSAndroid Build Coastguard Worker /*********************************/
636*49cdfc7eSAndroid Build Coastguard Worker /* */
637*49cdfc7eSAndroid Build Coastguard Worker else
638*49cdfc7eSAndroid Build Coastguard Worker name[position]++; /* otherwise, increment this one */
639*49cdfc7eSAndroid Build Coastguard Worker return 0; /* */
640*49cdfc7eSAndroid Build Coastguard Worker /*********************************/
641*49cdfc7eSAndroid Build Coastguard Worker }
642*49cdfc7eSAndroid Build Coastguard Worker
mode(char * path_string)643*49cdfc7eSAndroid Build Coastguard Worker int mode(char *path_string)
644*49cdfc7eSAndroid Build Coastguard Worker
645*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
646*49cdfc7eSAndroid Build Coastguard Worker /* */
647*49cdfc7eSAndroid Build Coastguard Worker /* determine and return the mode of */
648*49cdfc7eSAndroid Build Coastguard Worker /* the file named by path_string */
649*49cdfc7eSAndroid Build Coastguard Worker /* */
650*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
651*49cdfc7eSAndroid Build Coastguard Worker {
652*49cdfc7eSAndroid Build Coastguard Worker struct stat buf;
653*49cdfc7eSAndroid Build Coastguard Worker int ret_val, mod;
654*49cdfc7eSAndroid Build Coastguard Worker
655*49cdfc7eSAndroid Build Coastguard Worker ret_val = stat(path_string, &buf);
656*49cdfc7eSAndroid Build Coastguard Worker if (ret_val == -1)
657*49cdfc7eSAndroid Build Coastguard Worker return (-1);
658*49cdfc7eSAndroid Build Coastguard Worker else {
659*49cdfc7eSAndroid Build Coastguard Worker mod = buf.st_mode;
660*49cdfc7eSAndroid Build Coastguard Worker return (mod);
661*49cdfc7eSAndroid Build Coastguard Worker }
662*49cdfc7eSAndroid Build Coastguard Worker }
663*49cdfc7eSAndroid Build Coastguard Worker
escrivez(char * string)664*49cdfc7eSAndroid Build Coastguard Worker int escrivez(char *string)
665*49cdfc7eSAndroid Build Coastguard Worker {
666*49cdfc7eSAndroid Build Coastguard Worker char write_string[PATH_STRING_LENGTH + 1];
667*49cdfc7eSAndroid Build Coastguard Worker int len, ret_len;
668*49cdfc7eSAndroid Build Coastguard Worker
669*49cdfc7eSAndroid Build Coastguard Worker strcpy(write_string, string);
670*49cdfc7eSAndroid Build Coastguard Worker len = strlen(write_string);
671*49cdfc7eSAndroid Build Coastguard Worker write_string[len] = '\n';
672*49cdfc7eSAndroid Build Coastguard Worker len++;
673*49cdfc7eSAndroid Build Coastguard Worker ret_len = write(list_id, write_string, len);
674*49cdfc7eSAndroid Build Coastguard Worker if (len != ret_len) {
675*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp,
676*49cdfc7eSAndroid Build Coastguard Worker "\tA string of deviant length %d written to path_list, errno=%d\n",
677*49cdfc7eSAndroid Build Coastguard Worker ret_len, errno);
678*49cdfc7eSAndroid Build Coastguard Worker fail_exit();
679*49cdfc7eSAndroid Build Coastguard Worker }
680*49cdfc7eSAndroid Build Coastguard Worker return 0;
681*49cdfc7eSAndroid Build Coastguard Worker }
682*49cdfc7eSAndroid Build Coastguard Worker
term(void)683*49cdfc7eSAndroid Build Coastguard Worker int term(void)
684*49cdfc7eSAndroid Build Coastguard Worker {
685*49cdfc7eSAndroid Build Coastguard Worker int status;
686*49cdfc7eSAndroid Build Coastguard Worker
687*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp, "\tterm - got SIGTERM, cleaning up.\n");
688*49cdfc7eSAndroid Build Coastguard Worker
689*49cdfc7eSAndroid Build Coastguard Worker if (list_stream != NULL)
690*49cdfc7eSAndroid Build Coastguard Worker fclose(list_stream);
691*49cdfc7eSAndroid Build Coastguard Worker close(list_id);
692*49cdfc7eSAndroid Build Coastguard Worker close(file_id);
693*49cdfc7eSAndroid Build Coastguard Worker
694*49cdfc7eSAndroid Build Coastguard Worker status = system(rm_string);
695*49cdfc7eSAndroid Build Coastguard Worker if (status) {
696*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp, "Caution - ``%s'' may have failed.\n", rm_string);
697*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp, "rm command exit status = %d\n", status);
698*49cdfc7eSAndroid Build Coastguard Worker }
699*49cdfc7eSAndroid Build Coastguard Worker
700*49cdfc7eSAndroid Build Coastguard Worker ok_exit();
701*49cdfc7eSAndroid Build Coastguard Worker /***NOT REACHED***/
702*49cdfc7eSAndroid Build Coastguard Worker return 0;
703*49cdfc7eSAndroid Build Coastguard Worker
704*49cdfc7eSAndroid Build Coastguard Worker }
705*49cdfc7eSAndroid Build Coastguard Worker
706*49cdfc7eSAndroid Build Coastguard Worker /** LTP Port **/
707*49cdfc7eSAndroid Build Coastguard Worker /*
708*49cdfc7eSAndroid Build Coastguard Worker * setup
709*49cdfc7eSAndroid Build Coastguard Worker *
710*49cdfc7eSAndroid Build Coastguard Worker * Do set up - here its a dummy function
711*49cdfc7eSAndroid Build Coastguard Worker */
setup(void)712*49cdfc7eSAndroid Build Coastguard Worker void setup(void)
713*49cdfc7eSAndroid Build Coastguard Worker {
714*49cdfc7eSAndroid Build Coastguard Worker tst_tmpdir();
715*49cdfc7eSAndroid Build Coastguard Worker temp = stderr;
716*49cdfc7eSAndroid Build Coastguard Worker }
717*49cdfc7eSAndroid Build Coastguard Worker
718*49cdfc7eSAndroid Build Coastguard Worker /*
719*49cdfc7eSAndroid Build Coastguard Worker * Function: blexit()
720*49cdfc7eSAndroid Build Coastguard Worker *
721*49cdfc7eSAndroid Build Coastguard Worker * Description: This function will exit a block, a block may be a lo
722*49cdfc7eSAndroid Build Coastguard Worker gical unit
723*49cdfc7eSAndroid Build Coastguard Worker * of a test. It will report the status if the test ie
724*49cdfc7eSAndroid Build Coastguard Worker fail or
725*49cdfc7eSAndroid Build Coastguard Worker * pass.
726*49cdfc7eSAndroid Build Coastguard Worker */
blexit(void)727*49cdfc7eSAndroid Build Coastguard Worker void blexit(void)
728*49cdfc7eSAndroid Build Coastguard Worker {
729*49cdfc7eSAndroid Build Coastguard Worker (local_flag == PASSED) ? tst_resm(TPASS, "Test block %d", block_number)
730*49cdfc7eSAndroid Build Coastguard Worker : tst_resm(TFAIL, "Test block %d", block_number);
731*49cdfc7eSAndroid Build Coastguard Worker block_number++;
732*49cdfc7eSAndroid Build Coastguard Worker return;
733*49cdfc7eSAndroid Build Coastguard Worker }
734*49cdfc7eSAndroid Build Coastguard Worker
735*49cdfc7eSAndroid Build Coastguard Worker /*
736*49cdfc7eSAndroid Build Coastguard Worker * Function: blenter()
737*49cdfc7eSAndroid Build Coastguard Worker *
738*49cdfc7eSAndroid Build Coastguard Worker * Description: Print message on entering a new block
739*49cdfc7eSAndroid Build Coastguard Worker */
blenter(void)740*49cdfc7eSAndroid Build Coastguard Worker void blenter(void)
741*49cdfc7eSAndroid Build Coastguard Worker {
742*49cdfc7eSAndroid Build Coastguard Worker local_flag = PASSED;
743*49cdfc7eSAndroid Build Coastguard Worker return;
744*49cdfc7eSAndroid Build Coastguard Worker }
745*49cdfc7eSAndroid Build Coastguard Worker
746*49cdfc7eSAndroid Build Coastguard Worker /*
747*49cdfc7eSAndroid Build Coastguard Worker * fail_exit()
748*49cdfc7eSAndroid Build Coastguard Worker *
749*49cdfc7eSAndroid Build Coastguard Worker * Exit on failure
750*49cdfc7eSAndroid Build Coastguard Worker */
fail_exit(void)751*49cdfc7eSAndroid Build Coastguard Worker void fail_exit(void)
752*49cdfc7eSAndroid Build Coastguard Worker {
753*49cdfc7eSAndroid Build Coastguard Worker tst_brkm(TFAIL, tst_rmdir, "Test failed");
754*49cdfc7eSAndroid Build Coastguard Worker }
755*49cdfc7eSAndroid Build Coastguard Worker
756*49cdfc7eSAndroid Build Coastguard Worker /*
757*49cdfc7eSAndroid Build Coastguard Worker *
758*49cdfc7eSAndroid Build Coastguard Worker * Function: anyfail()
759*49cdfc7eSAndroid Build Coastguard Worker *
760*49cdfc7eSAndroid Build Coastguard Worker * Description: Exit a test.
761*49cdfc7eSAndroid Build Coastguard Worker */
anyfail(void)762*49cdfc7eSAndroid Build Coastguard Worker void anyfail(void)
763*49cdfc7eSAndroid Build Coastguard Worker {
764*49cdfc7eSAndroid Build Coastguard Worker (local_flag == FAILED) ? tst_resm(TFAIL, "Test failed")
765*49cdfc7eSAndroid Build Coastguard Worker : tst_resm(TPASS, "Test passed");
766*49cdfc7eSAndroid Build Coastguard Worker tst_rmdir();
767*49cdfc7eSAndroid Build Coastguard Worker tst_exit();
768*49cdfc7eSAndroid Build Coastguard Worker }
769*49cdfc7eSAndroid Build Coastguard Worker
770*49cdfc7eSAndroid Build Coastguard Worker /*
771*49cdfc7eSAndroid Build Coastguard Worker * ok_exit
772*49cdfc7eSAndroid Build Coastguard Worker *
773*49cdfc7eSAndroid Build Coastguard Worker * Calling block passed the test
774*49cdfc7eSAndroid Build Coastguard Worker */
ok_exit(void)775*49cdfc7eSAndroid Build Coastguard Worker void ok_exit(void)
776*49cdfc7eSAndroid Build Coastguard Worker {
777*49cdfc7eSAndroid Build Coastguard Worker local_flag = PASSED;
778*49cdfc7eSAndroid Build Coastguard Worker return;
779*49cdfc7eSAndroid Build Coastguard Worker }
780