2005-04-07 23:40:21 +08:00
|
|
|
/*
|
2007-12-12 22:25:40 +08:00
|
|
|
FUSE: Filesystem in Userspace
|
|
|
|
Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
|
2011-06-26 01:14:29 +08:00
|
|
|
Copyright (C) 2011 Sebastian Pipping <sebastian@pipping.org>
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
This program can be distributed under the terms of the GNU GPL.
|
|
|
|
See the file COPYING.
|
2006-10-01 21:46:02 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
gcc -Wall `pkg-config fuse --cflags --libs` -lulockmgr fusexmp_fh.c -o fusexmp_fh
|
2005-04-07 23:40:21 +08:00
|
|
|
*/
|
|
|
|
|
2006-10-01 21:46:02 +08:00
|
|
|
#define FUSE_USE_VERSION 26
|
|
|
|
|
2007-05-17 20:41:46 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2005-04-07 23:40:21 +08:00
|
|
|
#include <config.h>
|
2007-05-17 20:41:46 +08:00
|
|
|
#endif
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2005-08-11 23:48:10 +08:00
|
|
|
#define _GNU_SOURCE
|
2005-04-07 23:40:21 +08:00
|
|
|
|
|
|
|
#include <fuse.h>
|
2006-09-11 04:53:36 +08:00
|
|
|
#include <ulockmgr.h>
|
2005-04-07 23:40:21 +08:00
|
|
|
#include <stdio.h>
|
2008-02-08 19:26:15 +08:00
|
|
|
#include <stdlib.h>
|
2005-04-07 23:40:21 +08:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
2011-06-26 01:14:29 +08:00
|
|
|
#include <sys/stat.h>
|
2005-04-07 23:40:21 +08:00
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.h>
|
2006-09-02 17:51:08 +08:00
|
|
|
#include <sys/time.h>
|
2005-04-07 23:40:21 +08:00
|
|
|
#ifdef HAVE_SETXATTR
|
|
|
|
#include <sys/xattr.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int xmp_getattr(const char *path, struct stat *stbuf)
|
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
int res;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
res = lstat(path, stbuf);
|
|
|
|
if (res == -1)
|
|
|
|
return -errno;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
return 0;
|
2005-04-07 23:40:21 +08:00
|
|
|
}
|
|
|
|
|
2005-10-28 21:09:50 +08:00
|
|
|
static int xmp_fgetattr(const char *path, struct stat *stbuf,
|
2007-12-12 22:25:40 +08:00
|
|
|
struct fuse_file_info *fi)
|
2005-10-28 21:09:50 +08:00
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
int res;
|
2005-10-28 21:09:50 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
(void) path;
|
2005-10-28 21:09:50 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
res = fstat(fi->fh, stbuf);
|
|
|
|
if (res == -1)
|
|
|
|
return -errno;
|
2005-10-28 21:09:50 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
return 0;
|
2005-10-28 21:09:50 +08:00
|
|
|
}
|
|
|
|
|
2005-10-26 20:53:25 +08:00
|
|
|
static int xmp_access(const char *path, int mask)
|
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
int res;
|
2005-10-26 20:53:25 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
res = access(path, mask);
|
|
|
|
if (res == -1)
|
|
|
|
return -errno;
|
2005-10-26 20:53:25 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
return 0;
|
2005-10-26 20:53:25 +08:00
|
|
|
}
|
|
|
|
|
2005-04-07 23:40:21 +08:00
|
|
|
static int xmp_readlink(const char *path, char *buf, size_t size)
|
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
int res;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
res = readlink(path, buf, size - 1);
|
|
|
|
if (res == -1)
|
|
|
|
return -errno;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
buf[res] = '\0';
|
|
|
|
return 0;
|
2005-04-07 23:40:21 +08:00
|
|
|
}
|
|
|
|
|
2008-02-08 19:26:15 +08:00
|
|
|
struct xmp_dirp {
|
|
|
|
DIR *dp;
|
|
|
|
struct dirent *entry;
|
|
|
|
off_t offset;
|
|
|
|
};
|
|
|
|
|
2005-04-07 23:40:21 +08:00
|
|
|
static int xmp_opendir(const char *path, struct fuse_file_info *fi)
|
|
|
|
{
|
2008-02-08 19:26:15 +08:00
|
|
|
int res;
|
|
|
|
struct xmp_dirp *d = malloc(sizeof(struct xmp_dirp));
|
|
|
|
if (d == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
d->dp = opendir(path);
|
|
|
|
if (d->dp == NULL) {
|
|
|
|
res = -errno;
|
|
|
|
free(d);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
d->offset = 0;
|
|
|
|
d->entry = NULL;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2008-02-08 19:26:15 +08:00
|
|
|
fi->fh = (unsigned long) d;
|
2007-12-12 22:25:40 +08:00
|
|
|
return 0;
|
2005-04-07 23:40:21 +08:00
|
|
|
}
|
|
|
|
|
2008-02-08 19:26:15 +08:00
|
|
|
static inline struct xmp_dirp *get_dirp(struct fuse_file_info *fi)
|
2005-11-12 05:32:42 +08:00
|
|
|
{
|
2008-02-08 19:26:15 +08:00
|
|
|
return (struct xmp_dirp *) (uintptr_t) fi->fh;
|
2005-11-12 05:32:42 +08:00
|
|
|
}
|
|
|
|
|
2005-04-07 23:40:21 +08:00
|
|
|
static int xmp_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
|
2007-12-12 22:25:40 +08:00
|
|
|
off_t offset, struct fuse_file_info *fi)
|
2005-04-07 23:40:21 +08:00
|
|
|
{
|
2008-02-08 19:26:15 +08:00
|
|
|
struct xmp_dirp *d = get_dirp(fi);
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
(void) path;
|
2008-02-08 19:26:15 +08:00
|
|
|
if (offset != d->offset) {
|
|
|
|
seekdir(d->dp, offset);
|
|
|
|
d->entry = NULL;
|
|
|
|
d->offset = offset;
|
|
|
|
}
|
|
|
|
while (1) {
|
2007-12-12 22:25:40 +08:00
|
|
|
struct stat st;
|
2008-02-08 19:26:15 +08:00
|
|
|
off_t nextoff;
|
|
|
|
|
|
|
|
if (!d->entry) {
|
|
|
|
d->entry = readdir(d->dp);
|
|
|
|
if (!d->entry)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
memset(&st, 0, sizeof(st));
|
2008-02-08 19:26:15 +08:00
|
|
|
st.st_ino = d->entry->d_ino;
|
|
|
|
st.st_mode = d->entry->d_type << 12;
|
|
|
|
nextoff = telldir(d->dp);
|
|
|
|
if (filler(buf, d->entry->d_name, &st, nextoff))
|
2007-12-12 22:25:40 +08:00
|
|
|
break;
|
2008-02-08 19:26:15 +08:00
|
|
|
|
|
|
|
d->entry = NULL;
|
|
|
|
d->offset = nextoff;
|
2007-12-12 22:25:40 +08:00
|
|
|
}
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
return 0;
|
2005-04-07 23:40:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int xmp_releasedir(const char *path, struct fuse_file_info *fi)
|
|
|
|
{
|
2008-02-08 19:26:15 +08:00
|
|
|
struct xmp_dirp *d = get_dirp(fi);
|
2007-12-12 22:25:40 +08:00
|
|
|
(void) path;
|
2008-02-08 19:26:15 +08:00
|
|
|
closedir(d->dp);
|
|
|
|
free(d);
|
2007-12-12 22:25:40 +08:00
|
|
|
return 0;
|
2005-04-07 23:40:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int xmp_mknod(const char *path, mode_t mode, dev_t rdev)
|
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
int res;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
if (S_ISFIFO(mode))
|
|
|
|
res = mkfifo(path, mode);
|
|
|
|
else
|
|
|
|
res = mknod(path, mode, rdev);
|
|
|
|
if (res == -1)
|
|
|
|
return -errno;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
return 0;
|
2005-04-07 23:40:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int xmp_mkdir(const char *path, mode_t mode)
|
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
int res;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
res = mkdir(path, mode);
|
|
|
|
if (res == -1)
|
|
|
|
return -errno;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
return 0;
|
2005-04-07 23:40:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int xmp_unlink(const char *path)
|
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
int res;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
res = unlink(path);
|
|
|
|
if (res == -1)
|
|
|
|
return -errno;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
return 0;
|
2005-04-07 23:40:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int xmp_rmdir(const char *path)
|
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
int res;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
res = rmdir(path);
|
|
|
|
if (res == -1)
|
|
|
|
return -errno;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
return 0;
|
2005-04-07 23:40:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int xmp_symlink(const char *from, const char *to)
|
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
int res;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
res = symlink(from, to);
|
|
|
|
if (res == -1)
|
|
|
|
return -errno;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
return 0;
|
2005-04-07 23:40:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int xmp_rename(const char *from, const char *to)
|
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
int res;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
res = rename(from, to);
|
|
|
|
if (res == -1)
|
|
|
|
return -errno;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
return 0;
|
2005-04-07 23:40:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int xmp_link(const char *from, const char *to)
|
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
int res;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
res = link(from, to);
|
|
|
|
if (res == -1)
|
|
|
|
return -errno;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
return 0;
|
2005-04-07 23:40:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int xmp_chmod(const char *path, mode_t mode)
|
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
int res;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
res = chmod(path, mode);
|
|
|
|
if (res == -1)
|
|
|
|
return -errno;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
return 0;
|
2005-04-07 23:40:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int xmp_chown(const char *path, uid_t uid, gid_t gid)
|
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
int res;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
res = lchown(path, uid, gid);
|
|
|
|
if (res == -1)
|
|
|
|
return -errno;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
return 0;
|
2005-04-07 23:40:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int xmp_truncate(const char *path, off_t size)
|
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
int res;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
res = truncate(path, size);
|
|
|
|
if (res == -1)
|
|
|
|
return -errno;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
return 0;
|
2005-04-07 23:40:21 +08:00
|
|
|
}
|
|
|
|
|
2005-10-27 00:04:04 +08:00
|
|
|
static int xmp_ftruncate(const char *path, off_t size,
|
2007-12-12 22:25:40 +08:00
|
|
|
struct fuse_file_info *fi)
|
2005-10-27 00:04:04 +08:00
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
int res;
|
2005-10-27 00:04:04 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
(void) path;
|
2005-10-27 00:04:04 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
res = ftruncate(fi->fh, size);
|
|
|
|
if (res == -1)
|
|
|
|
return -errno;
|
2005-10-27 00:04:04 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
return 0;
|
2005-10-27 00:04:04 +08:00
|
|
|
}
|
|
|
|
|
2006-09-16 16:52:09 +08:00
|
|
|
static int xmp_utimens(const char *path, const struct timespec ts[2])
|
2005-04-07 23:40:21 +08:00
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
int res;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2011-06-26 01:14:29 +08:00
|
|
|
res = utimensat(0, path, ts, AT_SYMLINK_NOFOLLOW);
|
2007-12-12 22:25:40 +08:00
|
|
|
if (res == -1)
|
|
|
|
return -errno;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
return 0;
|
2005-04-07 23:40:21 +08:00
|
|
|
}
|
|
|
|
|
2005-10-26 23:29:06 +08:00
|
|
|
static int xmp_create(const char *path, mode_t mode, struct fuse_file_info *fi)
|
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
int fd;
|
2005-10-26 23:29:06 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
fd = open(path, fi->flags, mode);
|
|
|
|
if (fd == -1)
|
|
|
|
return -errno;
|
2005-10-26 23:29:06 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
fi->fh = fd;
|
|
|
|
return 0;
|
2005-10-26 23:29:06 +08:00
|
|
|
}
|
2005-04-07 23:40:21 +08:00
|
|
|
|
|
|
|
static int xmp_open(const char *path, struct fuse_file_info *fi)
|
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
int fd;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
fd = open(path, fi->flags);
|
|
|
|
if (fd == -1)
|
|
|
|
return -errno;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
fi->fh = fd;
|
|
|
|
return 0;
|
2005-04-07 23:40:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int xmp_read(const char *path, char *buf, size_t size, off_t offset,
|
2007-12-12 22:25:40 +08:00
|
|
|
struct fuse_file_info *fi)
|
2005-04-07 23:40:21 +08:00
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
int res;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
(void) path;
|
|
|
|
res = pread(fi->fh, buf, size, offset);
|
|
|
|
if (res == -1)
|
|
|
|
res = -errno;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
return res;
|
2005-04-07 23:40:21 +08:00
|
|
|
}
|
|
|
|
|
2010-11-10 18:45:50 +08:00
|
|
|
static int xmp_read_buf(const char *path, struct fuse_bufvec **bufp,
|
|
|
|
size_t size, off_t offset, struct fuse_file_info *fi)
|
|
|
|
{
|
|
|
|
struct fuse_bufvec *src;
|
|
|
|
|
|
|
|
(void) path;
|
|
|
|
|
|
|
|
src = malloc(sizeof(struct fuse_bufvec));
|
|
|
|
if (src == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
*src = FUSE_BUFVEC_INIT(size);
|
|
|
|
|
|
|
|
src->buf[0].flags = FUSE_BUF_IS_FD | FUSE_BUF_FD_SEEK;
|
|
|
|
src->buf[0].fd = fi->fh;
|
|
|
|
src->buf[0].pos = offset;
|
|
|
|
|
|
|
|
*bufp = src;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-07 23:40:21 +08:00
|
|
|
static int xmp_write(const char *path, const char *buf, size_t size,
|
2007-12-12 22:25:40 +08:00
|
|
|
off_t offset, struct fuse_file_info *fi)
|
2005-04-07 23:40:21 +08:00
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
int res;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
(void) path;
|
|
|
|
res = pwrite(fi->fh, buf, size, offset);
|
|
|
|
if (res == -1)
|
|
|
|
res = -errno;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
return res;
|
2005-04-07 23:40:21 +08:00
|
|
|
}
|
|
|
|
|
2010-11-10 18:45:50 +08:00
|
|
|
static int xmp_write_buf(const char *path, struct fuse_bufvec *buf,
|
|
|
|
off_t offset, struct fuse_file_info *fi)
|
|
|
|
{
|
|
|
|
struct fuse_bufvec dst = FUSE_BUFVEC_INIT(fuse_buf_size(buf));
|
|
|
|
|
|
|
|
(void) path;
|
|
|
|
|
|
|
|
dst.buf[0].flags = FUSE_BUF_IS_FD | FUSE_BUF_FD_SEEK;
|
|
|
|
dst.buf[0].fd = fi->fh;
|
|
|
|
dst.buf[0].pos = offset;
|
|
|
|
|
|
|
|
return fuse_buf_copy(&dst, buf, FUSE_BUF_SPLICE_NONBLOCK);
|
|
|
|
}
|
|
|
|
|
2005-11-07 19:59:00 +08:00
|
|
|
static int xmp_statfs(const char *path, struct statvfs *stbuf)
|
2005-04-07 23:40:21 +08:00
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
int res;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
res = statvfs(path, stbuf);
|
|
|
|
if (res == -1)
|
|
|
|
return -errno;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
return 0;
|
2005-04-07 23:40:21 +08:00
|
|
|
}
|
|
|
|
|
2006-02-22 02:31:29 +08:00
|
|
|
static int xmp_flush(const char *path, struct fuse_file_info *fi)
|
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
int res;
|
2006-02-22 02:31:29 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
(void) path;
|
|
|
|
/* This is called from every close on an open file, so call the
|
|
|
|
close on the underlying filesystem. But since flush may be
|
|
|
|
called multiple times for an open file, this must not really
|
|
|
|
close the file. This is important if used on a network
|
|
|
|
filesystem like NFS which flush the data/metadata on close() */
|
|
|
|
res = close(dup(fi->fh));
|
|
|
|
if (res == -1)
|
|
|
|
return -errno;
|
2006-02-22 02:31:29 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
return 0;
|
2006-02-22 02:31:29 +08:00
|
|
|
}
|
|
|
|
|
2005-04-07 23:40:21 +08:00
|
|
|
static int xmp_release(const char *path, struct fuse_file_info *fi)
|
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
(void) path;
|
|
|
|
close(fi->fh);
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
return 0;
|
2005-04-07 23:40:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int xmp_fsync(const char *path, int isdatasync,
|
2007-12-12 22:25:40 +08:00
|
|
|
struct fuse_file_info *fi)
|
2005-04-07 23:40:21 +08:00
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
int res;
|
|
|
|
(void) path;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2005-11-16 21:00:24 +08:00
|
|
|
#ifndef HAVE_FDATASYNC
|
2007-12-12 22:25:40 +08:00
|
|
|
(void) isdatasync;
|
2005-11-16 21:00:24 +08:00
|
|
|
#else
|
2007-12-12 22:25:40 +08:00
|
|
|
if (isdatasync)
|
|
|
|
res = fdatasync(fi->fh);
|
|
|
|
else
|
2005-11-16 21:00:24 +08:00
|
|
|
#endif
|
2007-12-12 22:25:40 +08:00
|
|
|
res = fsync(fi->fh);
|
|
|
|
if (res == -1)
|
|
|
|
return -errno;
|
2005-04-07 23:40:21 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
return 0;
|
2005-04-07 23:40:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_SETXATTR
|
|
|
|
/* xattr operations are optional and can safely be left unimplemented */
|
|
|
|
static int xmp_setxattr(const char *path, const char *name, const char *value,
|
2007-12-12 22:25:40 +08:00
|
|
|
size_t size, int flags)
|
2005-04-07 23:40:21 +08:00
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
int res = lsetxattr(path, name, value, size, flags);
|
|
|
|
if (res == -1)
|
|
|
|
return -errno;
|
|
|
|
return 0;
|
2005-04-07 23:40:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int xmp_getxattr(const char *path, const char *name, char *value,
|
2007-12-12 22:25:40 +08:00
|
|
|
size_t size)
|
2005-04-07 23:40:21 +08:00
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
int res = lgetxattr(path, name, value, size);
|
|
|
|
if (res == -1)
|
|
|
|
return -errno;
|
|
|
|
return res;
|
2005-04-07 23:40:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int xmp_listxattr(const char *path, char *list, size_t size)
|
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
int res = llistxattr(path, list, size);
|
|
|
|
if (res == -1)
|
|
|
|
return -errno;
|
|
|
|
return res;
|
2005-04-07 23:40:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int xmp_removexattr(const char *path, const char *name)
|
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
int res = lremovexattr(path, name);
|
|
|
|
if (res == -1)
|
|
|
|
return -errno;
|
|
|
|
return 0;
|
2005-04-07 23:40:21 +08:00
|
|
|
}
|
|
|
|
#endif /* HAVE_SETXATTR */
|
|
|
|
|
2006-09-11 04:53:36 +08:00
|
|
|
static int xmp_lock(const char *path, struct fuse_file_info *fi, int cmd,
|
2007-12-12 22:25:40 +08:00
|
|
|
struct flock *lock)
|
2006-09-11 04:53:36 +08:00
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
(void) path;
|
2006-09-11 04:53:36 +08:00
|
|
|
|
2007-12-12 22:25:40 +08:00
|
|
|
return ulockmgr_op(fi->fh, cmd, lock, &fi->lock_owner,
|
|
|
|
sizeof(fi->lock_owner));
|
2006-09-11 04:53:36 +08:00
|
|
|
}
|
|
|
|
|
2005-04-07 23:40:21 +08:00
|
|
|
static struct fuse_operations xmp_oper = {
|
2007-12-12 22:25:40 +08:00
|
|
|
.getattr = xmp_getattr,
|
|
|
|
.fgetattr = xmp_fgetattr,
|
|
|
|
.access = xmp_access,
|
|
|
|
.readlink = xmp_readlink,
|
|
|
|
.opendir = xmp_opendir,
|
|
|
|
.readdir = xmp_readdir,
|
|
|
|
.releasedir = xmp_releasedir,
|
|
|
|
.mknod = xmp_mknod,
|
|
|
|
.mkdir = xmp_mkdir,
|
|
|
|
.symlink = xmp_symlink,
|
|
|
|
.unlink = xmp_unlink,
|
|
|
|
.rmdir = xmp_rmdir,
|
|
|
|
.rename = xmp_rename,
|
|
|
|
.link = xmp_link,
|
|
|
|
.chmod = xmp_chmod,
|
|
|
|
.chown = xmp_chown,
|
|
|
|
.truncate = xmp_truncate,
|
|
|
|
.ftruncate = xmp_ftruncate,
|
|
|
|
.utimens = xmp_utimens,
|
|
|
|
.create = xmp_create,
|
|
|
|
.open = xmp_open,
|
|
|
|
.read = xmp_read,
|
2010-11-10 18:45:50 +08:00
|
|
|
.read_buf = xmp_read_buf,
|
2007-12-12 22:25:40 +08:00
|
|
|
.write = xmp_write,
|
2010-11-10 18:45:50 +08:00
|
|
|
.write_buf = xmp_write_buf,
|
2007-12-12 22:25:40 +08:00
|
|
|
.statfs = xmp_statfs,
|
|
|
|
.flush = xmp_flush,
|
|
|
|
.release = xmp_release,
|
|
|
|
.fsync = xmp_fsync,
|
2005-04-07 23:40:21 +08:00
|
|
|
#ifdef HAVE_SETXATTR
|
2007-12-12 22:25:40 +08:00
|
|
|
.setxattr = xmp_setxattr,
|
|
|
|
.getxattr = xmp_getxattr,
|
|
|
|
.listxattr = xmp_listxattr,
|
|
|
|
.removexattr = xmp_removexattr,
|
2005-04-07 23:40:21 +08:00
|
|
|
#endif
|
2007-12-12 22:25:40 +08:00
|
|
|
.lock = xmp_lock,
|
2008-02-09 01:22:15 +08:00
|
|
|
|
|
|
|
.flag_nullpath_ok = 1,
|
2005-04-07 23:40:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2007-12-12 22:25:40 +08:00
|
|
|
umask(0);
|
|
|
|
return fuse_main(argc, argv, &xmp_oper, NULL);
|
2005-04-07 23:40:21 +08:00
|
|
|
}
|