Hello, dnie...@gmail.com, le lun. 20 janv. 2025 23:47:58 +0000, a ecrit: > From: Diego Nieto Cid <dnie...@gmail.com> > > Thanks for the pointer Samuel. I managed to call procfs_lookup > and extract from the node stat structure its type. > > It mostly works except for the ".." and "self" entries: > > ./test-proc//..: d_type: 0 > ./test-proc//self: d_type: 0 > > Well "self" is probably a symlink or something similar. And ".." > probably comes from the parent translator (ext2fs), I'm not sure. > > Also, I noticed procfs_lookup does a netfs_nref call for the returned > node. So, I called netfs_nput after extracting its type. However, I > don't think I got the locking correctly.
It seems odd indeed. Actually, looking more into np->nn->ops->lookup, it allocates a new node, taking locks etc. That becomes actually quite heavy. I'm now thinking that perhaps best would be to make libgtop use lstat as readdir says. Sorry for the back&forth, we couldn't know before trying. Samuel > That are all the comments for version 2 of the patch. > > Regards, > Diego > > > -- >8 -- >8 -- >8 -- > > --- > procfs/netfs.c | 17 +++++++++++++---- > 1 file changed, 13 insertions(+), 4 deletions(-) > > diff --git a/procfs/netfs.c b/procfs/netfs.c > index 4ed5eab6..83db7517 100644 > --- a/procfs/netfs.c > +++ b/procfs/netfs.c > @@ -121,7 +121,7 @@ error_t netfs_attempt_readlink (struct iouser *user, > struct node *np, > DATA (if not NULL), write the number of entries processed in *AMT and > return the required/used space in DATACNT. */ > static int putentries (char *contents, size_t contents_len, int nentries, > - char *data, mach_msg_type_number_t *datacnt) > + char *data, mach_msg_type_number_t *datacnt, struct node > *dir) > { > int align = __alignof (struct dirent); > int i; > @@ -138,11 +138,20 @@ static int putentries (char *contents, size_t > contents_len, int nentries, > > if (data) > { > + error_t err; > + struct node *np; > struct dirent *d = (struct dirent *) (data + *datacnt); > d->d_fileno = 42; /* XXX */ > d->d_namlen = namlen; > d->d_reclen = reclen; > - d->d_type = DT_UNKNOWN; > + err = procfs_lookup(dir, contents, &np); > + if (err) > + d->d_type = DT_UNKNOWN; > + else > + { > + d->d_type = (np->nn_stat.st_mode & S_IFMT) == S_IFDIR ? DT_DIR > : DT_UNKNOWN; > + netfs_nput(np); > + } > memcpy (d->d_name, contents, namlen + 1); > if (pad) > memset(d->d_name + namlen + 1, 0, pad); > @@ -190,7 +199,7 @@ error_t netfs_get_dirents (struct iouser *cred, struct > node *dir, > } > > /* Allocate a buffer if necessary. */ > - putentries (contents, contents_len, nentries, NULL, datacnt); > + putentries (contents, contents_len, nentries, NULL, datacnt, NULL); > if (bufsize < *datacnt) > { > char *n = mmap (0, *datacnt, PROT_READ | PROT_WRITE, MAP_ANONYMOUS, 0, > 0); > @@ -201,7 +210,7 @@ error_t netfs_get_dirents (struct iouser *cred, struct > node *dir, > } > > /* Do the actual conversion. */ > - *amt = putentries (contents, contents_len, nentries, *data, datacnt); > + *amt = putentries (contents, contents_len, nentries, *data, datacnt, dir); > > return 0; > } > -- > 2.47.1 > > -- Samuel <m> bouhouhouh, b il m'a abandonné. Tout ca parce que je regardais plus mon emacs que lui ! <m> s/lui/ses messages irc/ -+- #ens-mim esseulé -+-