2007-08-19 18:45:46 +00:00
|
|
|
// -*- mode:C++; tab-width:8; c-basic-offset:4; indent-tabs-mode:t -*-
|
|
|
|
// vim: ts=8 sw=4 smarttab
|
|
|
|
|
|
|
|
/*
|
|
|
|
FUSE: Filesystem in Userspace
|
|
|
|
Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
|
|
|
|
|
|
|
|
This program can be distributed under the terms of the GNU GPL.
|
|
|
|
See the file COPYING.
|
|
|
|
|
|
|
|
gcc -Wall `pkg-config fuse --cflags --libs` -lulockmgr fusexmp_fh.c -o fusexmp_fh
|
|
|
|
*/
|
|
|
|
|
2013-08-01 03:19:02 +00:00
|
|
|
#define FUSE_USE_VERSION 30
|
2007-08-19 18:45:46 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
#include <fuse/fuse_lowlevel.h>
|
2007-08-19 18:45:46 +00:00
|
|
|
#include <ulockmgr.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#ifdef HAVE_SETXATTR
|
|
|
|
#include <sys/xattr.h>
|
|
|
|
#endif
|
2007-08-23 23:16:45 +00:00
|
|
|
#include <time.h>
|
2007-08-19 18:45:46 +00:00
|
|
|
|
|
|
|
|
2013-10-29 14:46:24 +00:00
|
|
|
#include "include/unordered_map.h"
|
|
|
|
#include "include/hash_namespace.h"
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-08-22 18:32:47 +00:00
|
|
|
#ifndef __LP64__
|
2013-10-29 14:46:24 +00:00
|
|
|
CEPH_HASH_NAMESPACE_START
|
2007-08-22 18:32:47 +00:00
|
|
|
template<> struct hash<uint64_t> {
|
|
|
|
size_t operator()(uint64_t __x) const {
|
|
|
|
static hash<uint32_t> H;
|
|
|
|
return H((__x >> 32) ^ (__x & 0xffffffff));
|
|
|
|
}
|
|
|
|
};
|
2013-10-29 14:46:24 +00:00
|
|
|
CEPH_HASH_NAMESPACE_END
|
2007-08-22 18:32:47 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2007-08-19 18:45:46 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
2007-08-21 16:33:20 +00:00
|
|
|
#include <map>
|
2007-08-23 04:08:24 +00:00
|
|
|
#include <set>
|
2007-08-19 18:45:46 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2007-08-21 16:33:20 +00:00
|
|
|
#include "common/Mutex.h"
|
2007-08-19 18:45:46 +00:00
|
|
|
|
|
|
|
Mutex trace_lock;
|
2007-08-21 19:02:49 +00:00
|
|
|
ofstream tracefile;
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
#define traceout (tracefile.is_open() ? tracefile : cout)
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
char *basedir = 0;
|
2007-08-22 22:32:39 +00:00
|
|
|
int debug = 0;
|
2007-08-23 23:16:45 +00:00
|
|
|
bool do_timestamps = true;
|
2007-08-22 22:32:39 +00:00
|
|
|
|
|
|
|
#define dout if (debug) cout
|
2007-08-21 19:02:49 +00:00
|
|
|
|
|
|
|
Mutex lock;
|
2007-08-23 04:08:24 +00:00
|
|
|
|
2007-08-21 16:33:20 +00:00
|
|
|
struct Inode {
|
2007-08-21 19:02:49 +00:00
|
|
|
struct stat stbuf;
|
|
|
|
int ref;
|
2007-08-23 04:08:24 +00:00
|
|
|
set<int> fds;
|
2007-08-22 23:28:03 +00:00
|
|
|
|
|
|
|
map<pair<string,ino_t>,Inode*> parents;
|
|
|
|
|
|
|
|
// if dir,
|
|
|
|
map<string,Inode*> dentries;
|
|
|
|
|
|
|
|
Inode() : ref(0) {}
|
|
|
|
|
|
|
|
Inode *lookup(const string& dname) {
|
|
|
|
if (dentries.count(dname))
|
|
|
|
return dentries[dname];
|
|
|
|
return 0;
|
|
|
|
}
|
2007-08-21 16:33:20 +00:00
|
|
|
};
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-08-22 23:04:04 +00:00
|
|
|
Inode *root = 0;
|
2013-10-29 14:46:24 +00:00
|
|
|
ceph::unordered_map<ino_t, Inode*> inode_map;
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-08-23 05:48:33 +00:00
|
|
|
bool make_inode_path(string &buf, Inode *in)
|
2007-08-19 18:45:46 +00:00
|
|
|
{
|
2007-08-22 21:41:11 +00:00
|
|
|
if (!in->parents.empty()) {
|
2007-08-23 05:48:33 +00:00
|
|
|
if (!make_inode_path(buf, in->parents.begin()->second))
|
|
|
|
return false;
|
2007-08-22 21:41:11 +00:00
|
|
|
buf += "/";
|
2007-08-22 23:04:04 +00:00
|
|
|
buf += in->parents.begin()->first.first;
|
2007-08-22 21:41:11 +00:00
|
|
|
} else {
|
2007-08-23 05:48:33 +00:00
|
|
|
if (in != root) return false;
|
2007-08-22 23:04:04 +00:00
|
|
|
assert(in->stbuf.st_ino == 1);
|
2007-08-21 19:02:49 +00:00
|
|
|
buf = basedir;
|
2007-08-22 21:41:11 +00:00
|
|
|
buf += "/";
|
|
|
|
}
|
2007-08-23 05:48:33 +00:00
|
|
|
return true;
|
2007-08-22 23:04:04 +00:00
|
|
|
//dout << "path: " << in->stbuf.st_ino << " -> " << buf << endl;
|
2007-08-19 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 05:48:33 +00:00
|
|
|
bool make_inode_path(string &buf, Inode *in, const char *name)
|
2007-08-19 18:45:46 +00:00
|
|
|
{
|
2007-08-23 05:48:33 +00:00
|
|
|
if (!make_inode_path(buf, in)) return false;
|
2007-08-21 19:02:49 +00:00
|
|
|
buf += "/";
|
|
|
|
buf += name;
|
2007-08-23 05:48:33 +00:00
|
|
|
return true;
|
2007-08-19 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 05:48:33 +00:00
|
|
|
bool make_ino_path(string &buf, ino_t ino)
|
2007-08-19 18:45:46 +00:00
|
|
|
{
|
2007-08-21 19:02:49 +00:00
|
|
|
Inode *in = inode_map[ino];
|
|
|
|
assert(in);
|
2007-08-23 05:48:33 +00:00
|
|
|
return make_inode_path(buf, in);
|
2007-08-19 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 05:48:33 +00:00
|
|
|
bool make_ino_path(string &buf, ino_t ino, const char *name)
|
2007-08-19 18:45:46 +00:00
|
|
|
{
|
2007-08-21 19:02:49 +00:00
|
|
|
Inode *in = inode_map[ino];
|
|
|
|
assert(in);
|
2007-08-23 05:48:33 +00:00
|
|
|
if (!make_inode_path(buf, in))
|
|
|
|
return false;
|
2007-08-21 19:02:49 +00:00
|
|
|
buf += "/";
|
|
|
|
buf += name;
|
2007-08-23 05:48:33 +00:00
|
|
|
return true;
|
2007-08-22 22:32:39 +00:00
|
|
|
}
|
2007-08-22 21:41:11 +00:00
|
|
|
|
2007-08-22 22:32:39 +00:00
|
|
|
void remove_dentry(Inode *pin, const string& dname)
|
2007-08-22 21:41:11 +00:00
|
|
|
{
|
2007-08-22 22:32:39 +00:00
|
|
|
dout << "remove_dentry " << pin->stbuf.st_ino << " " << dname << endl;
|
2007-08-22 21:41:11 +00:00
|
|
|
|
2007-08-22 23:28:03 +00:00
|
|
|
Inode *in = pin->lookup(dname);
|
|
|
|
assert(in);
|
|
|
|
pin->dentries.erase(dname);
|
2007-08-22 23:04:04 +00:00
|
|
|
in->parents.erase(pair<string,ino_t>(dname,pin->stbuf.st_ino));
|
2007-08-22 21:41:11 +00:00
|
|
|
|
2007-08-22 22:32:39 +00:00
|
|
|
dout << "remove_dentry " << pin->stbuf.st_ino << " " << dname
|
|
|
|
<< " ... inode " << in->stbuf.st_ino << " ref " << in->ref
|
|
|
|
<< endl;
|
2007-08-22 21:41:11 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 05:48:33 +00:00
|
|
|
void add_dentry(Inode *parent, const string& dname, Inode *in)
|
2007-08-21 19:02:49 +00:00
|
|
|
{
|
2007-08-23 05:48:33 +00:00
|
|
|
dout << "add_dentry " << parent->stbuf.st_ino << " " << dname << " to " << in->stbuf.st_ino << endl;
|
|
|
|
|
|
|
|
if (parent->dentries.count(dname))
|
|
|
|
remove_dentry(parent, dname); // e.g., when renaming over another file..
|
|
|
|
|
|
|
|
parent->dentries[dname] = in;
|
|
|
|
in->parents[pair<string,ino_t>(dname,parent->stbuf.st_ino)] = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void unlink_inode(Inode *in)
|
|
|
|
{
|
|
|
|
dout << "unlink_inode " << in->stbuf.st_ino << " ref " << in->ref << endl;
|
2007-08-22 22:32:39 +00:00
|
|
|
|
|
|
|
// remove parent links
|
|
|
|
while (!in->parents.empty()) {
|
2007-08-22 23:28:03 +00:00
|
|
|
Inode *parent = in->parents.begin()->second;
|
2007-08-22 23:04:04 +00:00
|
|
|
string dname = in->parents.begin()->first.first;
|
2007-08-22 22:32:39 +00:00
|
|
|
remove_dentry(parent, dname);
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove children
|
2007-08-22 23:28:03 +00:00
|
|
|
while (!in->dentries.empty())
|
|
|
|
remove_dentry(in, in->dentries.begin()->first);
|
2007-08-22 22:32:39 +00:00
|
|
|
|
2007-08-23 04:08:24 +00:00
|
|
|
while (!in->fds.empty()) {
|
|
|
|
int fd = *in->fds.begin();
|
|
|
|
::close(fd);
|
|
|
|
in->fds.erase(in->fds.begin());
|
|
|
|
dout << "remove_inode closeing stray fd " << fd << endl;
|
|
|
|
}
|
2007-08-23 05:48:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void remove_inode(Inode *in)
|
|
|
|
{
|
|
|
|
dout << "remove_inode " << in->stbuf.st_ino << " ref " << in->ref << endl;
|
|
|
|
|
|
|
|
unlink_inode(in);
|
2007-08-23 04:08:24 +00:00
|
|
|
|
2007-08-22 22:32:39 +00:00
|
|
|
inode_map.erase(in->stbuf.st_ino);
|
2007-08-22 23:04:04 +00:00
|
|
|
dout << "remove_inode " << in->stbuf.st_ino << " done" << endl;
|
2007-08-21 19:02:49 +00:00
|
|
|
delete in;
|
2007-08-19 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
Inode *add_inode(Inode *parent, const char *name, struct stat *attr)
|
2007-08-19 18:45:46 +00:00
|
|
|
{
|
2007-08-23 05:48:33 +00:00
|
|
|
dout << "add_inode " << parent->stbuf.st_ino << " " << name << " " << attr->st_ino << endl;
|
|
|
|
|
|
|
|
Inode *in;
|
|
|
|
if (inode_map.count(attr->st_ino)) {
|
|
|
|
// reuse inode
|
|
|
|
in = inode_map[attr->st_ino];
|
|
|
|
unlink_inode(in); // hrm.. should this close open fds? probably.
|
|
|
|
dout << "** REUSING INODE **" << endl;
|
|
|
|
} else {
|
|
|
|
inode_map[attr->st_ino] = in = new Inode;
|
|
|
|
}
|
2007-08-21 19:02:49 +00:00
|
|
|
memcpy(&in->stbuf, attr, sizeof(*attr));
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-08-22 22:32:39 +00:00
|
|
|
string dname(name);
|
|
|
|
add_dentry(parent, dname, in);
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
return in;
|
2007-08-19 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
|
2007-08-23 23:16:45 +00:00
|
|
|
void print_time()
|
|
|
|
{
|
|
|
|
if (do_timestamps) {
|
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday(&tv, 0);
|
|
|
|
traceout << "@" << endl
|
|
|
|
<< tv.tv_sec << endl
|
|
|
|
<< tv.tv_usec << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
|
2007-09-01 04:48:16 +00:00
|
|
|
bool has_perm(int mask, Inode *in, int uid, int gid)
|
|
|
|
{
|
|
|
|
dout << "hash_perm " << uid << "." << gid << " " << oct << mask << " in " << in->stbuf.st_mode
|
|
|
|
<< " " << in->stbuf.st_uid << "." << in->stbuf.st_gid << endl;
|
|
|
|
if (in->stbuf.st_mode & mask) return true;
|
|
|
|
if (in->stbuf.st_gid == gid && in->stbuf.st_mode & (mask << 3)) return true;
|
|
|
|
if (in->stbuf.st_uid == uid && in->stbuf.st_mode & (mask << 6)) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
static void ft_ll_lookup(fuse_req_t req, fuse_ino_t pino, const char *name)
|
2007-08-19 18:45:46 +00:00
|
|
|
{
|
2007-08-21 19:02:49 +00:00
|
|
|
int res = 0;
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-08-22 22:32:39 +00:00
|
|
|
//dout << "lookup " << pino << " " << name << endl;
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-08-21 23:51:22 +00:00
|
|
|
struct fuse_entry_param fe;
|
|
|
|
memset(&fe, 0, sizeof(fe));
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
lock.Lock();
|
|
|
|
Inode *parent = inode_map[pino];
|
|
|
|
assert(parent);
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-09-01 04:48:16 +00:00
|
|
|
// check permissions
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
string dname(name);
|
2007-08-22 23:04:04 +00:00
|
|
|
string path;
|
2007-08-23 05:48:33 +00:00
|
|
|
Inode *in = 0;
|
2007-09-01 04:48:16 +00:00
|
|
|
if (!has_perm(0001, parent, fuse_req_ctx(req)->uid, fuse_req_ctx(req)->gid)) {
|
|
|
|
res = EPERM;
|
|
|
|
}
|
|
|
|
else if (!make_inode_path(path, parent, name)) {
|
2007-08-23 05:48:33 +00:00
|
|
|
res = ENOENT;
|
2007-08-21 19:02:49 +00:00
|
|
|
} else {
|
2007-08-23 05:48:33 +00:00
|
|
|
in = parent->lookup(dname);
|
|
|
|
if (in && res == 0) {
|
|
|
|
// re-stat, for good measure
|
|
|
|
res = ::lstat(path.c_str(), &in->stbuf);
|
|
|
|
|
|
|
|
// hrm!
|
|
|
|
if (res != 0) {
|
|
|
|
dout << "** WEIRD ** lookup on " << pino << " " << name << " inode went away!" << endl;
|
|
|
|
in = 0;
|
|
|
|
res = errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
//dout << "have " << in->stbuf.st_ino << endl;
|
2007-08-21 19:02:49 +00:00
|
|
|
} else {
|
2007-08-23 05:48:33 +00:00
|
|
|
in = new Inode;
|
|
|
|
res = ::lstat(path.c_str(), &in->stbuf);
|
|
|
|
//dout << "stat " << path << " res = " << res << endl;
|
|
|
|
if (res == 0) {
|
|
|
|
inode_map[in->stbuf.st_ino] = in;
|
|
|
|
add_dentry(parent, dname, in);
|
|
|
|
} else {
|
|
|
|
delete in;
|
|
|
|
in = 0;
|
|
|
|
res = errno;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (in) {
|
|
|
|
in->ref++;
|
|
|
|
fe.ino = in->stbuf.st_ino;
|
|
|
|
memcpy(&fe.attr, &in->stbuf, sizeof(in->stbuf));
|
2007-08-21 19:02:49 +00:00
|
|
|
}
|
2007-08-21 23:51:22 +00:00
|
|
|
}
|
2007-08-21 19:02:49 +00:00
|
|
|
lock.Unlock();
|
2007-08-19 18:45:46 +00:00
|
|
|
|
|
|
|
trace_lock.Lock();
|
2007-08-23 23:16:45 +00:00
|
|
|
print_time();
|
2007-08-21 23:51:22 +00:00
|
|
|
traceout << "ll_lookup" << endl << pino << endl << name << endl << fe.attr.st_ino << endl;
|
2007-08-19 18:45:46 +00:00
|
|
|
trace_lock.Unlock();
|
|
|
|
|
2007-08-21 23:51:22 +00:00
|
|
|
if (in)
|
2007-08-21 19:02:49 +00:00
|
|
|
fuse_reply_entry(req, &fe);
|
2007-08-21 23:51:22 +00:00
|
|
|
else
|
2007-08-21 19:02:49 +00:00
|
|
|
fuse_reply_err(req, res);
|
2007-08-19 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
static void ft_ll_forget(fuse_req_t req, fuse_ino_t ino, long unsigned nlookup)
|
|
|
|
{
|
|
|
|
if (ino != 1) {
|
|
|
|
lock.Lock();
|
|
|
|
Inode *in = inode_map[ino];
|
|
|
|
if (in) {
|
2007-08-22 22:32:39 +00:00
|
|
|
dout << "forget on " << ino << " ref " << in->ref << ", forget " << nlookup << endl;
|
|
|
|
if (in->ref < nlookup)
|
|
|
|
dout << "**** BAD **** forget on " << ino << " ref " << in->ref << ", forget " << nlookup << endl;
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
in->ref -= nlookup;
|
2007-08-22 22:32:39 +00:00
|
|
|
if (in->ref <= 0)
|
2007-08-21 19:02:49 +00:00
|
|
|
remove_inode(in);
|
|
|
|
} else {
|
2007-08-22 23:04:04 +00:00
|
|
|
dout << "**** BAD **** forget " << nlookup << " on nonexistent inode " << ino << endl;
|
2007-08-21 19:02:49 +00:00
|
|
|
}
|
|
|
|
lock.Unlock();
|
|
|
|
}
|
2007-08-19 18:45:46 +00:00
|
|
|
|
|
|
|
trace_lock.Lock();
|
2007-08-23 23:16:45 +00:00
|
|
|
print_time();
|
2007-08-21 19:02:49 +00:00
|
|
|
traceout << "ll_forget" << endl << ino << endl << nlookup << endl;
|
2007-08-19 18:45:46 +00:00
|
|
|
trace_lock.Unlock();
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
fuse_reply_none(req);
|
2007-08-19 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
static void ft_ll_getattr(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
|
2007-08-19 18:45:46 +00:00
|
|
|
{
|
2007-08-23 05:48:33 +00:00
|
|
|
int res = 0;
|
2007-08-21 19:02:49 +00:00
|
|
|
string path;
|
2007-08-23 04:08:24 +00:00
|
|
|
int fd = 0;
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
Inode *in = 0;
|
2007-08-21 23:51:22 +00:00
|
|
|
struct stat attr;
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
lock.Lock();
|
|
|
|
in = inode_map[ino];
|
2007-08-23 05:48:33 +00:00
|
|
|
if (in->fds.empty()) {
|
|
|
|
if (!make_inode_path(path, in))
|
|
|
|
res = ENOENT;
|
|
|
|
} else
|
2007-08-23 04:08:24 +00:00
|
|
|
fd = *in->fds.begin();
|
2007-08-21 19:02:49 +00:00
|
|
|
lock.Unlock();
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-08-23 04:08:24 +00:00
|
|
|
if (fd > 0) {
|
|
|
|
res = ::fstat(fd, &attr);
|
|
|
|
dout << "getattr fstat on fd " << fd << " res " << res << endl;
|
2007-08-23 05:48:33 +00:00
|
|
|
} else if (res == 0) {
|
2007-08-23 04:08:24 +00:00
|
|
|
res = ::lstat(path.c_str(), &attr);
|
|
|
|
dout << "getattr lstat on " << path << " res " << res << endl;
|
|
|
|
}
|
2007-08-23 05:48:33 +00:00
|
|
|
if (res < 0) res = errno;
|
2007-08-22 23:04:04 +00:00
|
|
|
if (ino == 1) attr.st_ino = 1;
|
2007-08-21 19:02:49 +00:00
|
|
|
|
2007-08-19 18:45:46 +00:00
|
|
|
trace_lock.Lock();
|
2007-08-23 23:16:45 +00:00
|
|
|
print_time();
|
2007-08-21 19:02:49 +00:00
|
|
|
traceout << "ll_getattr" << endl << ino << endl;
|
2007-08-19 18:45:46 +00:00
|
|
|
trace_lock.Unlock();
|
|
|
|
|
2007-08-21 23:51:22 +00:00
|
|
|
if (res == 0) {
|
|
|
|
lock.Lock();
|
|
|
|
memcpy(&in->stbuf, &attr, sizeof(attr));
|
|
|
|
lock.Unlock();
|
|
|
|
fuse_reply_attr(req, &attr, 0);
|
|
|
|
} else
|
2007-08-23 05:48:33 +00:00
|
|
|
fuse_reply_err(req, res);
|
2007-08-19 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
static void ft_ll_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr,
|
|
|
|
int to_set, struct fuse_file_info *fi)
|
2007-08-19 18:45:46 +00:00
|
|
|
{
|
2007-08-21 19:02:49 +00:00
|
|
|
string path;
|
2007-08-21 23:51:22 +00:00
|
|
|
Inode *in = 0;
|
2007-08-23 04:08:24 +00:00
|
|
|
int fd = 0;
|
2007-08-23 05:48:33 +00:00
|
|
|
int res = 0;
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
lock.Lock();
|
2007-08-21 23:51:22 +00:00
|
|
|
in = inode_map[ino];
|
2007-08-23 05:48:33 +00:00
|
|
|
if (in->fds.empty() || (to_set & FUSE_SET_ATTR_MTIME)) {
|
|
|
|
if (!make_inode_path(path, in))
|
|
|
|
res = ENOENT;
|
|
|
|
} else
|
2007-08-23 04:08:24 +00:00
|
|
|
fd = *in->fds.begin();
|
2007-08-21 19:02:49 +00:00
|
|
|
lock.Unlock();
|
2007-08-19 18:45:46 +00:00
|
|
|
|
|
|
|
trace_lock.Lock();
|
2007-08-23 23:16:45 +00:00
|
|
|
print_time();
|
2007-08-21 19:02:49 +00:00
|
|
|
traceout << "ll_setattr" << endl << ino << endl;
|
|
|
|
traceout << attr->st_mode << endl;
|
|
|
|
traceout << attr->st_uid << endl << attr->st_gid << endl;
|
|
|
|
traceout << attr->st_size << endl;
|
|
|
|
traceout << attr->st_mtime << endl;
|
|
|
|
traceout << attr->st_atime << endl;
|
|
|
|
traceout << to_set << endl;
|
2007-08-19 18:45:46 +00:00
|
|
|
trace_lock.Unlock();
|
|
|
|
|
2007-09-01 04:48:16 +00:00
|
|
|
if (res == 0 && !has_perm(0010, in, fuse_req_ctx(req)->uid, fuse_req_ctx(req)->gid)) {
|
|
|
|
res = EPERM;
|
|
|
|
} else if (res == 0) {
|
2007-08-23 05:48:33 +00:00
|
|
|
if (to_set & FUSE_SET_ATTR_MODE) {
|
|
|
|
if (fd > 0)
|
|
|
|
res = ::fchmod(fd, attr->st_mode);
|
|
|
|
else
|
|
|
|
res = ::chmod(path.c_str(), attr->st_mode);
|
|
|
|
}
|
|
|
|
if (!res && to_set & FUSE_SET_ATTR_UID) {
|
|
|
|
if (fd > 0)
|
|
|
|
res = ::fchown(fd, attr->st_uid, attr->st_gid);
|
|
|
|
else
|
|
|
|
res = ::chown(path.c_str(), attr->st_uid, attr->st_gid);
|
|
|
|
}
|
|
|
|
if (!res && to_set & FUSE_SET_ATTR_SIZE) {
|
|
|
|
if (fd > 0)
|
|
|
|
res = ::ftruncate(fd, attr->st_size);
|
|
|
|
else
|
|
|
|
res = ::truncate(path.c_str(), attr->st_size);
|
|
|
|
}
|
|
|
|
if (!res && to_set & FUSE_SET_ATTR_MTIME) {
|
|
|
|
struct utimbuf ut;
|
|
|
|
ut.actime = attr->st_atime;
|
|
|
|
ut.modtime = attr->st_mtime;
|
|
|
|
res = ::utime(path.c_str(), &ut);
|
|
|
|
}
|
|
|
|
if (res < 0) res = errno;
|
2007-08-21 19:02:49 +00:00
|
|
|
}
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
if (res == 0) {
|
2007-08-21 23:51:22 +00:00
|
|
|
lock.Lock();
|
|
|
|
::lstat(path.c_str(), &in->stbuf);
|
2007-08-22 23:04:04 +00:00
|
|
|
if (ino == 1) in->stbuf.st_ino = 1;
|
2007-08-21 23:51:22 +00:00
|
|
|
memcpy(attr, &in->stbuf, sizeof(*attr));
|
|
|
|
lock.Unlock();
|
2007-08-21 19:02:49 +00:00
|
|
|
fuse_reply_attr(req, attr, 0);
|
|
|
|
} else
|
2007-08-23 05:48:33 +00:00
|
|
|
fuse_reply_err(req, res);
|
2007-08-19 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
|
|
|
|
static void ft_ll_readlink(fuse_req_t req, fuse_ino_t ino)
|
2007-08-19 18:45:46 +00:00
|
|
|
{
|
2007-08-21 19:02:49 +00:00
|
|
|
string path;
|
2007-08-23 05:48:33 +00:00
|
|
|
int res = 0;
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
lock.Lock();
|
2007-08-23 05:48:33 +00:00
|
|
|
if (!make_ino_path(path, ino))
|
|
|
|
res = ENOENT;
|
2007-08-21 19:02:49 +00:00
|
|
|
lock.Unlock();
|
2007-08-19 18:45:46 +00:00
|
|
|
|
|
|
|
trace_lock.Lock();
|
2007-08-23 23:16:45 +00:00
|
|
|
print_time();
|
2007-08-21 19:02:49 +00:00
|
|
|
traceout << "ll_readlink" << endl << ino << endl;
|
2007-08-19 18:45:46 +00:00
|
|
|
trace_lock.Unlock();
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
char buf[256];
|
2007-08-23 05:48:33 +00:00
|
|
|
if (res == 0) res = readlink(path.c_str(), buf, 255);
|
|
|
|
if (res < 0) res = errno;
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
if (res >= 0) {
|
|
|
|
buf[res] = 0;
|
|
|
|
fuse_reply_readlink(req, buf);
|
|
|
|
} else {
|
2007-08-23 05:48:33 +00:00
|
|
|
fuse_reply_err(req, res);
|
2007-08-21 19:02:49 +00:00
|
|
|
}
|
2007-08-19 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
|
|
|
|
static void ft_ll_opendir(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
|
2007-08-19 18:45:46 +00:00
|
|
|
{
|
2007-08-21 19:02:49 +00:00
|
|
|
string path;
|
2007-08-23 05:48:33 +00:00
|
|
|
int res = 0;
|
2007-08-21 19:02:49 +00:00
|
|
|
lock.Lock();
|
2007-09-01 04:48:16 +00:00
|
|
|
Inode *in = inode_map[ino];
|
|
|
|
if (!make_inode_path(path, in))
|
2007-08-23 05:48:33 +00:00
|
|
|
res = ENOENT;
|
2007-08-21 19:02:49 +00:00
|
|
|
lock.Unlock();
|
2007-08-23 05:48:33 +00:00
|
|
|
|
|
|
|
DIR *dir = 0;
|
2007-09-01 04:48:16 +00:00
|
|
|
if (res == 0 && !has_perm(0100, in, fuse_req_ctx(req)->uid, fuse_req_ctx(req)->gid))
|
|
|
|
res = EPERM;
|
|
|
|
else if (res == 0) dir = opendir(path.c_str());
|
2007-08-23 05:48:33 +00:00
|
|
|
if (res < 0) res = errno;
|
2007-08-19 18:45:46 +00:00
|
|
|
|
|
|
|
trace_lock.Lock();
|
2007-08-23 23:16:45 +00:00
|
|
|
print_time();
|
2007-08-22 18:33:18 +00:00
|
|
|
traceout << "ll_opendir" << endl << ino << endl << (unsigned long)dir << endl;
|
2007-08-19 18:45:46 +00:00
|
|
|
trace_lock.Unlock();
|
2007-08-21 19:02:49 +00:00
|
|
|
|
|
|
|
if (dir) {
|
|
|
|
fi->fh = (long)dir;
|
|
|
|
fuse_reply_open(req, fi);
|
|
|
|
} else
|
2007-08-23 05:48:33 +00:00
|
|
|
fuse_reply_err(req, res);
|
2007-08-19 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
static void ft_ll_readdir(fuse_req_t req, fuse_ino_t ino, size_t size,
|
|
|
|
off_t off, struct fuse_file_info *fi)
|
2007-08-19 18:45:46 +00:00
|
|
|
{
|
2007-08-21 19:02:49 +00:00
|
|
|
struct dirent *de;
|
|
|
|
DIR *dp = (DIR*)fi->fh;
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
// buffer
|
|
|
|
char *buf;
|
|
|
|
size_t pos = 0;
|
|
|
|
|
|
|
|
buf = new char[size];
|
|
|
|
if (!buf) {
|
|
|
|
fuse_reply_err(req, ENOMEM);
|
|
|
|
return;
|
|
|
|
}
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
seekdir(dp, off);
|
|
|
|
while ((de = readdir(dp)) != NULL) {
|
|
|
|
struct stat st;
|
|
|
|
memset(&st, 0, sizeof(st));
|
|
|
|
st.st_ino = de->d_ino;
|
|
|
|
st.st_mode = de->d_type << 12;
|
|
|
|
|
|
|
|
size_t entrysize = fuse_add_direntry(req, buf + pos, size - pos,
|
|
|
|
de->d_name, &st, telldir(dp));
|
|
|
|
if (entrysize > size - pos)
|
|
|
|
break; // didn't fit, done for now.
|
|
|
|
pos += entrysize;
|
|
|
|
}
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
fuse_reply_buf(req, buf, pos);
|
|
|
|
delete[] buf;
|
2007-08-19 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
static void ft_ll_releasedir(fuse_req_t req, fuse_ino_t ino,
|
|
|
|
struct fuse_file_info *fi)
|
2007-08-19 18:45:46 +00:00
|
|
|
{
|
2007-08-23 23:16:45 +00:00
|
|
|
DIR *dir = (DIR*)fi->fh;
|
|
|
|
|
|
|
|
trace_lock.Lock();
|
|
|
|
print_time();
|
|
|
|
traceout << "ll_releasedir" << endl << (unsigned long)dir << endl;
|
|
|
|
trace_lock.Unlock();
|
|
|
|
|
|
|
|
closedir(dir);
|
|
|
|
fuse_reply_err(req, 0);
|
2007-08-19 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
static void ft_ll_mknod(fuse_req_t req, fuse_ino_t parent, const char *name,
|
|
|
|
mode_t mode, dev_t rdev)
|
|
|
|
{
|
|
|
|
string path;
|
|
|
|
Inode *pin = 0;
|
2007-08-23 05:48:33 +00:00
|
|
|
int res = 0;
|
2007-08-21 19:02:49 +00:00
|
|
|
lock.Lock();
|
|
|
|
pin = inode_map[parent];
|
2007-08-23 05:48:33 +00:00
|
|
|
if (!make_inode_path(path, pin, name))
|
|
|
|
res = ENOENT;
|
2007-08-21 19:02:49 +00:00
|
|
|
lock.Unlock();
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-08-23 04:08:24 +00:00
|
|
|
dout << "mknod " << path << endl;
|
2007-09-01 04:48:16 +00:00
|
|
|
if (res == 0 && !has_perm(0010, pin, fuse_req_ctx(req)->uid, fuse_req_ctx(req)->gid))
|
|
|
|
res = EPERM;
|
|
|
|
else if (res == 0) res = ::mknod(path.c_str(), mode, rdev);
|
2007-08-24 21:49:13 +00:00
|
|
|
if (res < 0)
|
|
|
|
res = errno;
|
|
|
|
else
|
|
|
|
::chown(path.c_str(), fuse_req_ctx(req)->uid, fuse_req_ctx(req)->gid);
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
struct fuse_entry_param fe;
|
|
|
|
if (res == 0) {
|
|
|
|
memset(&fe, 0, sizeof(fe));
|
|
|
|
::lstat(path.c_str(), &fe.attr);
|
|
|
|
fe.ino = fe.attr.st_ino;
|
2007-08-21 23:51:22 +00:00
|
|
|
lock.Lock();
|
2007-08-22 22:32:39 +00:00
|
|
|
Inode *in = add_inode(pin, name, &fe.attr);
|
|
|
|
in->ref++;
|
2007-08-21 23:51:22 +00:00
|
|
|
lock.Unlock();
|
2007-08-21 19:02:49 +00:00
|
|
|
}
|
2007-08-19 18:45:46 +00:00
|
|
|
|
|
|
|
trace_lock.Lock();
|
2007-08-23 23:16:45 +00:00
|
|
|
print_time();
|
2007-08-21 19:02:49 +00:00
|
|
|
traceout << "ll_mknod" << endl << parent << endl << name << endl << mode << endl << rdev << endl;
|
|
|
|
traceout << (res == 0 ? fe.ino:0) << endl;
|
2007-08-19 18:45:46 +00:00
|
|
|
trace_lock.Unlock();
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
if (res == 0)
|
|
|
|
fuse_reply_entry(req, &fe);
|
|
|
|
else
|
2007-08-23 05:48:33 +00:00
|
|
|
fuse_reply_err(req, res);
|
2007-08-19 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
static void ft_ll_mkdir(fuse_req_t req, fuse_ino_t parent, const char *name,
|
|
|
|
mode_t mode)
|
2007-08-19 18:45:46 +00:00
|
|
|
{
|
2007-08-21 19:02:49 +00:00
|
|
|
string path;
|
|
|
|
Inode *pin = 0;
|
2007-08-23 05:48:33 +00:00
|
|
|
int res = 0;
|
2007-08-21 19:02:49 +00:00
|
|
|
lock.Lock();
|
|
|
|
pin = inode_map[parent];
|
2007-08-23 05:48:33 +00:00
|
|
|
if (!make_inode_path(path, pin, name))
|
|
|
|
res = ENOENT;
|
2007-08-21 19:02:49 +00:00
|
|
|
lock.Unlock();
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-09-01 04:48:16 +00:00
|
|
|
if (res == 0 && !has_perm(0010, pin, fuse_req_ctx(req)->uid, fuse_req_ctx(req)->gid))
|
|
|
|
res = EPERM;
|
|
|
|
else if (res == 0) res = ::mkdir(path.c_str(), mode);
|
2007-08-24 21:49:13 +00:00
|
|
|
if (res < 0)
|
|
|
|
res = errno;
|
|
|
|
else
|
|
|
|
::chown(path.c_str(), fuse_req_ctx(req)->uid, fuse_req_ctx(req)->gid);
|
2007-08-21 19:02:49 +00:00
|
|
|
|
|
|
|
struct fuse_entry_param fe;
|
|
|
|
if (res == 0) {
|
|
|
|
memset(&fe, 0, sizeof(fe));
|
|
|
|
::lstat(path.c_str(), &fe.attr);
|
|
|
|
fe.ino = fe.attr.st_ino;
|
2007-08-21 23:51:22 +00:00
|
|
|
lock.Lock();
|
2007-08-22 22:32:39 +00:00
|
|
|
Inode *in = add_inode(pin, name, &fe.attr);
|
|
|
|
in->ref++;
|
2007-08-21 23:51:22 +00:00
|
|
|
lock.Unlock();
|
2007-08-21 19:02:49 +00:00
|
|
|
}
|
2007-08-19 18:45:46 +00:00
|
|
|
|
|
|
|
trace_lock.Lock();
|
2007-08-23 23:16:45 +00:00
|
|
|
print_time();
|
2007-08-21 19:02:49 +00:00
|
|
|
traceout << "ll_mkdir" << endl << parent << endl << name << endl << mode << endl;
|
|
|
|
traceout << (res == 0 ? fe.ino:0) << endl;
|
2007-08-19 18:45:46 +00:00
|
|
|
trace_lock.Unlock();
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
if (res == 0)
|
|
|
|
fuse_reply_entry(req, &fe);
|
|
|
|
else
|
2007-08-23 05:48:33 +00:00
|
|
|
fuse_reply_err(req, res);
|
2007-08-19 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
static void ft_ll_symlink(fuse_req_t req, const char *value, fuse_ino_t parent, const char *name)
|
2007-08-19 18:45:46 +00:00
|
|
|
{
|
2007-08-21 19:02:49 +00:00
|
|
|
string path;
|
|
|
|
Inode *pin = 0;
|
2007-08-23 05:48:33 +00:00
|
|
|
int res = 0;
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
lock.Lock();
|
|
|
|
pin = inode_map[parent];
|
2007-08-23 05:48:33 +00:00
|
|
|
if (!make_inode_path(path, pin, name))
|
|
|
|
res = ENOENT;
|
2007-08-21 19:02:49 +00:00
|
|
|
lock.Unlock();
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-09-01 04:48:16 +00:00
|
|
|
if (res == 0 && !has_perm(0010, pin, fuse_req_ctx(req)->uid, fuse_req_ctx(req)->gid))
|
|
|
|
res = EPERM;
|
|
|
|
else if (res == 0) res = ::symlink(value, path.c_str());
|
2007-08-24 21:49:13 +00:00
|
|
|
if (res < 0)
|
|
|
|
res = errno;
|
|
|
|
else
|
|
|
|
::chown(path.c_str(), fuse_req_ctx(req)->uid, fuse_req_ctx(req)->gid);
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
struct fuse_entry_param fe;
|
|
|
|
if (res == 0) {
|
|
|
|
memset(&fe, 0, sizeof(fe));
|
|
|
|
::lstat(path.c_str(), &fe.attr);
|
|
|
|
fe.ino = fe.attr.st_ino;
|
2007-08-21 23:51:22 +00:00
|
|
|
lock.Lock();
|
2007-08-22 22:32:39 +00:00
|
|
|
Inode *in = add_inode(pin, name, &fe.attr);
|
|
|
|
in->ref++;
|
2007-08-21 23:51:22 +00:00
|
|
|
lock.Unlock();
|
2007-08-21 19:02:49 +00:00
|
|
|
}
|
2007-08-19 18:45:46 +00:00
|
|
|
|
|
|
|
trace_lock.Lock();
|
2007-08-23 23:16:45 +00:00
|
|
|
print_time();
|
2007-08-21 19:02:49 +00:00
|
|
|
traceout << "ll_symlink" << endl << parent << endl << name << endl << value << endl;
|
|
|
|
traceout << (res == 0 ? fe.ino:0) << endl;
|
2007-08-19 18:45:46 +00:00
|
|
|
trace_lock.Unlock();
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
if (res == 0)
|
|
|
|
fuse_reply_entry(req, &fe);
|
|
|
|
else
|
2007-08-23 05:48:33 +00:00
|
|
|
fuse_reply_err(req, res);
|
2007-08-19 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 23:16:45 +00:00
|
|
|
static void ft_ll_create(fuse_req_t req, fuse_ino_t parent, const char *name,
|
|
|
|
mode_t mode, struct fuse_file_info *fi)
|
|
|
|
{
|
|
|
|
string path;
|
|
|
|
Inode *pin = 0;
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
lock.Lock();
|
|
|
|
pin = inode_map[parent];
|
|
|
|
if (!make_inode_path(path, pin, name))
|
|
|
|
res = ENOENT;
|
|
|
|
lock.Unlock();
|
|
|
|
|
|
|
|
dout << "create " << path << endl;
|
|
|
|
int fd = 0;
|
2007-09-01 04:48:16 +00:00
|
|
|
if (res == 0 && !has_perm(0010, pin, fuse_req_ctx(req)->uid, fuse_req_ctx(req)->gid))
|
|
|
|
res = EPERM;
|
|
|
|
else if (res == 0) {
|
2007-08-23 23:16:45 +00:00
|
|
|
fd = ::open(path.c_str(), fi->flags|O_CREAT, mode);
|
2007-08-24 21:49:13 +00:00
|
|
|
if (fd < 0) {
|
|
|
|
res = errno;
|
|
|
|
} else {
|
|
|
|
::fchown(fd, fuse_req_ctx(req)->uid, fuse_req_ctx(req)->gid);
|
|
|
|
}
|
2007-08-23 23:16:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct fuse_entry_param fe;
|
|
|
|
memset(&fe, 0, sizeof(fe));
|
|
|
|
if (res == 0) {
|
|
|
|
::lstat(path.c_str(), &fe.attr);
|
|
|
|
fe.ino = fe.attr.st_ino;
|
|
|
|
lock.Lock();
|
|
|
|
Inode *in = add_inode(pin, name, &fe.attr);
|
|
|
|
in->ref++;
|
|
|
|
in->fds.insert(fd);
|
|
|
|
lock.Unlock();
|
|
|
|
fi->fh = fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
trace_lock.Lock();
|
|
|
|
print_time();
|
|
|
|
traceout << "ll_create" << endl
|
|
|
|
<< parent << endl
|
|
|
|
<< name << endl
|
|
|
|
<< mode << endl
|
|
|
|
<< fi->flags << endl
|
|
|
|
<< (res == 0 ? fd:0) << endl
|
|
|
|
<< fe.ino << endl;
|
|
|
|
trace_lock.Unlock();
|
|
|
|
|
|
|
|
if (res == 0)
|
|
|
|
fuse_reply_create(req, &fe, fi);
|
|
|
|
else
|
|
|
|
fuse_reply_err(req, res);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
static void ft_ll_statfs(fuse_req_t req, fuse_ino_t ino)
|
|
|
|
{
|
|
|
|
string path;
|
2007-08-23 05:48:33 +00:00
|
|
|
int res = 0;
|
2007-08-22 20:35:46 +00:00
|
|
|
if (ino) {
|
|
|
|
lock.Lock();
|
2007-08-23 05:48:33 +00:00
|
|
|
if (!make_ino_path(path, ino))
|
|
|
|
res = ENOENT;
|
2007-08-22 20:35:46 +00:00
|
|
|
lock.Unlock();
|
|
|
|
} else {
|
|
|
|
path = basedir;
|
|
|
|
}
|
|
|
|
|
2007-08-19 18:45:46 +00:00
|
|
|
trace_lock.Lock();
|
2007-08-23 23:16:45 +00:00
|
|
|
print_time();
|
2007-08-21 19:02:49 +00:00
|
|
|
traceout << "ll_statfs" << endl << ino << endl;
|
2007-08-19 18:45:46 +00:00
|
|
|
trace_lock.Unlock();
|
2007-08-21 19:02:49 +00:00
|
|
|
|
|
|
|
struct statvfs stbuf;
|
2007-08-23 05:48:33 +00:00
|
|
|
if (res == 0) res = statvfs(path.c_str(), &stbuf);
|
|
|
|
if (res < 0) res = errno;
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
if (res == 0)
|
|
|
|
fuse_reply_statfs(req, &stbuf);
|
|
|
|
else
|
2007-08-23 05:48:33 +00:00
|
|
|
fuse_reply_err(req, res);
|
2007-08-19 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
static void ft_ll_unlink(fuse_req_t req, fuse_ino_t parent, const char *name)
|
2007-08-19 18:45:46 +00:00
|
|
|
{
|
2007-08-21 19:02:49 +00:00
|
|
|
string path;
|
|
|
|
Inode *pin = 0;
|
2007-08-23 04:08:24 +00:00
|
|
|
Inode *in = 0;
|
|
|
|
string dname(name);
|
2007-08-23 05:48:33 +00:00
|
|
|
int res = 0;
|
2007-08-21 19:02:49 +00:00
|
|
|
lock.Lock();
|
|
|
|
pin = inode_map[parent];
|
2007-08-23 04:08:24 +00:00
|
|
|
in = pin->lookup(dname);
|
2007-08-23 05:48:33 +00:00
|
|
|
if (!make_inode_path(path, pin, name))
|
|
|
|
res = ENOENT;
|
2007-08-21 19:02:49 +00:00
|
|
|
lock.Unlock();
|
2007-08-19 18:45:46 +00:00
|
|
|
|
|
|
|
trace_lock.Lock();
|
2007-08-23 23:16:45 +00:00
|
|
|
print_time();
|
2007-08-21 19:02:49 +00:00
|
|
|
traceout << "ll_unlink" << endl << parent << endl << name << endl;
|
2007-08-19 18:45:46 +00:00
|
|
|
trace_lock.Unlock();
|
2007-08-23 04:08:24 +00:00
|
|
|
|
2007-09-01 04:48:16 +00:00
|
|
|
if (res == 0 && !has_perm(0010, pin, fuse_req_ctx(req)->uid, fuse_req_ctx(req)->gid))
|
|
|
|
res = EPERM;
|
|
|
|
else if (res == 0) {
|
2007-08-23 05:48:33 +00:00
|
|
|
if (in && in->fds.empty()) {
|
|
|
|
int fd = ::open(path.c_str(), O_RDWR);
|
|
|
|
if (fd > 0)
|
|
|
|
in->fds.insert(fd); // for slow getattrs.. wtf
|
|
|
|
dout << "unlink opening paranoia fd " << fd << endl;
|
|
|
|
}
|
|
|
|
res = ::unlink(path.c_str());
|
|
|
|
if (res < 0) res = errno;
|
2007-08-23 04:08:24 +00:00
|
|
|
}
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
if (res == 0) {
|
|
|
|
// remove from out cache
|
2007-08-21 23:51:22 +00:00
|
|
|
lock.Lock();
|
2007-08-21 19:02:49 +00:00
|
|
|
string dname(name);
|
2007-08-22 23:28:03 +00:00
|
|
|
if (pin->lookup(dname))
|
|
|
|
remove_dentry(pin, dname);
|
2007-08-21 23:51:22 +00:00
|
|
|
lock.Unlock();
|
2007-08-21 19:02:49 +00:00
|
|
|
fuse_reply_err(req, 0);
|
|
|
|
} else
|
2007-08-23 05:48:33 +00:00
|
|
|
fuse_reply_err(req, res);
|
2007-08-19 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
static void ft_ll_rmdir(fuse_req_t req, fuse_ino_t parent, const char *name)
|
2007-08-19 18:45:46 +00:00
|
|
|
{
|
2007-08-21 19:02:49 +00:00
|
|
|
string path;
|
|
|
|
Inode *pin = 0;
|
2007-08-23 05:48:33 +00:00
|
|
|
int res = 0;
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
lock.Lock();
|
|
|
|
pin = inode_map[parent];
|
2007-08-23 05:48:33 +00:00
|
|
|
if (!make_inode_path(path, pin, name))
|
|
|
|
res = ENOENT;
|
2007-08-21 19:02:49 +00:00
|
|
|
lock.Unlock();
|
2007-08-19 18:45:46 +00:00
|
|
|
|
|
|
|
trace_lock.Lock();
|
2007-08-23 23:16:45 +00:00
|
|
|
print_time();
|
2007-08-21 19:02:49 +00:00
|
|
|
traceout << "ll_rmdir" << endl << parent << endl << name << endl;
|
2007-08-19 18:45:46 +00:00
|
|
|
trace_lock.Unlock();
|
|
|
|
|
2007-09-01 04:48:16 +00:00
|
|
|
if (res == 0 && !has_perm(0010, pin, fuse_req_ctx(req)->uid, fuse_req_ctx(req)->gid))
|
|
|
|
res = EPERM;
|
|
|
|
else if (res == 0) res = ::rmdir(path.c_str());
|
2007-08-23 05:48:33 +00:00
|
|
|
if (res < 0) res = errno;
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
if (res == 0) {
|
|
|
|
// remove from out cache
|
2007-08-21 23:51:22 +00:00
|
|
|
lock.Lock();
|
2007-08-21 19:02:49 +00:00
|
|
|
string dname(name);
|
2007-08-22 23:28:03 +00:00
|
|
|
if (pin->lookup(dname))
|
|
|
|
remove_dentry(pin, dname);
|
2007-08-21 23:51:22 +00:00
|
|
|
lock.Unlock();
|
2007-08-21 19:02:49 +00:00
|
|
|
fuse_reply_err(req, 0);
|
|
|
|
} else
|
2007-08-23 05:48:33 +00:00
|
|
|
fuse_reply_err(req, res);
|
2007-08-19 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
|
|
|
|
static void ft_ll_rename(fuse_req_t req, fuse_ino_t parent, const char *name,
|
|
|
|
fuse_ino_t newparent, const char *newname)
|
2007-08-19 18:45:46 +00:00
|
|
|
{
|
2007-08-21 19:02:49 +00:00
|
|
|
string path;
|
|
|
|
string newpath;
|
|
|
|
Inode *pin = 0;
|
|
|
|
Inode *newpin = 0;
|
2007-08-23 05:48:33 +00:00
|
|
|
int res = 0;
|
2007-08-21 19:02:49 +00:00
|
|
|
lock.Lock();
|
|
|
|
pin = inode_map[parent];
|
2007-08-23 05:48:33 +00:00
|
|
|
if (!make_inode_path(path, pin, name))
|
|
|
|
res = ENOENT;
|
2007-08-21 19:02:49 +00:00
|
|
|
newpin = inode_map[newparent];
|
2007-08-23 05:48:33 +00:00
|
|
|
if (!make_inode_path(newpath, newpin, newname))
|
|
|
|
res = ENOENT;
|
2007-08-21 19:02:49 +00:00
|
|
|
lock.Unlock();
|
2007-08-19 18:45:46 +00:00
|
|
|
|
|
|
|
trace_lock.Lock();
|
2007-08-23 23:16:45 +00:00
|
|
|
print_time();
|
2007-08-21 23:51:22 +00:00
|
|
|
traceout << "ll_rename" << endl
|
|
|
|
<< parent << endl
|
|
|
|
<< name << endl
|
|
|
|
<< newparent << endl
|
|
|
|
<< newname << endl;
|
2007-08-19 18:45:46 +00:00
|
|
|
trace_lock.Unlock();
|
|
|
|
|
2007-09-01 04:48:16 +00:00
|
|
|
if (res == 0 && (!has_perm(0010, pin, fuse_req_ctx(req)->uid, fuse_req_ctx(req)->gid) ||
|
|
|
|
!has_perm(0010, newpin, fuse_req_ctx(req)->uid, fuse_req_ctx(req)->gid)))
|
|
|
|
res = EPERM;
|
|
|
|
else if (res == 0) res = ::rename(path.c_str(), newpath.c_str());
|
2007-08-23 05:48:33 +00:00
|
|
|
if (res < 0) res = errno;
|
2007-08-21 19:02:49 +00:00
|
|
|
|
|
|
|
if (res == 0) {
|
|
|
|
string dname(name);
|
|
|
|
string newdname(newname);
|
2007-08-21 23:51:22 +00:00
|
|
|
lock.Lock();
|
2007-08-22 23:28:03 +00:00
|
|
|
Inode *in = pin->lookup(dname);
|
|
|
|
if (in) {
|
2007-08-22 22:32:39 +00:00
|
|
|
add_dentry(newpin, newdname, in);
|
|
|
|
remove_dentry(pin, dname);
|
|
|
|
} else {
|
|
|
|
dout << "hrm, rename didn't have renamed inode.. " << path << " to " << newpath << endl;
|
2007-08-21 19:02:49 +00:00
|
|
|
}
|
2007-08-21 23:51:22 +00:00
|
|
|
lock.Unlock();
|
2007-08-21 19:02:49 +00:00
|
|
|
fuse_reply_err(req, 0);
|
|
|
|
} else
|
2007-08-23 05:48:33 +00:00
|
|
|
fuse_reply_err(req, res);
|
2007-08-21 19:02:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ft_ll_link(fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent,
|
|
|
|
const char *newname)
|
|
|
|
{
|
|
|
|
string path;
|
|
|
|
string newpath;
|
2007-08-22 21:41:11 +00:00
|
|
|
Inode *in = 0;
|
2007-08-21 19:02:49 +00:00
|
|
|
Inode *newpin = 0;
|
2007-08-23 05:48:33 +00:00
|
|
|
int res = 0;
|
2007-08-21 19:02:49 +00:00
|
|
|
lock.Lock();
|
2007-08-22 21:41:11 +00:00
|
|
|
in = inode_map[ino];
|
2007-08-23 05:48:33 +00:00
|
|
|
if (!make_inode_path(path, in))
|
|
|
|
res = ENOENT;
|
2007-08-22 21:41:11 +00:00
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
newpin = inode_map[newparent];
|
2007-08-23 05:48:33 +00:00
|
|
|
if (!make_inode_path(newpath, newpin, newname))
|
|
|
|
res = ENOENT;
|
2007-08-21 19:02:49 +00:00
|
|
|
lock.Unlock();
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
trace_lock.Lock();
|
2007-08-23 23:16:45 +00:00
|
|
|
print_time();
|
2007-08-21 23:51:22 +00:00
|
|
|
traceout << "ll_link" << endl
|
|
|
|
<< ino << endl
|
|
|
|
<< newparent << endl
|
|
|
|
<< newname << endl;
|
2007-08-21 19:02:49 +00:00
|
|
|
trace_lock.Unlock();
|
|
|
|
|
2007-08-22 21:10:31 +00:00
|
|
|
//cout << "link " << path << " newpath " << newpath << endl;
|
2007-09-01 04:48:16 +00:00
|
|
|
if (res == 0 && (!has_perm(0010, in, fuse_req_ctx(req)->uid, fuse_req_ctx(req)->gid) ||
|
|
|
|
!has_perm(0010, newpin, fuse_req_ctx(req)->uid, fuse_req_ctx(req)->gid)))
|
|
|
|
res = EPERM;
|
|
|
|
else if (res == 0) res = ::link(path.c_str(), newpath.c_str());
|
2007-08-23 05:48:33 +00:00
|
|
|
if (res < 0) res = errno;
|
2007-08-21 19:02:49 +00:00
|
|
|
|
|
|
|
if (res == 0) {
|
2007-08-22 23:04:04 +00:00
|
|
|
struct fuse_entry_param fe;
|
|
|
|
memset(&fe, 0, sizeof(fe));
|
|
|
|
::lstat(newpath.c_str(), &fe.attr);
|
|
|
|
|
2007-08-22 21:41:11 +00:00
|
|
|
lock.Lock();
|
|
|
|
string newdname(newname);
|
2007-08-22 22:32:39 +00:00
|
|
|
add_dentry(newpin, newdname, in);
|
|
|
|
in->ref++;
|
2007-08-22 23:04:04 +00:00
|
|
|
memcpy(&in->stbuf, &fe.attr, sizeof(fe.attr)); // re-read, bc we changed the link count
|
2007-08-22 21:41:11 +00:00
|
|
|
lock.Unlock();
|
|
|
|
|
2007-08-22 21:02:13 +00:00
|
|
|
fe.ino = fe.attr.st_ino;
|
|
|
|
fuse_reply_entry(req, &fe);
|
2007-08-21 19:02:49 +00:00
|
|
|
} else
|
2007-08-23 05:48:33 +00:00
|
|
|
fuse_reply_err(req, res);
|
2007-08-19 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
static void ft_ll_open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
|
2007-08-19 18:45:46 +00:00
|
|
|
{
|
2007-08-21 19:02:49 +00:00
|
|
|
string path;
|
2007-08-23 04:08:24 +00:00
|
|
|
Inode *in = 0;
|
2007-08-23 05:48:33 +00:00
|
|
|
int res = 0;
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
lock.Lock();
|
2007-08-23 04:08:24 +00:00
|
|
|
in = inode_map[ino];
|
2007-08-23 05:48:33 +00:00
|
|
|
if (!make_inode_path(path, in))
|
|
|
|
res = ENOENT;
|
2007-08-21 19:02:49 +00:00
|
|
|
lock.Unlock();
|
|
|
|
|
2007-09-01 04:48:16 +00:00
|
|
|
int want = 0100;
|
|
|
|
if (fi->flags & O_RDWR) want |= 0010;
|
|
|
|
if (fi->flags == O_WRONLY) want = 0010;
|
|
|
|
|
2007-08-23 05:48:33 +00:00
|
|
|
int fd = 0;
|
2007-09-01 04:48:16 +00:00
|
|
|
if (res == 0 && !has_perm(want, in, fuse_req_ctx(req)->uid, fuse_req_ctx(req)->gid))
|
|
|
|
res = EPERM;
|
|
|
|
else if (res == 0) {
|
2007-08-23 05:48:33 +00:00
|
|
|
fd = ::open(path.c_str(), fi->flags);
|
|
|
|
if (fd <= 0) res = errno;
|
|
|
|
}
|
2007-08-19 18:45:46 +00:00
|
|
|
|
|
|
|
trace_lock.Lock();
|
2007-08-23 23:16:45 +00:00
|
|
|
print_time();
|
2007-08-21 23:51:22 +00:00
|
|
|
traceout << "ll_open" << endl
|
|
|
|
<< ino << endl
|
|
|
|
<< fi->flags << endl
|
|
|
|
<< (fd > 0 ? fd:0) << endl;;
|
2007-08-19 18:45:46 +00:00
|
|
|
trace_lock.Unlock();
|
|
|
|
|
2007-08-23 23:18:18 +00:00
|
|
|
if (res == 0) {
|
2007-08-23 04:08:24 +00:00
|
|
|
lock.Lock();
|
|
|
|
in->fds.insert(fd);
|
|
|
|
lock.Unlock();
|
2007-08-21 19:02:49 +00:00
|
|
|
fi->fh = fd;
|
|
|
|
fuse_reply_open(req, fi);
|
|
|
|
} else
|
2007-08-23 05:48:33 +00:00
|
|
|
fuse_reply_err(req, res);
|
2007-08-19 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
static void ft_ll_read(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
|
|
|
|
struct fuse_file_info *fi)
|
2007-08-19 18:45:46 +00:00
|
|
|
{
|
2007-08-23 04:08:24 +00:00
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
char *buf = new char[size];
|
|
|
|
int res = ::pread(fi->fh, buf, size, off);
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-08-22 23:04:04 +00:00
|
|
|
//cout << "read " << path << " " << off << "~" << size << endl;
|
2007-08-19 18:45:46 +00:00
|
|
|
trace_lock.Lock();
|
2007-08-23 23:16:45 +00:00
|
|
|
print_time();
|
2007-08-21 23:51:22 +00:00
|
|
|
traceout << "ll_read" << endl
|
|
|
|
<< fi->fh << endl
|
|
|
|
<< off << endl
|
|
|
|
<< size << endl;
|
2007-08-19 18:45:46 +00:00
|
|
|
trace_lock.Unlock();
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
if (res >= 0)
|
|
|
|
fuse_reply_buf(req, buf, res);
|
|
|
|
else
|
|
|
|
fuse_reply_err(req, errno);
|
|
|
|
delete[] buf;
|
2007-08-19 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
static void ft_ll_write(fuse_req_t req, fuse_ino_t ino, const char *buf,
|
|
|
|
size_t size, off_t off, struct fuse_file_info *fi)
|
2007-08-19 18:45:46 +00:00
|
|
|
{
|
2007-08-21 19:02:49 +00:00
|
|
|
int res = ::pwrite(fi->fh, buf, size, off);
|
2007-08-19 18:45:46 +00:00
|
|
|
|
|
|
|
trace_lock.Lock();
|
2007-08-23 23:16:45 +00:00
|
|
|
print_time();
|
2007-08-21 23:51:22 +00:00
|
|
|
traceout << "ll_write" << endl
|
|
|
|
<< fi->fh << endl
|
|
|
|
<< off << endl
|
|
|
|
<< size << endl;
|
2007-08-19 18:45:46 +00:00
|
|
|
trace_lock.Unlock();
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
if (res >= 0)
|
|
|
|
fuse_reply_write(req, res);
|
|
|
|
else
|
|
|
|
fuse_reply_err(req, errno);
|
2007-08-19 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
static void ft_ll_flush(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
|
2007-08-19 18:45:46 +00:00
|
|
|
{
|
2007-08-21 19:02:49 +00:00
|
|
|
trace_lock.Lock();
|
2007-08-23 23:16:45 +00:00
|
|
|
print_time();
|
2007-08-21 19:02:49 +00:00
|
|
|
traceout << "ll_flush" << endl << fi->fh << endl;
|
|
|
|
trace_lock.Unlock();
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-08-22 23:58:27 +00:00
|
|
|
int res = ::fdatasync(fi->fh);
|
|
|
|
//int res = ::close(dup(fi->fh));
|
2007-08-21 19:02:49 +00:00
|
|
|
if (res >= 0)
|
|
|
|
fuse_reply_err(req, 0);
|
|
|
|
else
|
|
|
|
fuse_reply_err(req, errno);
|
2007-08-19 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
static void ft_ll_release(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
|
2007-08-19 18:45:46 +00:00
|
|
|
{
|
2007-08-21 19:02:49 +00:00
|
|
|
trace_lock.Lock();
|
2007-08-23 23:16:45 +00:00
|
|
|
print_time();
|
2007-08-21 19:02:49 +00:00
|
|
|
traceout << "ll_release" << endl << fi->fh << endl;
|
|
|
|
trace_lock.Unlock();
|
2007-08-19 18:45:46 +00:00
|
|
|
|
2007-08-23 04:08:24 +00:00
|
|
|
lock.Lock();
|
|
|
|
Inode *in = inode_map[ino];
|
|
|
|
in->fds.erase(fi->fh);
|
|
|
|
lock.Unlock();
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
int res = ::close(fi->fh);
|
|
|
|
if (res >= 0)
|
|
|
|
fuse_reply_err(req, 0);
|
|
|
|
else
|
|
|
|
fuse_reply_err(req, errno);
|
2007-08-19 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
static void ft_ll_fsync(fuse_req_t req, fuse_ino_t ino, int datasync,
|
|
|
|
struct fuse_file_info *fi)
|
2007-08-19 18:45:46 +00:00
|
|
|
{
|
|
|
|
trace_lock.Lock();
|
2007-08-23 23:16:45 +00:00
|
|
|
print_time();
|
2007-08-21 19:02:49 +00:00
|
|
|
traceout << "ll_fsync" << endl << fi->fh << endl;
|
2007-08-19 18:45:46 +00:00
|
|
|
trace_lock.Unlock();
|
2007-08-21 19:02:49 +00:00
|
|
|
|
|
|
|
int res = ::fsync(fi->fh);
|
|
|
|
if (res >= 0)
|
|
|
|
fuse_reply_err(req, 0);
|
|
|
|
else
|
|
|
|
fuse_reply_err(req, errno);
|
2007-08-19 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
static struct fuse_lowlevel_ops ft_ll_oper = {
|
2007-08-21 16:33:20 +00:00
|
|
|
init: 0,
|
|
|
|
destroy: 0,
|
|
|
|
lookup: ft_ll_lookup,
|
|
|
|
forget: ft_ll_forget,
|
|
|
|
getattr: ft_ll_getattr,
|
|
|
|
setattr: ft_ll_setattr,
|
|
|
|
readlink: ft_ll_readlink,
|
|
|
|
mknod: ft_ll_mknod,
|
|
|
|
mkdir: ft_ll_mkdir,
|
|
|
|
unlink: ft_ll_unlink,
|
|
|
|
rmdir: ft_ll_rmdir,
|
|
|
|
symlink: ft_ll_symlink,
|
|
|
|
rename: ft_ll_rename,
|
|
|
|
link: ft_ll_link,
|
|
|
|
open: ft_ll_open,
|
|
|
|
read: ft_ll_read,
|
|
|
|
write: ft_ll_write,
|
|
|
|
flush: ft_ll_flush,
|
|
|
|
release: ft_ll_release,
|
|
|
|
fsync: ft_ll_fsync,
|
|
|
|
opendir: ft_ll_opendir,
|
|
|
|
readdir: ft_ll_readdir,
|
|
|
|
releasedir: ft_ll_releasedir,
|
|
|
|
fsyncdir: 0,
|
|
|
|
statfs: ft_ll_statfs,
|
|
|
|
setxattr: 0,
|
|
|
|
getxattr: 0,
|
|
|
|
listxattr: 0,
|
|
|
|
removexattr: 0,
|
|
|
|
access: 0,
|
2007-08-23 23:16:45 +00:00
|
|
|
create: ft_ll_create,
|
2007-08-21 16:33:20 +00:00
|
|
|
getlk: 0,
|
|
|
|
setlk: 0,
|
|
|
|
bmap: 0
|
|
|
|
};
|
2007-08-19 18:45:46 +00:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
// open trace
|
|
|
|
|
2007-08-21 19:02:49 +00:00
|
|
|
// figure base dir
|
|
|
|
char *newargv[100];
|
|
|
|
int newargc = 0;
|
|
|
|
for (int i=0; i<argc; i++) {
|
|
|
|
if (strcmp(argv[i], "--basedir") == 0) {
|
|
|
|
basedir = argv[++i];
|
2007-08-23 23:16:45 +00:00
|
|
|
} else if (strcmp(argv[i], "--timestamps") == 0) {
|
|
|
|
do_timestamps = atoi(argv[++i]);
|
2007-08-21 19:02:49 +00:00
|
|
|
} else if (strcmp(argv[i], "--trace") == 0) {
|
|
|
|
tracefile.open(argv[++i], ios::out|ios::trunc);
|
|
|
|
if (!tracefile.is_open())
|
|
|
|
cerr << "** couldn't open trace file " << argv[i] << endl;
|
2007-08-22 22:32:39 +00:00
|
|
|
} else if (strcmp(argv[i], "--debug") == 0) {
|
|
|
|
debug = 1;
|
2007-08-21 19:02:49 +00:00
|
|
|
} else {
|
|
|
|
cout << "arg: " << newargc << " " << argv[i] << endl;
|
|
|
|
newargv[newargc++] = argv[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
newargv[newargc++] = "-o";
|
|
|
|
newargv[newargc++] = "allow_other";
|
2007-08-24 21:49:13 +00:00
|
|
|
// newargv[newargc++] = "-o";
|
|
|
|
// newargv[newargc++] = "default_permissions";
|
2007-08-21 19:02:49 +00:00
|
|
|
if (!basedir) return 1;
|
|
|
|
cout << "basedir is " << basedir << endl;
|
|
|
|
|
|
|
|
// create root ino
|
2007-08-22 23:04:04 +00:00
|
|
|
root = new Inode;
|
|
|
|
::lstat(basedir, &root->stbuf);
|
2007-08-21 19:02:49 +00:00
|
|
|
root->stbuf.st_ino = 1;
|
|
|
|
inode_map[1] = root;
|
|
|
|
root->ref++;
|
2007-08-21 23:51:22 +00:00
|
|
|
|
|
|
|
umask(0);
|
2007-08-21 19:02:49 +00:00
|
|
|
|
|
|
|
// go go gadget fuse
|
|
|
|
struct fuse_args args = FUSE_ARGS_INIT(newargc, newargv);
|
|
|
|
struct fuse_chan *ch;
|
|
|
|
char *mountpoint;
|
|
|
|
|
|
|
|
if (fuse_parse_cmdline(&args, &mountpoint, NULL, NULL) != -1 &&
|
|
|
|
(ch = fuse_mount(mountpoint, &args)) != NULL) {
|
|
|
|
struct fuse_session *se;
|
|
|
|
|
|
|
|
// init fuse
|
|
|
|
se = fuse_lowlevel_new(&args, &ft_ll_oper, sizeof(ft_ll_oper),
|
|
|
|
NULL);
|
|
|
|
if (se != NULL) {
|
|
|
|
if (fuse_set_signal_handlers(se) != -1) {
|
|
|
|
fuse_session_add_chan(se, ch);
|
2013-06-03 13:22:58 +00:00
|
|
|
if (fuse_session_loop(se) <= -1) {
|
|
|
|
cout << "Failed fuse_session_loop() call." << endl;
|
|
|
|
return 1;
|
|
|
|
}
|
2007-08-21 19:02:49 +00:00
|
|
|
fuse_remove_signal_handlers(se);
|
|
|
|
fuse_session_remove_chan(ch);
|
|
|
|
}
|
|
|
|
fuse_session_destroy(se);
|
|
|
|
}
|
|
|
|
fuse_unmount(mountpoint, ch);
|
|
|
|
}
|
|
|
|
fuse_opt_free_args(&args);
|
2007-08-19 18:45:46 +00:00
|
|
|
}
|