Lumiera  0.pre.03
»edityourfreedom«
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
file.h
Go to the documentation of this file.
1 /*
2  FILE.h - interface to files by filename
3 
4  Copyright (C) Lumiera.org
5  2008, Christian Thaeter <ct@pipapo.org>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
35 #ifndef BACKEND_FILE_H
36 #define BACKEND_FILE_H
37 
38 
39 #include "lib/mutex.h"
40 #include "lib/llist.h"
41 #include "lib/error.h"
42 
43 
44 LUMIERA_ERROR_DECLARE(FILE_CHANGED);
45 LUMIERA_ERROR_DECLARE(FILE_NOMMAPINGS);
46 
47 
48 typedef struct lumiera_file_struct lumiera_file;
49 typedef lumiera_file* LumieraFile;
50 
51 
52 #include "backend/filedescriptor.h"
53 #include "backend/filehandle.h"
54 #include "backend/mmapings.h"
55 #include "backend/mmap.h"
56 
64 #define LUMIERA_FILE_READONLY (O_RDONLY | O_LARGEFILE | O_NOATIME)
65 #define LUMIERA_FILE_READWRITE (O_RDWR | O_LARGEFILE | O_NOATIME)
66 #define LUMIERA_FILE_CREATE (O_RDWR | O_LARGEFILE | O_NOATIME | O_CREAT | O_EXCL)
67 #define LUMIERA_FILE_RECREATE (O_RDWR | O_LARGEFILE | O_NOATIME | O_CREAT | O_TRUNC)
68 
69 /* \c creat and \c excl flags will be masked out for descriptor lookup */
70 #define LUMIERA_FILE_MASK ~(O_CREAT | O_EXCL | O_TRUNC)
71 
73 {
74  /* all files of one descriptor */
75  llist node;
76  char* name;
78 };
79 
80 
89 lumiera_file_init (LumieraFile self, const char* name, int flags);
90 
91 
100 lumiera_file_destroy (LumieraFile self, int do_unlink);
101 
102 
110 lumiera_file_new (const char* name, int flags);
111 
112 
117 void
119 
120 
125 void
127 
128 
139 int
141 
142 
147 void
149 
150 
160 lumiera_file_mmap_acquire (LumieraFile self, off_t start, size_t size);
161 
162 
168 void
170 
171 
180 #define LUMIERA_FILE_MMAP_SECTION(nobugflag, file, start, size, addr) \
181  for (LumieraMMap map_##__LINE__ = \
182  lumiera_file_mmap_acquire (file, start, size); \
183  map_##__LINE__; \
184  ({ \
185  lumiera_file_release_mmap (file, map_##__LINE__); \
186  map_##__LINE__ = NULL; \
187  })) \
188  for (void* addr = lumiera_mmap_address (map_##__LINE__, start); \
189  addr; \
190  addr = NULL)
191 
192 
201 
202 
208 int
209 lumiera_file_checkflags (LumieraFile self, int flags);
210 
211 
219 size_t
220 lumiera_file_set_chunksize_bias (LumieraFile self, size_t chunksize, size_t bias);
221 
222 
227 size_t
229 
234 size_t
236 
237 
238 
239 
250 
253 
254 
257 
258 
259 #define LUMIERA_FILE_RDLOCK_SECTION(nobugflag, file) \
260  for (LumieraFile filelock_##__LINE__ = \
261  lumiera_file_rdlock (file); \
262  filelock_##__LINE__; \
263  ({ \
264  lumiera_file_unlock (filelock_##__LINE__); \
265  filelock_##__LINE__ = NULL; \
266  }))
267 
268 #define LUMIERA_FILE_WRLOCK_SECTION(nobugflag, file) \
269  for (LumieraFile filelock_##__LINE__ = \
270  lumiera_file_wrlock (file); \
271  filelock_##__LINE__; \
272  ({ \
273  lumiera_file_unlock (filelock_##__LINE__); \
274  filelock_##__LINE__ = NULL; \
275  }))
276 
277 
278 
279 
280 
281 #endif /*BACKEND_FILE_H*/
size_t lumiera_file_set_chunksize_bias(LumieraFile self, size_t chunksize, size_t bias)
Set the chunksize for mapping operations can only set once for a file descriptor, subsequent calls ar...
void lumiera_file_delete(LumieraFile self)
Frees a file structure.
Definition: file-handling.c:94
void lumiera_file_release_mmap(LumieraFile self, LumieraMMap map)
release a previously acquired MMap object
LumieraFile lumiera_file_wrlock(LumieraFile self)
int lumiera_file_checkflags(LumieraFile self, int flags)
Query the flags effective for a file.
lumiera_file * LumieraFile
Definition: file.h:49
lumiera_mmap * LumieraMMap
Definition: mmap.h:36
File descriptors are the underlying working horse in accessing files.
void lumiera_file_handle_release(LumieraFile self)
Put filehandle back into cache aging.
LumieraFile lumiera_file_destroy(LumieraFile self, int do_unlink)
Destroy a file structure.
Definition: file-handling.c:64
char * name
Definition: file.h:76
LumieraFiledescriptor descriptor
Definition: file.h:77
MMap objects cover a memory mapped range in a file.
void lumiera_file_delete_unlink(LumieraFile self)
Frees a file structure and deletes the associated file name from disk.
Lumiera error handling (C interface).
LumieraFile lumiera_file_rdlock(LumieraFile self)
Place and remove locks on a file.
LumieraMMap lumiera_file_mmap_acquire(LumieraFile self, off_t start, size_t size)
acquire a mmap which covers the given range
Manage the mmap objects of a file.
LumieraFile lumiera_file_init(LumieraFile self, const char *name, int flags)
Initialise a file structure.
Definition: file-handling.c:46
size_t lumiera_file_chunksize_get(LumieraFile self)
Get the chunksize for mapping operations.
Filehandles manage the underlying POSIX filehandle for a file descriptor.
LumieraFile lumiera_file_unlock(LumieraFile self)
Mutual exclusion locking, header.
lumiera_filedescriptor * LumieraFiledescriptor
LumieraFile lumiera_file_new(const char *name, int flags)
Allocate a new file structure.
Definition: file-handling.c:78
Intrusive cyclic double linked list There is only one node type which contains a forward and a backwa...
LumieraMMapings lumiera_file_mmapings(LumieraFile self)
Query the underlying mmapings object from a file The MMapings only exists after a chunksize got set w...
int lumiera_file_handle_acquire(LumieraFile self)
Get a POSIX filehandle for a file.
lumiera_mmapings * LumieraMMapings
Definition: mmapings.h:35
size_t lumiera_file_bias_get(LumieraFile self)
Get the bias for mapping operations.
LUMIERA_ERROR_DECLARE(FILE_CHANGED)