FreeCalypso > hg > freecalypso-sw
annotate rvinterf/etmsync/fsbasics.c @ 955:d7830aee0d35
c139-lldbg hack concocted
author | Mychaela Falconia <falcon@ivan.Harhan.ORG> |
---|---|
date | Wed, 04 Nov 2015 20:34:12 +0000 |
parents | d1333db6385f |
children |
rev | line source |
---|---|
278
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * Basic FFS2 operations |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 */ |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <sys/types.h> |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <stdio.h> |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <stdlib.h> |
279
36ad667341fc
fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
278
diff
changeset
|
8 #include <string.h> |
36ad667341fc
fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
278
diff
changeset
|
9 #include <strings.h> |
278
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include "etm.h" |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include "ffs.h" |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 #include "tmffs2.h" |
279
36ad667341fc
fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
278
diff
changeset
|
13 #include "limits.h" |
295
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
14 #include "ffslimits.h" |
282
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
15 #include "localtypes.h" |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
16 #include "localstruct.h" |
278
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 #include "exitcodes.h" |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 extern u_char rvi_msg[]; |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 extern int rvi_msg_len; |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 cmd_ffs2ver() |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 { |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 u_char cmdpkt[4]; |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 int rc; |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 cmdpkt[1] = ETM_FFS2; |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 cmdpkt[2] = TMFFS_VERSION; |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 rc = etm_pkt_exch(cmdpkt, 2); |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 if (rc) |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 return(rc); |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 if (rvi_msg[3]) { |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 printf("FFS2 error %d\n", rvi_msg[3]); |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 return(ERROR_TARGET); |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 } |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 if (rvi_msg_len != 7) { |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 printf("error: FFS2 version response has wrong length\n"); |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 return(ERROR_TARGET); |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 } |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 printf("FFS2 version: %02X.%02X\n", rvi_msg[5], rvi_msg[4]); |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 return(0); |
f77480d3dd21
fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 } |
279
36ad667341fc
fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
278
diff
changeset
|
43 |
36ad667341fc
fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
278
diff
changeset
|
44 cmd_ls(argc, argv) |
36ad667341fc
fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
278
diff
changeset
|
45 char **argv; |
36ad667341fc
fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
278
diff
changeset
|
46 { |
36ad667341fc
fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
278
diff
changeset
|
47 u_char state[4]; |
295
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
48 char namebuf[256]; |
279
36ad667341fc
fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
278
diff
changeset
|
49 int nument, i, rc; |
36ad667341fc
fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
278
diff
changeset
|
50 |
36ad667341fc
fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
278
diff
changeset
|
51 rc = do_opendir(argv[1], state, &nument); |
36ad667341fc
fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
278
diff
changeset
|
52 if (rc) |
36ad667341fc
fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
278
diff
changeset
|
53 return(rc); |
36ad667341fc
fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
278
diff
changeset
|
54 if (!nument) { |
36ad667341fc
fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
278
diff
changeset
|
55 printf("<empty dir>\n"); |
36ad667341fc
fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
278
diff
changeset
|
56 return(0); |
36ad667341fc
fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
278
diff
changeset
|
57 } |
36ad667341fc
fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
278
diff
changeset
|
58 for (i = 0; i < nument; i++) { |
295
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
59 rc = do_readdir(state, namebuf, sizeof namebuf); |
279
36ad667341fc
fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
278
diff
changeset
|
60 if (rc) |
36ad667341fc
fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
278
diff
changeset
|
61 return(rc); |
36ad667341fc
fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
278
diff
changeset
|
62 printf("%s\n", namebuf); |
36ad667341fc
fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
278
diff
changeset
|
63 } |
36ad667341fc
fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
278
diff
changeset
|
64 return(0); |
36ad667341fc
fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
278
diff
changeset
|
65 } |
282
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
66 |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
67 cmd_stat(argc, argv) |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
68 char **argv; |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
69 { |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
70 struct stat_info stat; |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
71 int rc; |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
72 char *type; |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
73 |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
74 rc = do_xlstat(argv[1], &stat); |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
75 if (rc) |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
76 return(rc); |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
77 switch (stat.type) { |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
78 case OT_FILE: |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
79 type = "file"; |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
80 break; |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
81 case OT_DIR: |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
82 type = "directory"; |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
83 break; |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
84 case OT_LINK: |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
85 type = "symlink"; |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
86 break; |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
87 default: |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
88 type = "???"; |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
89 } |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
90 printf("Type: %s%s\n", type, |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
91 stat.flags & OF_READONLY ? ", read-only" : ""); |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
92 printf("inode %x\n", stat.inode); |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
93 printf("size %u, space %u\n", stat.size, stat.space); |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
94 printf("location=%x, block %d\n", stat.location, stat.block); |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
95 return(0); |
517e8a428fde
fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
279
diff
changeset
|
96 } |