comparison rvinterf/etmsync/fsbasics.c @ 0:e7502631a0f9

initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Jun 2016 00:13:35 +0000
parents
children 46ad66a231af
comparison
equal deleted inserted replaced
-1:000000000000 0:e7502631a0f9
1 /*
2 * Basic FFS2 operations
3 */
4
5 #include <sys/types.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <strings.h>
10 #include "etm.h"
11 #include "ffs.h"
12 #include "tmffs2.h"
13 #include "limits.h"
14 #include "ffslimits.h"
15 #include "localtypes.h"
16 #include "localstruct.h"
17 #include "exitcodes.h"
18
19 extern u_char rvi_msg[];
20 extern int rvi_msg_len;
21
22 cmd_ffs2ver()
23 {
24 u_char cmdpkt[4];
25 int rc;
26
27 cmdpkt[1] = ETM_FFS2;
28 cmdpkt[2] = TMFFS_VERSION;
29 rc = etm_pkt_exch(cmdpkt, 2);
30 if (rc)
31 return(rc);
32 if (rvi_msg[3]) {
33 printf("FFS2 error %d\n", rvi_msg[3]);
34 return(ERROR_TARGET);
35 }
36 if (rvi_msg_len != 7) {
37 printf("error: FFS2 version response has wrong length\n");
38 return(ERROR_TARGET);
39 }
40 printf("FFS2 version: %02X.%02X\n", rvi_msg[5], rvi_msg[4]);
41 return(0);
42 }
43
44 cmd_ls(argc, argv)
45 char **argv;
46 {
47 u_char state[4];
48 char namebuf[256];
49 int nument, i, rc;
50
51 rc = do_opendir(argv[1], state, &nument);
52 if (rc)
53 return(rc);
54 if (!nument) {
55 printf("<empty dir>\n");
56 return(0);
57 }
58 for (i = 0; i < nument; i++) {
59 rc = do_readdir(state, namebuf, sizeof namebuf);
60 if (rc)
61 return(rc);
62 printf("%s\n", namebuf);
63 }
64 return(0);
65 }
66
67 cmd_stat(argc, argv)
68 char **argv;
69 {
70 struct stat_info stat;
71 int rc;
72 char *type;
73
74 rc = do_xlstat(argv[1], &stat);
75 if (rc)
76 return(rc);
77 switch (stat.type) {
78 case OT_FILE:
79 type = "file";
80 break;
81 case OT_DIR:
82 type = "directory";
83 break;
84 case OT_LINK:
85 type = "symlink";
86 break;
87 default:
88 type = "???";
89 }
90 printf("Type: %s%s\n", type,
91 stat.flags & OF_READONLY ? ", read-only" : "");
92 printf("inode %x\n", stat.inode);
93 printf("size %u, space %u\n", stat.size, stat.space);
94 printf("location=%x, block %d\n", stat.location, stat.block);
95 return(0);
96 }