1 /* v1tov2: given a root directory, run down and convert all the
2 * files/directories into appledouble v2. */
14 #include <sys/types.h>
16 #include <sys/param.h>
18 #include <atalk/adouble.h>
20 #if AD_VERSION == AD_VERSION2
21 /* translate characters */
22 static int xlate(char *name, int flags) {
23 static const char hexdig[] = "0123456789abcdef";
24 char upath[MAXPATHLEN + 1];
31 if (isascii(*m) && !isprint(*m)) {
34 *u++ = hexdig[(*m & 0xf0) >> 4];
35 *u++ = hexdig[*m & 0x0f];
44 if ((flags & ADFLAGS_DIR) == 0)
45 rename(ad_path(name, flags), ad_path(upath, flags)); /* rename rfork */
50 #define MAXDESCEND 0xFFFF
51 /* recursively descend subdirectories.
52 * oh the stack space we use up! */
63 if (count++ > MAXDESCEND) {
64 fprintf(stderr, "FAILURE: too many subdirectories! possible infinite recursion.");
69 for (de = readdir(dp); de; de = readdir(dp)) {
70 if (de->d_name[0] == '.')
73 if (stat(de->d_name, &st) < 0) {
74 fprintf(stderr, "FAILURE: can't stat %s\n", de->d_name);
78 /* go down subdirectory */
80 if (S_ISDIR(st.st_mode) && (dpnew = opendir(de->d_name))) {
88 if (ad_open(de->d_name, flags, O_RDWR, 0, &ad) < 0) {
89 fprintf(stderr, "FAILURE: can't convert %s\n", de->d_name);
92 ad_close(&ad, ADFLAGS_HF);
93 xlate(de->d_name, flags);
100 int main(int argc, char **argv)
106 fprintf(stderr, "%s <directory>\n", *argv);
110 /* convert main directory */
111 if (ad_open(argv[1], ADFLAGS_HF | ADFLAGS_DIR, O_RDWR, 0,
113 fprintf(stderr, "FAILURE: can't convert %s\n", argv[1]);
117 ad_close(&ad, ADFLAGS_HF);
118 if ((dp = opendir(argv[1])) == NULL) {
119 fprintf(stderr, "%s: unable to open %s\n", *argv, argv[1]);
128 xlate(argv[1], ADFLAGS_HF | ADFLAGS_DIR);
134 int main(int argc, char **argv)
136 fprintf(stderr, "%s not built for v2 AppleDouble files.\n", *argv);