mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-12 13:59:46 -04:00
metadata_v2: update fuse driver
This commit is contained in:
parent
8395aaa85d
commit
c09fb580b4
@ -32,9 +32,15 @@
|
|||||||
|
|
||||||
#include <fuse3/fuse_lowlevel.h>
|
#include <fuse3/fuse_lowlevel.h>
|
||||||
|
|
||||||
|
#define USE_META_V2
|
||||||
|
|
||||||
|
#ifdef USE_META_V2
|
||||||
|
#include "dwarfs/filesystem_v2.h"
|
||||||
|
#else
|
||||||
#include "dwarfs/filesystem.h"
|
#include "dwarfs/filesystem.h"
|
||||||
#include "dwarfs/inode_reader.h"
|
#endif
|
||||||
#include "dwarfs/metadata.h"
|
|
||||||
|
#include "dwarfs/metadata_v2.h"
|
||||||
#include "dwarfs/mmap.h"
|
#include "dwarfs/mmap.h"
|
||||||
#include "dwarfs/options.h"
|
#include "dwarfs/options.h"
|
||||||
#include "dwarfs/util.h"
|
#include "dwarfs/util.h"
|
||||||
@ -72,6 +78,13 @@ const struct fuse_opt dwarfs_opts[] = {
|
|||||||
DWARFS_OPT("workers=%s", workers_str, 0),
|
DWARFS_OPT("workers=%s", workers_str, 0),
|
||||||
DWARFS_OPT("decratio=%s", decompress_ratio_str, 0), FUSE_OPT_END};
|
DWARFS_OPT("decratio=%s", decompress_ratio_str, 0), FUSE_OPT_END};
|
||||||
|
|
||||||
|
#ifdef USE_META_V2
|
||||||
|
using filesystem = filesystem_v2;
|
||||||
|
#define ENTRY_V2(e) (*(e))
|
||||||
|
#else
|
||||||
|
#define ENTRY_V2(e) (e)
|
||||||
|
#endif
|
||||||
|
|
||||||
options opts;
|
options opts;
|
||||||
stream_logger s_lgr(std::cerr);
|
stream_logger s_lgr(std::cerr);
|
||||||
std::shared_ptr<filesystem> s_fs;
|
std::shared_ptr<filesystem> s_fs;
|
||||||
@ -103,7 +116,7 @@ void op_lookup(fuse_req_t req, fuse_ino_t parent, const char* name) {
|
|||||||
if (de) {
|
if (de) {
|
||||||
struct ::fuse_entry_param e;
|
struct ::fuse_entry_param e;
|
||||||
|
|
||||||
err = s_fs->getattr(de, &e.attr);
|
err = s_fs->getattr(ENTRY_V2(de), &e.attr);
|
||||||
|
|
||||||
if (err == 0) {
|
if (err == 0) {
|
||||||
e.generation = 1;
|
e.generation = 1;
|
||||||
@ -139,7 +152,7 @@ void op_getattr(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info*) {
|
|||||||
if (de) {
|
if (de) {
|
||||||
struct ::stat stbuf;
|
struct ::stat stbuf;
|
||||||
|
|
||||||
err = s_fs->getattr(de, &stbuf);
|
err = s_fs->getattr(ENTRY_V2(de), &stbuf);
|
||||||
|
|
||||||
if (err == 0) {
|
if (err == 0) {
|
||||||
fuse_reply_attr(req, &stbuf, std::numeric_limits<double>::max());
|
fuse_reply_attr(req, &stbuf, std::numeric_limits<double>::max());
|
||||||
@ -169,7 +182,7 @@ void op_access(fuse_req_t req, fuse_ino_t ino, int mode) {
|
|||||||
|
|
||||||
if (de) {
|
if (de) {
|
||||||
auto ctx = fuse_req_ctx(req);
|
auto ctx = fuse_req_ctx(req);
|
||||||
err = s_fs->access(de, mode, ctx->uid, ctx->gid);
|
err = s_fs->access(ENTRY_V2(de), mode, ctx->uid, ctx->gid);
|
||||||
}
|
}
|
||||||
} catch (const dwarfs::error& e) {
|
} catch (const dwarfs::error& e) {
|
||||||
std::cerr << "ERROR: " << e.what() << std::endl;
|
std::cerr << "ERROR: " << e.what() << std::endl;
|
||||||
@ -193,7 +206,7 @@ void op_readlink(fuse_req_t req, fuse_ino_t ino) {
|
|||||||
if (de) {
|
if (de) {
|
||||||
std::string str;
|
std::string str;
|
||||||
|
|
||||||
err = s_fs->readlink(de, &str);
|
err = s_fs->readlink(ENTRY_V2(de), &str);
|
||||||
|
|
||||||
if (err == 0) {
|
if (err == 0) {
|
||||||
fuse_reply_readlink(req, str.c_str());
|
fuse_reply_readlink(req, str.c_str());
|
||||||
@ -221,12 +234,20 @@ void op_open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info* fi) {
|
|||||||
auto de = s_fs->find(ino);
|
auto de = s_fs->find(ino);
|
||||||
|
|
||||||
if (de) {
|
if (de) {
|
||||||
|
#ifdef USE_META_V2
|
||||||
|
if (S_ISDIR(de->mode())) {
|
||||||
|
#else
|
||||||
if (S_ISDIR(de->mode)) {
|
if (S_ISDIR(de->mode)) {
|
||||||
|
#endif
|
||||||
err = EISDIR;
|
err = EISDIR;
|
||||||
} else if (fi->flags & (O_APPEND | O_CREAT | O_TRUNC)) {
|
} else if (fi->flags & (O_APPEND | O_CREAT | O_TRUNC)) {
|
||||||
err = EACCES;
|
err = EACCES;
|
||||||
} else {
|
} else {
|
||||||
|
#ifdef USE_META_V2
|
||||||
|
fi->fh = de->inode();
|
||||||
|
#else
|
||||||
fi->fh = reinterpret_cast<intptr_t>(de);
|
fi->fh = reinterpret_cast<intptr_t>(de);
|
||||||
|
#endif
|
||||||
fi->keep_cache = 1;
|
fi->keep_cache = 1;
|
||||||
fuse_reply_open(req, fi);
|
fuse_reply_open(req, fi);
|
||||||
return;
|
return;
|
||||||
@ -250,33 +271,41 @@ void op_read(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
|
|||||||
int err = ENOENT;
|
int err = ENOENT;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
#ifdef USE_META_V2
|
||||||
|
assert(fi->fh == ino);
|
||||||
|
#else
|
||||||
auto de = reinterpret_cast<const dir_entry*>(fi->fh);
|
auto de = reinterpret_cast<const dir_entry*>(fi->fh);
|
||||||
|
|
||||||
if (de) {
|
if (de) {
|
||||||
iovec_read_buf buf;
|
#endif
|
||||||
ssize_t rv = s_fs->readv(ino, buf, size, off);
|
iovec_read_buf buf;
|
||||||
|
ssize_t rv = s_fs->readv(ino, buf, size, off);
|
||||||
|
|
||||||
// std::cerr << ">>> " << rv << std::endl;
|
// std::cerr << ">>> " << rv << std::endl;
|
||||||
|
|
||||||
if (rv >= 0) {
|
if (rv >= 0) {
|
||||||
fuse_reply_iov(req, buf.buf.empty() ? nullptr : &buf.buf[0],
|
fuse_reply_iov(req, buf.buf.empty() ? nullptr : &buf.buf[0],
|
||||||
buf.buf.size());
|
buf.buf.size());
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
err = -rv;
|
|
||||||
}
|
}
|
||||||
} catch (const dwarfs::error& e) {
|
|
||||||
std::cerr << "ERROR: " << e.what() << std::endl;
|
|
||||||
err = e.get_errno();
|
|
||||||
} catch (const std::exception& e) {
|
|
||||||
std::cerr << "ERROR: " << e.what() << std::endl;
|
|
||||||
err = EIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
fuse_reply_err(req, err);
|
err = -rv;
|
||||||
|
#ifndef USE_META_V2
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
catch (const dwarfs::error& e) {
|
||||||
|
std::cerr << "ERROR: " << e.what() << std::endl;
|
||||||
|
err = e.get_errno();
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
std::cerr << "ERROR: " << e.what() << std::endl;
|
||||||
|
err = EIO;
|
||||||
|
}
|
||||||
|
|
||||||
|
fuse_reply_err(req, err);
|
||||||
|
} // namespace dwarfs
|
||||||
|
|
||||||
void op_readdir(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
|
void op_readdir(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
|
||||||
struct fuse_file_info* /*fi*/) {
|
struct fuse_file_info* /*fi*/) {
|
||||||
@ -288,18 +317,27 @@ void op_readdir(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
|
|||||||
auto de = s_fs->find(ino);
|
auto de = s_fs->find(ino);
|
||||||
|
|
||||||
if (de) {
|
if (de) {
|
||||||
auto d = s_fs->opendir(de);
|
auto d = s_fs->opendir(ENTRY_V2(de));
|
||||||
|
|
||||||
if (d) {
|
if (d) {
|
||||||
off_t lastoff = s_fs->dirsize(d);
|
off_t lastoff = s_fs->dirsize(ENTRY_V2(d));
|
||||||
|
#ifndef USE_META_V2
|
||||||
std::string name;
|
std::string name;
|
||||||
|
#endif
|
||||||
struct stat stbuf;
|
struct stat stbuf;
|
||||||
std::vector<char> buf(size);
|
std::vector<char> buf(size);
|
||||||
size_t written = 0;
|
size_t written = 0;
|
||||||
|
|
||||||
while (off < lastoff) {
|
while (off < lastoff) {
|
||||||
auto de = s_fs->readdir(d, off, &name);
|
#ifdef USE_META_V2
|
||||||
s_fs->getattr(de, &stbuf);
|
auto res = s_fs->readdir(*d, off);
|
||||||
|
assert(res);
|
||||||
|
auto [de2, name_view] = *res;
|
||||||
|
std::string name(name_view);
|
||||||
|
#else
|
||||||
|
auto de2 = s_fs->readdir(d, off, &name);
|
||||||
|
#endif
|
||||||
|
s_fs->getattr(de2, &stbuf);
|
||||||
|
|
||||||
/// std::cerr << ">>> " << off << "/" << lastoff << " - " << name << "
|
/// std::cerr << ">>> " << off << "/" << lastoff << " - " << name << "
|
||||||
/// - " << stbuf.st_ino << std::endl;
|
/// - " << stbuf.st_ino << std::endl;
|
||||||
@ -456,6 +494,7 @@ int run_fuse(struct fuse_args& args) {
|
|||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dwarfs
|
} // namespace dwarfs
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
@ -487,7 +526,7 @@ int main(int argc, char* argv[]) {
|
|||||||
usage(opts.progname);
|
usage(opts.progname);
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata::get_stat_defaults(&opts.stat_defaults);
|
metadata_v2::get_stat_defaults(&opts.stat_defaults);
|
||||||
|
|
||||||
return run_fuse(args);
|
return run_fuse(args);
|
||||||
}
|
}
|
||||||
|
@ -398,7 +398,8 @@ void filesystem_v2::identify(logger& lgr, std::shared_ptr<mmif> mm,
|
|||||||
|
|
||||||
os << "SECTION " << s->header.to_string()
|
os << "SECTION " << s->header.to_string()
|
||||||
<< ", blocksize=" << bd.uncompressed_size()
|
<< ", blocksize=" << bd.uncompressed_size()
|
||||||
<< ", ratio=" << fmt::format("{:.2f}%", 100.0*compression_ratio) << std::endl;
|
<< ", ratio=" << fmt::format("{:.2f}%", 100.0 * compression_ratio)
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
if (s->header.type != section_type::BLOCK) {
|
if (s->header.type != section_type::BLOCK) {
|
||||||
if (!sections.emplace(s->header.type, *s).second) {
|
if (!sections.emplace(s->header.type, *s).second) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user