fs-api.h revision 2766f1de8141c09767a959d2d2c3065c5a300bf0
#ifndef FS_API_H
#define FS_API_H
struct stat;
struct fs;
struct fs_file;
struct fs_lock;
enum fs_properties {
FS_PROPERTY_METADATA = 0x01,
FS_PROPERTY_LOCKS = 0x02,
FS_PROPERTY_FASTCOPY = 0x04,
FS_PROPERTY_RENAME = 0x08,
FS_PROPERTY_STAT = 0x10
};
enum fs_open_mode {
/* Open only for reading, or fail with ENOENT if it doesn't exist */
/* Create a new file, fail with EEXIST if it already exists */
/* Create a new file with a new unique name. The generated name is a
128bit hex-encoded string. The fs_open()'s path parameter specifies
only the directory where the file is created to. */
/* Create or replace a file */
/* Append to existing file, fail with ENOENT if it doesn't exist */
#define FS_OPEN_MODE_MASK 0x0f
};
enum fs_open_flags {
/* File being written isn't very important, performance is more
important than actually guaranteeing that the file gets saved */
FS_OPEN_FLAG_UNIMPORTANT = 0x10,
/* Asynchronous writes: fs_write() will fail with EAGAIN if it needs to
be called again (the retries can use size=0). For streams
fs_write_stream_finish() may request retrying with 0.
Asynchronous reads: fs_read() will fail with EAGAIN if it's not
finished and fs_read_stream() returns a nonblocking stream. */
FS_OPEN_FLAG_ASYNC = 0x20
};
struct fs_settings {
/* Dovecot instance's base_dir */
const char *base_dir;
/* Automatically try to rmdir() directories up to this path when
deleting files. */
const char *root_path;
/* When creating temporary files, use this prefix
(to avoid conflicts with existing files). */
const char *temp_file_prefix;
};
struct fs_metadata {
const char *key;
const char *value;
};
typedef void fs_file_async_callback_t(void *context);
const struct fs_settings *set,
/* Return properties supported by backend. */
/* Return file's all metadata. */
/* Returns the path given to fs_open(). If file was opened with
FS_OPEN_MODE_CREATE_UNIQUE_128 and the write has already finished,
return the path including the generated filename. */
/* Return the error message for the last failed operation. */
/* Convenience function for the above. Errors aren't preserved across files. */
/* Try to asynchronously prefetch file into memory. Returns TRUE if file is
already in memory (i.e. caller should handle this file before prefetching
more), FALSE if not. The length is a hint of how much the caller expects
to read, but it may be more or less (0=whole file). */
/* Returns >0 if something was read, -1 if error (errno is set). */
/* Returns a stream for reading from file. Multiple streams can be opened,
and caller must destroy the streams before closing the file. */
files you can call fs_write() only once, the file creation is finished by it.
CREATE can return EEXIST here, if the destination file was already created.
With APPEND mode each fs_write() atomically appends the given data to
file. */
/* Write to file via output stream. The stream will be destroyed by
after this call, same as with fs_write(). Anything written to the stream
won't be visible earlier. Returns 1 if ok, 0 if async write isn't finished
yet (retry calling fs_write_stream_finish_async()), -1 if error */
/* Abort writing via stream. Anything written to the stream is discarded. */
May call the callback immediately. */
void *context);
It's an error to call this when there are no pending async operations.
Returns 0 if ok, -1 if timed out. */
/* Returns 1 if file exists, 0 if not, -1 if error occurred. */
/* Delete a file. Returns 1 if file was actually deleted by us,
0 if file didn't exist, -1 if error. */
/* Returns 0 if ok, -1 if error occurred (e.g. errno=ENOENT).
All fs backends may not support all stat fields. */
/* Copy an object with possibly updated metadata. Destination parent
directories are created automatically. Returns 0 if ok, -1 if error
occurred. */
/* Try to finish asynchronous fs_copy() */
/* Atomically rename a file. Destination parent directories are created
automatically. Returns 0 if ok, -1 if error occurred. */
/* Exclusively lock a file. If file is already locked, wait for it for given
number of seconds (0 = fail immediately). Returns 1 if locked, 0 if wait
timed out, -1 if error. */
/* Iterate through all files (but not directories) in the given directory.
Doesn't recurse to child directories. */
/* Returns 0 if ok, -1 if iteration failed. */
/* Returns the next filename. */
#endif