FreeCalypso > hg > freecalypso-sw
annotate 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 | 
| 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 } | 
