comparison rvinterf/etmsync/fsread.c @ 283:88eed3327682

fc-fsio: ll command implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 28 Feb 2014 04:54:47 +0000
parents
children 7b4d4e3e610a
comparison
equal deleted inserted replaced
282:517e8a428fde 283:88eed3327682
1 /*
2 * Commands for reading the content of a GSM device's file system
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 "localtypes.h"
15 #include "localstruct.h"
16 #include "exitcodes.h"
17
18 void
19 ll_print_line(pathname, stat)
20 char *pathname;
21 struct stat_info *stat;
22 {
23 char readonly;
24
25 if (stat->flags & OF_READONLY)
26 readonly = 'r';
27 else
28 readonly = ' ';
29 switch (stat->type) {
30 case OT_FILE:
31 printf("f%c %7u %s\n", readonly, stat->size, pathname);
32 return;
33 case OT_DIR:
34 printf("d%c %s\n", readonly, pathname);
35 return;
36 case OT_LINK:
37 printf("l%c %s\n", readonly, pathname);
38 return;
39 default:
40 printf("?%c %s\n", readonly, pathname);
41 }
42 }
43
44 void
45 mk_ffs_child_path_from_readdir(dirpath, rdname, buf)
46 char *dirpath, *rdname, *buf;
47 {
48 char *tailp;
49
50 tailp = index(dirpath, '\0') - 1;
51 if (*tailp == '/')
52 sprintf(buf, "%s%s", dirpath, rdname);
53 else
54 sprintf(buf, "%s/%s", dirpath, rdname);
55 }
56
57 cmd_ll(argc, argv)
58 char **argv;
59 {
60 struct stat_info stat;
61 u_char rdstate[4];
62 char rdbuf[TMFFS_STRING_SIZE], childpath[TMFFS_STRING_SIZE*2];
63 int nument, i, rc;
64
65 rc = do_xlstat(argv[1], &stat);
66 if (rc)
67 return(rc);
68 if (stat.type != OT_DIR) {
69 ll_print_line(argv[1], &stat);
70 return(0);
71 }
72 rc = do_opendir(argv[1], rdstate, &nument);
73 if (rc)
74 return(rc);
75 if (!nument) {
76 printf("<empty dir>\n");
77 return(0);
78 }
79 for (i = 0; i < nument; i++) {
80 rc = do_readdir(rdstate, rdbuf);
81 if (rc)
82 return(rc);
83 mk_ffs_child_path_from_readdir(argv[1], rdbuf, childpath);
84 rc = do_xlstat(childpath, &stat);
85 if (rc) {
86 printf("xlstat failed on %s\n", childpath);
87 return(rc);
88 }
89 ll_print_line(childpath, &stat);
90 }
91 return(0);
92 }