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

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

Updates to dircache code to be more independent from samba. 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#include "smbwrp.h"
16
17//
18// enable if not defined in your plugin
19//
20// dircache code uses only the fname field to scan the directory listing.
21// other fields are just passed to FNADD callback as are.
22//
23#if 0
24typedef struct smbwrp_fileinfo
25{
26 unsigned long long size;
27 unsigned long mtime;
28 unsigned type;
29 char fname[PATH_MAX];
30} smbwrp_fileinfo;
31#endif
32
33/*
34 * An entry in the directory cache contains one directory listing.
35 */
36typedef struct DirectoryCacheEntry
37{
38 struct DirectoryCacheEntry *pNext;
39 struct DirectoryCacheEntry *pPrev;
40
41 struct DirectoryCache *pdc;
42
43 smbwrp_fileinfo *aInfos;
44 int cInfos;
45 int cInfosAllocated;
46
47 char *pszPath;
48 ULONG ulHash;
49 ULONG ulLastUpdateTime;
50 int fInvalid;
51} DirectoryCacheEntry;
52
53typedef struct DirectoryCache
54{
55 NDMUTEX mutex;
56
57 DirectoryCacheEntry *pEntriesHead;
58 DirectoryCacheEntry *pEntriesTail;
59 int cEntries;
60 int fEnabled;
61 unsigned long ulExpirationTime;
62 int cMaxEntries;
63 // resource handle, used only for per-share logging
64 void* resource;
65} DirectoryCache;
66
67enum {
68 CacheFault = 0,
69 CacheOk = 1
70};
71
72
73/* Directory cache helpers. */
74int dircache_create(DirectoryCache **ppdc, void* pRes, int cachetimeout, int cachedepth);
75void dircache_delete(DirectoryCache *pdc);
76
77/* callback for fsphAddFile32L */
78typedef void FNADDDIRENTRY(const char *mnt, smbwrp_fileinfo *finfo,
79 const char *mask, void *state);
80typedef FNADDDIRENTRY *PFNADDDIRENTRY;
81
82/* directory cache scanning */
83int dircache_list_files(DirectoryCache *pdc, PFNADDDIRENTRY fn,
84 void *plist,
85 char* dir_mask, char* fullpath,
86 int *ptotal_received);
87int dircache_find_path(DirectoryCache *pdc,
88 const char *path,
89 smbwrp_fileinfo *finfo,
90 unsigned long *pulAge);
91
92/* directory cache creation */
93void *dircache_write_begin(DirectoryCache *pdc,
94 char* dir_mask, char* fullpath,
95 int cFiles);
96void dircache_write_entry(DirectoryCache *pdc, void *dircachectx,
97 const smbwrp_fileinfo *finfo);
98void dircache_write_end(DirectoryCache *pdc, void *dircachectx);
99
100/* directory cache invalidation */
101void dircache_invalidate(DirectoryCache *pdc,
102 const char *path,
103 int fParent);
104
105#endif // __DIRCACHE_H__
Note: See TracBrowser for help on using the repository browser.