int archivefs_opendir(const char *path, struct fuse_file_info *info) { char fpath[PATH_MAX]; fullpath(fpath, path); /* Stejná logika jako u archivefs_open. */ DIR* dir; if ((dir = opendir(fpath)) != NULL) { info->fh = intptr_t(dir); return 0; } FileSystem* fs; FileNode* node; if (!getFile(fpath, &fs, &node)) { print_err("OPENDIR", path, ENOENT); return -ENOENT; } struct fuse_context* context = fuse_get_context(); if (fs->access(node, R_OK, context->uid, context->gid)) return -EACCES; info->fh = intptr_t(new FileHandle(fs, node)); return 0; }
int archivefs_truncate(const char* path, off_t size) { char fpath[PATH_MAX]; fullpath(fpath, path); FileSystem* fs; FileNode* node; int ret; if (!getFile(fpath, &fs, &node)) { ret = truncate(fpath, size); if (ret) { ret = errno; } } else { struct fuse_context* context = fuse_get_context(); if (fs->access(node, W_OK, context->uid, context->gid)) return -EACCES; ret = fs->truncate(node, size); } if (ret) print_err("TRUNCATE", path, ret); return -ret; }
int archivefs_open(const char* path, struct fuse_file_info* info) { char fpath[PATH_MAX]; fullpath(fpath, path); /* Nejprve se pokusím otevřít soubor s cestou path jakoby byl přítomen * fyzicky na disku - použiju systémový open. * Pokud volání této funkce selže, jedná se o soubor uvnitř archivu. */ int fd; if ((fd = open(fpath, info->flags)) != -1) { info->fh = intptr_t(fd); return 0; } FileSystem* fs; FileNode* node; if (!getFile(fpath, &fs, &node)) { print_err("OPEN", path, ENOENT); return -ENOENT; } int ret; struct fuse_context* context = fuse_get_context(); if (info->flags & O_RDWR) { if (fs->access(node, R_OK|W_OK, context->uid, context->gid)) return -EACCES; } else if (info->flags & O_WRONLY) { if (fs->access(node, W_OK, context->uid, context->gid)) return -EACCES; } else { if (fs->access(node, R_OK, context->uid, context->gid)) return -EACCES; } if ((ret = fs->open(node, info->flags)) < 0) { print_err("OPEN", path, ret); return -ret; } info->fh = intptr_t(new FileHandle(fs, node)); return 0; }
int archivefs_access(const char* path, int mask) { char fpath[PATH_MAX]; fullpath(fpath, path); FileSystem* fs; FileNode* node; int ret; struct fuse_context* context = fuse_get_context(); if (!getFile(fpath, &fs, &node)) { ret = access(fpath, mask); if (ret) { ret = errno; print_err("ACCESS", path, ret); } return -ret; } ret = fs->access(node, mask, context->uid, context->gid); if (ret) print_err("ACCESS", path, ret); return -ret; }