static int
fs_posix_init(struct fs *_fs, const char *args, const struct fs_settings *set)
{
- struct posix_fs *fs = (struct posix_fs *)_fs;
+ struct posix_fs *fs = container_of(_fs, struct posix_fs, fs);
const char *const *tmp;
fs->temp_file_prefix = set->temp_file_prefix != NULL ?
static void fs_posix_deinit(struct fs *_fs)
{
- struct posix_fs *fs = (struct posix_fs *)_fs;
+ struct posix_fs *fs = container_of(_fs, struct posix_fs, fs);
i_free(fs->temp_file_prefix);
i_free(fs->root_path);
static enum fs_properties fs_posix_get_properties(struct fs *_fs)
{
- struct posix_fs *fs = (struct posix_fs *)_fs;
+ struct posix_fs *fs = container_of(_fs, struct posix_fs, fs);
enum fs_properties props =
FS_PROPERTY_LOCKS | FS_PROPERTY_FASTCOPY | FS_PROPERTY_RENAME |
FS_PROPERTY_STAT | FS_PROPERTY_ITER | FS_PROPERTY_RELIABLEITER;
static int fs_posix_create(struct posix_fs_file *file)
{
- struct posix_fs *fs = (struct posix_fs *)file->file.fs;
+ struct posix_fs *fs = container_of(file->file.fs, struct posix_fs, fs);
string_t *str = t_str_new(256);
const char *slash;
unsigned int try_count = 0;
static int fs_posix_open(struct posix_fs_file *file)
{
- struct posix_fs *fs = (struct posix_fs *)file->file.fs;
+ struct posix_fs *fs = container_of(file->file.fs, struct posix_fs, fs);
const char *path = file->full_path;
i_assert(file->fd == -1);
fs_posix_file_init(struct fs_file *_file, const char *path,
enum fs_open_mode mode, enum fs_open_flags flags)
{
- struct posix_fs_file *file = (struct posix_fs_file *)_file;
- struct posix_fs *fs = (struct posix_fs *)_file->fs;
+ struct posix_fs_file *file =
+ container_of(_file, struct posix_fs_file, file);
+ struct posix_fs *fs = container_of(_file->fs, struct posix_fs, fs);
guid_128_t guid;
size_t path_len = strlen(path);
static void fs_posix_file_close(struct fs_file *_file)
{
- struct posix_fs_file *file = (struct posix_fs_file *)_file;
+ struct posix_fs_file *file =
+ container_of(_file, struct posix_fs_file, file);
if (file->fd != -1 && file->file.output == NULL) {
if (close(file->fd) < 0) {
static void fs_posix_file_deinit(struct fs_file *_file)
{
- struct posix_fs_file *file = (struct posix_fs_file *)_file;
+ struct posix_fs_file *file =
+ container_of(_file, struct posix_fs_file, file);
i_assert(_file->output == NULL);
static bool fs_posix_prefetch(struct fs_file *_file, uoff_t length ATTR_UNUSED)
{
- struct posix_fs_file *file = (struct posix_fs_file *)_file;
+ struct posix_fs_file *file =
+ container_of(_file, struct posix_fs_file, file);
if (fs_posix_open_for_read(file) < 0)
return TRUE;
static ssize_t fs_posix_read(struct fs_file *_file, void *buf, size_t size)
{
- struct posix_fs_file *file = (struct posix_fs_file *)_file;
+ struct posix_fs_file *file =
+ container_of(_file, struct posix_fs_file, file);
ssize_t ret;
if (fs_posix_open_for_read(file) < 0)
static struct istream *
fs_posix_read_stream(struct fs_file *_file, size_t max_buffer_size)
{
- struct posix_fs_file *file = (struct posix_fs_file *)_file;
+ struct posix_fs_file *file =
+ container_of(_file, struct posix_fs_file, file);
struct istream *input;
int fd_dup;
static void fs_posix_write_rename_if_needed(struct posix_fs_file *file)
{
- struct posix_fs *fs = (struct posix_fs *)file->file.fs;
+ struct posix_fs *fs = container_of(file->file.fs, struct posix_fs, fs);
const char *new_fname;
new_fname = fs_metadata_find(&file->file.metadata, FS_METADATA_WRITE_FNAME);
static int fs_posix_write_finish_link(struct posix_fs_file *file)
{
- struct posix_fs *fs = (struct posix_fs *)file->file.fs;
+ struct posix_fs *fs = container_of(file->file.fs, struct posix_fs, fs);
unsigned int try_count = 0;
int ret;
static int fs_posix_write_finish(struct posix_fs_file *file)
{
- struct posix_fs *fs = (struct posix_fs *)file->file.fs;
+ struct posix_fs *fs = container_of(file->file.fs, struct posix_fs, fs);
unsigned int try_count = 0;
int ret, old_errno;
static int fs_posix_write(struct fs_file *_file, const void *data, size_t size)
{
- struct posix_fs_file *file = (struct posix_fs_file *)_file;
+ struct posix_fs_file *file =
+ container_of(_file, struct posix_fs_file, file);
ssize_t ret;
if (file->fd == -1) {
static void fs_posix_write_stream(struct fs_file *_file)
{
- struct posix_fs_file *file = (struct posix_fs_file *)_file;
+ struct posix_fs_file *file =
+ container_of(_file, struct posix_fs_file, file);
i_assert(_file->output == NULL);
static int fs_posix_write_stream_finish(struct fs_file *_file, bool success)
{
- struct posix_fs_file *file = (struct posix_fs_file *)_file;
+ struct posix_fs_file *file =
+ container_of(_file, struct posix_fs_file, file);
int ret = success ? 0 : -1;
o_stream_destroy(&_file->output);
static int
fs_posix_lock(struct fs_file *_file, unsigned int secs, struct fs_lock **lock_r)
{
- struct posix_fs_file *file = (struct posix_fs_file *)_file;
- struct posix_fs *fs = (struct posix_fs *)_file->fs;
+ struct posix_fs_file *file =
+ container_of(_file, struct posix_fs_file, file);
+ struct posix_fs *fs = container_of(_file->fs, struct posix_fs, fs);
struct dotlock_settings dotlock_set;
struct posix_fs_lock fs_lock, *ret_lock;
int ret = -1;
static void fs_posix_unlock(struct fs_lock *_lock)
{
- struct posix_fs_lock *lock = (struct posix_fs_lock *)_lock;
+ struct posix_fs_lock *lock =
+ container_of(_lock, struct posix_fs_lock, lock);
if (lock->file_lock != NULL)
file_unlock(&lock->file_lock);
static int fs_posix_exists(struct fs_file *_file)
{
- struct posix_fs_file *file = (struct posix_fs_file *)_file;
+ struct posix_fs_file *file =
+ container_of(_file, struct posix_fs_file, file);
struct stat st;
if (stat(file->full_path, &st) < 0) {
static int fs_posix_stat(struct fs_file *_file, struct stat *st_r)
{
- struct posix_fs_file *file = (struct posix_fs_file *)_file;
+ struct posix_fs_file *file =
+ container_of(_file, struct posix_fs_file, file);
/* in case output != NULL it means that we're still writing to the file
and fs_stat() shouldn't stat the unfinished file. this is done by
static int fs_posix_copy(struct fs_file *_src, struct fs_file *_dest)
{
- struct posix_fs_file *src = (struct posix_fs_file *)_src;
- struct posix_fs_file *dest = (struct posix_fs_file *)_dest;
- struct posix_fs *fs = (struct posix_fs *)_src->fs;
+ struct posix_fs_file *src =
+ container_of(_src, struct posix_fs_file, file);
+ struct posix_fs_file *dest =
+ container_of(_dest, struct posix_fs_file, file);
+ struct posix_fs *fs = container_of(_src->fs, struct posix_fs, fs);
unsigned int try_count = 0;
int ret;
static int fs_posix_rename(struct fs_file *_src, struct fs_file *_dest)
{
- struct posix_fs *fs = (struct posix_fs *)_src->fs;
- struct posix_fs_file *src = (struct posix_fs_file *)_src;
- struct posix_fs_file *dest = (struct posix_fs_file *)_dest;
+ struct posix_fs *fs = container_of(_src->fs, struct posix_fs, fs);
+ struct posix_fs_file *src =
+ container_of(_src, struct posix_fs_file, file);
+ struct posix_fs_file *dest =
+ container_of(_dest, struct posix_fs_file, file);
unsigned int try_count = 0;
int ret;
static int fs_posix_delete(struct fs_file *_file)
{
- struct posix_fs_file *file = (struct posix_fs_file *)_file;
- struct posix_fs *fs = (struct posix_fs *)_file->fs;
+ struct posix_fs_file *file =
+ container_of(_file, struct posix_fs_file, file);
+ struct posix_fs *fs = container_of(_file->fs, struct posix_fs, fs);
if (unlink(file->full_path) < 0) {
if (!UNLINK_EISDIR(errno)) {
fs_posix_iter_init(struct fs_iter *_iter, const char *path,
enum fs_iter_flags flags ATTR_UNUSED)
{
- struct posix_fs_iter *iter = (struct posix_fs_iter *)_iter;
- struct posix_fs *fs = (struct posix_fs *)_iter->fs;
+ struct posix_fs_iter *iter =
+ container_of(_iter, struct posix_fs_iter, iter);
+ struct posix_fs *fs = container_of(_iter->fs, struct posix_fs, fs);
iter->path = fs->path_prefix == NULL ? i_strdup(path) :
i_strconcat(fs->path_prefix, path, NULL);
static const char *fs_posix_iter_next(struct fs_iter *_iter)
{
- struct posix_fs_iter *iter = (struct posix_fs_iter *)_iter;
- struct posix_fs *fs = (struct posix_fs *)_iter->fs;
+ struct posix_fs_iter *iter =
+ container_of(_iter, struct posix_fs_iter, iter);
+ struct posix_fs *fs = container_of(_iter->fs, struct posix_fs, fs);
struct dirent *d;
if (iter->dir == NULL)
static int fs_posix_iter_deinit(struct fs_iter *_iter)
{
- struct posix_fs_iter *iter = (struct posix_fs_iter *)_iter;
+ struct posix_fs_iter *iter =
+ container_of(_iter, struct posix_fs_iter, iter);
int ret = 0;
if (iter->dir != NULL && closedir(iter->dir) < 0 && iter->err == 0) {