From c56cf579b7d7b78d26772331efbf099b3e53c456 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Wed, 18 Nov 2020 01:08:14 +0100 Subject: console-client: Fix listing nodes * console-client/trans.c (netfs_get_dirents): Fix counting the start node. Return 0 when there are no entries left, instead of trying to mmap zero bytes. (console_create_consnode): Set inode number, other entries get ignored by glibc's readdir(). --- console-client/trans.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'console-client/trans.c') diff --git a/console-client/trans.c b/console-client/trans.c index a636b3f5..0285a234 100644 --- a/console-client/trans.c +++ b/console-client/trans.c @@ -698,8 +698,8 @@ netfs_get_dirents (struct iouser *cred, struct node *dir, for (first_node = node_list, count = 2; first_node && first_entry > count; - first_node = first_node->next); - count++; + first_node = first_node->next) + count++; count = 0; @@ -711,8 +711,14 @@ netfs_get_dirents (struct iouser *cred, struct node *dir, for (cn = first_node; cn; cn = cn->next) bump_size (cn->name); - - + + if (size == 0) + { + *data_len = size; + *data_entries = count; + return 0; + } + /* Allocate it. */ *data = mmap (0, size, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0); err = ((void *) *data == (void *) -1) ? errno : 0; @@ -798,6 +804,9 @@ console_client_translator (void *unused) error_t console_create_consnode (const char *name, consnode_t *cn) { + /* inode number, 2 is reserved for the root */ + static int cn_id = 3; + *cn = malloc (sizeof (struct consnode)); if (!*cn) return ENOMEM; @@ -809,6 +818,7 @@ console_create_consnode (const char *name, consnode_t *cn) return ENOMEM; } + (*cn)->id = cn_id++; (*cn)->readlink = NULL; (*cn)->mksymlink = NULL; -- cgit v1.2.3