source: trunk/client/src/dircache.h@ 976

Last change on this file since 976 was 975, checked in by Yuri Dario, 9 years ago

Made code completely independent from samba data structures. ticket#274.

File size: 2.7 KB
Line 
1/*
2 Directory caching code for Netdrive plugins.
3 Copyright (C) netlabs.org 2010-2016
4*/
5
6#ifndef __DIRCACHE_H__
7#define __DIRCACHE_H__
8
9#include <limits.h>
10
11#define NDPL_LARGEFILES
12#define INCL_LONGLONG
13#include <ndextpl2.h>
14
15
16/* callback for fsphAddFile32L */
17typedef void FNADDDIRENTRY(void *plist, void *finfo);
18typedef FNADDDIRENTRY *PFNADDDIRENTRY;
19
20/* callback for releasing memory */
21typedef void FNFREEDIRENTRY(void *finfo);
22typedef FNFREEDIRENTRY *PFNFREEDIRENTRY;
23
24
25/*
26 * An entry holds file name and a pointer to custom data
27 */
28typedef struct DirectoryCacheEntryData
29{
30 const char fname[PATH_MAX];
31 const void* customData;
32} DirectoryCacheEntryData;
33
34/*
35 * An entry in the directory cache contains one directory listing.
36 */
37typedef struct DirectoryCacheEntry
38{
39 struct DirectoryCacheEntry *pNext;
40 struct DirectoryCacheEntry *pPrev;
41
42 DirectoryCacheEntryData *aInfos;
43 int cInfos;
44 int cInfosAllocated;
45
46 char *pszPath;
47 ULONG ulHash;
48 ULONG ulLastUpdateTime;
49 int fInvalid;
50} DirectoryCacheEntry;
51
52typedef struct DirectoryCache
53{
54 NDMUTEX mutex;
55
56 DirectoryCacheEntry *pEntriesHead;
57 DirectoryCacheEntry *pEntriesTail;
58 int cEntries;
59 int fEnabled;
60 unsigned long ulExpirationTime;
61 int cMaxEntries;
62 // resource handle, used only for per-share logging
63 void* resource;
64 // callback called to release data structures
65 PFNFREEDIRENTRY release;
66
67} DirectoryCache;
68
69enum {
70 CacheFault = 0,
71 CacheOk = 1
72};
73
74
75/* Directory cache helpers. */
76int dircache_create(DirectoryCache **ppdc, void* pRes, int cachetimeout, int cachedepth,
77 PFNFREEDIRENTRY fn);
78void dircache_delete(DirectoryCache *pdc);
79
80/* directory cache scanning */
81int dircache_list_files(DirectoryCache *pdc, PFNADDDIRENTRY fn,
82 void *plist,
83 char* dir_mask, char* fullpath,
84 int *ptotal_received);
85int dircache_find_path(DirectoryCache *pdc,
86 const char *path,
87 void **finfo,
88 unsigned long *pulAge);
89
90/* directory cache creation */
91void *dircache_write_begin(DirectoryCache *pdc,
92 char* dir_mask, char* fullpath,
93 int cFiles);
94void dircache_write_entry(DirectoryCache *pdc, void *dircachectx,
95 const char *fname, const void *finfo);
96void dircache_write_end(DirectoryCache *pdc, void *dircachectx);
97
98/* directory cache invalidation */
99void dircache_invalidate(DirectoryCache *pdc,
100 const char *path,
101 int fParent);
102
103#endif // __DIRCACHE_H__
Note: See TracBrowser for help on using the repository browser.