2
** DAV directory chache
6
* This file is part of davfs2.
8
* davfs2 is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* davfs2 is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with davfs2; if not, write to the Free Software
20
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
#ifndef __DAV_CACHE_H__
25
#define __DAV_CACHE_H__
1
/* cache.h: directory and file cache.
2
Copyright (C) 2006, 2007, 2008, 2009 Werner Baumann
4
This file is part of davfs2.
6
davfs2 is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 3 of the License, or
9
(at your option) any later version.
11
davfs2 is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with davfs2; if not, write to the Free Software Foundation,
18
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
150
148
/* Returned by dav_statfs(). */
151
149
typedef struct dav_stat dav_stat;
152
150
struct dav_stat {
158
time_t utime; /* Time when last updated with data from the server.
159
must When 0 this structure contains fake data,
160
that not be changed when a file is changed or
188
190
filesystem can be mounted, but will only get useable when the connection
190
192
paramters: if not self explaining, please see mount_davfs.c, struct args. */
191
void dav_init_cache(uid_t uid, gid_t gid, mode_t file_mode, mode_t dir_mode,
192
mode_t f_umask, mode_t d_umask, size_t hash_table_sz,
193
time_t dir_rf, time_t file_rf, int delay_upl, int gui_opt,
194
time_t dir_rt, time_t dir_max_rt, time_t lock_rf,
195
size_t cache_sz, const char *tl_cache_dir,
196
const char *backup_dir, const char *host, const char *path,
197
const char *mpoint, int dbg);
194
dav_init_cache(const dav_args *args, const char *mpoint);
200
197
/* Tries to write back to the server all open files that have been changed or
204
201
permanent cache is created.
205
202
If got_sigterm is 1, dirty files will not be stored back to the server.
206
203
Finally it frees all nodes. */
207
void dav_close_cache(int got_sigterm);
205
dav_close_cache(int got_sigterm);
210
208
/* Registers the kernel_interface.
211
209
Sets pointers to the write_dir_entry_fn flush_flag.
212
210
If blksize is not NULL, the preferred bloksize for IO is asigned.
213
211
It returns the value of alignment. */
214
size_t dav_register_kernel_interface(dav_write_dir_entry_fn write_fn,
215
int *flush_flag, unsigned int *blksize);
213
dav_register_kernel_interface(dav_write_dir_entry_fn write_fn, int *flush_flag,
214
unsigned int *blksize);
218
217
/* Scans the hash table for file nodes to be saved them back on the server,
223
222
The return value indicates whether another run would be useful.
224
223
return value: 0 there is nothing left to do.
225
224
1 another call of dav_tidy_cache would be useful. */
226
int dav_tidy_cache(void);
226
dav_tidy_cache(void);
229
229
/* Upcalls from the kernel, via the interface module. */
259
259
/* Tests whether user uid has access described by how to node.
260
260
int how : A bit mask describing the kind of acces. It may be any combination
261
261
of R_OK, W_OK, X_OK and F_OK. */
262
int dav_access(dav_node *node, uid_t uid, int how);
263
dav_access(dav_node *node, uid_t uid, int how);
265
266
/* Closed file descriptor fd of node.
267
268
opening. If fd is 0 (coda), flags, pid and pgid are used to find the best
268
269
matching file descriptor.
269
270
Only access mode bits must be set in flags.*/
270
int dav_close(dav_node *node, int fd, int flags, pid_t pid, pid_t pgid);
272
dav_close(dav_node *node, int fd, int flags, pid_t pid, pid_t pgid);
273
275
/* Creates a new file node with name name in directory parent. The file is
279
281
uid must have execute permission for parent and all of its ancestors, as
280
282
well as write permission for parent. */
281
int dav_create(dav_node **nodep, dav_node *parent, const char *name,
282
uid_t uid, mode_t mode);
284
dav_create(dav_node **nodep, dav_node *parent, const char *name, uid_t uid,
285
288
/* Checks whether node exists and uid has permissions. The kernel interface
288
291
uid must have execute permission for parent and all of its ancestors, as
289
292
well as read permission for parent. */
290
int dav_getattr(dav_node *node, uid_t uid);
294
dav_getattr(dav_node *node, uid_t uid);
293
297
/* Checks whether node exists and uid has permissions. The value of
297
301
uid must have execute permission for parent and all of its ancestors, as
298
302
well as read permission for parent. */
299
int dav_getxattr(dav_node *node, const char *name, char *buf, size_t *size,
304
dav_getxattr(dav_node *node, const char *name, char *buf, size_t *size,
308
/* Returns the list of supported extended attributes. This is just
311
dav_listxattr(dav_node *node, char *buf, size_t *size, uid_t uid);
303
314
/* Searches for a node with name name in the directory parent and returns the
306
317
uid must have execute permission for parent and all of its ancestors, as
307
318
well as read permission for parent. */
308
int dav_lookup(dav_node **nodep, dav_node *parent, const char *name, uid_t uid);
320
dav_lookup(dav_node **nodep, dav_node *parent, const char *name, uid_t uid);
311
323
/* Creates a new directory named name in direcotry parent. The directory must
316
328
uid must have execute permission for parent and all of its ancestors, as
317
329
well as write permission for parent. */
318
int dav_mkdir(dav_node **nodep, dav_node *parent, const char *name, uid_t uid,
331
dav_mkdir(dav_node **nodep, dav_node *parent, const char *name, uid_t uid,
322
335
/* Opens file or directory node according to flags and returns file descriptor
328
341
uid must have execute permission for parent and all of its ancestors, as
329
342
as well as read and/or write permission for node, according to the
331
int dav_open(int *fd, dav_node *node, int flags, pid_t pid, pid_t pgid,
344
If open_create is set to 1, permissions will not be checked. This flag must
345
only be set when the call to dav_open is part of an open-call with flag
346
O_CREATE. It allows dav_open to succeed if when the file mode would not
349
dav_open(int *fd, dav_node *node, int flags, pid_t pid, pid_t pgid, uid_t uid,
334
352
/* Reads size bytes from file descriptor fd, starting at position offset
335
353
and copies them into buf.
336
354
The number of bytes read is returned in len.
337
355
The file must be opened readonly or readwrite. */
338
int dav_read(ssize_t *len, dav_node * node, int fd, char *buf, size_t size,
357
dav_read(ssize_t *len, dav_node * node, int fd, char *buf, size_t size,
342
361
/* Removes file node name in directory parent from the cache and on the server.
345
364
uid must have execute permission for parent and all of its ancestors, as
346
365
well as write permission for parent. */
347
int dav_remove(dav_node *parent, const char *name, uid_t uid);
367
dav_remove(dav_node *parent, const char *name, uid_t uid);
350
370
/* Moves file or directory src_name from directory src_parent to directory
356
376
uid must have execute permission for src_parent and dst_parent and all of
357
377
their ancestors, as well as write permission for src_parent and
359
int dav_rename(dav_node *src_parent, const char *src_name,
360
dav_node *dst_parent, const char *dst_name, uid_t uid);
380
dav_rename(dav_node *src_parent, const char *src_name, dav_node *dst_parent,
381
const char *dst_name, uid_t uid);
363
384
/* Removes direcotry name in directory parent.
364
385
The directory must be empty and not the local backup directory.
365
386
uid must have execute permission for parent and all of its ancestors, as
366
387
well as write permission for parent. */
367
int dav_rmdir(dav_node *parent, const char *name, uid_t uid);
389
dav_rmdir(dav_node *parent, const char *name, uid_t uid);
370
392
/* Returns a pointer to the root node in nodep.
372
394
uid must be root, as this function is only called when the file system is
374
int dav_root(dav_node **nodep, uid_t uid);
397
dav_root(dav_node **nodep, uid_t uid);
377
400
/* Changes attributes of the node.
386
409
To change gid, uid must be member of the new group or root.
387
410
Note: This attributes, except size and the execute bit of mode, are only
388
411
changed locally and not on the server. */
389
int dav_setattr(dav_node *node, uid_t uid, int sm, mode_t mode,
390
int so, uid_t owner, int sg, gid_t gid, int sat, time_t atime,
391
int smt, time_t mtime, int ssz, off_t size);
393
/* Returns struct dav_stat which currently is mainly fake.
413
dav_setattr(dav_node *node, uid_t uid, int sm, mode_t mode, int so,
414
uid_t owner, int sg, gid_t gid, int sat, time_t atime, int smt,
415
time_t mtime, int ssz, off_t size);
418
/* Returns struct dav_stat. If the server does not provide theinformation
419
it will contain fake data.
394
420
No permissions necessary. */
395
dav_stat dav_statfs(void);
398
425
/* Calls fsync() for all filedescriptors of node, that are not read only.
399
426
No permissions are checked. */
400
int dav_sync(dav_node *node);
428
dav_sync(dav_node *node);
403
431
/* Writes size bytes from buf to file descriptor fd, starting at position
405
433
The number of bytes written is returned in len.
406
434
The file must be opened writeonly or readwrite. */
407
/* TODO: Remove pid; check flags. */
408
int dav_write(size_t *written, dav_node * node, int fd, char *buf, size_t size,
436
dav_write(size_t *written, dav_node * node, int fd, char *buf, size_t size,
440
#endif /* DAV_CACHE_H */