|
|
beb904 |
autofs-5.1.7 - add mapent tree implementation
|
|
|
beb904 |
|
|
|
beb904 |
From: Ian Kent <raven@themaw.net>
|
|
|
beb904 |
|
|
|
beb904 |
Add a struct mapent basic tree implementation.
|
|
|
beb904 |
|
|
|
beb904 |
Signed-off-by: Ian Kent <raven@themaw.net>
|
|
|
beb904 |
---
|
|
|
beb904 |
CHANGELOG | 1 +
|
|
|
beb904 |
include/automount.h | 4 ++++
|
|
|
beb904 |
include/mounts.h | 8 ++++++++
|
|
|
beb904 |
lib/cache.c | 9 ++++++++-
|
|
|
beb904 |
lib/mounts.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
beb904 |
5 files changed, 71 insertions(+), 1 deletion(-)
|
|
|
beb904 |
|
|
|
beb904 |
--- autofs-5.1.4.orig/CHANGELOG
|
|
|
beb904 |
+++ autofs-5.1.4/CHANGELOG
|
|
|
beb904 |
@@ -32,6 +32,7 @@
|
|
|
beb904 |
- remove unused functions cache_dump_multi() and cache_dump_cache().
|
|
|
beb904 |
- add a len field to struct autofs_point.
|
|
|
beb904 |
- make tree implementation data independent.
|
|
|
beb904 |
+- add mapent tree implementation.
|
|
|
beb904 |
|
|
|
beb904 |
xx/xx/2018 autofs-5.1.5
|
|
|
beb904 |
- fix flag file permission.
|
|
|
beb904 |
--- autofs-5.1.4.orig/include/automount.h
|
|
|
beb904 |
+++ autofs-5.1.4/include/automount.h
|
|
|
beb904 |
@@ -166,10 +166,14 @@ struct mapent {
|
|
|
beb904 |
struct mapent_cache *mc;
|
|
|
beb904 |
struct map_source *source;
|
|
|
beb904 |
/* Need to know owner if we're a multi-mount */
|
|
|
beb904 |
+ struct tree_node *mm_root;
|
|
|
beb904 |
+ struct tree_node *mm_parent;
|
|
|
beb904 |
+ struct tree_node node;
|
|
|
beb904 |
struct mapent *multi;
|
|
|
beb904 |
/* Parent nesting point within multi-mount */
|
|
|
beb904 |
struct mapent *parent;
|
|
|
beb904 |
char *key;
|
|
|
beb904 |
+ size_t len;
|
|
|
beb904 |
char *mapent;
|
|
|
beb904 |
struct stack *stack;
|
|
|
beb904 |
time_t age;
|
|
|
beb904 |
--- autofs-5.1.4.orig/include/mounts.h
|
|
|
beb904 |
+++ autofs-5.1.4/include/mounts.h
|
|
|
beb904 |
@@ -66,6 +66,13 @@ struct tree_node {
|
|
|
beb904 |
#define MNT_LIST(n) (container_of(n, struct mnt_list, node))
|
|
|
beb904 |
#define MNT_LIST_NODE(ptr) ((struct tree_node *) &((struct mnt_list *) ptr)->node)
|
|
|
beb904 |
|
|
|
beb904 |
+#define MAPENT(n) (container_of(n, struct mapent, node))
|
|
|
beb904 |
+#define MAPENT_NODE(p) ((struct tree_node *) &((struct mapent *) p)->node)
|
|
|
beb904 |
+#define MAPENT_ROOT(p) ((struct tree_node *) ((struct mapent *) p)->mm_root)
|
|
|
beb904 |
+#define MAPENT_PARENT(p) ((struct tree_node *) ((struct mapent *) p)->mm_parent)
|
|
|
beb904 |
+#define MAPENT_SET_ROOT(p, r) { (((struct mapent *) p)->mm_root = (struct tree_node *) r); }
|
|
|
beb904 |
+#define MAPENT_SET_PARENT(p, n) { (((struct mapent *) p)->mm_parent = (struct tree_node *) n); }
|
|
|
beb904 |
+
|
|
|
beb904 |
typedef struct tree_node *(*tree_new_t) (void *ptr);
|
|
|
beb904 |
typedef int (*tree_cmp_t) (struct tree_node *n, void *ptr);
|
|
|
beb904 |
typedef void (*tree_free_t) (struct tree_node *n);
|
|
|
beb904 |
@@ -161,6 +168,7 @@ unsigned int mnts_has_mounted_mounts(str
|
|
|
beb904 |
void mnts_get_expire_list(struct list_head *mnts, struct autofs_point *ap);
|
|
|
beb904 |
void mnts_put_expire_list(struct list_head *mnts);
|
|
|
beb904 |
void mnts_set_mounted_mount(struct autofs_point *ap, const char *name, unsigned int flags);
|
|
|
beb904 |
+struct tree_node *tree_mapent_root(struct mapent *me);
|
|
|
beb904 |
int unlink_mount_tree(struct autofs_point *ap, const char *mp);
|
|
|
beb904 |
void free_mnt_list(struct mnt_list *list);
|
|
|
beb904 |
int is_mounted(const char *mp, unsigned int type);
|
|
|
beb904 |
--- autofs-5.1.4.orig/lib/cache.c
|
|
|
beb904 |
+++ autofs-5.1.4/lib/cache.c
|
|
|
beb904 |
@@ -546,17 +546,21 @@ int cache_add(struct mapent_cache *mc, s
|
|
|
beb904 |
struct mapent *me, *existing = NULL;
|
|
|
beb904 |
char *pkey, *pent;
|
|
|
beb904 |
u_int32_t hashval = hash(key, mc->size);
|
|
|
beb904 |
+ size_t len;
|
|
|
beb904 |
|
|
|
beb904 |
me = (struct mapent *) malloc(sizeof(struct mapent));
|
|
|
beb904 |
if (!me)
|
|
|
beb904 |
return CHE_FAIL;
|
|
|
beb904 |
|
|
|
beb904 |
- pkey = malloc(strlen(key) + 1);
|
|
|
beb904 |
+ len = strlen(key);
|
|
|
beb904 |
+
|
|
|
beb904 |
+ pkey = malloc(len + 1);
|
|
|
beb904 |
if (!pkey) {
|
|
|
beb904 |
free(me);
|
|
|
beb904 |
return CHE_FAIL;
|
|
|
beb904 |
}
|
|
|
beb904 |
me->key = strcpy(pkey, key);
|
|
|
beb904 |
+ me->len = len;
|
|
|
beb904 |
|
|
|
beb904 |
if (mapent) {
|
|
|
beb904 |
pent = malloc(strlen(mapent) + 1);
|
|
|
beb904 |
@@ -575,6 +579,9 @@ int cache_add(struct mapent_cache *mc, s
|
|
|
beb904 |
me->status = 0;
|
|
|
beb904 |
me->mc = mc;
|
|
|
beb904 |
me->source = ms;
|
|
|
beb904 |
+ me->mm_root = NULL;
|
|
|
beb904 |
+ me->mm_parent = NULL;
|
|
|
beb904 |
+ INIT_TREE_NODE(&me->node);
|
|
|
beb904 |
INIT_LIST_HEAD(&me->ino_index);
|
|
|
beb904 |
INIT_LIST_HEAD(&me->multi_list);
|
|
|
beb904 |
me->multi = NULL;
|
|
|
beb904 |
--- autofs-5.1.4.orig/lib/mounts.c
|
|
|
beb904 |
+++ autofs-5.1.4/lib/mounts.c
|
|
|
beb904 |
@@ -79,6 +79,17 @@ static struct tree_ops mnt_ops = {
|
|
|
beb904 |
};
|
|
|
beb904 |
static struct tree_ops *tree_mnt_ops = &mnt_ops;
|
|
|
beb904 |
|
|
|
beb904 |
+static struct tree_node *tree_mapent_new(void *ptr);
|
|
|
beb904 |
+static int tree_mapent_cmp(struct tree_node *n, void *ptr);
|
|
|
beb904 |
+static void tree_mapent_free(struct tree_node *n);
|
|
|
beb904 |
+
|
|
|
beb904 |
+static struct tree_ops mapent_ops = {
|
|
|
beb904 |
+ .new = tree_mapent_new,
|
|
|
beb904 |
+ .cmp = tree_mapent_cmp,
|
|
|
beb904 |
+ .free = tree_mapent_free,
|
|
|
beb904 |
+};
|
|
|
beb904 |
+static struct tree_ops *tree_mapent_ops = &mapent_ops;
|
|
|
beb904 |
+
|
|
|
beb904 |
unsigned int linux_version_code(void)
|
|
|
beb904 |
{
|
|
|
beb904 |
struct utsname my_utsname;
|
|
|
beb904 |
@@ -1431,6 +1442,45 @@ void mnts_put_expire_list(struct list_he
|
|
|
beb904 |
mnts_hash_mutex_unlock();
|
|
|
beb904 |
}
|
|
|
beb904 |
|
|
|
beb904 |
+struct tree_node *tree_mapent_root(struct mapent *me)
|
|
|
beb904 |
+{
|
|
|
beb904 |
+ return tree_root(tree_mapent_ops, me);
|
|
|
beb904 |
+}
|
|
|
beb904 |
+
|
|
|
beb904 |
+static struct tree_node *tree_mapent_new(void *ptr)
|
|
|
beb904 |
+{
|
|
|
beb904 |
+ struct tree_node *n = MAPENT_NODE(ptr);
|
|
|
beb904 |
+
|
|
|
beb904 |
+ n->ops = tree_mapent_ops;
|
|
|
beb904 |
+ n->left = NULL;
|
|
|
beb904 |
+ n->right = NULL;
|
|
|
beb904 |
+
|
|
|
beb904 |
+ return n;
|
|
|
beb904 |
+}
|
|
|
beb904 |
+
|
|
|
beb904 |
+static int tree_mapent_cmp(struct tree_node *n, void *ptr)
|
|
|
beb904 |
+{
|
|
|
beb904 |
+ struct mapent *n_me = MAPENT(n);
|
|
|
beb904 |
+ size_t n_me_len = n_me->len;
|
|
|
beb904 |
+ struct mapent *me = ptr;
|
|
|
beb904 |
+ size_t me_len = me->len;
|
|
|
beb904 |
+
|
|
|
beb904 |
+ if (strncmp(me->key, n_me->key, n_me_len) == 0) {
|
|
|
beb904 |
+ if (me_len < n_me_len)
|
|
|
beb904 |
+ return -1;
|
|
|
beb904 |
+ else if (me_len > n_me_len)
|
|
|
beb904 |
+ return 1;
|
|
|
beb904 |
+ }
|
|
|
beb904 |
+ return strcmp(me->key, n_me->key);
|
|
|
beb904 |
+}
|
|
|
beb904 |
+
|
|
|
beb904 |
+static void tree_mapent_free(struct tree_node *n)
|
|
|
beb904 |
+{
|
|
|
beb904 |
+ n->ops = NULL;
|
|
|
beb904 |
+ n->left = NULL;
|
|
|
beb904 |
+ n->right = NULL;
|
|
|
beb904 |
+}
|
|
|
beb904 |
+
|
|
|
beb904 |
/* From glibc decode_name() */
|
|
|
beb904 |
/* Since the values in a line are separated by spaces, a name cannot
|
|
|
beb904 |
* contain a space. Therefore some programs encode spaces in names
|