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 */
|
---|
17 | typedef void FNADDDIRENTRY(void *plist, void *finfo);
|
---|
18 | typedef FNADDDIRENTRY *PFNADDDIRENTRY;
|
---|
19 |
|
---|
20 | /* callback for releasing memory */
|
---|
21 | typedef void FNFREEDIRENTRY(void *finfo);
|
---|
22 | typedef FNFREEDIRENTRY *PFNFREEDIRENTRY;
|
---|
23 |
|
---|
24 |
|
---|
25 | /*
|
---|
26 | * An entry holds file name and a pointer to custom data
|
---|
27 | */
|
---|
28 | typedef 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 | */
|
---|
37 | typedef 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 |
|
---|
52 | typedef 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 |
|
---|
69 | enum {
|
---|
70 | CacheFault = 0,
|
---|
71 | CacheOk = 1
|
---|
72 | };
|
---|
73 |
|
---|
74 |
|
---|
75 | /* Directory cache helpers. */
|
---|
76 | int dircache_create(DirectoryCache **ppdc, void* pRes, int cachetimeout, int cachedepth,
|
---|
77 | PFNFREEDIRENTRY fn);
|
---|
78 | void dircache_delete(DirectoryCache *pdc);
|
---|
79 |
|
---|
80 | /* directory cache scanning */
|
---|
81 | int dircache_list_files(DirectoryCache *pdc, PFNADDDIRENTRY fn,
|
---|
82 | void *plist,
|
---|
83 | char* dir_mask, char* fullpath,
|
---|
84 | int *ptotal_received);
|
---|
85 | int dircache_find_path(DirectoryCache *pdc,
|
---|
86 | const char *path,
|
---|
87 | void **finfo,
|
---|
88 | unsigned long *pulAge);
|
---|
89 |
|
---|
90 | /* directory cache creation */
|
---|
91 | void *dircache_write_begin(DirectoryCache *pdc,
|
---|
92 | char* dir_mask, char* fullpath,
|
---|
93 | int cFiles);
|
---|
94 | void dircache_write_entry(DirectoryCache *pdc, void *dircachectx,
|
---|
95 | const char *fname, const void *finfo);
|
---|
96 | void dircache_write_end(DirectoryCache *pdc, void *dircachectx);
|
---|
97 |
|
---|
98 | /* directory cache invalidation */
|
---|
99 | void dircache_invalidate(DirectoryCache *pdc,
|
---|
100 | const char *path,
|
---|
101 | int fParent);
|
---|
102 |
|
---|
103 | #endif // __DIRCACHE_H__
|
---|