3 * Copyright (C) 1990, 1993 Regents of The University of Michigan
4 * All Rights Reserved. See COPYRIGHT
9 * This file contains FPCatSearch implementation. FPCatSearch performs
10 * file/directory search based on specified criteria. It is used by client
11 * to perform fast searches on (propably) big volumes. So, it has to be
14 * This implementation bypasses most of adouble/libatalk stuff as long as
15 * possible and does a standard filesystem search. It calls higher-level
16 * libatalk/afpd functions only when it is really needed, mainly while
17 * returning some non-UNIX information or filtering by non-UNIX criteria.
19 * Initial version written by Rafal Lewczuk <rlewczuk@pronet.pl>
25 #endif /* HAVE_CONFIG_H */
41 #define memcpy(d,s,n) bcopy ((s), (d), (n))
42 #define memmove(d,s,n) bcopy ((s), (d), (n))
43 #endif /* ! HAVE_MEMCPY */
46 #include <sys/types.h>
49 #include <netinet/in.h>
51 #include <netatalk/endian.h>
52 #include <atalk/afp.h>
53 #include <atalk/adouble.h>
54 #include <atalk/logger.h>
56 #include <atalk/cnid.h>
59 #include "directory.h"
70 u_int8_t attrs; /* File attributes (8 bits)*/
71 u_int8_t label; /* Label (8 bits)*/
72 char reserved[22]; /* Unknown (at least for now...) */
76 * 0x04 - has a custom icon
77 * 0x20 - name/icon is locked
91 /* This is our search-criteria structure. */
93 u_int32_t rbitmap; /* Request bitmap - which values should we check ? */
94 u_int16_t fbitmap, dbitmap; /* file & directory bitmap - which values should we return ? */
95 u_int16_t attr; /* File attributes */
96 time_t cdate; /* Creation date */
97 time_t mdate; /* Last modification date */
98 time_t bdate; /* Last backup date */
99 u_int32_t pdid; /* Parent DID */
100 u_int16_t offcnt; /* Offspring count */
101 struct finderinfo finfo; /* Finder info */
102 char lname[64]; /* Long name */
103 char utf8name[512]; /* UTF8 name */
107 * Directory tree search is recursive by its nature. But AFP specification
108 * requires FPCatSearch to pause after returning n results and be able to
109 * resume the search later. So we have to do recursive search using flat
110 * (iterative) algorithm and remember all directories to look into in an
111 * stack-like structure. The structure below is one item of directory stack.
115 char *m_name; /* Mac name */
116 char *u_name; /* unix name (== strrchr('/', path)) */
117 struct dir *dir; /* Structure describing this directory */
118 int pidx; /* Parent's dsitem structure index. */
119 int checked; /* Have we checked this directory ? */
120 char *path; /* absolute UNIX path to this directory */
125 static int cur_pos = 0; /* Saved position index (ID) - used to remember "position" across FPCatSearch calls */
126 static DIR *dirpos = NULL; /* UNIX structure describing currently opened directory. */
127 static int save_cidx = -1; /* Saved index of currently scanned directory. */
129 static struct dsitem *dstack = NULL; /* Directory stack data... */
130 static int dssize = 0; /* Directory stack (allocated) size... */
131 static int dsidx = 0; /* First free item index... */
133 static struct scrit c1, c2; /* search criteria */
135 /* Puts new item onto directory stack. */
136 static int addstack(char *uname, char *mname, struct dir *dir, int pidx)
141 /* check if we have some space on stack... */
142 if (dsidx >= dssize) {
144 dstack = realloc(dstack, dssize * sizeof(struct dsitem));
149 /* Put new element. Allocate and copy lname and path. */
150 ds = dstack + dsidx++;
151 if (!(ds->m_name = strdup(mname)))
156 l = strlen(dstack[pidx].path);
157 if (!(ds->path = malloc(l + strlen(uname) + 2) ))
159 strcpy(ds->path, dstack[pidx].path);
160 strcat(ds->path, "/");
161 strcat(ds->path, uname);
162 ds->u_name = ds->path +l +1;
170 /* Removes checked items from top of directory stack. Returns index of the first unchecked elements or -1. */
171 static int reducestack()
174 if (save_cidx != -1) {
181 if (dstack[dsidx-1].checked) {
183 free(dstack[dsidx].m_name);
184 free(dstack[dsidx].path);
185 /* Check if we need to free (or release) dir structures */
190 } /* reducestack() */
192 /* Clears directory stack. */
193 static void clearstack()
198 free(dstack[dsidx].m_name);
199 free(dstack[dsidx].path);
200 /* Check if we need to free (or release) dir structures */
204 /* Fills in dir field of dstack[cidx]. Must fill parent dirs' fields if needed... */
205 static int resolve_dir(struct vol *vol, int cidx)
207 struct dir *dir, *cdir;
209 if (dstack[cidx].dir != NULL)
212 if (dstack[cidx].pidx < 0)
215 if (dstack[dstack[cidx].pidx].dir == NULL && resolve_dir(vol, dstack[cidx].pidx) == 0)
218 cdir = dstack[dstack[cidx].pidx].dir;
221 if (strcmp(dir->d_m_name, dstack[cidx].m_name) == 0)
223 dir = (dir == cdir->d_child->d_prev) ? NULL : dir->d_next;
229 path.u_name = dstack[cidx].path;
230 if (of_stat(&path)==-1) {
231 syslog(LOG_DEBUG, "resolve_dir: stat %s: %s", dstack[cidx].path, strerror(errno));
234 path.m_name = dstack[cidx].m_name;
235 path.u_name = dstack[cidx].u_name;
236 /* adddir works with a filename not absolute pathname */
237 if ((dir = adddir(vol, cdir, &path)) == NULL)
240 dstack[cidx].dir = dir;
245 /* Looks up for an opened adouble structure, opens resource fork of selected file.
246 * FIXME What about noadouble?
248 static struct adouble *adl_lkup(struct vol *vol, struct path *path)
250 static struct adouble ad;
253 int isdir = S_ISDIR(path->st.st_mode);
255 if (!isdir && (of = of_findname(path))) {
258 ad_init(&ad, vol->v_adouble);
262 if ( ad_open( path->u_name, ADFLAGS_HF | ((isdir)?ADFLAGS_DIR:0), O_RDONLY, 0, adp) < 0 ) {
268 #define CATPBIT_PARTIAL 31
269 /* Criteria checker. This function returns a 2-bit value. */
270 /* bit 0 means if checked file meets given criteria. */
271 /* bit 1 means if it is a directory and we should descent into it. */
273 * fname - our fname (translated to UNIX)
274 * cidx - index in directory stack
276 static int crit_check(struct vol *vol, struct path *path, int cidx) {
278 u_int16_t attr, flags = CONV_PRECOMPOSE;
279 struct finderinfo *finfo = NULL, finderinfo;
280 struct adouble *adp = NULL;
281 time_t c_date, b_date;
282 static char convbuf[512];
285 if (S_ISDIR(path->st.st_mode)) {
290 else if (!c1.fbitmap)
293 /* Kind of optimization:
294 * -- first check things we've already have - filename
295 * -- last check things we get from ad_open()
296 * FIXME strmcp strstr (icase)
299 /* Check for filename */
300 if (c1.rbitmap & (1<<DIRPBIT_LNAME)) {
302 LOG(log_debug, logtype_afpd, "Crit check: comparing %s/%s to %s", path->m_name, path->u_name, c1.lname);
304 if ( (size_t)(-1) == (len = convert_string(vol->v_maccharset, CH_UCS2, path->m_name, strlen(path->m_name), convbuf, 512)) )
307 if (c1.rbitmap & (1<<CATPBIT_PARTIAL)) {
308 if (strcasestr_w( (ucs2_t*) convbuf, (ucs2_t*) c1.lname) == NULL)
311 if (strcasecmp_w((ucs2_t*) convbuf, (ucs2_t*) c1.lname) != 0)
313 } /* if (c1.rbitmap & ... */
315 if ((c1.rbitmap & (1<<FILPBIT_PDINFO))) {
317 LOG(log_debug, logtype_afpd, "Crit check: comparing %s to %s", path->m_name, c1.utf8name);
319 if ( (size_t)(-1) == (len = convert_charset( CH_UTF8_MAC, CH_UCS2, CH_UTF8, path->m_name, strlen(path->m_name), convbuf, 512, &flags)) )
322 if (c1.rbitmap & (1<<CATPBIT_PARTIAL)) {
323 if (strcasestr_w((ucs2_t *) convbuf, (ucs2_t*)c1.utf8name) == NULL)
326 if (strcasecmp_w((ucs2_t *)convbuf, (ucs2_t*)c1.utf8name) != 0)
328 } /* if (c1.rbitmap & ... */
333 if ((unsigned)c2.mdate > 0x7fffffff)
334 c2.mdate = 0x7fffffff;
335 if ((unsigned)c2.cdate > 0x7fffffff)
336 c2.cdate = 0x7fffffff;
337 if ((unsigned)c2.bdate > 0x7fffffff)
338 c2.bdate = 0x7fffffff;
340 /* Check for modification date FIXME: should we look at adouble structure ? */
341 if ((c1.rbitmap & (1<<DIRPBIT_MDATE)))
342 if (path->st.st_mtime < c1.mdate || path->st.st_mtime > c2.mdate)
345 /* Check for creation date... */
346 if (c1.rbitmap & (1<<DIRPBIT_CDATE)) {
347 if (adp || (adp = adl_lkup(vol, path))) {
348 if (ad_getdate(adp, AD_DATE_CREATE, (u_int32_t*)&c_date) >= 0)
349 c_date = AD_DATE_TO_UNIX(c_date);
350 else c_date = path->st.st_mtime;
351 } else c_date = path->st.st_mtime;
352 if (c_date < c1.cdate || c_date > c2.cdate)
356 /* Check for backup date... */
357 if (c1.rbitmap & (1<<DIRPBIT_BDATE)) {
358 if (adp || (adp == adl_lkup(vol, path))) {
359 if (ad_getdate(adp, AD_DATE_BACKUP, (u_int32_t*)&b_date) >= 0)
360 b_date = AD_DATE_TO_UNIX(b_date);
361 else b_date = path->st.st_mtime;
362 } else b_date = path->st.st_mtime;
363 if (b_date < c1.bdate || b_date > c2.bdate)
367 /* Check attributes */
368 if ((c1.rbitmap & (1<<DIRPBIT_ATTR)) && c2.attr != 0) {
369 if (adp || (adp = adl_lkup(vol, path))) {
370 ad_getattr(adp, &attr);
371 if ((attr & c2.attr) != c1.attr)
373 } else goto crit_check_ret;
376 /* Check file type ID */
377 if ((c1.rbitmap & (1<<DIRPBIT_FINFO)) && c2.finfo.f_type != 0) {
379 adp = adl_lkup(vol, path);
380 finfo = get_finderinfo(path->m_name, adp, &finderinfo);
381 if (finfo->f_type != c1.finfo.f_type)
385 /* Check creator ID */
386 if ((c1.rbitmap & (1<<DIRPBIT_FINFO)) && c2.finfo.creator != 0) {
389 adp = adl_lkup(vol, path);
390 finfo = get_finderinfo(path->m_name, adp, &finderinfo);
392 if (finfo->creator != c1.finfo.creator)
396 /* Check finder info attributes */
397 if ((c1.rbitmap & (1<<DIRPBIT_FINFO)) && c2.finfo.attrs != 0) {
400 if (adp || (adp = adl_lkup(vol, path))) {
401 finfo = (struct finderinfo*)ad_entry(adp, ADEID_FINDERI);
402 attrs = finfo->attrs;
404 else if (*path->u_name == '.') {
405 attrs = htons(FINDERINFO_INVISIBLE);
408 if ((attrs & c2.finfo.attrs) != c1.finfo.attrs)
413 if ((c1.rbitmap & (1<<DIRPBIT_FINFO)) && c2.finfo.label != 0) {
414 if (adp || (adp = adl_lkup(vol, path))) {
415 finfo = (struct finderinfo*)ad_entry(adp, ADEID_FINDERI);
416 if ((finfo->label & c2.finfo.label) != c1.finfo.label)
418 } else goto crit_check_ret;
420 /* FIXME: Attributes check ! */
422 /* All criteria are met. */
426 ad_close(adp, ADFLAGS_HF);
431 /* Adds an item to resultset. */
432 static int rslt_add(struct vol *vol, char *fname, short cidx, int isdir, char **rbuf)
435 int l = fname != NULL ? strlen(fname) : 0;
439 p0 = p[0] = cidx != -1 ? l + 7 : l + 5;
441 p[1] = isdir ? 128 : 0;
444 if (dstack[cidx].dir == NULL && resolve_dir(vol, cidx) == 0)
446 did = dstack[cidx].dir->d_did;
447 memcpy(p, &did, sizeof(did));
451 /* Fill offset of returned file name */
454 *p = (int)(p - *rbuf) - 1;
465 /* *rbuf[0] = (int)(p-*rbuf); */
469 static int rslt_add_ext ( struct vol *vol, struct path *path, char **buf, short cidx)
474 u_int16_t resultsize;
475 int isdir = S_ISDIR(path->st.st_mode);
477 if (dstack[cidx].dir == NULL && resolve_dir(vol, cidx) == 0)
480 p += sizeof(resultsize); /* Skip resultsize */
481 *p++ = isdir ? FILDIRBIT_ISDIR : FILDIRBIT_ISFILE; /* IsDir ? */
486 struct dir* dir = NULL;
488 dir = dirsearch_byname(dstack[cidx].dir, path->u_name);
490 if ((dir = adddir( vol, dstack[cidx].dir, path)) == NULL) {
494 ret = getdirparams(vol, c1.dbitmap, path, dir, p , &tbuf );
498 ret = getfilparams ( vol, c1.fbitmap, path, dstack[cidx].dir, p, &tbuf);
504 /* Make sure entry length is even */
510 resultsize = htons(tbuf);
511 memcpy ( *buf, &resultsize, sizeof(resultsize) );
521 "./../.AppleDouble/.AppleDB/Network Trash Folder/TheVolumeSettingsFolder/TheFindByContentFolder/.AppleDesktop/.Parent/"
523 /* This function performs search. It is called directly from afp_catsearch
524 * vol - volume we are searching on ...
525 * dir - directory we are starting from ...
526 * c1, c2 - search criteria
527 * rmatches - maximum number of matches we can return
528 * pos - position we've stopped recently
529 * rbuf - output buffer
530 * rbuflen - output buffer length
532 #define NUM_ROUNDS 100
533 static int catsearch(struct vol *vol, struct dir *dir,
534 int rmatches, int *pos, char *rbuf, u_int32_t *nrecs, int *rsize, int ext)
538 struct dirent *entry;
542 char *orig_dir = NULL;
543 int orig_dir_len = 128;
544 char *vpath = vol->v_path;
547 int num_rounds = NUM_ROUNDS;
549 if (*pos != 0 && *pos != cur_pos)
550 return AFPERR_CATCHNG;
552 /* FIXME: Category "offspring count ! */
554 /* So we are beginning... */
555 start_time = time(NULL);
557 /* We need to initialize all mandatory structures/variables and change working directory appropriate... */
560 if (dirpos != NULL) {
565 if (addstack("","", dir, -1) == -1) {
566 result = AFPERR_MISC;
569 dstack[0].path = strdup(vpath);
570 /* FIXME: Sometimes DID is given by client ! (correct this one above !) */
573 /* Save current path */
574 orig_dir = (char*)malloc(orig_dir_len);
575 while (getcwd(orig_dir, orig_dir_len-1)==NULL) {
576 if (errno != ERANGE) {
577 result = AFPERR_MISC;
581 orig_dir = realloc(orig_dir, orig_dir_len);
584 while ((cidx = reducestack()) != -1) {
586 dirpos = opendir(dstack[cidx].path);
587 if (dirpos == NULL) {
590 dstack[cidx].checked = 1;
595 result = AFPERR_NFILE;
600 result = AFPERR_MISC;
601 } /* switch (errno) */
604 chdir(dstack[cidx].path);
605 while ((entry=readdir(dirpos)) != NULL) {
608 if (!(fname = path.m_name = check_dirent(vol, entry->d_name)))
611 if (NULL == (fname = path.m_name = utompath(vol, entry->d_name, 0, utf8_encoding())))
614 /* now check against too big a file */
615 if (strlen(path.m_name) > vol->max_filename)
619 path.u_name = entry->d_name;
620 if (of_stat(&path) != 0) {
631 result = AFPERR_MISC;
633 } /* switch (errno) */
634 } /* if (stat(entry->d_name, &path.st) != 0) */
636 for (i = 0; fname[i] != 0; i++)
637 fname[i] = tolower(fname[i]);
639 ccr = crit_check(vol, &path, cidx);
640 /* bit 1 means that we have to descend into this directory. */
641 if ((ccr & 2) && S_ISDIR(path.st.st_mode)) {
642 if (addstack(entry->d_name, fname, NULL, cidx) == -1) {
643 result = AFPERR_MISC;
648 /* bit 0 means that criteria has been met */
651 r = rslt_add_ext ( vol, &path, &rrbuf, cidx);
656 (c1.fbitmap&(1<<FILPBIT_LNAME))|(c1.dbitmap&(1<<DIRPBIT_LNAME)) ?
658 (c1.fbitmap&(1<<FILPBIT_PDID))|(c1.dbitmap&(1<<DIRPBIT_PDID)) ?
660 S_ISDIR(path.st.st_mode), &rrbuf);
664 result = AFPERR_MISC;
668 /* Number of matches limit */
670 goto catsearch_pause;
671 /* Block size limit */
672 if (rrbuf - rbuf >= 448)
673 goto catsearch_pause;
675 /* MacOS 9 doesn't like servers executing commands longer than few seconds */
676 if (--num_rounds <= 0) {
677 if (start_time != time(NULL)) {
679 goto catsearch_pause;
681 num_rounds = NUM_ROUNDS;
683 } /* while ((entry=readdir(dirpos)) != NULL) */
686 dstack[cidx].checked = 1;
687 } /* while (current_idx = reducestack()) != -1) */
689 /* We have finished traversing our tree. Return EOF here. */
697 catsearch_end: /* Exiting catsearch: error condition */
698 *rsize = rrbuf - rbuf;
699 if (orig_dir != NULL) {
706 int catsearch_afp(AFPObj *obj, char *ibuf, int ibuflen,
707 char *rbuf, int *rbuflen, int ext)
712 u_int32_t rmatches, reserved;
717 unsigned char *spec1, *spec2, *bspec1, *bspec2;
723 memset(&c1, 0, sizeof(c1));
724 memset(&c2, 0, sizeof(c2));
727 memcpy(&vid, ibuf, sizeof(vid));
731 if ((vol = getvolbyvid(vid)) == NULL) {
735 memcpy(&rmatches, ibuf, sizeof(rmatches));
736 rmatches = ntohl(rmatches);
737 ibuf += sizeof(rmatches);
739 /* FIXME: (rl) should we check if reserved == 0 ? */
740 ibuf += sizeof(reserved);
742 memcpy(catpos, ibuf, sizeof(catpos));
743 ibuf += sizeof(catpos);
745 memcpy(&c1.fbitmap, ibuf, sizeof(c1.fbitmap));
746 c1.fbitmap = c2.fbitmap = ntohs(c1.fbitmap);
747 ibuf += sizeof(c1.fbitmap);
749 memcpy(&c1.dbitmap, ibuf, sizeof(c1.dbitmap));
750 c1.dbitmap = c2.dbitmap = ntohs(c1.dbitmap);
751 ibuf += sizeof(c1.dbitmap);
753 memcpy(&c1.rbitmap, ibuf, sizeof(c1.rbitmap));
754 c1.rbitmap = c2.rbitmap = ntohl(c1.rbitmap);
755 ibuf += sizeof(c1.rbitmap);
757 if (! (c1.fbitmap || c1.dbitmap)) {
758 return AFPERR_BITMAP;
762 memcpy(&spec_len, ibuf, sizeof(spec_len));
763 spec_len = ntohs(spec_len);
766 spec_len = *(unsigned char*)ibuf;
769 /* Parse file specifications */
771 spec2 = ibuf + spec_len + 2;
778 /* File attribute bits... */
779 if (c1.rbitmap & (1 << FILPBIT_ATTR)) {
780 memcpy(&c1.attr, spec1, sizeof(c1.attr));
781 spec1 += sizeof(c1.attr);
782 memcpy(&c2.attr, spec2, sizeof(c2.attr));
783 spec2 += sizeof(c1.attr);
787 if (c1.rbitmap & (1 << FILPBIT_PDID)) {
788 memcpy(&c1.pdid, spec1, sizeof(pdid));
789 spec1 += sizeof(c1.pdid);
790 memcpy(&c2.pdid, spec2, sizeof(pdid));
791 spec2 += sizeof(c2.pdid);
792 } /* FIXME: PDID - do we demarshall this argument ? */
795 if (c1.rbitmap & (1 << FILPBIT_CDATE)) {
796 memcpy(&c1.cdate, spec1, sizeof(c1.cdate));
797 spec1 += sizeof(c1.cdate);
798 c1.cdate = AD_DATE_TO_UNIX(c1.cdate);
799 memcpy(&c2.cdate, spec2, sizeof(c2.cdate));
800 spec2 += sizeof(c1.cdate);
801 ibuf += sizeof(c1.cdate);;
802 c2.cdate = AD_DATE_TO_UNIX(c2.cdate);
805 /* Modification date */
806 if (c1.rbitmap & (1 << FILPBIT_MDATE)) {
807 memcpy(&c1.mdate, spec1, sizeof(c1.mdate));
808 c1.mdate = AD_DATE_TO_UNIX(c1.mdate);
809 spec1 += sizeof(c1.mdate);
810 memcpy(&c2.mdate, spec2, sizeof(c2.mdate));
811 c2.mdate = AD_DATE_TO_UNIX(c2.mdate);
812 spec2 += sizeof(c1.mdate);
816 if (c1.rbitmap & (1 << FILPBIT_BDATE)) {
817 memcpy(&c1.bdate, spec1, sizeof(c1.bdate));
818 spec1 += sizeof(c1.bdate);
819 c1.bdate = AD_DATE_TO_UNIX(c1.bdate);
820 memcpy(&c2.bdate, spec2, sizeof(c2.bdate));
821 spec2 += sizeof(c2.bdate);
822 c1.bdate = AD_DATE_TO_UNIX(c2.bdate);
826 if (c1.rbitmap & (1 << FILPBIT_FINFO)) {
827 memcpy(&c1.finfo, spec1, sizeof(c1.finfo));
828 spec1 += sizeof(c1.finfo);
829 memcpy(&c2.finfo, spec2, sizeof(c2.finfo));
830 spec2 += sizeof(c2.finfo);
833 if ((c1.rbitmap & (1 << DIRPBIT_OFFCNT)) != 0) {
834 /* Offspring count - only directories */
835 if (c1.fbitmap == 0) {
836 memcpy(&c1.offcnt, spec1, sizeof(c1.offcnt));
837 spec1 += sizeof(c1.offcnt);
838 c1.offcnt = ntohs(c1.offcnt);
839 memcpy(&c2.offcnt, spec2, sizeof(c2.offcnt));
840 spec2 += sizeof(c2.offcnt);
841 c2.offcnt = ntohs(c2.offcnt);
843 else if (c1.dbitmap == 0) {
844 /* ressource fork length */
847 return AFPERR_BITMAP; /* error */
849 } /* Offspring count/ressource fork length */
852 if (c1.rbitmap & (1 << FILPBIT_LNAME)) {
853 /* Get the long filename */
854 memcpy(tmppath, bspec1 + spec1[1] + 1, (bspec1 + spec1[1])[0]);
855 tmppath[(bspec1 + spec1[1])[0]]= 0;
856 len = convert_string ( vol->v_maccharset, CH_UCS2, tmppath, strlen(tmppath), c1.lname, 64);
857 if (len == (size_t)(-1))
862 /* FIXME: do we need it ? It's always null ! */
863 memcpy(c2.lname, bspec2 + spec2[1] + 1, (bspec2 + spec2[1])[0]);
864 c2.lname[(bspec2 + spec2[1])[0]]= 0;
868 if (c1.rbitmap & (1 << FILPBIT_PDINFO)) {
871 memcpy(&namelen, spec1, sizeof(namelen));
872 namelen = ntohs (namelen);
874 spec1 = bspec1+namelen+4; /* Skip Unicode Hint */
877 memcpy(&namelen, spec1, sizeof(namelen));
878 namelen = ntohs (namelen);
879 if (namelen > 255) /* Safeguard */
882 memcpy (c1.utf8name, spec1+2, namelen);
883 c1.utf8name[(namelen+1)] =0;
885 /* convert charset */
886 flags = CONV_PRECOMPOSE;
887 len = convert_charset(CH_UTF8_MAC, CH_UCS2, CH_UTF8, c1.utf8name, namelen, c1.utf8name, 512, &flags);
888 if (len == (size_t)(-1))
895 ret = catsearch(vol, vol->v_dir, rmatches, &catpos[0], rbuf+24, &nrecs, &rsize, ext);
896 memcpy(rbuf, catpos, sizeof(catpos));
897 rbuf += sizeof(catpos);
899 c1.fbitmap = htons(c1.fbitmap);
900 memcpy(rbuf, &c1.fbitmap, sizeof(c1.fbitmap));
901 rbuf += sizeof(c1.fbitmap);
903 c1.dbitmap = htons(c1.dbitmap);
904 memcpy(rbuf, &c1.dbitmap, sizeof(c1.dbitmap));
905 rbuf += sizeof(c1.dbitmap);
907 nrecs = htonl(nrecs);
908 memcpy(rbuf, &nrecs, sizeof(nrecs));
909 rbuf += sizeof(nrecs);
913 } /* catsearch_afp */
915 int afp_catsearch (AFPObj *obj, char *ibuf, int ibuflen,
916 char *rbuf, int *rbuflen)
918 return catsearch_afp( obj, ibuf, ibuflen, rbuf, rbuflen, 0);
922 int afp_catsearch_ext (AFPObj *obj, char *ibuf, int ibuflen,
923 char *rbuf, int *rbuflen)
925 return catsearch_afp( obj, ibuf, ibuflen, rbuf, rbuflen, 1);
928 /* FIXME: we need a clean separation between afp stubs and 'real' implementation */
929 /* (so, all buffer packing/unpacking should be done in stub, everything else
930 should be done in other functions) */