annotate rvinterf/etmsync/cleandir.c @ 833:625bee54ed34

CHANGES: document lunadrv init-kwh addition
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 22 Jun 2021 02:28:18 +0000
parents e6fe9d25377a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
594
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * The implementation of cleandir and rm-subtree commands lives here.
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdlib.h>
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <string.h>
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <strings.h>
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "etm.h"
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "ffs.h"
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "tmffs2.h"
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "limits.h"
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "ffslimits.h"
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include "localtypes.h"
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include "localstruct.h"
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include "exitcodes.h"
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 extern char *pathname_for_ffs_child();
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 cleandir_level(ffspath_dir)
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 char *ffspath_dir;
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 {
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 u_char rdstate[4];
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 char rdbuf[MAX_FN_COMPONENT+1], ffspath_child[MAX_FULL_PATHNAME+1];
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 char *childp;
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 int nument, i, rc;
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 struct stat_info stat;
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 rc = do_opendir(ffspath_dir, rdstate, &nument);
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 if (rc)
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 return(rc);
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 if (!nument)
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 return(0);
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 childp = pathname_for_ffs_child(ffspath_dir, ffspath_child);
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 if (!childp) {
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 printf("error: non-empty dir at the limit of pathname depth\n");
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 return(ERROR_TARGET);
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 }
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 for (i = 0; i < nument; i++) {
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 rc = do_readdir(rdstate, rdbuf, MAX_FN_COMPONENT+1);
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 if (rc)
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 return(rc);
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 if (index(rdbuf, '/')) {
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 printf("error: readdir result contains a slash\n");
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 return(ERROR_TARGET);
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 }
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 strcpy(childp, rdbuf);
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 rc = do_xlstat(ffspath_child, &stat);
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 if (rc) {
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 printf("xlstat failed on %s\n", ffspath_child);
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 return(rc);
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 }
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 if (stat.type == OT_DIR) {
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 rc = cleandir_level(ffspath_child);
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 if (rc)
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 return(rc);
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 }
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 rc = do_ffs_remove(ffspath_child, 0);
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 if (rc)
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 return(rc);
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 }
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 return(0);
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 cmd_cleandir(argc, argv)
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 char **argv;
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 {
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 int rc;
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 rc = validate_ffs_pathname(argv[1]);
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 if (rc < 0)
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 return(ERROR_USAGE); /* err msg already printed */
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 if (rc == 0) {
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 fprintf(stderr, "error: cleandir / is not allowed\n");
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 return(ERROR_USAGE);
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 }
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 return cleandir_level(argv[1]);
2c75cf810146 fc-fsio: cleandir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 }
595
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
80
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
81 cmd_rm_subtree(argc, argv)
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
82 char **argv;
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
83 {
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
84 char *pathname;
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
85 int rc, minusf_mode, found;
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
86 struct stat_info stat;
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
87
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
88 if (argc == 2) {
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
89 pathname = argv[1];
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
90 minusf_mode = 0;
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
91 } else {
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
92 if (strcmp(argv[1], "-f")) {
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
93 fprintf(stderr,
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
94 "usage: rm-subtree [-f] ffs_pathname\n");
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
95 return(ERROR_USAGE);
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
96 }
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
97 pathname = argv[2];
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
98 minusf_mode = 1;
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
99 }
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
100 rc = validate_ffs_pathname(pathname);
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
101 if (rc < 0)
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
102 return(ERROR_USAGE); /* err msg already printed */
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
103 if (rc == 0) {
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
104 fprintf(stderr, "error: rm-subtree / is not allowed\n");
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
105 return(ERROR_USAGE);
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
106 }
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
107 if (minusf_mode) {
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
108 rc = do_xlstat_notfoundok(pathname, &found, &stat);
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
109 if (rc)
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
110 return(rc);
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
111 if (!found)
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
112 return(0);
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
113 } else {
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
114 rc = do_xlstat(pathname, &stat);
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
115 if (rc)
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
116 return(rc);
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
117 }
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
118 if (stat.type != OT_DIR) {
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
119 printf("error: %s exists and is not a directory\n", pathname);
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
120 return(ERROR_TARGET);
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
121 }
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
122 rc = cleandir_level(pathname);
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
123 if (rc)
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
124 return(rc);
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
125 return do_ffs_remove(pathname, 0);
e6fe9d25377a fc-fsio: rm-subtree command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 594
diff changeset
126 }