static int fs_sis_open(struct fs *_fs, const char *path, enum fs_open_mode mode, enum fs_open_flags flags, struct fs_file **file_r) { struct sis_fs *fs = (struct sis_fs *)_fs; struct sis_fs_file *file; struct fs_file *super; const char *dir, *hash; if (mode == FS_OPEN_MODE_APPEND) { fs_set_error(_fs, "APPEND mode not supported"); return -1; } if (fs_open(fs->super, path, mode | flags, &super) < 0) { fs_sis_copy_error(fs); return -1; } switch (mode) { case FS_OPEN_MODE_RDONLY: *file_r = super; return 0; case FS_OPEN_MODE_CREATE: case FS_OPEN_MODE_REPLACE: break; case FS_OPEN_MODE_APPEND: i_unreached(); } if (fs_sis_path_parse(_fs, path, &dir, &hash) < 0) return -1; file = i_new(struct sis_fs_file, 1); file->file.fs = _fs; file->file.path = i_strdup(fs_file_path(super)); file->super = super; file->open_mode = mode; file->hash = i_strdup(hash); /* if hashes/<hash> already exists, open it */ file->hash_path = i_strdup_printf("%s/"HASH_DIR_NAME"/%s", dir, hash); if (fs_open(fs->super, file->hash_path, FS_OPEN_MODE_RDONLY, &file->hash_file) < 0 && errno != ENOENT) { i_error("fs-sis: Couldn't open hash file: %s", fs_last_error(fs->super)); } if (file->hash_file != NULL) { file->hash_input = fs_read_stream(file->hash_file, IO_BLOCK_SIZE); } *file_r = &file->file; return 0; }
static void fs_sis_file_copy_error(struct sis_fs_file *file) { struct sis_fs *fs = (struct sis_fs *)file->file.fs; fs_sis_copy_error(fs); }