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>
28 #include <atalk/adouble.h>
29 #include <atalk/cnid.h>
30 #include <atalk/cnid_dbd_private.h>
31 #include <atalk/volinfo.h>
32 #include <atalk/bstrlib.h>
33 #include <atalk/bstradd.h>
34 #include <atalk/directory.h>
35 #include <atalk/util.h>
38 static volatile sig_atomic_t alarmed;
42 catch SIGINT and SIGTERM which cause clean exit. Ignore anything else.
45 static void sig_handler(int signo)
51 static void set_signal(void)
55 sv.sa_handler = sig_handler;
56 sv.sa_flags = SA_RESTART;
57 sigemptyset(&sv.sa_mask);
58 if (sigaction(SIGTERM, &sv, NULL) < 0)
59 ERROR("error in sigaction(SIGTERM): %s", strerror(errno));
61 if (sigaction(SIGINT, &sv, NULL) < 0)
62 ERROR("error in sigaction(SIGINT): %s", strerror(errno));
64 memset(&sv, 0, sizeof(struct sigaction));
65 sv.sa_handler = SIG_IGN;
66 sigemptyset(&sv.sa_mask);
68 if (sigaction(SIGABRT, &sv, NULL) < 0)
69 ERROR("error in sigaction(SIGABRT): %s", strerror(errno));
71 if (sigaction(SIGHUP, &sv, NULL) < 0)
72 ERROR("error in sigaction(SIGHUP): %s", strerror(errno));
74 if (sigaction(SIGQUIT, &sv, NULL) < 0)
75 ERROR("error in sigaction(SIGQUIT): %s", strerror(errno));
78 static void usage_find(void)
81 "Usage: ad find [-v VOLUME_PATH] NAME\n"
85 int ad_find(int argc, char **argv)
89 const char *srchvol = getcwdpath();
91 while ((c = getopt(argc-1, &argv[1], ":v:")) != -1) {
94 srchvol = strdup(optarg);
106 if ((argc - optind) != 1) {
114 if (openvol(srchvol, &vol) != 0)
115 ERROR("Cant open volume \"%s\"", srchvol);
118 char resbuf[DBD_MAX_SRCH_RSLTS * sizeof(cnid_t)];
119 if ((count = cnid_find(vol.volume.v_cdb, argv[optind], strlen(argv[optind]), resbuf, sizeof(resbuf))) < 1) {
125 bstring sep = bfromcstr("/");
127 memcpy(&cnid, bufp, sizeof(cnid_t));
128 bufp += sizeof(cnid_t);
131 bstring volpath = bfromcstr(vol.volinfo.v_path);
132 BSTRING_STRIP_SLASH(volpath);
133 char buffer[12 + MAXPATHLEN + 1];
134 int buflen = 12 + MAXPATHLEN + 1;
137 struct bstrList *pathlist = bstrListCreateMin(32);
139 while (did != DIRDID_ROOT) {
140 if ((name = cnid_resolve(vol.volume.v_cdb, &did, buffer, buflen)) == NULL)
142 bstrListPush(pathlist, bfromcstr(name));
144 bstrListPush(pathlist, volpath);
145 path = bjoinInv(pathlist, sep);
147 printf("%s\n", cfrombstr(path));
150 bstrListDestroy(pathlist);