annotate rvinterf/etmsync/fsread.c @ 295:3dd74b16df82

fc-fsio: pathname recursion handling revamped
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sat, 01 Mar 2014 08:01:08 +0000
parents e33d71e9033f
children 792f164b63a6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
283
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * Commands for reading the content of a GSM device's file system
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 */
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <sys/types.h>
288
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
6 #include <sys/param.h>
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
7 #include <sys/stat.h>
283
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <stdio.h>
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <stdlib.h>
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <string.h>
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include <strings.h>
288
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
12 #include <unistd.h>
283
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 #include "etm.h"
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 #include "ffs.h"
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 #include "tmffs2.h"
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 #include "limits.h"
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
17 #include "ffslimits.h"
283
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 #include "localtypes.h"
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 #include "localstruct.h"
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 #include "exitcodes.h"
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
22 extern char *pathname_for_ffs_child();
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
23
283
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 void
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 ll_print_line(pathname, stat)
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 char *pathname;
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 struct stat_info *stat;
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 {
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 char readonly;
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 if (stat->flags & OF_READONLY)
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 readonly = 'r';
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 else
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 readonly = ' ';
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 switch (stat->type) {
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 case OT_FILE:
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 printf("f%c %7u %s\n", readonly, stat->size, pathname);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 return;
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 case OT_DIR:
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 printf("d%c %s\n", readonly, pathname);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 return;
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 case OT_LINK:
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 printf("l%c %s\n", readonly, pathname);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 return;
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 default:
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 printf("?%c %s\n", readonly, pathname);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 }
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 }
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 cmd_ll(argc, argv)
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 char **argv;
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 {
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 struct stat_info stat;
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 u_char rdstate[4];
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
55 char rdbuf[MAX_FN_COMPONENT+1], childpath[MAX_FULL_PATHNAME+1], *childp;
283
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 int nument, i, rc;
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
58 if (validate_ffs_pathname(argv[1]) < 0)
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
59 return(ERROR_USAGE); /* err msg already printed */
283
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 rc = do_xlstat(argv[1], &stat);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 if (rc)
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 return(rc);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 if (stat.type != OT_DIR) {
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 ll_print_line(argv[1], &stat);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 return(0);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 }
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 rc = do_opendir(argv[1], rdstate, &nument);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 if (rc)
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 return(rc);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 if (!nument) {
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 printf("<empty dir>\n");
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 return(0);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 }
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
74 childp = pathname_for_ffs_child(argv[1], childpath);
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
75 if (!childp) {
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
76 printf("error: non-empty dir at the limit of pathname depth\n");
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
77 return(ERROR_TARGET);
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
78 }
283
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 for (i = 0; i < nument; i++) {
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
80 rc = do_readdir(rdstate, rdbuf, MAX_FN_COMPONENT+1);
283
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 if (rc)
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 return(rc);
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
83 if (index(rdbuf, '/')) {
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
84 printf("error: readdir result contains a slash\n");
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
85 return(ERROR_TARGET);
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
86 }
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
87 strcpy(childp, rdbuf);
283
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 rc = do_xlstat(childpath, &stat);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 if (rc) {
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90 printf("xlstat failed on %s\n", childpath);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 return(rc);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 }
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93 ll_print_line(childpath, &stat);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94 }
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95 return(0);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
96 }
284
7b4d4e3e610a fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 283
diff changeset
97
285
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
98 void
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
99 hexdump_line(offset, buf, len)
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
100 u_char *buf;
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
101 {
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
102 int i, c;
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
103
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
104 printf("%02X: ", offset);
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
105 for (i = 0; i < 16; i++) {
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
106 if (i < len)
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
107 printf("%02X ", buf[i]);
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
108 else
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
109 fputs(" ", stdout);
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
110 if (i == 7 || i == 15)
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
111 putchar(' ');
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
112 }
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
113 for (i = 0; i < len; i++) {
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
114 c = buf[i];
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
115 if (c < ' ' || c > '~')
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
116 c = '.';
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
117 putchar(c);
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
118 }
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
119 putchar('\n');
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
120 }
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
121
284
7b4d4e3e610a fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 283
diff changeset
122 cmd_hd(argc, argv)
7b4d4e3e610a fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 283
diff changeset
123 char **argv;
7b4d4e3e610a fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 283
diff changeset
124 {
285
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
125 u_char databuf[MAX_READ_DATA];
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
126 int rc, sz, off, l;
284
7b4d4e3e610a fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 283
diff changeset
127
285
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
128 rc = do_file_read(argv[1], databuf, MAX_READ_DATA, &sz);
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
129 if (rc)
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
130 return(rc);
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
131 printf("%d bytes read\n", sz);
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
132 for (off = 0; off < sz; off += 16) {
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
133 l = sz - off;
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
134 if (l > 16)
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
135 l = 16;
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
136 hexdump_line(off, databuf + off, l);
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
137 }
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
138 return(0);
284
7b4d4e3e610a fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 283
diff changeset
139 }
287
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
140
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
141 cpout_object(ffspath, hostpath)
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
142 char *ffspath, *hostpath;
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
143 {
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
144 struct stat_info stat;
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
145 int rc;
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
146
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
147 rc = do_xlstat(ffspath, &stat);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
148 if (rc)
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
149 return(rc);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
150 switch (stat.type) {
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
151 case OT_FILE:
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
152 return cpout_file(ffspath, hostpath);
287
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
153 case OT_DIR:
288
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
154 return cpout_dir(ffspath, hostpath);
287
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
155 case OT_LINK:
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
156 printf("skipping FFS symlink %s\n", ffspath);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
157 return(0);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
158 default:
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
159 printf("error: stat returned bad objtype for %s\n", ffspath);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
160 return(ERROR_TARGET);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
161 }
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
162 }
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
163
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
164 cpout_file(ffspath, hostpath)
287
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
165 char *ffspath, *hostpath;
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
166 {
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
167 int tfd;
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
168 FILE *of;
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
169 u_char buf[MAX_READ_DATA];
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
170 int rc, sz;
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
171
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
172 printf("copying %s\n", ffspath);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
173 rc = fd_open(ffspath, FFS_O_RDONLY, &tfd);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
174 if (rc)
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
175 return(rc);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
176 of = fopen(hostpath, "w");
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
177 if (!of) {
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
178 perror(hostpath);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
179 fd_close(tfd);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
180 return(ERROR_UNIX);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
181 }
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
182 for (;;) {
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
183 rc = fd_read(tfd, buf, MAX_READ_DATA, &sz);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
184 if (rc) {
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
185 fd_close(tfd);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
186 fclose(of);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
187 return(rc);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
188 }
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
189 if (!sz)
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
190 break;
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
191 fwrite(buf, 1, sz, of);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
192 }
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
193 fclose(of);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
194 return fd_close(tfd);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
195 }
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
196
288
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
197 host_mkdir(pathname)
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
198 char *pathname;
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
199 {
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
200 int rc;
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
201 struct stat st;
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
202
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
203 rc = stat(pathname, &st);
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
204 if (rc < 0) {
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
205 rc = mkdir(pathname, 0777);
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
206 if (rc < 0) {
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
207 perror(pathname);
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
208 return(ERROR_UNIX);
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
209 }
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
210 return(0);
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
211 } else {
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
212 if (S_ISDIR(st.st_mode))
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
213 return(0);
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
214 else {
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
215 fprintf(stderr,
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
216 "error: %s already exists and is not a directory\n",
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
217 pathname);
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
218 return(ERROR_UNIX);
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
219 }
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
220 }
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
221 }
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
222
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
223 cpout_dir(ffspath_dir, hostpath_dir)
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
224 char *ffspath_dir, *hostpath_dir;
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
225 {
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
226 u_char rdstate[4];
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
227 char rdbuf[MAX_FN_COMPONENT+1], ffspath_child[MAX_FULL_PATHNAME+1];
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
228 char *childp;
288
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
229 char hostpath_child[MAXPATHLEN];
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
230 int nument, i, rc, childerr;
288
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
231
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
232 printf("dir %s\n", ffspath_dir);
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
233 rc = host_mkdir(hostpath_dir);
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
234 if (rc)
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
235 return(rc);
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
236 rc = do_opendir(ffspath_dir, rdstate, &nument);
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
237 if (rc)
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
238 return(rc);
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
239 if (!nument)
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
240 return(0);
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
241 childp = pathname_for_ffs_child(ffspath_dir, ffspath_child);
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
242 if (!childp) {
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
243 printf("error: non-empty dir at the limit of pathname depth\n");
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
244 return(ERROR_TARGET);
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
245 }
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
246 childerr = 0;
288
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
247 for (i = 0; i < nument; i++) {
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
248 rc = do_readdir(rdstate, rdbuf);
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
249 if (rc)
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
250 return(rc);
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
251 if (index(rdbuf, '/')) {
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
252 printf("error: readdir result contains a slash\n");
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
253 return(ERROR_TARGET);
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
254 }
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
255 strcpy(childp, rdbuf);
288
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
256 if (rdbuf[0] == '.') {
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
257 printf("skipping %s\n", ffspath_child);
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
258 continue;
288
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
259 }
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
260 if (strlen(hostpath_dir) + strlen(rdbuf) + 2 >
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
261 sizeof hostpath_child) {
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
262 fprintf(stderr,
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
263 "error: host side pathname buffer overflow\n");
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
264 return(ERROR_UNIX);
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
265 }
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
266 sprintf(hostpath_child, "%s/%s", hostpath_dir, rdbuf);
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
267 rc = cpout_object(ffspath_child, hostpath_child);
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
268 if (rc && rc != ERROR_TARGET)
288
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
269 return(rc);
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
270 if (rc)
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
271 childerr = rc;
288
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
272 }
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
273 return(childerr);
288
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
274 }
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
275
287
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
276 cmd_cpout(argc, argv)
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
277 char **argv;
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
278 {
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
279 if (validate_ffs_pathname(argv[1]) < 0)
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
280 return(ERROR_USAGE); /* err msg already printed */
287
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
281 return cpout_object(argv[1], argv[2]);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
282 }
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
283
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
284 cmd_cpout_file(argc, argv)
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
285 char **argv;
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
286 {
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
287 return cpout_file(argv[1], argv[2]);
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
288 }