21#ifdef HAVE_ATTR_XATTR_H
22#include <attr/xattr.h>
23#elif defined(HAVE_SYS_XATTR_H)
28#define ENOATTR ENODATA
30#ifdef HAVE_ATTR_ATTRIBUTES_H
31#include <attr/attributes.h>
38#define XATTR_NAME "user.epoc"
44#define ENOMEDIUM ENODEV
58 if (vasprintf(&buf, fmt, ap) == -1)
59 syslog(LOG_DEBUG,
"vasprintf error in debuglog");
61 syslog(LOG_DEBUG,
"%s", buf);
68xattr2pattr(
long *psisattr,
long *psidattr,
const char *oxattr,
const char *nxattr)
70 if ((strchr(oxattr,
'a') == NULL) != (strchr(nxattr,
'a') == NULL)) {
71 if (strchr(nxattr,
'a'))
76 if ((strchr(oxattr,
'h') == NULL) != (strchr(nxattr,
'h') == NULL)) {
77 if (strchr(nxattr,
'h'))
82 if ((strchr(oxattr,
's') == NULL) != (strchr(nxattr,
's') == NULL)) {
83 if (strchr(nxattr,
's'))
91attr2pattr(
long oattr,
long nattr,
char *oxattr,
char *nxattr,
long *psisattr,
long *psidattr)
93 *psisattr = *psidattr = 0;
94 if ((oattr & 0400) != (nattr & 0400)) {
100 if ((oattr & 0200) != (nattr & 0200)) {
123pattr2attr(
long psiattr,
long size,
long ftime,
struct stat *st,
char *xattr)
125 struct fuse_context *ct = fuse_get_context();
127 memset(st, 0,
sizeof(*st));
128 st->st_uid = ct->uid;
129 st->st_gid = ct->gid;
132 st->st_mode = 0700 | S_IFDIR;
140 st->st_mode = S_IFREG;
147 st->st_mtime = st->st_ctime = st->st_atime = ftime;
159 for (dp =
devices; dp; dp = np) {
173 static char *namebuf = NULL;
176 if (asprintf(&namebuf,
"%s\\", dir) == -1)
185 if ((p = (
char *) rindex(dir,
'\\')))
218static int getlinks(
const char *path,
struct stat *st)
223 st->st_nlink = dcount + 2;
232 debuglog(
"plp_getattr `%s'", ++path);
234 if (strcmp(path,
"") == 0) {
241 debuglog(
"root has %d links", st->st_nlink);
245 long pattr, psize, ptime;
247 if (strlen(path) == 2 && path[1] ==
':') {
254 if (dp->
letter == path[0])
257 debuglog(
"device: %s", dp ?
"exists" :
"does not exist");
265 if ((ret =
rfsv_getattr(path, &pattr, &psize, &ptime)) == 0) {
267 debuglog(
" attrs Psion: %x %d %d, UNIX modes: %o, xattrs: %s", pattr, psize, ptime, st->st_mode, xattr);
268 if (st->st_nlink > 1)
273 debuglog(
"getattr: returned %d", ret);
280 debuglog(
"plp_access `%s'", ++path);
288 debuglog(
"plp_readlink `%s'", ++path);
293static int plp_readdir(
const char *path,
void *buf, fuse_fill_dir_t filler,
294 off_t offset,
struct fuse_file_info *fi)
300 debuglog(
"plp_readdir `%s'", ++path);
305 if (strcmp(path,
"") == 0) {
310 unsigned char name[3];
316 if (filler(buf, (
char *)name, &st, 0))
333 debuglog(
" %s %o %d %d", name, st.st_mode, st.st_size, st.st_mtime);
334 if (filler(buf, name, &st, 0))
347static int plp_mknod(
const char *path, mode_t mode, dev_t dev)
351 debuglog(
"plp_mknod `%s' %o", ++path, mode);
353 if (S_ISREG(mode) && dev == 0) {
364 debuglog(
"plp_mkdir `%s' %o", ++path, mode);
370 debuglog(
"plp_unlink `%s'", ++path);
382 debuglog(
"plp_symlink `%s' -> `'%s'", ++from, ++to);
388 debuglog(
"plp_rename `%s' -> `%s'", ++from, ++to);
393static int plp_link(
const char *from,
const char *to)
395 debuglog(
"plp_link `%s' -> `%s'", ++from, ++to);
402 long psisattr, psidattr, pattr, psize, ptime;
408 if ((ret =
rfsv_getattr(path, &pattr, &psize, &ptime)) == 0) {
410 attr2pattr(st.st_mode, mode,
"",
"", &psisattr, &psidattr);
411 debuglog(
" UNIX old, new: %o, %o; Psion set, clear: %x, %x", st.st_mode, mode, psisattr, psidattr);
412 if ((ret =
rfsv_setattr(path, psisattr, psidattr)) == 0)
419static int plp_getxattr(
const char *path,
const char *name,
char *value,
size_t size
421 , _GL_UNUSED uint32_t position
425 debuglog(
"plp_getxattr `%s' %s", ++path, name);
428 long pattr, psize, ptime;
430 if ((ret =
rfsv_getattr(path, &pattr, &psize, &ptime)) == 0) {
432 debuglog(
"getxattr succeeded: %s", value);
433 return strlen(value);
444static int plp_setxattr(
const char *path,
const char *name,
const char *value,
size_t size,
int flags
446 , _GL_UNUSED uint32_t position
450 debuglog(
"plp_setxattr `%s'", ++path);
453 long psisattr, psidattr;
457 if (flags & XATTR_CREATE)
469 psisattr = psidattr = 0;
471 debuglog(
"attrs set %x delete %x; %s, %s", psisattr, psidattr, oxattr, value);
472 if ((ret =
rfsv_setattr(path, psisattr, psidattr)) != 0)
479 if (flags & XATTR_REPLACE)
489 debuglog(
"plp_listxattr `%s'", ++path);
497 debuglog(
"plp_removexattr `%s'", ++path);
502static int plp_chown(
const char *path, uid_t uid, gid_t gid)
512 debuglog(
"plp_truncate `%s'", ++path);
516static int plp_utimens(
const char *path,
const struct timespec ts[2])
518 debuglog(
"plp_utimens `%s'", ++path);
522static int plp_open(
const char *path,
struct fuse_file_info *fi)
529static int plp_read(
const char *path,
char *buf,
size_t size, off_t offset,
530 struct fuse_file_info *fi)
535 debuglog(
"plp_read `%s' offset %lld size %ld", ++path, offset, size);
536 read =
rfsv_read(buf, (
long)offset, size, path);
537 debuglog(
"read returned %ld", read);
541static int plp_write(
const char *path,
const char *buf,
size_t size,
542 off_t offset,
struct fuse_file_info *fi)
547 debuglog(
"plp_write `%s' offset %lld size %ld", ++path, offset, size);
548 written =
rfsv_write(buf, offset, size, path);
549 debuglog(
"write returned %ld", written);
553static int plp_statfs(
const char *path,
struct statvfs *stbuf)
568 stbuf->f_bavail = stbuf->f_bfree;
572 stbuf->f_ffree = stbuf->f_favail = 0;
576 stbuf->f_namemax = 255;
static int plp_unlink(const char *path)
static int getlinks(const char *path, struct stat *st)
static int plp_link(const char *from, const char *to)
static int plp_utimens(const char *path, const struct timespec ts[2])
void debuglog(const char *fmt,...)
static int plp_removexattr(const char *path, const char *name)
static int plp_mknod(const char *path, mode_t mode, dev_t dev)
static int plp_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi)
static int plp_open(const char *path, struct fuse_file_info *fi)
static int plp_readlink(const char *path, char *buf, size_t size)
static char * dirname(const char *dir)
static int plp_listxattr(const char *path, char *list, size_t size)
static void attr2pattr(long oattr, long nattr, char *oxattr, char *nxattr, long *psisattr, long *psidattr)
static int plp_rename(const char *from, const char *to)
static int plp_mkdir(const char *path, mode_t mode)
static int plp_access(const char *path, int mask)
static int query_devices(void)
static void pattr2attr(long psiattr, long size, long ftime, struct stat *st, char *xattr)
static int plp_rmdir(const char *path)
static void xattr2pattr(long *psisattr, long *psidattr, const char *oxattr, const char *nxattr)
static int plp_setxattr(const char *path, const char *name, const char *value, size_t size, int flags)
static int plp_getattr(const char *path, struct stat *st)
struct fuse_operations plp_oper
static int plp_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi)
static int plp_statfs(const char *path, struct statvfs *stbuf)
static int plp_symlink(const char *from, const char *to)
static int dircount(const char *path, long *count)
static int plp_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi)
static int plp_chown(const char *path, uid_t uid, gid_t gid)
static int plp_chmod(const char *path, mode_t mode)
static int plp_truncate(const char *path, off_t size)
static int plp_getxattr(const char *path, const char *name, char *value, size_t size)
static const char * filname(const char *dir)
static void pattr2xattr(long psiattr, char *xattr)
int rfsv_rmdir(const char *name)
int rfsv_dir(const char *file, dentry **e)
int rfsv_drivelist(int *cnt, device **dlist)
int rfsv_mkdir(const char *file)
int rfsv_getattr(const char *name, long *attr, long *size, long *time)
int rfsv_remove(const char *file)
int rfsv_setmtime(const char *name, long time)
int rfsv_write(const char *buf, long offset, long len, const char *name)
int rfsv_fcreate(long attr, const char *file, uint32_t *handle)
int rfsv_setattr(const char *name, long sattr, long dattr)
int rfsv_fclose(long handle)
int rfsv_rename(const char *oldname, const char *newname)
int rfsv_setsize(const char *name, long size)
int rfsv_read(char *buf, long offset, long len, const char *name)
Description of a Psion-Device.