comparison rvinterf/etmsync/symlink.c @ 303:61c68a55f2a2

fc-fsio: readlink implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 02 Mar 2014 04:48:33 +0000
parents cd5068cf0551
children e0ca3ca46a06
comparison
equal deleted inserted replaced
302:cd5068cf0551 303:61c68a55f2a2
61 cmd_symlink(argc, argv) 61 cmd_symlink(argc, argv)
62 char **argv; 62 char **argv;
63 { 63 {
64 return do_symlink(argv[1], argv[2]); 64 return do_symlink(argv[1], argv[2]);
65 } 65 }
66
67 do_readlink(pathname, databuf, rdret)
68 char *pathname;
69 u_char *databuf;
70 int *rdret;
71 {
72 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
73 int rc, slen, sz;
74
75 slen = strlen(pathname);
76 if (slen >= TMFFS_STRING_SIZE) {
77 printf("error: pathname arg exceeds string length limit\n");
78 return(ERROR_USAGE);
79 }
80 dp = cmdpkt + 1;
81 *dp++ = ETM_FFS2;
82 *dp++ = TMFFS_READLINK;
83 *dp++ = slen + 1;
84 strcpy(dp, pathname);
85 dp += slen + 1;
86 *dp++ = 0; /* dummy 2nd buffer */
87 rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1);
88 if (rc)
89 return(rc);
90 if (rvi_msg[3]) {
91 report_ffs_err("readlink", rvi_msg[3]);
92 return(ERROR_TARGET);
93 }
94 if (rvi_msg_len < 6) {
95 *rdret = 0;
96 return(0);
97 }
98 sz = rvi_msg[4];
99 if (rvi_msg_len != sz + 6) {
100 printf("error: readlink response has wrong length\n");
101 return(ERROR_TARGET);
102 }
103 bcopy(rvi_msg + 5, databuf, sz);
104 *rdret = sz;
105 return(0);
106 }
107
108 cmd_readlink(argc, argv)
109 char **argv;
110 {
111 u_char databuf[256];
112 int rc, sz, off, l;
113
114 rc = do_readlink(argv[1], databuf, &sz);
115 if (rc)
116 return(rc);
117 printf("%d bytes read\n", sz);
118 for (off = 0; off < sz; off += 16) {
119 l = sz - off;
120 if (l > 16)
121 l = 16;
122 hexdump_line(off, databuf + off, l);
123 }
124 return(0);
125 }