2 Copyright (c) 2010 Frank Lahm <franklahm@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
17 #endif /* HAVE_CONFIG_H */
20 #include <sys/types.h>
34 #include <atalk/adouble.h>
35 #include <atalk/cnid.h>
36 #include <atalk/cnid_dbd_private.h>
37 #include <atalk/volinfo.h>
38 #include <atalk/bstrlib.h>
39 #include <atalk/bstradd.h>
40 #include <atalk/directory.h>
43 static volatile sig_atomic_t alarmed;
47 catch SIGINT and SIGTERM which cause clean exit. Ignore anything else.
50 static void sig_handler(int signo)
56 static void set_signal(void)
60 sv.sa_handler = sig_handler;
61 sv.sa_flags = SA_RESTART;
62 sigemptyset(&sv.sa_mask);
63 if (sigaction(SIGTERM, &sv, NULL) < 0)
64 ERROR("error in sigaction(SIGTERM): %s", strerror(errno));
66 if (sigaction(SIGINT, &sv, NULL) < 0)
67 ERROR("error in sigaction(SIGINT): %s", strerror(errno));
69 memset(&sv, 0, sizeof(struct sigaction));
70 sv.sa_handler = SIG_IGN;
71 sigemptyset(&sv.sa_mask);
73 if (sigaction(SIGABRT, &sv, NULL) < 0)
74 ERROR("error in sigaction(SIGABRT): %s", strerror(errno));
76 if (sigaction(SIGHUP, &sv, NULL) < 0)
77 ERROR("error in sigaction(SIGHUP): %s", strerror(errno));
79 if (sigaction(SIGQUIT, &sv, NULL) < 0)
80 ERROR("error in sigaction(SIGQUIT): %s", strerror(errno));
83 static void usage_find(void)
86 "Usage: ad find VOLUME_PATH NAME\n"
90 int ad_find(int argc, char **argv)
103 if (openvol(argv[2], &vol) != 0)
104 ERROR("Cant open volume \"%s\"", argv[2]);
107 char resbuf[DBD_MAX_SRCH_RSLTS * sizeof(cnid_t)];
108 if ((count = cnid_find(vol.volume.v_cdb, argv[3], strlen(argv[3]), resbuf, sizeof(resbuf))) < 1) {
113 bstring sep = bfromcstr("/");
115 memcpy(&cnid, bufp, sizeof(cnid_t));
116 bufp += sizeof(cnid_t);
119 bstring volpath = bfromcstr(vol.volinfo.v_path);
120 BSTRING_STRIP_SLASH(volpath);
121 char buffer[12 + MAXPATHLEN + 1];
122 int buflen = 12 + MAXPATHLEN + 1;
125 struct bstrList *pathlist = bstrListCreateMin(32);
127 while (did != DIRDID_ROOT) {
128 if ((name = cnid_resolve(vol.volume.v_cdb, &did, buffer, buflen)) == NULL)
129 ERROR("Can't resolve CNID: %u", ntohl(did));
130 bstrListPush(pathlist, bfromcstr(name));
132 bstrListPush(pathlist, volpath);
133 path = bjoinInv(pathlist, sep);
134 bstrListDestroy(pathlist);
136 printf("%s\n", cfrombstr(path));