FreeCalypso > hg > freecalypso-sw
annotate rvinterf/etmsync/symlink.c @ 302:cd5068cf0551
fc-fsio: symlink command implemented
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sun, 02 Mar 2014 04:34:49 +0000 |
parents | |
children | 61c68a55f2a2 |
rev | line source |
---|---|
302
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * Commands for experimenting with FFS symlinks |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 */ |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <sys/types.h> |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <stdio.h> |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <stdlib.h> |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <string.h> |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <strings.h> |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include "etm.h" |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include "ffs.h" |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 #include "tmffs2.h" |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 #include "limits.h" |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 #include "ffslimits.h" |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 #include "localtypes.h" |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 #include "localstruct.h" |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 #include "exitcodes.h" |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 extern u_char rvi_msg[]; |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 extern int rvi_msg_len; |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 do_symlink(target, realobj) |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 char *target, *realobj; |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 { |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 int rc, targlen, reallen; |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 reallen = strlen(realobj); |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 if (reallen >= TMFFS_STRING_SIZE) { |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 printf("error: pathname arg exceeds string length limit\n"); |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 return(ERROR_USAGE); |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 } |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 targlen = strlen(target); |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 if (3 + (reallen+2) + (targlen+2) + 1 > MAX_PKT_TO_TARGET) { |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 printf("error: symlink request fails to fit into packet\n"); |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 return(ERROR_USAGE); |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 } |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 dp = cmdpkt + 1; |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 *dp++ = ETM_FFS2; |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 *dp++ = TMFFS_SYMLINK; |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 *dp++ = reallen + 1; |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 strcpy(dp, realobj); |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 dp += reallen + 1; |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 *dp++ = targlen + 1; |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 strcpy(dp, target); |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 dp += targlen + 1; |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1); |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 if (rc) |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 return(rc); |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 if (rvi_msg_len != 5) { |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 printf("error: TMFFS_SYMLINK response has wrong length\n"); |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 return(ERROR_TARGET); |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 } |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 if (rvi_msg[3]) { |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 report_ffs_err("symlink", rvi_msg[3]); |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 return(ERROR_TARGET); |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 } |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 return(0); |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 } |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 cmd_symlink(argc, argv) |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 char **argv; |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 { |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 return do_symlink(argv[1], argv[2]); |
cd5068cf0551
fc-fsio: symlink command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 } |