diff options
author | Justus Winter <4winter@informatik.uni-hamburg.de> | 2014-08-31 14:47:42 +0200 |
---|---|---|
committer | Justus Winter <4winter@informatik.uni-hamburg.de> | 2014-08-31 17:40:46 +0200 |
commit | 334801c52c9844c06eacbe2e3af65852f7412e3c (patch) | |
tree | a17a8e828dcba6e868266a4ed30330b6584243ec /libfshelp | |
parent | c5f866e17c72302d826b885f098b1c07d7abdbc7 (diff) |
hurd: fix semantic of file_get_children
When first introduced as fsys_get_children, it made sense to return
the list of children using paths relative to the root of the
filesystem that was queried. Making the get_children method part of
the fsys protocol was a mistake that has since been corrected in
9366d6b2.
Instead of returning paths relative to the root of the translator,
return paths relative to the path of the receiving node.
This fixes a problem with the mtab translator. Previously, the mtab
translator invoked on a target that was not the root directory of a
translator would compute invalid paths, e.g.:
/hurd/mtab: /any/path/servers/socket/26 No such file or directory
* hurd/fs.defs (file_get_children): Update comment.
* libfshelp/translator-list.c (fshelp_get_active_translators): Add
argument PREFIX. Filter entries not beginning with PREFIX if
non-NULL, and omit PREFIX from the returned paths.
* libfshelp/fshelp.h (fshelp_get_active_translators): Update comment
accordingly. Also clarify that both FILTER and PREFIX can be NULL.
* libdiskfs/file-get-children.c (diskfs_S_file_get_children): Update
comment, pass prefix to fshelp_get_active_translators.
* libnetfs/file-get-children.c (netfs_S_file_get_children): Likewise.
Diffstat (limited to 'libfshelp')
-rw-r--r-- | libfshelp/fshelp.h | 9 | ||||
-rw-r--r-- | libfshelp/translator-list.c | 21 |
2 files changed, 23 insertions, 7 deletions
diff --git a/libfshelp/fshelp.h b/libfshelp/fshelp.h index 5d3a0ceb..1c6f04a2 100644 --- a/libfshelp/fshelp.h +++ b/libfshelp/fshelp.h @@ -61,12 +61,15 @@ fshelp_remove_active_translator (mach_port_t active); included in the list. */ typedef error_t (*fshelp_filter) (const char *path); -/* Records the list of active translators into the argz vector - specified by TRANSLATORS filtered by FILTER. */ +/* Records the list of active translators below PREFIX into the argz + vector specified by TRANSLATORS filtered by FILTER. If PREFIX is + NULL, entries with any prefix are considered. If FILTER is NULL, + no filter is applied. */ error_t fshelp_get_active_translators (char **translators, size_t *translators_len, - fshelp_filter filter); + fshelp_filter filter, + const char *prefix); /* Passive translator linkage */ diff --git a/libfshelp/translator-list.c b/libfshelp/translator-list.c index 3ece7112..be7ce4de 100644 --- a/libfshelp/translator-list.c +++ b/libfshelp/translator-list.c @@ -160,19 +160,32 @@ fshelp_remove_active_translator (mach_port_t active) return err; } -/* Records the list of active translators into the argz vector - specified by TRANSLATORS filtered by FILTER. */ +/* Records the list of active translators below PREFIX into the argz + vector specified by TRANSLATORS filtered by FILTER. If PREFIX is + NULL, entries with any prefix are considered. If FILTER is NULL, + no filter is applied. */ error_t fshelp_get_active_translators (char **translators, size_t *translators_len, - fshelp_filter filter) + fshelp_filter filter, + const char *prefix) { error_t err = 0; pthread_mutex_lock (&translator_ihash_lock); + if (prefix && strlen (prefix) == 0) + prefix = NULL; + HURD_IHASH_ITERATE (&translator_ihash, value) { struct translator *t = value; + + if (prefix != NULL + && (strncmp (t->name, prefix, strlen (prefix)) != 0 + || t->name[strlen (prefix)] != '/')) + /* Skip this entry, as it is not below PREFIX. */ + continue; + if (filter) { char *dir = strdup (t->name); @@ -192,7 +205,7 @@ fshelp_get_active_translators (char **translators, } err = argz_add (translators, translators_len, - t->name); + &t->name[prefix? strlen (prefix) + 1: 0]); if (err) break; } |