forked from hasse69/rar2fs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilecache.h
148 lines (127 loc) · 4.76 KB
/
filecache.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
Copyright (C) 2009 Hans Beckerus ([email protected])
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
This program take use of the freeware "Unrar C++ Library" (libunrar)
by Alexander Roshal and some extensions to it.
Unrar source may be used in any software to handle RAR archives
without limitations free of charge, but cannot be used to re-create
the RAR compression algorithm, which is proprietary. Distribution
of modified Unrar source in separate form or as a part of other
software is permitted, provided that it is clearly stated in
the documentation and source comments that the code may not be used
to develop a RAR (WinRAR) compatible archiver.
*/
#ifndef FILECACHE_H_
#define FILECACHE_H_
#include <platform.h>
#include <sys/stat.h>
#include <pthread.h>
#include <hash.h>
typedef struct dir_elem dir_elem;
__extension__
struct dir_elem {
char *name_p;
char *rar_p;
char *file_p;
char *file2_p;
char *link_target_p;
short method; /* for getxattr() */
struct stat stat;
uint32_t dir_hash;
off_t offset; /* >0: offset in rar file (raw read) */
union {
off_t vsize_first; /* >0: volume file size (raw read) */
off_t msize; /* >0: mmap size */
};
off_t vsize_real_first;
off_t vsize_real_next;
off_t vsize_next;
short vno_base;
short vno_first;
short vlen;
short vpos;
short vtype;
union {
struct {
#ifndef WORDS_BIGENDIAN
unsigned int raw:1;
unsigned int multipart:1;
unsigned int image:1;
unsigned int fake_iso:1;
unsigned int mmap:2;
unsigned int force_dir:1;
unsigned int vsize_fixup_needed:1;
unsigned int encrypted:1;
unsigned int vsize_resolved:1;
unsigned int :18;
unsigned int check_atime:1;
unsigned int direct_io:1;
unsigned int avi_tested:1;
unsigned int save_eof:1;
#else
unsigned int save_eof:1;
unsigned int avi_tested:1;
unsigned int direct_io:1;
unsigned int check_atime:1;
unsigned int :18;
unsigned int vsize_resolved:1;
unsigned int encrypted:1;
unsigned int vsize_fixup_needed:1;
unsigned int force_dir:1;
unsigned int mmap:2;
unsigned int fake_iso:1;
unsigned int image:1;
unsigned int multipart:1;
unsigned int raw:1;
#endif
} flags;
uint32_t flags_uint32;
};
struct dir_elem *next_p;
};
typedef struct dir_elem dir_elem_t;
#define LOCAL_FS_ENTRY ((void*)-1)
#define LOOP_FS_ENTRY ((void*)-2)
#define ABS_ROOT(s, path) \
do { \
(s) = alloca(strlen(path) + strlen(OPT_STR2(OPT_KEY_SRC,0)) + 1); \
strcpy((s), OPT_STR2(OPT_KEY_SRC,0)); \
strcat((s), path); \
} while (0)
#define ABS_MP(s, path, file) \
do { \
int l = strlen(path); \
/* add +2 in case of fake .iso */ \
(s) = alloca(l + strlen(file) + 3 + 2); \
strcpy((s), path); \
if (l && path[l - 1] != '/') \
strcat((s), "/"); \
strcat((s), file); \
} while(0)
extern pthread_mutex_t file_access_mutex;
dir_elem_t *
filecache_alloc(const char *path);
dir_elem_t *
filecache_get(const char *path);
void
filecache_invalidate(const char *path);
dir_elem_t *
filecache_clone(const dir_elem_t *src);
void
filecache_copy(const dir_elem_t *src, dir_elem_t *dest);
void
filecache_freeclone(dir_elem_t *dest);
void
filecache_init();
void
filecache_destroy();
#endif