/** Create a hard link to a file */ int bb_link(const char *path, const char *newpath) { int retstat = 0; char fpath[PATH_MAX], fnewpath[PATH_MAX]; log_msg("\nbb_link(path=\"%s\", newpath=\"%s\")\n", path, newpath); bb_fullpath(fpath, path); bb_fullpath(fnewpath, newpath); retstat = link(fpath, fnewpath); if (retstat < 0) retstat = bb_error("bb_link link"); return retstat; }
/** Create a file node * * If there is no create() operation, mknod() will be called for * creation of all non-directory, non-symlink nodes. */ int bb_mknod(const char *path, mode_t mode, dev_t dev) { int retstat = 0; char fpath[PATH_MAX]; log_msg("\nbb_mknod(path=\"%s\", mode=0%3o, dev=%lld)\n", path, mode, dev); bb_fullpath(fpath, path); // On Linux this could just be 'mknod(path, mode, rdev)' but this // is more portable if (S_ISREG(mode)) { retstat = open(fpath, O_CREAT | O_EXCL | O_WRONLY, mode); if (retstat < 0) retstat = bb_error("bb_mknod open"); else { retstat = close(retstat); if (retstat < 0) retstat = bb_error("bb_mknod close"); } } else if (S_ISFIFO(mode)) { retstat = mkfifo(fpath, mode); if (retstat < 0) retstat = bb_error("bb_mknod mkfifo"); } else { retstat = mknod(fpath, mode, dev); if (retstat < 0) retstat = bb_error("bb_mknod mknod"); } return retstat; }
// shouldn't that comment be "if" there is no.... ? int bb_mknod(const char *path, mode_t mode, dev_t dev) { int retstat; char fpath[PATH_MAX]; log_msg("\nbb_mknod(path=\"%s\", mode=0%3o, dev=%lld)\n", path, mode, dev); bb_fullpath(fpath, path); // On Linux this could just be 'mknod(path, mode, dev)' but this // tries to be be more portable by honoring the quote in the Linux // mknod man page stating the only portable use of mknod() is to // make a fifo, but saying it should never actually be used for // that. if (S_ISREG(mode)) { retstat = log_syscall("open", open(fpath, O_CREAT | O_EXCL | O_WRONLY, mode), 0); if (retstat >= 0) retstat = log_syscall("close", close(retstat), 0); } else if (S_ISFIFO(mode)) retstat = log_syscall("mkfifo", mkfifo(fpath, mode), 0); else retstat = log_syscall("mknod", mknod(fpath, mode, dev), 0); return retstat; }
/** File open operation * * No creation, or truncation flags (O_CREAT, O_EXCL, O_TRUNC) * will be passed to open(). Open should check if the operation * is permitted for the given flags. Optionally open may also * return an arbitrary filehandle in the fuse_file_info structure, * which will be passed to all file operations. * * path = path to file, relative to rootdir * fi = contains file information for the file to be opened * struct fuse_file_info defined in Rootdir/fuse-2.9.2/include/fuse_common.h */ int bb_open(const char *path, struct fuse_file_info *fi) { int retstat = 0; int fd; char fpath[PATH_MAX]; log_msg("\nbb_open(path\"%s\", fi=0x%08x)\n", path, fi); bb_fullpath(fpath, path); // path is relative to rootdir, must change it // to a full path fd = open(fpath, fi->flags); // uses system open to open or return an error // returns a file despcriptor (> 0) on success if (fd < 0) retstat = bb_error("bb_open open"); fi->fh = fd; // sets the handle field of fi log_fi(fi); return retstat; // This should be 0 - but we would like to return a file // descriptor. Fuse automatically chooses a file descriptor // and returns that one (may be different from open's ret) // fi->fh is different from descriptor returned as retstat // Calls to read, say, include fi, hence fi->fh // But programs think they are talking to retstat // When program does a read, the call is intercepted by // the kernel and redirected to a bb_read where fi->fh // is used as the handle }
// both path and newpath are fs-relative int bb_rename(const char *path, const char *newpath) { int retstat = 0; char fpath[PATH_MAX]; char fnewpath[PATH_MAX]; log_msg("\nbb_rename(fpath=\"%s\", newpath=\"%s\")\n", path, newpath); bb_fullpath(fpath, path); bb_fullpath(fnewpath, newpath); retstat = rename(fpath, fnewpath); if (retstat < 0) retstat = bb_error("bb_rename rename"); return retstat; }
/** Remove a directory */ int bb_rmdir(const char *path) { int retstat = 0; char fpath[PATH_MAX]; bb_fullpath(fpath, path); retstat = rmdir(fpath); return retstat; }
/** Remove a file */ int bb_unlink(const char *path) { int retstat = 0; char fpath[PATH_MAX]; bb_fullpath(fpath, path); retstat = unlink(fpath); return retstat; }
/** Remove extended attributes */ int bb_removexattr(const char *path, const char *name) { char fpath[PATH_MAX]; log_msg("\nbb_removexattr(path=\"%s\", name=\"%s\")\n", path, name); bb_fullpath(fpath, path); return log_syscall("lremovexattr", lremovexattr(fpath, name), 0); }
/** Remove extended attributes */ int bb_removexattr(const char *path, const char *name) { int retstat = 0; char fpath[PATH_MAX]; bb_fullpath(fpath, path); retstat = lremovexattr(fpath, name); return retstat; }
/* note -- I'll want to change this as soon as 2.6 is in debian testing */ int bb_utime(const char *path, struct utimbuf *ubuf) { int retstat = 0; char fpath[PATH_MAX]; bb_fullpath(fpath, path); retstat = utime(fpath, ubuf); return retstat; }
/** Change the permission bits of a file */ int bb_chmod(const char *path, mode_t mode) { char fpath[PATH_MAX]; log_msg("\nbb_chmod(fpath=\"%s\", mode=0%03o)\n", path, mode); bb_fullpath(fpath, path); return log_syscall("chmod", chmod(fpath, mode), 0); }
// The parameters here are a little bit confusing, but do correspond // to the symlink() system call. The 'path' is where the link points, // while the 'link' is the link itself. So we need to leave the path // unaltered, but insert the link into the mounted directory. int bb_symlink(const char *path, const char *link) { char flink[PATH_MAX]; log_msg("\nbb_symlink(path=\"%s\", link=\"%s\")\n", path, link); bb_fullpath(flink, link); return log_syscall("symlink", symlink(path, flink), 0); }
/** Remove a directory */ int bb_rmdir(const char *path) { char fpath[PATH_MAX]; log_msg("bb_rmdir(path=\"%s\")\n", path); bb_fullpath(fpath, path); return log_syscall("rmdir", rmdir(fpath), 0); }
/** Remove a file */ int bb_unlink(const char *path) { char fpath[PATH_MAX]; log_msg("bb_unlink(path=\"%s\")\n", path); bb_fullpath(fpath, path); return log_syscall("unlink", unlink(fpath), 0); }
/** Create a directory */ int bb_mkdir(const char *path, mode_t mode) { char fpath[PATH_MAX]; log_msg("\nbb_mkdir(path=\"%s\", mode=0%3o)\n", path, mode); bb_fullpath(fpath, path); return log_syscall("mkdir", mkdir(fpath, mode), 0); }
/** Change the permission bits of a file */ int bb_chmod(const char *path, mode_t mode) { int retstat = 0; char fpath[PATH_MAX]; bb_fullpath(fpath, path); retstat = chmod(fpath, mode); return retstat; }
/** Change the size of a file */ int bb_truncate(const char *path, off_t newsize) { int retstat = 0; char fpath[PATH_MAX]; bb_fullpath(fpath, path); retstat = truncate(fpath, newsize); return retstat; }
/** Change the size of a file */ int bb_truncate(const char *path, off_t newsize) { char fpath[PATH_MAX]; log_msg("\nbb_truncate(path=\"%s\", newsize=%lld)\n", path, newsize); bb_fullpath(fpath, path); return log_syscall("truncate", truncate(fpath, newsize), 0); }
/** Set extended attributes */ int bb_setxattr(const char *path, const char *name, const char *value, size_t size, int flags) { int retstat = 0; char fpath[PATH_MAX]; bb_fullpath(fpath, path); retstat = lsetxattr(fpath, name, value, size, flags); return retstat; }
/* note -- I'll want to change this as soon as 2.6 is in debian testing */ int bb_utime(const char *path, struct utimbuf *ubuf) { char fpath[PATH_MAX]; log_msg("\nbb_utime(path=\"%s\", ubuf=0x%08x)\n", path, ubuf); bb_fullpath(fpath, path); return log_syscall("utime", utime(fpath, ubuf), 0); }
/** Get file attributes. * * Similar to stat(). The 'st_dev' and 'st_blksize' fields are * ignored. The 'st_ino' field is ignored except if the 'use_ino' * mount option is given. */ int bb_getattr(const char *path, struct stat *statbuf) { int retstat = 0; char fpath[PATH_MAX]; bb_fullpath(fpath, path); retstat = lstat(fpath, statbuf); return retstat; }
/** Set extended attributes */ int bb_setxattr(const char *path, const char *name, const char *value, size_t size, int flags) { char fpath[PATH_MAX]; log_msg("\nbb_setxattr(path=\"%s\", name=\"%s\", value=\"%s\", size=%d, flags=0x%08x)\n", path, name, value, size, flags); bb_fullpath(fpath, path); return log_syscall("lsetxattr", lsetxattr(fpath, name, value, size, flags), 0); }
// The parameters here are a little bit confusing, but do correspond // to the symlink() system call. The 'path' is where the link points, // while the 'link' is the link itself. So we need to leave the path // unaltered, but insert the link into the mounted directory. int bb_symlink(const char *path, const char *link) { int retstat = 0; char flink[PATH_MAX]; bb_fullpath(flink, link); retstat = symlink(path, flink); return retstat; }
/** Remove extended attributes */ int bb_removexattr(const char *path, const char *name) { int retstat = 0; char fpath[PATH_MAX]; log_msg("\nbb_removexattr(path=\"%s\", name=\"%s\")\n", path, name); bb_fullpath(fpath, path); retstat = lremovexattr(fpath, name); if (retstat < 0) retstat = bb_error("bb_removexattr lrmovexattr"); return retstat; }
/** * Check file access permissions * * This will be called for the access() system call. If the * 'default_permissions' mount option is given, this method is not * called. * * This method is not called under Linux kernel versions 2.4.x * * Introduced in version 2.5 */ int bb_access(const char *path, int mask) { int retstat = 0; char fpath[PATH_MAX]; log_msg("\nbb_access(path=\"%s\", mask=0%o)\n", path, mask); bb_fullpath(fpath, path); retstat = access(fpath, mask); if (retstat < 0) retstat = bb_error("bb_access access"); return retstat; }
/** Set extended attributes */ int bb_setxattr(const char *path, const char *name, const char *value, size_t size, int flags) { int retstat = 0; char fpath[PATH_MAX]; log_msg("\nbb_setxattr(path=\"%s\", name=\"%s\", value=\"%s\", size=%d, flags=0x%08x)\n", path, name, value, size, flags); bb_fullpath(fpath, path); retstat = lsetxattr(fpath, name, value, size, flags); if (retstat < 0) retstat = bb_error("bb_setxattr lsetxattr"); return retstat; }
/* note -- I'll want to change this as soon as 2.6 is in debian testing */ int bb_utime(const char *path, struct utimbuf *ubuf) { int retstat = 0; char fpath[PATH_MAX]; log_msg("\nbb_utime(path=\"%s\", ubuf=0x%08x)\n", path, ubuf); bb_fullpath(fpath, path); retstat = utime(fpath, ubuf); if (retstat < 0) retstat = bb_error("bb_utime utime"); return retstat; }
/** Change the size of a file */ int bb_truncate(const char *path, off_t newsize) { int retstat = 0; char fpath[PATH_MAX]; log_msg("\nbb_truncate(path=\"%s\", newsize=%lld)\n", path, newsize); bb_fullpath(fpath, path); retstat = truncate(fpath, newsize); if (retstat < 0) bb_error("bb_truncate truncate"); return retstat; }
/** Change the owner and group of a file */ int bb_chown(const char *path, uid_t uid, gid_t gid) { int retstat = 0; char fpath[PATH_MAX]; log_msg("\nbb_chown(path=\"%s\", uid=%d, gid=%d)\n", path, uid, gid); bb_fullpath(fpath, path); retstat = chown(fpath, uid, gid); if (retstat < 0) retstat = bb_error("bb_chown chown"); return retstat; }
/** Change the permission bits of a file */ int bb_chmod(const char *path, mode_t mode) { int retstat = 0; char fpath[PATH_MAX]; log_msg("\nbb_chmod(fpath=\"%s\", mode=0%03o)\n", path, mode); bb_fullpath(fpath, path); retstat = chmod(fpath, mode); if (retstat < 0) retstat = bb_error("bb_chmod chmod"); return retstat; }