2007-03-16 11:17:36 +03:00
|
|
|
|
/* $NetBSD: refuse.c,v 1.44 2007/03/16 08:17:36 pooka Exp $ */
|
2007-02-11 19:02:24 +03:00
|
|
|
|
|
2007-02-11 13:31:37 +03:00
|
|
|
|
/*
|
|
|
|
|
* Copyright <EFBFBD> 2007 Alistair Crooks. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
|
* are met:
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
|
* 3. The name of the author may not be used to endorse or promote
|
|
|
|
|
* products derived from this software without specific prior written
|
|
|
|
|
* permission.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
|
|
|
|
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
|
|
|
|
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*/
|
2007-02-11 19:02:24 +03:00
|
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
#if !defined(lint)
|
2007-03-16 11:17:36 +03:00
|
|
|
|
__RCSID("$NetBSD: refuse.c,v 1.44 2007/03/16 08:17:36 pooka Exp $");
|
2007-02-11 19:02:24 +03:00
|
|
|
|
#endif /* !lint */
|
|
|
|
|
|
2007-02-19 02:30:45 +03:00
|
|
|
|
#include <assert.h>
|
2007-02-11 13:31:37 +03:00
|
|
|
|
#include <err.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <fuse.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
|
|
typedef uint64_t fuse_ino_t;
|
|
|
|
|
|
|
|
|
|
struct fuse_config {
|
|
|
|
|
uid_t uid;
|
|
|
|
|
gid_t gid;
|
|
|
|
|
mode_t umask;
|
|
|
|
|
double entry_timeout;
|
|
|
|
|
double negative_timeout;
|
|
|
|
|
double attr_timeout;
|
|
|
|
|
double ac_attr_timeout;
|
|
|
|
|
int ac_attr_timeout_set;
|
|
|
|
|
int debug;
|
|
|
|
|
int hard_remove;
|
|
|
|
|
int use_ino;
|
|
|
|
|
int readdir_ino;
|
|
|
|
|
int set_mode;
|
|
|
|
|
int set_uid;
|
|
|
|
|
int set_gid;
|
|
|
|
|
int direct_io;
|
|
|
|
|
int kernel_cache;
|
|
|
|
|
int auto_cache;
|
|
|
|
|
int intr;
|
|
|
|
|
int intr_signal;
|
|
|
|
|
};
|
|
|
|
|
|
2007-02-26 18:57:33 +03:00
|
|
|
|
struct fuse_chan {
|
2007-03-14 01:47:03 +03:00
|
|
|
|
const char *dir;
|
|
|
|
|
struct fuse_args *args;
|
|
|
|
|
|
|
|
|
|
struct puffs_usermount *pu;
|
2007-02-26 18:57:33 +03:00
|
|
|
|
};
|
|
|
|
|
|
2007-02-11 13:31:37 +03:00
|
|
|
|
/* this is the private fuse structure */
|
|
|
|
|
struct fuse {
|
2007-02-26 18:57:33 +03:00
|
|
|
|
struct fuse_chan *fc; /* fuse channel pointer */
|
2007-02-11 13:31:37 +03:00
|
|
|
|
struct fuse_operations op; /* switch table of operations */
|
2007-02-11 19:02:24 +03:00
|
|
|
|
int compat; /* compat level -
|
|
|
|
|
* not used in puffs_fuse */
|
2007-02-11 13:31:37 +03:00
|
|
|
|
struct node **name_table;
|
|
|
|
|
size_t name_table_size;
|
|
|
|
|
struct node **id_table;
|
|
|
|
|
size_t id_table_size;
|
|
|
|
|
fuse_ino_t ctr;
|
|
|
|
|
unsigned int generation;
|
|
|
|
|
unsigned int hidectr;
|
|
|
|
|
pthread_mutex_t lock;
|
|
|
|
|
pthread_rwlock_t tree_lock;
|
|
|
|
|
void *user_data;
|
|
|
|
|
struct fuse_config conf;
|
|
|
|
|
int intr_installed;
|
|
|
|
|
};
|
|
|
|
|
|
2007-02-26 16:52:16 +03:00
|
|
|
|
struct puffs_fuse_dirh {
|
2007-03-14 01:47:03 +03:00
|
|
|
|
void *dbuf;
|
|
|
|
|
struct dirent *d;
|
|
|
|
|
|
|
|
|
|
size_t reslen;
|
|
|
|
|
size_t bufsize;
|
2007-02-26 16:52:16 +03:00
|
|
|
|
};
|
|
|
|
|
|
2007-03-14 01:47:03 +03:00
|
|
|
|
struct refusenode {
|
|
|
|
|
struct fuse_file_info file_info;
|
|
|
|
|
struct puffs_fuse_dirh dirh;
|
|
|
|
|
int opencount;
|
|
|
|
|
int flags;
|
|
|
|
|
};
|
2007-02-20 17:51:52 +03:00
|
|
|
|
#define RN_ROOT 0x01
|
2007-02-20 22:00:21 +03:00
|
|
|
|
#define RN_OPEN 0x02 /* XXX: could just use opencount */
|
2007-02-11 15:12:39 +03:00
|
|
|
|
|
2007-03-14 01:47:03 +03:00
|
|
|
|
static int fuse_setattr(struct fuse *, struct puffs_node *,
|
|
|
|
|
const char *, const struct vattr *);
|
2007-02-20 01:04:26 +03:00
|
|
|
|
|
2007-02-11 15:12:39 +03:00
|
|
|
|
static struct puffs_node *
|
|
|
|
|
newrn(struct puffs_usermount *pu)
|
|
|
|
|
{
|
|
|
|
|
struct puffs_node *pn;
|
|
|
|
|
struct refusenode *rn;
|
|
|
|
|
|
2007-02-26 18:57:33 +03:00
|
|
|
|
NEW(struct refusenode, rn, "newrn", exit(EXIT_FAILURE));
|
2007-02-11 15:12:39 +03:00
|
|
|
|
pn = puffs_pn_new(pu, rn);
|
|
|
|
|
|
|
|
|
|
return pn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
nukern(struct puffs_node *pn)
|
|
|
|
|
{
|
2007-02-26 16:52:16 +03:00
|
|
|
|
struct refusenode *rn = pn->pn_data;
|
2007-02-11 15:12:39 +03:00
|
|
|
|
|
2007-02-26 16:52:16 +03:00
|
|
|
|
free(rn->dirh.dbuf);
|
|
|
|
|
free(rn);
|
2007-02-11 15:12:39 +03:00
|
|
|
|
puffs_pn_put(pn);
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-11 13:31:37 +03:00
|
|
|
|
static ino_t fakeino = 3;
|
|
|
|
|
|
2007-02-18 23:38:07 +03:00
|
|
|
|
/*
|
2007-03-14 01:47:03 +03:00
|
|
|
|
* XXX: do this otherwise if/when we grow thread support
|
2007-02-18 23:38:07 +03:00
|
|
|
|
*
|
|
|
|
|
* XXX2: does not consistently supply uid, gid or pid currently
|
|
|
|
|
*/
|
|
|
|
|
static struct fuse_context fcon;
|
|
|
|
|
|
2007-02-26 16:52:16 +03:00
|
|
|
|
#define DIR_CHUNKSIZE 4096
|
|
|
|
|
static int
|
|
|
|
|
fill_dirbuf(struct puffs_fuse_dirh *dh, const char *name, ino_t dino,
|
|
|
|
|
uint8_t dtype)
|
|
|
|
|
{
|
2007-02-18 23:38:07 +03:00
|
|
|
|
|
2007-02-26 16:52:16 +03:00
|
|
|
|
/* initial? */
|
|
|
|
|
if (dh->bufsize == 0) {
|
|
|
|
|
dh->dbuf = malloc(DIR_CHUNKSIZE);
|
2007-03-14 01:47:03 +03:00
|
|
|
|
if (dh->dbuf == NULL)
|
|
|
|
|
err(1, "fill_dirbuf");
|
2007-02-26 16:52:16 +03:00
|
|
|
|
dh->d = dh->dbuf;
|
|
|
|
|
dh->reslen = dh->bufsize = DIR_CHUNKSIZE;
|
|
|
|
|
}
|
2007-02-11 13:31:37 +03:00
|
|
|
|
|
2007-03-14 01:47:03 +03:00
|
|
|
|
if (puffs_nextdent(&dh->d, name, dino, dtype, &dh->reslen))
|
2007-02-26 16:52:16 +03:00
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
/* try to increase buffer space */
|
|
|
|
|
dh->dbuf = realloc(dh->dbuf, dh->bufsize + DIR_CHUNKSIZE);
|
2007-03-14 01:47:03 +03:00
|
|
|
|
if (dh->dbuf == NULL)
|
|
|
|
|
err(1, "fill_dirbuf realloc");
|
2007-02-26 16:52:16 +03:00
|
|
|
|
dh->d = (void *)((uint8_t *)dh->dbuf + (dh->bufsize - dh->reslen));
|
|
|
|
|
dh->reslen += DIR_CHUNKSIZE;
|
|
|
|
|
dh->bufsize += DIR_CHUNKSIZE;
|
|
|
|
|
|
|
|
|
|
return !puffs_nextdent(&dh->d, name, dino, dtype, &dh->reslen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ARGSUSED3 */
|
|
|
|
|
/* XXX: I have no idea how "off" is supposed to be used */
|
2007-02-11 13:31:37 +03:00
|
|
|
|
static int
|
2007-02-11 14:57:41 +03:00
|
|
|
|
puffs_fuse_fill_dir(void *buf, const char *name,
|
2007-02-11 13:31:37 +03:00
|
|
|
|
const struct stat *stbuf, off_t off)
|
|
|
|
|
{
|
2007-02-26 16:52:16 +03:00
|
|
|
|
struct puffs_fuse_dirh *deh = buf;
|
2007-02-15 21:35:16 +03:00
|
|
|
|
ino_t dino;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
uint8_t dtype;
|
|
|
|
|
|
2007-02-15 21:35:16 +03:00
|
|
|
|
if (stbuf == NULL) {
|
|
|
|
|
dtype = DT_UNKNOWN;
|
|
|
|
|
dino = fakeino++;
|
|
|
|
|
} else {
|
|
|
|
|
dtype = puffs_vtype2dt(puffs_mode2vt(stbuf->st_mode));
|
|
|
|
|
dino = stbuf->st_ino;
|
|
|
|
|
}
|
2007-02-11 13:31:37 +03:00
|
|
|
|
|
2007-02-26 16:52:16 +03:00
|
|
|
|
return fill_dirbuf(deh, name, dino, dtype);
|
2007-02-11 14:57:41 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
puffs_fuse_dirfil(fuse_dirh_t h, const char *name, int type, ino_t ino)
|
|
|
|
|
{
|
2007-03-14 01:47:03 +03:00
|
|
|
|
ino_t dino;
|
|
|
|
|
int dtype;
|
2007-02-11 14:57:41 +03:00
|
|
|
|
|
2007-03-14 01:47:03 +03:00
|
|
|
|
if (type == 0)
|
2007-02-15 21:35:16 +03:00
|
|
|
|
dtype = DT_UNKNOWN;
|
2007-03-14 01:47:03 +03:00
|
|
|
|
else
|
|
|
|
|
dtype = type;
|
|
|
|
|
|
|
|
|
|
if (ino)
|
|
|
|
|
dino = ino;
|
|
|
|
|
else
|
2007-02-11 14:57:41 +03:00
|
|
|
|
dino = fakeino++;
|
|
|
|
|
|
2007-02-26 16:52:16 +03:00
|
|
|
|
return fill_dirbuf(h, name, dino, dtype);
|
2007-02-11 13:31:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-16 03:35:06 +03:00
|
|
|
|
#define FUSE_ERR_UNLINK(fuse, file) if (fuse->op.unlink) fuse->op.unlink(file)
|
|
|
|
|
#define FUSE_ERR_RMDIR(fuse, dir) if (fuse->op.rmdir) fuse->op.rmdir(dir)
|
|
|
|
|
|
2007-02-20 01:04:26 +03:00
|
|
|
|
/* ARGSUSED1 */
|
|
|
|
|
static int
|
|
|
|
|
fuse_getattr(struct fuse *fuse, struct puffs_node *pn, const char *path,
|
|
|
|
|
struct vattr *va)
|
|
|
|
|
{
|
|
|
|
|
struct stat st;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
if (fuse->op.getattr == NULL) {
|
|
|
|
|
return ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* wrap up return code */
|
|
|
|
|
ret = (*fuse->op.getattr)(path, &st);
|
|
|
|
|
|
|
|
|
|
if (ret == 0) {
|
|
|
|
|
puffs_stat2vattr(va, &st);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
fuse_setattr(struct fuse *fuse, struct puffs_node *pn, const char *path,
|
|
|
|
|
const struct vattr *va)
|
|
|
|
|
{
|
|
|
|
|
struct refusenode *rn = pn->pn_data;
|
|
|
|
|
mode_t mode;
|
|
|
|
|
uid_t uid;
|
|
|
|
|
gid_t gid;
|
|
|
|
|
int error, ret;
|
|
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
|
|
mode = va->va_mode;
|
|
|
|
|
uid = va->va_uid;
|
|
|
|
|
gid = va->va_gid;
|
|
|
|
|
|
|
|
|
|
if (mode != (mode_t)PUFFS_VNOVAL) {
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
|
|
if (fuse->op.chmod == NULL) {
|
|
|
|
|
error = -ENOSYS;
|
|
|
|
|
} else {
|
|
|
|
|
ret = fuse->op.chmod(path, mode);
|
|
|
|
|
if (ret)
|
|
|
|
|
error = ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (uid != (uid_t)PUFFS_VNOVAL || gid != (gid_t)PUFFS_VNOVAL) {
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
|
|
if (fuse->op.chown == NULL) {
|
|
|
|
|
error = -ENOSYS;
|
|
|
|
|
} else {
|
|
|
|
|
ret = fuse->op.chown(path, uid, gid);
|
|
|
|
|
if (ret)
|
|
|
|
|
error = ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (va->va_atime.tv_sec != (time_t)PUFFS_VNOVAL
|
|
|
|
|
|| va->va_mtime.tv_sec != (long)PUFFS_VNOVAL) {
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
|
|
if (fuse->op.utimens) {
|
|
|
|
|
struct timespec tv[2];
|
|
|
|
|
|
|
|
|
|
tv[0].tv_sec = va->va_atime.tv_sec;
|
|
|
|
|
tv[0].tv_nsec = va->va_atime.tv_nsec;
|
|
|
|
|
tv[1].tv_sec = va->va_mtime.tv_sec;
|
|
|
|
|
tv[1].tv_nsec = va->va_mtime.tv_nsec;
|
|
|
|
|
|
|
|
|
|
ret = fuse->op.utimens(path, tv);
|
|
|
|
|
} else if (fuse->op.utime) {
|
|
|
|
|
struct utimbuf timbuf;
|
|
|
|
|
|
|
|
|
|
timbuf.actime = va->va_atime.tv_sec;
|
|
|
|
|
timbuf.modtime = va->va_mtime.tv_sec;
|
|
|
|
|
|
|
|
|
|
ret = fuse->op.utime(path, &timbuf);
|
|
|
|
|
} else {
|
|
|
|
|
error = -ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
|
error = ret;
|
|
|
|
|
}
|
|
|
|
|
if (va->va_size != (u_quad_t)PUFFS_VNOVAL) {
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
|
|
if (fuse->op.truncate) {
|
|
|
|
|
ret = fuse->op.truncate(path, (off_t)va->va_size);
|
|
|
|
|
} else if (fuse->op.ftruncate) {
|
|
|
|
|
ret = fuse->op.ftruncate(path, (off_t)va->va_size,
|
|
|
|
|
&rn->file_info);
|
|
|
|
|
} else {
|
|
|
|
|
error = -ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
|
error = ret;
|
|
|
|
|
}
|
|
|
|
|
/* XXX: no reflection with reality */
|
|
|
|
|
puffs_setvattr(&pn->pn_va, va);
|
|
|
|
|
|
|
|
|
|
return -error;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
fuse_newnode(struct puffs_usermount *pu, const char *path,
|
|
|
|
|
const struct vattr *va, struct fuse_file_info *fi, void **newnode)
|
|
|
|
|
{
|
|
|
|
|
struct vattr newva;
|
|
|
|
|
struct fuse *fuse;
|
|
|
|
|
struct puffs_node *pn;
|
|
|
|
|
struct refusenode *rn;
|
|
|
|
|
|
|
|
|
|
fuse = (struct fuse *)pu->pu_privdata;
|
|
|
|
|
|
|
|
|
|
/* fix up nodes */
|
|
|
|
|
pn = newrn(pu);
|
|
|
|
|
if (pn == NULL) {
|
|
|
|
|
if (va->va_type == VDIR) {
|
|
|
|
|
FUSE_ERR_RMDIR(fuse, path);
|
|
|
|
|
} else {
|
|
|
|
|
FUSE_ERR_UNLINK(fuse, path);
|
|
|
|
|
}
|
|
|
|
|
return ENOMEM;
|
|
|
|
|
}
|
|
|
|
|
fuse_setattr(fuse, pn, path, va);
|
|
|
|
|
if (fuse_getattr(fuse, pn, path, &newva) == 0)
|
|
|
|
|
puffs_setvattr(&pn->pn_va, &newva);
|
|
|
|
|
|
|
|
|
|
rn = pn->pn_data;
|
|
|
|
|
if (fi)
|
|
|
|
|
memcpy(&rn->file_info, fi, sizeof(struct fuse_file_info));
|
|
|
|
|
|
|
|
|
|
*newnode = pn;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-02-11 13:31:37 +03:00
|
|
|
|
/* operation wrappers start here */
|
|
|
|
|
|
|
|
|
|
/* lookup the path */
|
|
|
|
|
/* ARGSUSED1 */
|
|
|
|
|
static int
|
|
|
|
|
puffs_fuse_node_lookup(struct puffs_cc *pcc, void *opc, void **newnode,
|
|
|
|
|
enum vtype *newtype, voff_t *newsize, dev_t *newrdev,
|
|
|
|
|
const struct puffs_cn *pcn)
|
|
|
|
|
{
|
|
|
|
|
struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
|
2007-02-15 20:06:24 +03:00
|
|
|
|
struct puffs_node *pn_res;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
struct stat st;
|
|
|
|
|
struct fuse *fuse;
|
|
|
|
|
const char *path = PCNPATH(pcn);
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
fuse = (struct fuse *)pu->pu_privdata;
|
|
|
|
|
ret = fuse->op.getattr(path, &st);
|
2007-02-15 20:06:24 +03:00
|
|
|
|
|
2007-02-11 13:31:37 +03:00
|
|
|
|
if (ret != 0) {
|
2007-02-16 03:35:06 +03:00
|
|
|
|
return -ret;
|
2007-02-15 20:06:24 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* XXX: fiXXXme unconst */
|
|
|
|
|
pn_res = puffs_pn_nodewalk(pu, puffs_path_walkcmp,
|
|
|
|
|
__UNCONST(&pcn->pcn_po_full));
|
|
|
|
|
if (pn_res == NULL) {
|
|
|
|
|
pn_res = newrn(pu);
|
|
|
|
|
if (pn_res == NULL)
|
|
|
|
|
return errno;
|
2007-02-20 01:04:26 +03:00
|
|
|
|
puffs_stat2vattr(&pn_res->pn_va, &st);
|
2007-02-11 13:31:37 +03:00
|
|
|
|
}
|
2007-02-15 20:06:24 +03:00
|
|
|
|
|
|
|
|
|
*newnode = pn_res;
|
|
|
|
|
*newtype = pn_res->pn_va.va_type;
|
|
|
|
|
*newsize = pn_res->pn_va.va_size;
|
|
|
|
|
*newrdev = pn_res->pn_va.va_rdev;
|
|
|
|
|
|
|
|
|
|
return 0;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* get attributes for the path name */
|
|
|
|
|
/* ARGSUSED3 */
|
|
|
|
|
static int
|
|
|
|
|
puffs_fuse_node_getattr(struct puffs_cc *pcc, void *opc, struct vattr *va,
|
|
|
|
|
const struct puffs_cred *pcr, pid_t pid)
|
|
|
|
|
{
|
|
|
|
|
struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
|
|
|
|
|
struct puffs_node *pn = opc;
|
|
|
|
|
struct fuse *fuse;
|
|
|
|
|
const char *path = PNPATH(pn);
|
|
|
|
|
|
|
|
|
|
fuse = (struct fuse *)pu->pu_privdata;
|
2007-02-20 01:04:26 +03:00
|
|
|
|
return fuse_getattr(fuse, pn, path, va);
|
2007-02-11 13:31:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* read the contents of the symbolic link */
|
|
|
|
|
/* ARGSUSED2 */
|
|
|
|
|
static int
|
|
|
|
|
puffs_fuse_node_readlink(struct puffs_cc *pcc, void *opc,
|
|
|
|
|
const struct puffs_cred *cred, char *linkname, size_t *linklen)
|
|
|
|
|
{
|
|
|
|
|
struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
|
|
|
|
|
struct puffs_node *pn = opc;
|
|
|
|
|
struct fuse *fuse;
|
2007-02-15 21:35:16 +03:00
|
|
|
|
const char *path = PNPATH(pn), *p;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
fuse = (struct fuse *)pu->pu_privdata;
|
|
|
|
|
if (fuse->op.readlink == NULL) {
|
|
|
|
|
return ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* wrap up return code */
|
|
|
|
|
ret = (*fuse->op.readlink)(path, linkname, *linklen);
|
|
|
|
|
|
|
|
|
|
if (ret == 0) {
|
2007-03-14 01:47:03 +03:00
|
|
|
|
p = memchr(linkname, '\0', *linklen);
|
2007-02-15 21:35:16 +03:00
|
|
|
|
if (!p)
|
|
|
|
|
return EINVAL;
|
|
|
|
|
|
2007-02-15 22:33:51 +03:00
|
|
|
|
*linklen = p - linkname;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-15 21:35:16 +03:00
|
|
|
|
return -ret;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* make the special node */
|
|
|
|
|
/* ARGSUSED1 */
|
|
|
|
|
static int
|
|
|
|
|
puffs_fuse_node_mknod(struct puffs_cc *pcc, void *opc, void **newnode,
|
|
|
|
|
const struct puffs_cn *pcn, const struct vattr *va)
|
|
|
|
|
{
|
|
|
|
|
struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
|
|
|
|
|
struct fuse *fuse;
|
2007-03-16 11:17:36 +03:00
|
|
|
|
mode_t mode;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
const char *path = PCNPATH(pcn);
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
fuse = (struct fuse *)pu->pu_privdata;
|
|
|
|
|
if (fuse->op.mknod == NULL) {
|
|
|
|
|
return ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* wrap up return code */
|
2007-03-16 11:17:36 +03:00
|
|
|
|
mode = puffs_addvtype2mode(va->va_mode, va->va_type);
|
2007-02-11 13:31:37 +03:00
|
|
|
|
ret = (*fuse->op.mknod)(path, mode, va->va_rdev);
|
|
|
|
|
|
|
|
|
|
if (ret == 0) {
|
2007-02-20 01:04:26 +03:00
|
|
|
|
ret = fuse_newnode(pu, path, va, NULL, newnode);
|
2007-02-11 13:31:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-16 03:35:06 +03:00
|
|
|
|
return -ret;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* make a directory */
|
|
|
|
|
/* ARGSUSED1 */
|
|
|
|
|
static int
|
|
|
|
|
puffs_fuse_node_mkdir(struct puffs_cc *pcc, void *opc, void **newnode,
|
|
|
|
|
const struct puffs_cn *pcn, const struct vattr *va)
|
|
|
|
|
{
|
|
|
|
|
struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
|
|
|
|
|
struct fuse *fuse;
|
|
|
|
|
mode_t mode = va->va_mode;
|
|
|
|
|
const char *path = PCNPATH(pcn);
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
fuse = (struct fuse *)pu->pu_privdata;
|
|
|
|
|
if (fuse->op.mkdir == NULL) {
|
|
|
|
|
return ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* wrap up return code */
|
|
|
|
|
ret = (*fuse->op.mkdir)(path, mode);
|
|
|
|
|
|
|
|
|
|
if (ret == 0) {
|
2007-02-20 01:04:26 +03:00
|
|
|
|
ret = fuse_newnode(pu, path, va, NULL, newnode);
|
2007-02-11 13:31:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-16 03:35:06 +03:00
|
|
|
|
return -ret;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-18 23:38:07 +03:00
|
|
|
|
/*
|
|
|
|
|
* create a regular file
|
|
|
|
|
*
|
|
|
|
|
* since linux/fuse sports using mknod for creating regular files
|
|
|
|
|
* instead of having a separate call for it in some versions, if
|
|
|
|
|
* we don't have create, just jump to op->mknod.
|
|
|
|
|
*/
|
2007-02-16 03:13:02 +03:00
|
|
|
|
/*ARGSUSED1*/
|
|
|
|
|
static int
|
|
|
|
|
puffs_fuse_node_create(struct puffs_cc *pcc, void *opc, void **newnode,
|
|
|
|
|
const struct puffs_cn *pcn, const struct vattr *va)
|
|
|
|
|
{
|
|
|
|
|
struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
|
|
|
|
|
struct fuse *fuse;
|
|
|
|
|
struct fuse_file_info fi;
|
|
|
|
|
mode_t mode = va->va_mode;
|
|
|
|
|
const char *path = PCNPATH(pcn);
|
2007-02-20 22:00:21 +03:00
|
|
|
|
int ret, created;
|
2007-02-16 03:13:02 +03:00
|
|
|
|
|
|
|
|
|
fuse = (struct fuse *)pu->pu_privdata;
|
|
|
|
|
|
2007-02-20 22:00:21 +03:00
|
|
|
|
created = 0;
|
2007-02-18 23:38:07 +03:00
|
|
|
|
if (fuse->op.create) {
|
|
|
|
|
ret = fuse->op.create(path, mode, &fi);
|
2007-02-20 22:00:21 +03:00
|
|
|
|
if (ret == 0)
|
|
|
|
|
created = 1;
|
2007-02-18 23:38:07 +03:00
|
|
|
|
|
|
|
|
|
} else if (fuse->op.mknod) {
|
|
|
|
|
fcon.uid = va->va_uid; /*XXX*/
|
|
|
|
|
fcon.gid = va->va_gid; /*XXX*/
|
|
|
|
|
|
|
|
|
|
ret = fuse->op.mknod(path, mode | S_IFREG, 0);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
ret = -ENOSYS;
|
|
|
|
|
}
|
2007-02-16 03:13:02 +03:00
|
|
|
|
|
|
|
|
|
if (ret == 0) {
|
2007-02-20 01:04:26 +03:00
|
|
|
|
ret = fuse_newnode(pu, path, va, &fi, newnode);
|
2007-02-20 22:00:21 +03:00
|
|
|
|
|
|
|
|
|
/* sweet.. create also open the file */
|
|
|
|
|
if (created) {
|
|
|
|
|
struct puffs_node *pn;
|
|
|
|
|
struct refusenode *rn;
|
|
|
|
|
|
|
|
|
|
pn = *newnode;
|
|
|
|
|
rn = pn->pn_data;
|
|
|
|
|
rn->flags |= RN_OPEN;
|
|
|
|
|
rn->opencount++;
|
|
|
|
|
}
|
2007-02-16 03:13:02 +03:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-16 03:35:06 +03:00
|
|
|
|
return -ret;
|
2007-02-16 03:13:02 +03:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-11 13:31:37 +03:00
|
|
|
|
/* remove the directory entry */
|
2007-02-19 01:30:59 +03:00
|
|
|
|
/* ARGSUSED1 */
|
2007-02-11 13:31:37 +03:00
|
|
|
|
static int
|
|
|
|
|
puffs_fuse_node_remove(struct puffs_cc *pcc, void *opc, void *targ,
|
|
|
|
|
const struct puffs_cn *pcn)
|
|
|
|
|
{
|
|
|
|
|
struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
|
2007-02-19 01:30:59 +03:00
|
|
|
|
struct puffs_node *pn_targ = targ;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
struct fuse *fuse;
|
2007-02-19 01:30:59 +03:00
|
|
|
|
const char *path = PNPATH(pn_targ);
|
2007-02-11 13:31:37 +03:00
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
fuse = (struct fuse *)pu->pu_privdata;
|
|
|
|
|
if (fuse->op.unlink == NULL) {
|
|
|
|
|
return ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* wrap up return code */
|
|
|
|
|
ret = (*fuse->op.unlink)(path);
|
|
|
|
|
|
2007-02-16 03:35:06 +03:00
|
|
|
|
return -ret;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* remove the directory */
|
|
|
|
|
/* ARGSUSED1 */
|
|
|
|
|
static int
|
|
|
|
|
puffs_fuse_node_rmdir(struct puffs_cc *pcc, void *opc, void *targ,
|
|
|
|
|
const struct puffs_cn *pcn)
|
|
|
|
|
{
|
|
|
|
|
struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
|
2007-02-19 01:30:59 +03:00
|
|
|
|
struct puffs_node *pn_targ = targ;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
struct fuse *fuse;
|
2007-02-19 01:30:59 +03:00
|
|
|
|
const char *path = PNPATH(pn_targ);
|
2007-02-11 13:31:37 +03:00
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
fuse = (struct fuse *)pu->pu_privdata;
|
|
|
|
|
if (fuse->op.rmdir == NULL) {
|
|
|
|
|
return ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* wrap up return code */
|
|
|
|
|
ret = (*fuse->op.rmdir)(path);
|
|
|
|
|
|
2007-02-16 03:35:06 +03:00
|
|
|
|
return -ret;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* create a symbolic link */
|
|
|
|
|
/* ARGSUSED1 */
|
|
|
|
|
static int
|
|
|
|
|
puffs_fuse_node_symlink(struct puffs_cc *pcc, void *opc, void **newnode,
|
|
|
|
|
const struct puffs_cn *pcn_src, const struct vattr *va,
|
|
|
|
|
const char *link_target)
|
|
|
|
|
{
|
|
|
|
|
struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
|
|
|
|
|
struct fuse *fuse;
|
|
|
|
|
const char *path = PCNPATH(pcn_src);
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
fuse = (struct fuse *)pu->pu_privdata;
|
|
|
|
|
if (fuse->op.symlink == NULL) {
|
|
|
|
|
return ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* wrap up return code */
|
2007-02-20 22:13:28 +03:00
|
|
|
|
ret = fuse->op.symlink(link_target, path);
|
2007-02-11 13:31:37 +03:00
|
|
|
|
|
|
|
|
|
if (ret == 0) {
|
2007-02-20 01:04:26 +03:00
|
|
|
|
ret = fuse_newnode(pu, path, va, NULL, newnode);
|
2007-02-11 13:31:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-16 03:35:06 +03:00
|
|
|
|
return -ret;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* rename a directory entry */
|
|
|
|
|
/* ARGSUSED1 */
|
|
|
|
|
static int
|
|
|
|
|
puffs_fuse_node_rename(struct puffs_cc *pcc, void *opc, void *src,
|
|
|
|
|
const struct puffs_cn *pcn_src, void *targ_dir, void *targ,
|
|
|
|
|
const struct puffs_cn *pcn_targ)
|
|
|
|
|
{
|
|
|
|
|
struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
|
|
|
|
|
struct fuse *fuse;
|
2007-02-19 01:42:33 +03:00
|
|
|
|
const char *path_src = PCNPATH(pcn_src);
|
|
|
|
|
const char *path_dest = PCNPATH(pcn_targ);
|
2007-02-11 13:31:37 +03:00
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
fuse = (struct fuse *)pu->pu_privdata;
|
|
|
|
|
if (fuse->op.rename == NULL) {
|
|
|
|
|
return ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-19 01:42:33 +03:00
|
|
|
|
ret = fuse->op.rename(path_src, path_dest);
|
2007-02-11 13:31:37 +03:00
|
|
|
|
|
|
|
|
|
if (ret == 0) {
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-16 03:35:06 +03:00
|
|
|
|
return -ret;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* create a link in the file system */
|
|
|
|
|
/* ARGSUSED1 */
|
|
|
|
|
static int
|
|
|
|
|
puffs_fuse_node_link(struct puffs_cc *pcc, void *opc, void *targ,
|
|
|
|
|
const struct puffs_cn *pcn)
|
|
|
|
|
{
|
|
|
|
|
struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
|
|
|
|
|
struct puffs_node *pn = targ;
|
|
|
|
|
struct fuse *fuse;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
fuse = (struct fuse *)pu->pu_privdata;
|
|
|
|
|
if (fuse->op.link == NULL) {
|
|
|
|
|
return ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* wrap up return code */
|
|
|
|
|
ret = (*fuse->op.link)(PNPATH(pn), PCNPATH(pcn));
|
|
|
|
|
|
2007-02-16 03:35:06 +03:00
|
|
|
|
return -ret;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2007-02-18 03:01:18 +03:00
|
|
|
|
* fuse's regular interface provides chmod(), chown(), utimes()
|
|
|
|
|
* and truncate() + some variations, so try to fit the square block
|
|
|
|
|
* in the circle hole and the circle block .... something like that
|
2007-02-11 19:02:24 +03:00
|
|
|
|
*/
|
2007-02-11 13:31:37 +03:00
|
|
|
|
/* ARGSUSED3 */
|
|
|
|
|
static int
|
|
|
|
|
puffs_fuse_node_setattr(struct puffs_cc *pcc, void *opc,
|
|
|
|
|
const struct vattr *va, const struct puffs_cred *pcr, pid_t pid)
|
|
|
|
|
{
|
|
|
|
|
struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
|
|
|
|
|
struct puffs_node *pn = opc;
|
|
|
|
|
struct fuse *fuse;
|
|
|
|
|
const char *path = PNPATH(pn);
|
|
|
|
|
|
|
|
|
|
fuse = (struct fuse *)pu->pu_privdata;
|
|
|
|
|
|
2007-02-20 01:04:26 +03:00
|
|
|
|
return fuse_setattr(fuse, pn, path, va);
|
2007-02-11 13:31:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ARGSUSED2 */
|
|
|
|
|
static int
|
2007-02-20 22:00:21 +03:00
|
|
|
|
puffs_fuse_node_open(struct puffs_cc *pcc, void *opc, int mode,
|
2007-02-11 13:31:37 +03:00
|
|
|
|
const struct puffs_cred *cred, pid_t pid)
|
|
|
|
|
{
|
|
|
|
|
struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
|
|
|
|
|
struct puffs_node *pn = opc;
|
2007-02-11 15:12:39 +03:00
|
|
|
|
struct refusenode *rn = pn->pn_data;
|
2007-02-20 22:00:21 +03:00
|
|
|
|
struct fuse_file_info *fi = &rn->file_info;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
struct fuse *fuse;
|
|
|
|
|
const char *path = PNPATH(pn);
|
|
|
|
|
|
|
|
|
|
fuse = (struct fuse *)pu->pu_privdata;
|
|
|
|
|
|
2007-02-20 17:51:52 +03:00
|
|
|
|
/* if open, don't open again, lest risk nuking file private info */
|
2007-02-20 22:00:21 +03:00
|
|
|
|
if (rn->flags & RN_OPEN) {
|
|
|
|
|
rn->opencount++;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
return 0;
|
2007-02-20 22:00:21 +03:00
|
|
|
|
}
|
2007-02-11 13:31:37 +03:00
|
|
|
|
|
2007-02-26 18:09:19 +03:00
|
|
|
|
/* OFLAGS(), need to convert FREAD/FWRITE to O_RD/WR */
|
|
|
|
|
fi->flags = (mode & ~(O_CREAT | O_EXCL | O_TRUNC)) - 1;
|
|
|
|
|
|
2007-02-20 17:51:52 +03:00
|
|
|
|
if (pn->pn_va.va_type == VDIR) {
|
|
|
|
|
if (fuse->op.opendir)
|
2007-02-21 02:49:15 +03:00
|
|
|
|
fuse->op.opendir(path, fi);
|
2007-02-20 17:51:52 +03:00
|
|
|
|
} else {
|
|
|
|
|
if (fuse->op.open)
|
2007-02-21 02:49:15 +03:00
|
|
|
|
fuse->op.open(path, fi);
|
2007-02-20 17:51:52 +03:00
|
|
|
|
}
|
2007-02-11 13:31:37 +03:00
|
|
|
|
|
2007-02-21 02:49:15 +03:00
|
|
|
|
rn->flags |= RN_OPEN;
|
|
|
|
|
rn->opencount++;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
|
2007-02-21 02:49:15 +03:00
|
|
|
|
return 0;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-20 22:00:21 +03:00
|
|
|
|
/* ARGSUSED2 */
|
|
|
|
|
static int
|
|
|
|
|
puffs_fuse_node_close(struct puffs_cc *pcc, void *opc, int fflag,
|
|
|
|
|
const struct puffs_cred *pcr, pid_t pid)
|
|
|
|
|
{
|
|
|
|
|
struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
|
|
|
|
|
struct puffs_node *pn = opc;
|
|
|
|
|
struct refusenode *rn = pn->pn_data;
|
|
|
|
|
struct fuse *fuse;
|
|
|
|
|
struct fuse_file_info *fi;
|
|
|
|
|
const char *path = PNPATH(pn);
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
fuse = (struct fuse *)pu->pu_privdata;
|
|
|
|
|
fi = &rn->file_info;
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
|
|
if (rn->flags & RN_OPEN) {
|
|
|
|
|
if (pn->pn_va.va_type == VDIR) {
|
|
|
|
|
if (fuse->op.releasedir)
|
|
|
|
|
ret = fuse->op.releasedir(path, fi);
|
|
|
|
|
} else {
|
|
|
|
|
if (fuse->op.release)
|
|
|
|
|
ret = fuse->op.release(path, fi);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
rn->flags &= ~RN_OPEN;
|
|
|
|
|
rn->opencount--;
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-11 13:31:37 +03:00
|
|
|
|
/* read some more from the file */
|
|
|
|
|
/* ARGSUSED5 */
|
|
|
|
|
static int
|
|
|
|
|
puffs_fuse_node_read(struct puffs_cc *pcc, void *opc, uint8_t *buf,
|
|
|
|
|
off_t offset, size_t *resid, const struct puffs_cred *pcr,
|
|
|
|
|
int ioflag)
|
|
|
|
|
{
|
|
|
|
|
struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
|
|
|
|
|
struct puffs_node *pn = opc;
|
2007-02-11 15:12:39 +03:00
|
|
|
|
struct refusenode *rn = pn->pn_data;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
struct fuse *fuse;
|
|
|
|
|
const char *path = PNPATH(pn);
|
2007-02-19 02:30:45 +03:00
|
|
|
|
size_t maxread;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
fuse = (struct fuse *)pu->pu_privdata;
|
|
|
|
|
if (fuse->op.read == NULL) {
|
|
|
|
|
return ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-19 02:30:45 +03:00
|
|
|
|
maxread = *resid;
|
2007-02-20 01:04:26 +03:00
|
|
|
|
if (maxread > pn->pn_va.va_size - offset) {
|
|
|
|
|
/*LINTED*/
|
2007-02-19 02:30:45 +03:00
|
|
|
|
maxread = pn->pn_va.va_size - offset;
|
2007-02-20 01:04:26 +03:00
|
|
|
|
}
|
2007-02-19 02:30:45 +03:00
|
|
|
|
if (maxread == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
ret = (*fuse->op.read)(path, (char *)buf, maxread, offset,
|
2007-02-11 19:02:24 +03:00
|
|
|
|
&rn->file_info);
|
2007-02-11 13:31:37 +03:00
|
|
|
|
|
|
|
|
|
if (ret > 0) {
|
|
|
|
|
*resid -= ret;
|
2007-02-16 03:13:02 +03:00
|
|
|
|
ret = 0;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-16 03:13:02 +03:00
|
|
|
|
return -ret;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* write to the file */
|
|
|
|
|
/* ARGSUSED0 */
|
|
|
|
|
static int
|
|
|
|
|
puffs_fuse_node_write(struct puffs_cc *pcc, void *opc, uint8_t *buf,
|
|
|
|
|
off_t offset, size_t *resid, const struct puffs_cred *pcr,
|
|
|
|
|
int ioflag)
|
|
|
|
|
{
|
|
|
|
|
struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
|
|
|
|
|
struct puffs_node *pn = opc;
|
2007-02-11 19:06:52 +03:00
|
|
|
|
struct refusenode *rn = pn->pn_data;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
struct fuse *fuse;
|
|
|
|
|
const char *path = PNPATH(pn);
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
fuse = (struct fuse *)pu->pu_privdata;
|
|
|
|
|
if (fuse->op.write == NULL) {
|
|
|
|
|
return ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-16 03:16:39 +03:00
|
|
|
|
if (ioflag & PUFFS_IO_APPEND)
|
|
|
|
|
offset = pn->pn_va.va_size;
|
|
|
|
|
|
2007-02-11 19:06:52 +03:00
|
|
|
|
ret = (*fuse->op.write)(path, (char *)buf, *resid, offset,
|
|
|
|
|
&rn->file_info);
|
2007-02-11 13:31:37 +03:00
|
|
|
|
|
|
|
|
|
if (ret > 0) {
|
2007-02-19 01:30:59 +03:00
|
|
|
|
if (offset + ret > pn->pn_va.va_size)
|
|
|
|
|
pn->pn_va.va_size = offset + ret;
|
2007-02-20 01:04:26 +03:00
|
|
|
|
*resid -= ret;
|
2007-02-16 03:13:02 +03:00
|
|
|
|
ret = 0;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-16 03:13:02 +03:00
|
|
|
|
return -ret;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ARGSUSED3 */
|
|
|
|
|
static int
|
|
|
|
|
puffs_fuse_node_readdir(struct puffs_cc *pcc, void *opc,
|
|
|
|
|
struct dirent *dent, const struct puffs_cred *pcr, off_t *readoff,
|
|
|
|
|
size_t *reslen)
|
|
|
|
|
{
|
|
|
|
|
struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
|
|
|
|
|
struct puffs_node *pn = opc;
|
2007-02-11 19:06:52 +03:00
|
|
|
|
struct refusenode *rn = pn->pn_data;
|
2007-03-14 01:47:03 +03:00
|
|
|
|
struct puffs_fuse_dirh *dirh;
|
2007-03-13 23:50:47 +03:00
|
|
|
|
struct fuse *fuse;
|
2007-03-14 01:47:03 +03:00
|
|
|
|
struct dirent *fromdent;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
const char *path = PNPATH(pn);
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
fuse = (struct fuse *)pu->pu_privdata;
|
2007-02-11 14:57:41 +03:00
|
|
|
|
if (fuse->op.readdir == NULL && fuse->op.getdir == NULL) {
|
2007-02-11 13:31:37 +03:00
|
|
|
|
return ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-26 16:52:16 +03:00
|
|
|
|
if (pn->pn_va.va_type != VDIR)
|
|
|
|
|
return ENOTDIR;
|
|
|
|
|
|
|
|
|
|
dirh = &rn->dirh;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* if we are starting from the beginning, slurp entire directory
|
|
|
|
|
* into our buffers
|
|
|
|
|
*/
|
|
|
|
|
if (*readoff == 0) {
|
|
|
|
|
/* free old buffers */
|
|
|
|
|
free(dirh->dbuf);
|
|
|
|
|
memset(dirh, 0, sizeof(struct puffs_fuse_dirh));
|
|
|
|
|
|
|
|
|
|
if (fuse->op.readdir)
|
|
|
|
|
ret = fuse->op.readdir(path, dirh, puffs_fuse_fill_dir,
|
|
|
|
|
0, &rn->file_info);
|
|
|
|
|
else
|
|
|
|
|
ret = fuse->op.getdir(path, dirh, puffs_fuse_dirfil);
|
|
|
|
|
if (ret)
|
|
|
|
|
return -ret;
|
2007-02-26 03:25:40 +03:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-26 16:52:16 +03:00
|
|
|
|
/* now, stuff results into the kernel buffers */
|
|
|
|
|
while (*readoff < dirh->bufsize - dirh->reslen) {
|
|
|
|
|
/*LINTED*/
|
|
|
|
|
fromdent = (struct dirent *)((uint8_t *)dirh->dbuf + *readoff);
|
2007-02-11 14:57:41 +03:00
|
|
|
|
|
2007-02-26 16:52:16 +03:00
|
|
|
|
if (*reslen < _DIRENT_SIZE(fromdent))
|
|
|
|
|
break;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
|
2007-02-26 16:52:16 +03:00
|
|
|
|
memcpy(dent, fromdent, _DIRENT_SIZE(fromdent));
|
|
|
|
|
*readoff += _DIRENT_SIZE(fromdent);
|
|
|
|
|
*reslen -= _DIRENT_SIZE(fromdent);
|
|
|
|
|
|
|
|
|
|
dent = _DIRENT_NEXT(dent);
|
2007-02-11 13:31:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-26 16:52:16 +03:00
|
|
|
|
return 0;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-20 01:04:26 +03:00
|
|
|
|
/* ARGSUSED */
|
|
|
|
|
static int
|
|
|
|
|
puffs_fuse_node_reclaim(struct puffs_cc *pcc, void *opc, pid_t pid)
|
|
|
|
|
{
|
|
|
|
|
struct puffs_node *pn = opc;
|
2007-02-11 13:58:43 +03:00
|
|
|
|
|
2007-02-11 15:12:39 +03:00
|
|
|
|
nukern(pn);
|
2007-02-11 13:58:43 +03:00
|
|
|
|
|
2007-02-20 01:04:26 +03:00
|
|
|
|
return 0;
|
2007-02-11 13:58:43 +03:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-11 13:31:37 +03:00
|
|
|
|
/* ARGSUSED1 */
|
|
|
|
|
static int
|
|
|
|
|
puffs_fuse_fs_unmount(struct puffs_cc *pcc, int flags, pid_t pid)
|
|
|
|
|
{
|
|
|
|
|
struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
|
|
|
|
|
struct fuse *fuse;
|
|
|
|
|
|
|
|
|
|
fuse = (struct fuse *)pu->pu_privdata;
|
|
|
|
|
if (fuse->op.destroy == NULL) {
|
2007-02-11 13:51:53 +03:00
|
|
|
|
return 0;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
}
|
|
|
|
|
(*fuse->op.destroy)(fuse);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ARGSUSED0 */
|
|
|
|
|
static int
|
|
|
|
|
puffs_fuse_fs_sync(struct puffs_cc *pcc, int flags,
|
|
|
|
|
const struct puffs_cred *cr, pid_t pid)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ARGSUSED2 */
|
|
|
|
|
static int
|
|
|
|
|
puffs_fuse_fs_statvfs(struct puffs_cc *pcc, struct statvfs *svfsb, pid_t pid)
|
|
|
|
|
{
|
|
|
|
|
struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
|
|
|
|
|
struct fuse *fuse;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
fuse = (struct fuse *)pu->pu_privdata;
|
|
|
|
|
if (fuse->op.statfs == NULL) {
|
|
|
|
|
if ((ret = statvfs(PNPATH(pu->pu_pn_root), svfsb)) == -1) {
|
|
|
|
|
return errno;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
ret = (*fuse->op.statfs)(PNPATH(pu->pu_pn_root), svfsb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* End of puffs_fuse operations */
|
|
|
|
|
|
|
|
|
|
/* ARGSUSED3 */
|
|
|
|
|
int
|
|
|
|
|
fuse_main_real(int argc, char **argv, const struct fuse_operations *ops,
|
|
|
|
|
size_t size, void *userdata)
|
2007-02-26 18:57:33 +03:00
|
|
|
|
{
|
2007-03-13 23:50:47 +03:00
|
|
|
|
struct fuse *fuse;
|
2007-03-14 01:47:03 +03:00
|
|
|
|
struct fuse_chan *fc;
|
|
|
|
|
char name[64];
|
|
|
|
|
char *slash;
|
2007-02-26 18:57:33 +03:00
|
|
|
|
int ret;
|
|
|
|
|
|
2007-03-14 01:47:03 +03:00
|
|
|
|
/* whilst this (assigning the pu_privdata in the puffs
|
|
|
|
|
* usermount struct to be the fuse struct) might seem like
|
|
|
|
|
* we are chasing our tail here, the logic is as follows:
|
|
|
|
|
+ the operation wrapper gets called with the puffs
|
|
|
|
|
calling conventions
|
|
|
|
|
+ we need to fix up args first
|
|
|
|
|
+ then call the fuse user-supplied operation
|
|
|
|
|
+ then we fix up any values on return that we need to
|
|
|
|
|
+ and fix up any nodes, etc
|
|
|
|
|
* so we need to be able to get at the fuse ops from within the
|
|
|
|
|
* puffs_usermount struct
|
|
|
|
|
*/
|
|
|
|
|
if ((slash = strrchr(*argv, '/')) == NULL) {
|
|
|
|
|
slash = *argv;
|
|
|
|
|
} else {
|
|
|
|
|
slash += 1;
|
2007-03-13 23:50:47 +03:00
|
|
|
|
}
|
2007-03-14 01:47:03 +03:00
|
|
|
|
(void) snprintf(name, sizeof(name), "refuse:%s", slash);
|
|
|
|
|
|
2007-02-26 18:57:33 +03:00
|
|
|
|
/* XXX: stuff name into fuse_args */
|
2007-03-14 01:47:03 +03:00
|
|
|
|
|
|
|
|
|
fc = fuse_mount(argv[argc - 1], NULL);
|
|
|
|
|
fuse = fuse_new(fc, NULL, ops, size, userdata);
|
2007-02-26 18:57:33 +03:00
|
|
|
|
|
|
|
|
|
ret = fuse_loop(fuse);
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* XXX: just defer the operation until fuse_new() when we have more
|
|
|
|
|
* info on our hands. The real beef is why's this separate in fuse in
|
|
|
|
|
* the first place?
|
|
|
|
|
*/
|
|
|
|
|
/* ARGSUSED1 */
|
|
|
|
|
struct fuse_chan *
|
|
|
|
|
fuse_mount(const char *dir, struct fuse_args *args)
|
|
|
|
|
{
|
2007-03-14 01:47:03 +03:00
|
|
|
|
struct fuse_chan *fc;
|
2007-02-26 18:57:33 +03:00
|
|
|
|
|
2007-03-14 01:47:03 +03:00
|
|
|
|
NEW(struct fuse_chan, fc, "fuse_mount", exit(EXIT_FAILURE));
|
2007-02-26 18:57:33 +03:00
|
|
|
|
|
2007-03-14 01:47:03 +03:00
|
|
|
|
fc->dir = strdup(dir);
|
|
|
|
|
fc->args = args; /* XXXX: do we need to deep copy? */
|
|
|
|
|
|
2007-02-26 18:57:33 +03:00
|
|
|
|
return fc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ARGSUSED1 */
|
|
|
|
|
struct fuse *
|
|
|
|
|
fuse_new(struct fuse_chan *fc, struct fuse_args *args,
|
|
|
|
|
const struct fuse_operations *ops, size_t size, void *userdata)
|
2007-02-11 13:31:37 +03:00
|
|
|
|
{
|
|
|
|
|
struct puffs_usermount *pu;
|
|
|
|
|
struct puffs_pathobj *po_root;
|
2007-03-13 23:50:47 +03:00
|
|
|
|
struct puffs_ops *pops;
|
2007-03-14 01:47:03 +03:00
|
|
|
|
struct refusenode *rn_root;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
struct statvfs svfsb;
|
2007-02-19 02:30:45 +03:00
|
|
|
|
struct stat st;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
struct fuse *fuse;
|
2007-02-26 18:57:33 +03:00
|
|
|
|
|
|
|
|
|
NEW(struct fuse, fuse, "fuse_new", exit(EXIT_FAILURE));
|
|
|
|
|
|
|
|
|
|
/* copy fuse ops to their own stucture */
|
|
|
|
|
(void) memcpy(&fuse->op, ops, sizeof(fuse->op));
|
|
|
|
|
|
|
|
|
|
fcon.fuse = fuse;
|
|
|
|
|
fcon.private_data = userdata;
|
|
|
|
|
|
|
|
|
|
fuse->fc = fc;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
|
|
|
|
|
/* initialise the puffs operations structure */
|
|
|
|
|
PUFFSOP_INIT(pops);
|
|
|
|
|
|
|
|
|
|
PUFFSOP_SET(pops, puffs_fuse, fs, sync);
|
|
|
|
|
PUFFSOP_SET(pops, puffs_fuse, fs, statvfs);
|
|
|
|
|
PUFFSOP_SET(pops, puffs_fuse, fs, unmount);
|
|
|
|
|
|
2007-02-11 13:51:53 +03:00
|
|
|
|
/*
|
|
|
|
|
* XXX: all of these don't possibly need to be
|
|
|
|
|
* unconditionally set
|
|
|
|
|
*/
|
2007-02-11 13:31:37 +03:00
|
|
|
|
PUFFSOP_SET(pops, puffs_fuse, node, lookup);
|
|
|
|
|
PUFFSOP_SET(pops, puffs_fuse, node, getattr);
|
2007-02-16 00:57:09 +03:00
|
|
|
|
PUFFSOP_SET(pops, puffs_fuse, node, setattr);
|
2007-02-11 13:31:37 +03:00
|
|
|
|
PUFFSOP_SET(pops, puffs_fuse, node, readdir);
|
|
|
|
|
PUFFSOP_SET(pops, puffs_fuse, node, readlink);
|
|
|
|
|
PUFFSOP_SET(pops, puffs_fuse, node, mknod);
|
2007-02-16 03:13:02 +03:00
|
|
|
|
PUFFSOP_SET(pops, puffs_fuse, node, create);
|
2007-02-11 13:31:37 +03:00
|
|
|
|
PUFFSOP_SET(pops, puffs_fuse, node, remove);
|
2007-02-16 00:57:09 +03:00
|
|
|
|
PUFFSOP_SET(pops, puffs_fuse, node, mkdir);
|
2007-02-11 13:31:37 +03:00
|
|
|
|
PUFFSOP_SET(pops, puffs_fuse, node, rmdir);
|
|
|
|
|
PUFFSOP_SET(pops, puffs_fuse, node, symlink);
|
|
|
|
|
PUFFSOP_SET(pops, puffs_fuse, node, rename);
|
|
|
|
|
PUFFSOP_SET(pops, puffs_fuse, node, link);
|
|
|
|
|
PUFFSOP_SET(pops, puffs_fuse, node, open);
|
2007-02-20 22:00:21 +03:00
|
|
|
|
PUFFSOP_SET(pops, puffs_fuse, node, close);
|
2007-02-11 13:31:37 +03:00
|
|
|
|
PUFFSOP_SET(pops, puffs_fuse, node, read);
|
|
|
|
|
PUFFSOP_SET(pops, puffs_fuse, node, write);
|
2007-02-11 13:58:43 +03:00
|
|
|
|
PUFFSOP_SET(pops, puffs_fuse, node, reclaim);
|
2007-02-11 13:31:37 +03:00
|
|
|
|
|
2007-02-26 18:57:33 +03:00
|
|
|
|
pu = puffs_mount(pops, fc->dir, MNT_NODEV | MNT_NOSUID,
|
2007-03-14 01:47:03 +03:00
|
|
|
|
"refuse", NULL,
|
2007-02-26 18:57:33 +03:00
|
|
|
|
PUFFS_FLAG_BUILDPATH
|
|
|
|
|
| PUFFS_FLAG_OPDUMP
|
|
|
|
|
| PUFFS_KFLAG_NOCACHE,
|
|
|
|
|
0);
|
2007-02-11 13:31:37 +03:00
|
|
|
|
if (pu == NULL) {
|
|
|
|
|
err(EXIT_FAILURE, "puffs_mount");
|
|
|
|
|
}
|
2007-02-26 18:57:33 +03:00
|
|
|
|
fc->pu = pu;
|
|
|
|
|
pu->pu_privdata = fuse;
|
2007-02-11 13:31:37 +03:00
|
|
|
|
|
2007-02-20 17:51:52 +03:00
|
|
|
|
pu->pu_pn_root = newrn(pu);
|
|
|
|
|
rn_root = pu->pu_pn_root->pn_data;
|
|
|
|
|
rn_root->flags |= RN_ROOT;
|
|
|
|
|
|
2007-02-11 13:31:37 +03:00
|
|
|
|
po_root = puffs_getrootpathobj(pu);
|
|
|
|
|
po_root->po_path = strdup("/");
|
|
|
|
|
po_root->po_len = 1;
|
|
|
|
|
|
2007-02-19 02:30:45 +03:00
|
|
|
|
/* sane defaults */
|
|
|
|
|
puffs_vattr_null(&pu->pu_pn_root->pn_va);
|
|
|
|
|
pu->pu_pn_root->pn_va.va_type = VDIR;
|
|
|
|
|
pu->pu_pn_root->pn_va.va_mode = 0755;
|
|
|
|
|
if (fuse->op.getattr)
|
|
|
|
|
if (fuse->op.getattr(po_root->po_path, &st) == 0)
|
|
|
|
|
puffs_stat2vattr(&pu->pu_pn_root->pn_va, &st);
|
|
|
|
|
assert(pu->pu_pn_root->pn_va.va_type == VDIR);
|
|
|
|
|
|
2007-02-15 13:54:40 +03:00
|
|
|
|
if (fuse->op.init)
|
|
|
|
|
fcon.private_data = fuse->op.init(NULL); /* XXX */
|
|
|
|
|
|
2007-02-26 18:57:33 +03:00
|
|
|
|
puffs_zerostatvfs(&svfsb);
|
2007-02-11 13:31:37 +03:00
|
|
|
|
if (puffs_start(pu, pu->pu_pn_root, &svfsb) == -1) {
|
|
|
|
|
err(EXIT_FAILURE, "puffs_start");
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-26 18:57:33 +03:00
|
|
|
|
return fuse;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
fuse_loop(struct fuse *fuse)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return puffs_mainloop(fuse->fc->pu, PUFFSLOOP_NODAEMON);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
fuse_destroy(struct fuse *fuse)
|
|
|
|
|
{
|
|
|
|
|
|
2007-02-11 13:31:37 +03:00
|
|
|
|
|
2007-02-26 18:57:33 +03:00
|
|
|
|
/* XXXXXX: missing stuff */
|
2007-02-11 13:31:37 +03:00
|
|
|
|
FREE(fuse);
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-15 13:54:40 +03:00
|
|
|
|
/* XXX: threads */
|
|
|
|
|
struct fuse_context *
|
|
|
|
|
fuse_get_context()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return &fcon;
|
|
|
|
|
}
|
2007-02-18 20:44:57 +03:00
|
|
|
|
|
|
|
|
|
void
|
2007-02-26 18:57:33 +03:00
|
|
|
|
fuse_exit(struct fuse *fuse)
|
2007-02-18 20:44:57 +03:00
|
|
|
|
{
|
|
|
|
|
|
2007-02-26 18:57:33 +03:00
|
|
|
|
puffs_exit(fuse->fc->pu, 1);
|
2007-02-18 20:44:57 +03:00
|
|
|
|
}
|
2007-02-20 02:12:29 +03:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* XXX: obviously not the most perfect of functions, but needs some
|
|
|
|
|
* puffs tweaking for a better tomorrow
|
|
|
|
|
*/
|
2007-02-20 22:00:21 +03:00
|
|
|
|
/*ARGSUSED*/
|
2007-02-20 02:12:29 +03:00
|
|
|
|
void
|
2007-02-26 18:57:33 +03:00
|
|
|
|
fuse_unmount(const char *mp, struct fuse_chan *fc)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
puffs_exit(fc->pu, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
|
void
|
|
|
|
|
fuse_unmount_compat22(const char *mp)
|
2007-02-20 02:12:29 +03:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|