summaryrefslogtreecommitdiff
path: root/procfs.c
diff options
context:
space:
mode:
authorJeremie Koenig <jk@jk.fr.eu.org>2010-08-19 23:10:11 +0000
committerJeremie Koenig <jk@jk.fr.eu.org>2010-08-30 14:19:08 +0200
commit2c7dcef74c3259d2d5db7a11f5c77d18d3a51e85 (patch)
tree5135e8ce3082dc172cfce4d4b08f31a43f73590f /procfs.c
parentc6c770c33eb0f23e7e8e04976c711653cdf1a41d (diff)
Invent path-based inode numbers
* procfs.h, procfs.c (procfs_make_ino): New function, invents an inode number by hashing the parent's and the name of an entry. (procfs_lookup): Use it to assign an inode number to child nodes at lookup time. * main.c (root_make_node): Assign an arbitrary inode number to the root directory.
Diffstat (limited to 'procfs.c')
-rw-r--r--procfs.c28
1 files changed, 27 insertions, 1 deletions
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;