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, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group.
8 */
9
10#ifndef VFS_OPS_H
11#define VFS_OPS_H
12
13#include <vfs/vfs.h>
14
15struct vfs_ops {
16    // operations on files
17    errval_t (*open)(void *st, const char *path, vfs_handle_t *handle);
18    errval_t (*create)(void *st, const char *path, vfs_handle_t *handle);
19    errval_t (*remove)(void *st, const char *path);
20
21    // operations on file handles
22    errval_t (*read)(void *st, vfs_handle_t handle, void *buffer, size_t bytes,
23                     size_t *bytes_read);
24    errval_t (*write)(void *st, vfs_handle_t handle, const void *buffer, size_t bytes,
25                      size_t *bytes_written);
26    errval_t (*truncate)(void *st, vfs_handle_t handle, size_t bytes);
27    errval_t (*seek)(void *st, vfs_handle_t handle, enum vfs_seekpos whence,
28                     off_t offset);
29    errval_t (*tell)(void *st, vfs_handle_t handle, size_t *pos);
30    errval_t (*stat)(void *st, vfs_handle_t handle, struct vfs_fileinfo *info);
31    errval_t (*close)(void *st, vfs_handle_t handle);
32    errval_t (*flush)(void *st, vfs_handle_t handle);
33
34    // manipulation of directories
35    errval_t (*mkdir)(void *st, const char *path); // fail if already present
36    errval_t (*rmdir)(void *st, const char *path); // fail if not empty
37    errval_t (*opendir)(void *st, const char *path, vfs_handle_t *dhandle);
38    errval_t (*dir_read_next)(void *st, vfs_handle_t dhandle,
39                              char **name, struct vfs_fileinfo *info);
40    errval_t (*closedir)(void *st, vfs_handle_t dhandle);
41
42#ifdef WITH_BUFFER_CACHE
43    // Buffer cache operations
44    errval_t (*get_bcache_key)(void *st, vfs_handle_t handle,
45                               char **retkey, size_t *keylen, size_t *retoffset);
46
47    // Block based operations
48    errval_t (*read_block)(void *st, vfs_handle_t handle, void *buffer,
49                           size_t *bytes_read);
50    errval_t (*write_block)(void *st, vfs_handle_t handle, const void *buffer,
51                            size_t bytes, size_t *bytes_written);
52#endif
53};
54
55#endif
56