netatalk 4.5.0
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
catsearch.c File Reference

FPCatSearch implementation. More...

`#include <ctype.h>`
`#include <errno.h>`
`#include <netinet/in.h>`
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include <sys/file.h>`
`#include <sys/stat.h>`
`#include <sys/types.h>`
`#include <time.h>`
`#include <unistd.h>`
`#include <atalk/adouble.h>`
`#include <atalk/afp.h>`
`#include <atalk/cnid_bdb_private.h>`
`#include <atalk/cnid.h>`
`#include <atalk/globals.h>`
`#include <atalk/logger.h>`
`#include <atalk/netatalk_conf.h>`
`#include <atalk/unicode.h>`
`#include <atalk/util.h>`
`#include "ad_cache.h"`
`#include "desktop.h"`
`#include "dircache.h"`
`#include "directory.h"`
`#include "file.h"`
`#include "filedir.h"`
`#include "fork.h"`
`#include "volume.h"`

## Data Structures
struct | finderinfo
struct | scrit
struct | dsitem
struct | catsearch_spec_layout

## Macros
#define | DS_BSIZE 128
#define | CATPBIT_PARTIAL 31
#define | VETO_STR "./../.AppleDouble/.AppleDB/Network Trash Folder/TheVolumeSettingsFolder/TheFindByContentFolder/.AppleDesktop/.Parent/"
#define | NUM_ROUNDS 200

## Typedefs
typedef char | packed_finder[ADEDLEN_FINDERI]

## Functions
static int | catsearch_spec_addlen (size_t *len, size_t add)
static int | catsearch_spec_layout (uint16_t fbitmap, uint16_t dbitmap, uint32_t rbitmap, struct catsearch_spec_layout *layout)
static int | catsearch_validate_spec (const unsigned char *spec, size_t spec_len, const struct catsearch_spec_layout *layout)
static void | clearstack (void)
| Clears directory stack.
static int | addstack (char *uname, struct dir *dir, int pidx)
static int | reducestack (void)
| Removes checked items from top of directory stack.
static struct adouble * | adl_lkup (struct vol *vol, struct path *path, struct adouble *adp)
static struct finderinfo * | unpack_buffer (struct finderinfo *finfo, char *buffer)
static struct finderinfo * | unpack_finderinfo (struct vol *vol, struct path *path, struct adouble **adp, struct finderinfo *finfo, int islnk)
static int | crit_check (struct vol *vol, struct path *path)
| Criteria checker.
static int | rslt_add (const AFPObj *obj, struct vol *vol, struct path *path, char **buf, int ext)
static int | catsearch (const AFPObj *obj, struct vol *vol, struct dir *dir, int rmatches, uint32_t *pos, char *rbuf, uint32_t *nrecs, int *rsize, int ext)
| This function performs a filesystem search.
static int | catsearch_db (const AFPObj *obj, struct vol *vol, const char *uname, int rmatches, uint32_t *pos, char *rbuf, uint32_t *nrecs, int *rsize, int ext)
| This function performs a CNID db search.
static int | catsearch_afp (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen, int ext)
int | afp_catsearch (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
int | afp_catsearch_ext (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)

## Variables
static int | save_cidx = -1
static struct dsitem * | dstack = NULL
static int | dssize = 0
static int | dsidx = 0
static struct scrit c1 | c2

## Detailed Description

FPCatSearch implementation.

This file contains FPCatSearch implementation. FPCatSearch performs file/directory search based on specified criteria. It is used by client to perform fast searches on (propably) big volumes. So, it has to be pretty fast.

This implementation bypasses most of adouble/libatalk stuff as long as possible and does a standard filesystem search. It calls higher-level libatalk/afpd functions only when it is really needed, mainly while returning some non-UNIX information or filtering by non-UNIX criteria.

## Macro Definition Documentation

## ◆ CATPBIT_PARTIAL

#define CATPBIT_PARTIAL 31

## ◆ DS_BSIZE

#define DS_BSIZE 128

## ◆ NUM_ROUNDS

#define NUM_ROUNDS 200

## ◆ VETO_STR

#define VETO_STR "./../.AppleDouble/.AppleDB/Network Trash Folder/TheVolumeSettingsFolder/TheFindByContentFolder/.AppleDesktop/.Parent/"

## Typedef Documentation

## ◆ packed_finder

typedef char packed_finder[ADEDLEN_FINDERI]

## Function Documentation

## ◆ addstack()

int addstack | ( | char * | uname,
|  | struct dir * | dir,
|  | int | pidx )
| static

Puts new item onto directory stack.

## ◆ adl_lkup()

struct adouble * adl_lkup | ( | struct vol * | vol,
|  | struct path * | path,
|  | struct adouble * | adp )
| static

Looks up for an opened adouble structure, opens resource fork of selected file.

## ◆ afp_catsearch()

int afp_catsearch | ( | AFPObj * | obj,
|  | char * | ibuf,
|  | size_t | ibuflen,
|  | char * | rbuf,
|  | size_t * | rbuflen )

## ◆ afp_catsearch_ext()

int afp_catsearch_ext | ( | AFPObj * | obj,
|  | char * | ibuf,
|  | size_t | ibuflen,
|  | char * | rbuf,
|  | size_t * | rbuflen )

## ◆ catsearch()

int catsearch | ( | const AFPObj * | obj,
|  | struct vol * | vol,
|  | struct dir * | dir,
|  | int | rmatches,
|  | uint32_t * | pos,
|  | char * | rbuf,
|  | uint32_t * | nrecs,
|  | int * | rsize,
|  | int | ext )
| static

This function performs a filesystem search.

Uses globals c1, c2, the search criteria

Parameters

  [in] | obj | AFP connection object
  [in] | vol | volume we are searching on ...
  [in,out] | dir | directory we are starting from ...
  [in] | rmatches | maximum number of matches we can return
  [in] | pos | position we've stopped recently
  [out] | rbuf | output buffer
  [out] | nrecs | number of matches
  [out] | rsize | length of data written to output buffer
  [in] | ext | extended search flag

## ◆ catsearch_afp()

int catsearch_afp | ( | AFPObj * | obj,
|  | char * | ibuf,
|  | size_t | ibuflen,
|  | char * | rbuf,
|  | size_t * | rbuflen,
|  | int | ext )
| static

## ◆ catsearch_db()

int catsearch_db | ( | const AFPObj * | obj,
|  | struct vol * | vol,
|  | const char * | uname,
|  | int | rmatches,
|  | uint32_t * | pos,
|  | char * | rbuf,
|  | uint32_t * | nrecs,
|  | int * | rsize,
|  | int | ext )
| static

This function performs a CNID db search.

Uses globals c1, c2, the search criteria Always searches the whole volume, not a subtree

Parameters

  [in] | obj | AFP connection object
  [in] | vol | volume we are searching on ...
  [in] | uname | UNIX name of object to search
  [in] | rmatches | maximum number of matches we can return
  [in] | pos | position we've stopped recently
  [out] | rbuf | output buffer
  [out] | nrecs | number of matches
  [out] | rsize | length of data written to output buffer
  [in] | ext | extended search flag

## ◆ catsearch_spec_addlen()

int catsearch_spec_addlen | ( | size_t * | len,
|  | size_t | add )
| static

## ◆ catsearch_spec_layout()

int catsearch_spec_layout | ( | uint16_t | fbitmap,
|  | uint16_t | dbitmap,
|  | uint32_t | rbitmap,
|  | struct catsearch_spec_layout * | layout )
| static

## ◆ catsearch_validate_spec()

int catsearch_validate_spec | ( | const unsigned char * | spec,
|  | size_t | spec_len,
|  | const struct catsearch_spec_layout * | layout )
| static

## ◆ clearstack()

void clearstack | ( | void |  | ) |
| static

Clears directory stack.

## ◆ crit_check()

int crit_check | ( | struct vol * | vol,
|  | struct path * | path )
| static

Criteria checker.

Returns
  a 2-bit value.
  - bit 0 means if checked file meets given criteria.
  - bit 1 means if it is a directory and we should descent into it.
    - uname - UNIX name
    - fname - our fname (translated to UNIX)
    - cidx - index in directory stack

## ◆ reducestack()

int reducestack | ( | void |  | ) |
| static

Removes checked items from top of directory stack.

Returns
  index of the first unchecked elements or -1.

## ◆ rslt_add()

int rslt_add | ( | const AFPObj * | obj,
|  | struct vol * | vol,
|  | struct path * | path,
|  | char ** | buf,
|  | int | ext )
| static

## ◆ unpack_buffer()

struct finderinfo * unpack_buffer | ( | struct finderinfo * | finfo,
|  | char * | buffer )
| static

## ◆ unpack_finderinfo()

struct finderinfo * unpack_finderinfo | ( | struct vol * | vol,
|  | struct path * | path,
|  | struct adouble ** | adp,
|  | struct finderinfo * | finfo,
|  | int | islnk )
| static

## Variable Documentation

## ◆ c2

struct scrit c1 c2
| static

search criteria

## ◆ dsidx

int dsidx = 0
| static

First free item index...

## ◆ dssize

int dssize = 0
| static

Directory stack (allocated) size...

## ◆ dstack

struct dsitem* dstack = NULL
| static

Directory stack data...

## ◆ save_cidx

int save_cidx = -1
| static

Saved index of currently scanned directory.