annotate rvinterf/etmsync/fsread.c @ 287:211b35db427c

fc-fsio: cpout of single files implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 28 Feb 2014 08:22:50 +0000
parents bb28ba9e82c5
children e33d71e9033f
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>
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <stdio.h>
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdlib.h>
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <string.h>
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <strings.h>
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include "etm.h"
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include "ffs.h"
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include "tmffs2.h"
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 #include "limits.h"
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 #include "localtypes.h"
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 #include "localstruct.h"
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 #include "exitcodes.h"
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 void
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 ll_print_line(pathname, stat)
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 char *pathname;
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 struct stat_info *stat;
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 {
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 char readonly;
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 if (stat->flags & OF_READONLY)
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 readonly = 'r';
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 else
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 readonly = ' ';
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 switch (stat->type) {
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 case OT_FILE:
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 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
32 return;
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 case OT_DIR:
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 printf("d%c %s\n", readonly, pathname);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 return;
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 case OT_LINK:
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 printf("l%c %s\n", readonly, 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 default:
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 printf("?%c %s\n", readonly, pathname);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 }
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 }
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 void
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 mk_ffs_child_path_from_readdir(dirpath, rdname, buf)
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 char *dirpath, *rdname, *buf;
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 char *tailp;
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 tailp = index(dirpath, '\0') - 1;
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 if (*tailp == '/')
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 sprintf(buf, "%s%s", dirpath, rdname);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 else
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 sprintf(buf, "%s/%s", dirpath, rdname);
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
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 cmd_ll(argc, argv)
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 char **argv;
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 {
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 struct stat_info stat;
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 u_char rdstate[4];
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 char rdbuf[TMFFS_STRING_SIZE], childpath[TMFFS_STRING_SIZE*2];
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 int nument, i, rc;
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 rc = do_xlstat(argv[1], &stat);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 if (rc)
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 return(rc);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 if (stat.type != OT_DIR) {
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 ll_print_line(argv[1], &stat);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 return(0);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 }
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 rc = do_opendir(argv[1], rdstate, &nument);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 if (rc)
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 return(rc);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 if (!nument) {
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 printf("<empty dir>\n");
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 return(0);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 }
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 for (i = 0; i < nument; i++) {
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 rc = do_readdir(rdstate, rdbuf);
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);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 mk_ffs_child_path_from_readdir(argv[1], rdbuf, childpath);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 rc = do_xlstat(childpath, &stat);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 if (rc) {
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 printf("xlstat failed on %s\n", childpath);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 return(rc);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 }
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 ll_print_line(childpath, &stat);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90 }
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 return(0);
88eed3327682 fc-fsio: ll command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 }
284
7b4d4e3e610a fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 283
diff changeset
93
285
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
94 void
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
95 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
96 u_char *buf;
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
97 {
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
98 int i, c;
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
99
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
100 printf("%02X: ", offset);
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
101 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
102 if (i < len)
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
103 printf("%02X ", buf[i]);
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
104 else
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
105 fputs(" ", stdout);
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
106 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
107 putchar(' ');
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
108 }
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
109 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
110 c = buf[i];
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
111 if (c < ' ' || c > '~')
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
112 c = '.';
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
113 putchar(c);
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
114 }
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
115 putchar('\n');
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
116 }
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
117
284
7b4d4e3e610a fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 283
diff changeset
118 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
119 char **argv;
7b4d4e3e610a fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 283
diff changeset
120 {
285
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
121 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
122 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
123
285
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
124 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
125 if (rc)
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
126 return(rc);
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
127 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
128 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
129 l = sz - off;
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
130 if (l > 16)
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
131 l = 16;
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
132 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
133 }
bb28ba9e82c5 fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 284
diff changeset
134 return(0);
284
7b4d4e3e610a fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 283
diff changeset
135 }
287
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
136
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
137 cpout_object(ffspath, hostpath)
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
138 char *ffspath, *hostpath;
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
139 {
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
140 struct stat_info stat;
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
141 int rc;
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
142
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
143 rc = do_xlstat(ffspath, &stat);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
144 if (rc)
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
145 return(rc);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
146 switch (stat.type) {
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
147 case OT_FILE:
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
148 return cpout_file(ffspath, &stat, hostpath);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
149 case OT_DIR:
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
150 printf("cpout dir handling not yet implemented\n");
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
151 return(ERROR_BUG);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
152 case OT_LINK:
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
153 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
154 return(0);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
155 default:
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
156 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
157 return(ERROR_TARGET);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
158 }
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
159 }
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
160
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
161 cpout_file(ffspath, stat, hostpath)
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
162 char *ffspath, *hostpath;
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
163 struct stat_info *stat;
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 int tfd;
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
166 FILE *of;
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
167 u_char buf[MAX_READ_DATA];
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
168 int rc, sz;
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 printf("copying %s\n", ffspath);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
171 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
172 if (rc)
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
173 return(rc);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
174 of = fopen(hostpath, "w");
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
175 if (!of) {
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
176 perror(hostpath);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
177 fd_close(tfd);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
178 return(ERROR_UNIX);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
179 }
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
180 for (;;) {
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
181 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
182 if (rc) {
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
183 fd_close(tfd);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
184 fclose(of);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
185 return(rc);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
186 }
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
187 if (!sz)
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
188 break;
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
189 fwrite(buf, 1, sz, of);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
190 }
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
191 fclose(of);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
192 return fd_close(tfd);
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
193 }
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
194
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
195 cmd_cpout(argc, argv)
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
196 char **argv;
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
197 {
211b35db427c fc-fsio: cpout of single files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 285
diff changeset
198 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
199 }