summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c4
-rw-r--r--procfs.c28
-rw-r--r--procfs.h5
3 files changed, 36 insertions, 1 deletions
diff --git a/main.c b/main.c
index e08bbdb..1560281 100644
--- a/main.c
+++ b/main.c
@@ -42,6 +42,10 @@ root_make_node (struct node **np)
if (! *np)
return ENOMEM;
+ /* Since this one is not created through proc_lookup(), we have to affect an
+ inode number to it. */
+ (*np)->nn_stat.st_ino = * (uint32_t *) "PROC";
+
return 0;
}
diff --git a/procfs.c b/procfs.c
index c5f1949..4cce46b 100644
--- a/procfs.c
+++ b/procfs.c
@@ -67,6 +67,29 @@ fail:
return NULL;
}
+/* FIXME: possibly not the fastest hash function... */
+ino64_t
+procfs_make_ino (struct node *np, const char *filename)
+{
+ unsigned short x[3];
+
+ if (! strcmp (filename, "."))
+ return np->nn_stat.st_ino;
+ if (! strcmp (filename, ".."))
+ return np->nn->parent ? np->nn->parent->nn_stat.st_ino : /* FIXME: */ 42;
+
+ assert (sizeof np->nn_stat.st_ino > sizeof x);
+ memcpy (x, &np->nn_stat.st_ino, sizeof x);
+
+ while (*filename)
+ {
+ x[0] ^= *(filename++);
+ jrand48 (x);
+ }
+
+ return jrand48 (x);
+}
+
error_t procfs_get_contents (struct node *np, void **data, size_t *data_len)
{
if (np->nn->ops->enable_refresh_hack_and_break_readdir && np->nn->contents)
@@ -116,7 +139,10 @@ error_t procfs_lookup (struct node *np, const char *name, struct node **npp)
{
err = np->nn->ops->lookup (np->nn->hook, name, npp);
if (! err)
- netfs_nref ((*npp)->nn->parent = np);
+ {
+ (*npp)->nn_stat.st_ino = procfs_make_ino (np, name);
+ netfs_nref ((*npp)->nn->parent = np);
+ }
}
return err;
diff --git a/procfs.h b/procfs.h
index 42eed0e..4c9d828 100644
--- a/procfs.h
+++ b/procfs.h
@@ -51,6 +51,11 @@ struct node *procfs_make_node (const struct procfs_node_ops *ops, void *hook);
/* Interface for the libnetfs side. */
+/* Get the inode number which will be given to a child of NP named FILENAME.
+ This allows us to retreive them for readdir() without creating the
+ corresponding child nodes. */
+ino64_t procfs_make_ino (struct node *np, const char *filename);
+
error_t procfs_get_contents (struct node *np, void **data, size_t *data_len);
error_t procfs_lookup (struct node *np, const char *name, struct node **npp);
void procfs_cleanup (struct node *np);