2 * $Id: adv1tov2.c,v 1.5 2009-10-14 01:38:28 didg Exp $
3 * v1tov2: given a root directory, run down and convert all the
4 * files/directories into appledouble v2.
9 #endif /* HAVE_CONFIG_H */
11 #include <atalk/adouble.h>
17 #endif /* HAVE_FCNTL_H */
20 #endif /* HAVE_UNISTD_H */
22 #include <sys/types.h>
24 #include <sys/param.h>
28 #include <atalk/util.h>
30 #if AD_VERSION == AD_VERSION2
32 /* translate characters */
33 static void xlate(char *name, int flags) {
34 static const char hexdig[] = "0123456789abcdef";
35 char upath[MAXPATHLEN + 1];
42 if (isascii(*m) && !isprint(*m)) {
45 *u++ = hexdig[(*m & 0xf0) >> 4];
46 *u++ = hexdig[*m & 0x0f];
55 if ((flags & ADFLAGS_DIR) == 0)
56 rename(ad_path(name, flags), ad_path(upath, flags)); /* rename rfork */
61 #define MAXDESCEND 0xFFFF
62 /* recursively descend subdirectories.
63 * oh the stack space we use up! */
64 static void descend(DIR *dp)
73 ad_init(&ad, AD_VERSION2, 0);
74 if (count++ > MAXDESCEND) {
75 fprintf(stderr, "FAILURE: too many subdirectories! possible infinite recursion.");
80 for (de = readdir(dp); de; de = readdir(dp)) {
81 if (de->d_name[0] == '.')
84 if (stat(de->d_name, &st) < 0) {
85 fprintf(stderr, "FAILURE: can't stat %s\n", de->d_name);
89 /* go down subdirectory */
91 if (S_ISDIR(st.st_mode) && (dpnew = opendir(de->d_name))) {
99 if (ad_open(de->d_name, flags, O_RDWR, 0, &ad) < 0) {
101 fprintf(stderr, "\nFAILURE: can't convert %s, %s\n", fullpathname(de->d_name), strerror(errno));
104 ad_close(&ad, ADFLAGS_HF);
111 int main(int argc, char **argv)
116 ad_init(&ad, AD_VERSION2, 0);
118 fprintf(stderr, "%s <directory>\n", *argv);
122 /* convert main directory */
123 if (ad_open(argv[1], ADFLAGS_HF | ADFLAGS_DIR, O_RDWR, 0,
125 fprintf(stderr, "FAILURE: can't convert %s\n", argv[1]);
129 ad_close(&ad, ADFLAGS_HF);
130 if ((dp = opendir(argv[1])) == NULL) {
131 fprintf(stderr, "%s: unable to open %s\n", *argv, argv[1]);
144 #else /* AD_VERSION == AD_VERSION2 */
145 int main(int argc, char **argv)
147 fprintf(stderr, "%s not built for v2 AppleDouble files.\n", *argv);
150 #endif /* AD_VERSION == AD_VERSION2 */