1/*
2 * Copyright (c) 2009, 2011, ETH Zurich.
3 * All rights reserved.
4 *
5 * This file is distributed under the terms in the attached LICENSE file.
6 * If you do not find this file, copies can be found by writing to:
7 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
8 */
9
10#ifndef VFS_H
11#define VFS_H
12
13#include <errors/errno.h> // for errval_t
14#include <stddef.h>
15#include <sys/cdefs.h>
16#include <sys/types.h>
17
18typedef void *vfs_handle_t;
19#define NULL_VFS_HANDLE NULL
20
21/* XXX: remove this for partitioned cache */
22
23#ifdef WITH_SHARED_CACHE
24static const char vfs_cache_str[] = "single-shared";
25#else
26static const char vfs_cache_str[] = "partitioned";
27#endif
28
29//#define WITH_BUFFER_CACHE
30//#define WITH_WRITE_BACK_CACHE
31//#define WITH_META_DATA_CACHE
32
33#ifdef WITH_BUFFER_CACHE
34#define BUFFER_CACHE_BLOCK_SIZE      (1U << 12)      // 4KB
35#endif
36
37/// Enum defining interpretation of offset argument to #vfs_seek
38enum vfs_seekpos {
39    VFS_SEEK_SET,   ///< Offset relative to start of file
40    VFS_SEEK_CUR,   ///< Offset relative to current position
41    VFS_SEEK_END,   ///< Offset relative to end of file
42};
43
44enum vfs_filetype {
45    VFS_FILE,       ///< Regular file
46    VFS_DIRECTORY,  ///< Directory
47};
48
49/// Data returned from #vfs_stat
50struct vfs_fileinfo {
51    enum vfs_filetype type; ///< Type of the object
52    size_t size;            ///< Size of the object (in bytes, for a regular file)
53};
54
55__BEGIN_DECLS
56
57// initialization
58void vfs_init(void);
59
60// operations on files
61errval_t vfs_open(const char *path, vfs_handle_t *handle); // fail if it doesn't exist
62errval_t vfs_create(const char *path, vfs_handle_t *handle); // ok if already present
63errval_t vfs_remove(const char *path);
64
65// operations on file handles
66errval_t vfs_read(vfs_handle_t handle, void *buffer, size_t bytes, size_t *bytes_read);
67errval_t vfs_write(vfs_handle_t handle, const void *buffer, size_t bytes, size_t *bytes_written);
68errval_t vfs_truncate(vfs_handle_t xhandle, size_t bytes);
69errval_t vfs_seek(vfs_handle_t handle, enum vfs_seekpos whence, off_t offset);
70errval_t vfs_tell(vfs_handle_t handle, size_t *pos);
71errval_t vfs_stat(vfs_handle_t handle, struct vfs_fileinfo *info);
72errval_t vfs_close(vfs_handle_t handle);
73errval_t vfs_flush(vfs_handle_t handle);
74
75// manipulation of directories
76errval_t vfs_mkdir(const char *path); // fail if already present
77errval_t vfs_rmdir(const char *path); // fail if not empty
78errval_t vfs_opendir(const char *path, vfs_handle_t *dhandle);
79errval_t vfs_dir_read_next(vfs_handle_t dhandle, char **name /* malloced, optional */,
80                           struct vfs_fileinfo *info /* optional */);
81errval_t vfs_closedir(vfs_handle_t dhandle);
82
83// manipulation of VFS mounts
84errval_t vfs_mount(const char *mountpoint, const char *uri);
85errval_t vfs_unmount(const char *mountpoint);
86
87__END_DECLS
88
89#endif
90