コード例 #1
0
int main(int argc, char **argv)
{
    SMTPFileSystem *filesystem = SMTPFileSystem::instance();

    if (!filesystem->parseOptions(argc, argv)) {
        std::cout << "Wrong usage! See `" << smtpfs_basename(argv[0])
            << " -h' for details\n";
        return 1;
    }

    if (filesystem->isHelp()) {
        filesystem->printHelp();
        return 0;
    }

    if (filesystem->isVersion()) {
        filesystem->printVersion();
        return 0;
    }

    if (filesystem->isListDevices())
        return !filesystem->listDevices();

    return !filesystem->exec();
}
コード例 #2
0
int SMTPFileSystem::utime(const char *path, struct utimbuf *ubuf)
{
    std::string tmp_basename(smtpfs_basename(std::string(path)));
    std::string tmp_dirname(smtpfs_dirname(std::string(path)));
    const TypeDir *parent = m_device.dirFetchContent(tmp_dirname);
    if (!parent)
        return -ENOENT;
    const TypeFile *file = parent->file(tmp_basename);
    if (!file)
        return -ENOENT;
    const_cast<TypeFile*>(file)->setModificationDate(ubuf->modtime);
    return 0;
}
コード例 #3
0
int SMTPFileSystem::getattr(const char *path, struct stat *buf)
{
    memset(buf, 0, sizeof(struct stat));
    struct fuse_context *fc = fuse_get_context();
    buf->st_uid = fc->uid;
    buf->st_gid = fc->gid;
    if (path == std::string("/")) {
        buf->st_mode = S_IFDIR | 0775;
        buf->st_nlink = 2;
        return 0;
    } else {
        std::string tmp_path(smtpfs_dirname(path));
        std::string tmp_file(smtpfs_basename(path));
        const TypeDir *content = m_device.dirFetchContent(tmp_path);
        if (!content) {
            return -ENOENT;
        }

        if (content->dir(tmp_file)) {
            const TypeDir *dir = content->dir(tmp_file);
            buf->st_ino = dir->id();
            buf->st_mode = S_IFDIR | 0775;
            buf->st_nlink = 2;
            buf->st_mtime = dir->modificationDate();
        } else if (content->file(tmp_file)) {
            const TypeFile *file = content->file(tmp_file);
            buf->st_ino = file->id();
            buf->st_size = file->size();
            buf->st_blocks = (file->size() / 512) + (file->size() % 512 > 0 ? 1 : 0);
            buf->st_nlink = 1;
            buf->st_mode = S_IFREG | 0644;
            buf->st_mtime = file->modificationDate();
            buf->st_ctime = buf->st_mtime;
            buf->st_atime = buf->st_mtime;
        } else {
            return -ENOENT;
        }
    }

    return 0;
}
コード例 #4
0
void SMTPFileSystem::printHelp() const
{
    struct fuse_args args = FUSE_ARGS_INIT(0, NULL);
    struct fuse_operations tmp_operations;
    memset(&tmp_operations, 0, sizeof(tmp_operations));
    std::cerr << "usage: " << smtpfs_basename(m_args.argv[0])
              << " <source> mountpoint [options]\n\n"
        << "general options:\n"
        << "    -o opt,[opt...]        mount options\n"
        << "    -h   --help            print help\n"
        << "    -V   --version         print version\n\n"
        << "simple-mtpfs options:\n"
        << "    -v   --verbose         verbose output, implies -f\n"
        << "    -l   --list-devices    print available devices. Supports <source> option\n"
        << "         --device          select a device number to mount\n"
        << "    -o enable-move         enable the move operations\n\n";
    fuse_opt_add_arg(&args, m_args.argv[0]);
    fuse_opt_add_arg(&args, "-ho");
    fuse_main(args.argc, args.argv, &tmp_operations, nullptr);
    fuse_opt_free_args(&args);
    std::cerr << "\nReport bugs to <" << PACKAGE_BUGREPORT << ">.\n";
}