annotate rvinterf/etmsync/fsread.c @ 528:1affe428bf72

getting closer to compiling l1_cust.c
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Tue, 15 Jul 2014 16:54:52 +0000
parents e0ca3ca46a06
children
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;
304
e0ca3ca46a06 fc-fsio: ll reads and shows symlinks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 296
diff changeset
30 char rlbuf[256];
283
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 if (stat->flags & OF_READONLY)
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 readonly = 'r';
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 else
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 readonly = ' ';
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 switch (stat->type) {
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 case OT_FILE:
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 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
39 return;
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 case OT_DIR:
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 printf("d%c %s\n", readonly, pathname);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 return;
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 case OT_LINK:
304
e0ca3ca46a06 fc-fsio: ll reads and shows symlinks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 296
diff changeset
44 if (do_readlink_sancheck(pathname, rlbuf))
e0ca3ca46a06 fc-fsio: ll reads and shows symlinks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 296
diff changeset
45 strcpy(rlbuf, "<invalid>");
e0ca3ca46a06 fc-fsio: ll reads and shows symlinks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 296
diff changeset
46 printf("l%c %s -> %s\n", readonly, pathname, rlbuf);
283
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 return;
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 default:
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 printf("?%c %s\n", readonly, pathname);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 }
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 }
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 cmd_ll(argc, argv)
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 char **argv;
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 {
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 struct stat_info stat;
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 u_char rdstate[4];
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
58 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
59 int nument, i, rc;
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
61 if (validate_ffs_pathname(argv[1]) < 0)
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
62 return(ERROR_USAGE); /* err msg already printed */
283
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 rc = do_xlstat(argv[1], &stat);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 if (rc)
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 return(rc);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 if (stat.type != OT_DIR) {
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 ll_print_line(argv[1], &stat);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 return(0);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 }
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 rc = do_opendir(argv[1], rdstate, &nument);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 if (rc)
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 return(rc);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 if (!nument) {
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 printf("<empty dir>\n");
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 return(0);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 }
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
77 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
78 if (!childp) {
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
79 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
80 return(ERROR_TARGET);
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
81 }
283
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 for (i = 0; i < nument; i++) {
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
83 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
84 if (rc)
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 return(rc);
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
86 if (index(rdbuf, '/')) {
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
87 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
88 return(ERROR_TARGET);
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
89 }
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
90 strcpy(childp, rdbuf);
283
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 rc = do_xlstat(childpath, &stat);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 if (rc) {
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93 printf("xlstat failed on %s\n", childpath);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94 return(rc);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95 }
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
96 ll_print_line(childpath, &stat);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
97 }
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98 return(0);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
99 }
284
7b4d4e3e610a fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 283
diff changeset
100
285
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
101 void
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
102 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
103 u_char *buf;
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
104 {
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
105 int i, c;
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
106
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
107 printf("%02X: ", offset);
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
108 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
109 if (i < len)
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
110 printf("%02X ", buf[i]);
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
111 else
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
112 fputs(" ", stdout);
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
113 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
114 putchar(' ');
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
115 }
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
116 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
117 c = buf[i];
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
118 if (c < ' ' || c > '~')
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
119 c = '.';
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
120 putchar(c);
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
121 }
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
122 putchar('\n');
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
123 }
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
124
284
7b4d4e3e610a fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 283
diff changeset
125 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
126 char **argv;
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 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
129 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
130
285
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
131 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
132 if (rc)
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
133 return(rc);
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
134 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
135 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
136 l = sz - off;
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
137 if (l > 16)
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
138 l = 16;
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
139 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
140 }
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
141 return(0);
284
7b4d4e3e610a fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 283
diff changeset
142 }
287
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 cpout_object(ffspath, hostpath)
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
145 char *ffspath, *hostpath;
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 struct stat_info stat;
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
148 int rc;
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
149
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
150 rc = do_xlstat(ffspath, &stat);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
151 if (rc)
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
152 return(rc);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
153 switch (stat.type) {
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
154 case OT_FILE:
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
155 return cpout_file(ffspath, hostpath);
287
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
156 case OT_DIR:
288
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
157 return cpout_dir(ffspath, hostpath);
287
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
158 case OT_LINK:
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
159 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
160 return(0);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
161 default:
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
162 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
163 return(ERROR_TARGET);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
164 }
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
165 }
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
166
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
167 cpout_file(ffspath, hostpath)
287
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
168 char *ffspath, *hostpath;
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
169 {
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
170 int tfd;
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
171 FILE *of;
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
172 u_char buf[MAX_READ_DATA];
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
173 int rc, sz;
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
174
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
175 printf("copying %s\n", ffspath);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
176 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
177 if (rc)
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
178 return(rc);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
179 of = fopen(hostpath, "w");
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
180 if (!of) {
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
181 perror(hostpath);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
182 fd_close(tfd);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
183 return(ERROR_UNIX);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
184 }
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
185 for (;;) {
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
186 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
187 if (rc) {
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
188 fd_close(tfd);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
189 fclose(of);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
190 return(rc);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
191 }
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
192 if (!sz)
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
193 break;
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
194 fwrite(buf, 1, sz, of);
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 fclose(of);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
197 return fd_close(tfd);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
198 }
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
199
288
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
200 host_mkdir(pathname)
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
201 char *pathname;
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 int rc;
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
204 struct stat st;
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
205
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
206 rc = stat(pathname, &st);
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
207 if (rc < 0) {
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
208 rc = mkdir(pathname, 0777);
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
209 if (rc < 0) {
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
210 perror(pathname);
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
211 return(ERROR_UNIX);
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
212 }
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 if (S_ISDIR(st.st_mode))
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
216 return(0);
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
217 else {
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
218 fprintf(stderr,
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
219 "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
220 pathname);
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
221 return(ERROR_UNIX);
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 }
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
224 }
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 cpout_dir(ffspath_dir, hostpath_dir)
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
227 char *ffspath_dir, *hostpath_dir;
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
228 {
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
229 u_char rdstate[4];
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
230 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
231 char *childp;
288
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
232 char hostpath_child[MAXPATHLEN];
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
233 int nument, i, rc, childerr;
288
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
234
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
235 printf("dir %s\n", ffspath_dir);
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
236 rc = host_mkdir(hostpath_dir);
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);
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
239 rc = do_opendir(ffspath_dir, rdstate, &nument);
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
240 if (rc)
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
241 return(rc);
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
242 if (!nument)
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
243 return(0);
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
244 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
245 if (!childp) {
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
246 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
247 return(ERROR_TARGET);
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
248 }
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
249 childerr = 0;
288
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
250 for (i = 0; i < nument; i++) {
296
792f164b63a6 fc-fsio: cpout now works the way it should
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 295
diff changeset
251 rc = do_readdir(rdstate, rdbuf, MAX_FN_COMPONENT+1);
288
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
252 if (rc)
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
253 return(rc);
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
254 if (index(rdbuf, '/')) {
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
255 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
256 return(ERROR_TARGET);
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
257 }
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
258 strcpy(childp, rdbuf);
288
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
259 if (rdbuf[0] == '.') {
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
260 printf("skipping %s\n", ffspath_child);
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
261 continue;
288
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
262 }
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
263 if (strlen(hostpath_dir) + strlen(rdbuf) + 2 >
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
264 sizeof hostpath_child) {
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
265 fprintf(stderr,
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
266 "error: host side pathname buffer overflow\n");
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
267 return(ERROR_UNIX);
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
268 }
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
269 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
270 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
271 if (rc && rc != ERROR_TARGET)
288
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
272 return(rc);
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
273 if (rc)
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
274 childerr = rc;
288
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
275 }
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
276 return(childerr);
288
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
277 }
e33d71e9033f fc-fsio: cpout directory recursion implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 287
diff changeset
278
287
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
279 cmd_cpout(argc, argv)
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
280 char **argv;
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
281 {
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
282 if (validate_ffs_pathname(argv[1]) < 0)
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
283 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
284 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
285 }
295
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 cmd_cpout_file(argc, argv)
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
288 char **argv;
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
289 {
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
290 return cpout_file(argv[1], argv[2]);
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 288
diff changeset
291 }