Hi Daniel,<br><br>right now I do not have any new tasks so I can take a look your patches and... they won't to apply (patches from 2 to 4).<br>Can you send me your current procfs.c single file with patches added?<br><br>
Thanks<br><br>-- <br>K<br><br><div class="gmail_quote">2009/9/4 Daniel Lezcano <span dir="ltr"><<a href="mailto:daniel.lezcano@free.fr">daniel.lezcano@free.fr</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
This patch makes possible to mount the fuse-procfs on top of /proc<br>
and display the content of /proc via fuse.<br>
<br>
Signed-off-by: Daniel Lezcano <<a href="mailto:daniel.lezcano@free.fr">daniel.lezcano@free.fr</a>><br>
---<br>
 procfs.c |  246 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>
 1 file changed, 246 insertions(+)<br>
<br>
Index: lxcfs/procfs.c<br>
===================================================================<br>
--- /dev/null<br>
+++ lxcfs/procfs.c<br>
@@ -0,0 +1,246 @@<br>
+<br>
+#include <fuse.h><br>
+<br>
+#include <stdio.h><br>
+#include <stdlib.h><br>
+#include <string.h><br>
+#include <libgen.h><br>
+#include <errno.h><br>
+#include <dirent.h><br>
+#include <mntent.h><br>
+#include <limits.h><br>
+#include <fcntl.h><br>
+#include <sys/types.h><br>
+#include <sys/stat.h><br>
+#include <sys/param.h><br>
+<br>
+enum {<br>
+       PROCFS_PROXY,<br>
+};<br>
+<br>
+struct procfs_info {<br>
+       DIR *procdir;<br>
+       DIR *subdir;<br>
+};<br>
+<br>
+struct proxy_file {<br>
+       int fd;<br>
+};<br>
+<br>
+struct procfs_file {<br>
+       int type;<br>
+       union {<br>
+               struct proxy_file proxy;<br>
+       } file;<br>
+};<br>
+<br>
+static int procfs_readlink(const char *path, char *buf, size_t bufsiz)<br>
+{<br>
+       struct fuse_context *context = fuse_get_context();<br>
+       struct procfs_info *fsinfo = context->private_data;<br>
+       char *bname = strchr(path, '/');<br>
+       int ret;<br>
+<br>
+       if (strcmp(path, "/"))<br>
+               bname += 1;<br>
+<br>
+       ret = readlinkat(dirfd(fsinfo->procdir), bname, buf, bufsiz);<br>
+       if (ret < 0)<br>
+               return -errno;<br>
+<br>
+       buf[ret] = '\0';<br>
+<br>
+       return 0;<br>
+}<br>
+<br>
+static int procfs_getattr(const char *path, struct stat *stbuf)<br>
+{<br>
+       struct fuse_context *context = fuse_get_context();<br>
+       struct procfs_info *fsinfo = context->private_data;<br>
+       char *bname = strchr(path, '/');<br>
+<br>
+       if (strcmp(path, "/"))<br>
+               bname += 1;<br>
+<br>
+       if (fstatat(dirfd(fsinfo->procdir), bname, stbuf, AT_SYMLINK_NOFOLLOW))<br>
+               return -errno;<br>
+<br>
+       return 0;<br>
+}<br>
+<br>
+static int procfs_open(const char *path, struct fuse_file_info *fi)<br>
+{<br>
+       struct fuse_context *context = fuse_get_context();<br>
+       struct procfs_info *fsinfo = context->private_data;<br>
+       char *bname = strchr(path, '/');<br>
+       struct procfs_file *pfile;<br>
+<br>
+       if (strcmp(path, "/"))<br>
+               bname += 1;<br>
+<br>
+       pfile = malloc(sizeof(*pfile));<br>
+       if (!pfile)<br>
+               return -ENOMEM;<br>
+<br>
+       pfile->type = PROCFS_PROXY;<br>
+       pfile->file.proxy.fd = openat(dirfd(fsinfo->procdir), bname, fi->flags);<br>
+       if (pfile->file.proxy.fd < 0) {<br>
+               free(pfile);<br>
+               return -errno;<br>
+       }<br>
+<br>
+       fi->fh = (typeof(fi->fh))pfile;<br>
+<br>
+       return 0;<br>
+}<br>
+<br>
+static int procfs_read(const char *path, char *buf, size_t size,<br>
+                     off_t offset, struct fuse_file_info *fi)<br>
+{<br>
+       int ret;<br>
+       struct procfs_file *pfile = (typeof(pfile))fi->fh;;<br>
+<br>
+       switch (pfile->type) {<br>
+<br>
+       case PROCFS_PROXY:<br>
+               ret = read(pfile->file.proxy.fd, buf, size);<br>
+               if (ret < 0)<br>
+                       return -errno;<br>
+               break;<br>
+       }<br>
+<br>
+       return ret;<br>
+}<br>
+<br>
+static int procfs_write(const char *path, const char *buf, size_t size,<br>
+                      off_t offset, struct fuse_file_info *fi)<br>
+{<br>
+       int ret;<br>
+       struct procfs_file *pfile = (typeof(pfile))fi->fh;;<br>
+<br>
+       switch (pfile->type) {<br>
+<br>
+       case PROCFS_PROXY:<br>
+               ret = write(pfile->file.proxy.fd, buf, size);<br>
+               if (ret < 0)<br>
+                       return -errno;<br>
+               break;<br>
+       }<br>
+<br>
+       return ret;<br>
+}<br>
+<br>
+static int procfs_release(const char *path, struct fuse_file_info *fi)<br>
+{<br>
+       struct procfs_file *pfile = (typeof(pfile))fi->fh;;<br>
+<br>
+       switch (pfile->type) {<br>
+<br>
+       case PROCFS_PROXY:<br>
+               if (close(pfile->file.proxy.fd))<br>
+                       return -errno;<br>
+               break;<br>
+       }<br>
+<br>
+       return 0;<br>
+}<br>
+<br>
+static int procfs_opendir(const char *path, struct fuse_file_info *fi)<br>
+{<br>
+       struct fuse_context *context = fuse_get_context();<br>
+       struct procfs_info *fsinfo = context->private_data;<br>
+       char *bname = strchr(path, '/');<br>
+       int fd;<br>
+<br>
+       if (!strcmp(path, "/")) {<br>
+               fsinfo->subdir = fsinfo->procdir;<br>
+               return 0;<br>
+       }<br>
+<br>
+       fd = openat(dirfd(fsinfo->procdir), bname + 1, O_DIRECTORY);<br>
+       if (fd < 0)<br>
+               return -errno;<br>
+<br>
+       fsinfo->subdir = fdopendir(fd);<br>
+<br>
+       return 0;<br>
+}<br>
+<br>
+static int procfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,<br>
+                        off_t offset, struct fuse_file_info *fi)<br>
+{<br>
+       struct fuse_context *context = fuse_get_context();<br>
+       struct procfs_info *fsinfo = context->private_data;<br>
+        struct dirent dirent, *direntp;<br>
+<br>
+       if (!offset)<br>
+               rewinddir(fsinfo->subdir);<br>
+<br>
+        while (!readdir_r(fsinfo->subdir, &dirent, &direntp) && direntp)<br>
+               if (filler(buf, direntp->d_name, NULL, offset++))<br>
+                       break;<br>
+<br>
+       return 0;<br>
+}<br>
+<br>
+static int procfs_releasedir(const char *path, struct fuse_file_info *fi)<br>
+{<br>
+       struct fuse_context *context = fuse_get_context();<br>
+       struct procfs_info *fsinfo = context->private_data;<br>
+       DIR *subdir = fsinfo->subdir;<br>
+<br>
+       fsinfo->subdir = NULL;<br>
+       if (subdir && subdir != fsinfo->procdir)<br>
+               closedir(subdir);<br>
+<br>
+       return 0;<br>
+}<br>
+<br>
+static void *procfs_init(struct fuse_conn_info *conn)<br>
+{<br>
+       struct procfs_info *fsinfo;<br>
+<br>
+       fsinfo = malloc(sizeof(*fsinfo));<br>
+       if (!fsinfo)<br>
+               return NULL;<br>
+<br>
+       fsinfo->procdir = opendir("/proc");<br>
+       if (!fsinfo->procdir)<br>
+               goto out_free_fsinfo;<br>
+<br>
+       fsinfo->subdir = NULL;<br>
+out:<br>
+       return fsinfo;<br>
+<br>
+out_free_fsinfo:<br>
+       free(fsinfo);<br>
+       fsinfo = NULL;<br>
+       goto out;<br>
+}<br>
+<br>
+static void procfs_destroy(void *private_data)<br>
+{<br>
+       struct procfs_info *fsinfo = private_data;<br>
+<br>
+       closedir(fsinfo->procdir);<br>
+       free(fsinfo);<br>
+}<br>
+<br>
+static struct fuse_operations procfs_ops = {<br>
+       .readlink   = procfs_readlink,<br>
+       .getattr    = procfs_getattr,<br>
+       .open       = procfs_open,<br>
+       .read       = procfs_read,<br>
+       .write      = procfs_write,<br>
+       .opendir    = procfs_opendir,<br>
+       .releasedir = procfs_releasedir,<br>
+       .readdir    = procfs_readdir,<br>
+       .release    = procfs_release,<br>
+       .init       = procfs_init,<br>
+       .destroy    = procfs_destroy,<br>
+};<br>
+<br>
+int main(int argc, char *argv[])<br>
+{<br>
+       return fuse_main(argc, argv, &procfs_ops, NULL);<br>
+}<br>
<br>
</blockquote></div><br>