[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] procfs: set d_type on returned direntries
From: |
dnietoc |
Subject: |
[PATCH] procfs: set d_type on returned direntries |
Date: |
Sun, 19 Jan 2025 23:50:10 +0000 |
From: Diego Nieto Cid <dnietoc@gmail.com>
Hello,
This sets d_type to DT_DIR in those entries of procfs
which are actually directories; which allows libgtop
to list processes using the linux port code.
Hope this is what you had in mind Samuel. It's not
very robust, but I couldn't find other way to do it.
Regards,
Diego
-- >8 -- >8 -- >8 --
---
procfs/netfs.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/procfs/netfs.c b/procfs/netfs.c
index 4ed5eab6..3cf7a8e2 100644
--- a/procfs/netfs.c
+++ b/procfs/netfs.c
@@ -115,6 +115,29 @@ error_t netfs_attempt_readlink (struct iouser *user,
struct node *np,
return 0;
}
+static unsigned char entry_type(char *name)
+{
+ char c;
+ int only_numbers;
+
+ if (name[0] == '.' && name[1] == 0)
+ return DT_DIR;
+
+ if (name[0] == '.' && name[1] == '.' && name[2] == 0)
+ return DT_DIR;
+
+ if (strcmp(name, "self") == 0)
+ return DT_DIR;
+
+ for(only_numbers = 1, c = *name; only_numbers && c; c = *++name)
+ {
+ if (c < '0' || c > '9')
+ only_numbers = 0;
+ }
+
+ return only_numbers ? DT_DIR : DT_UNKNOWN;
+}
+
/* Helper function for netfs_get_dirents() below. CONTENTS is an argz
vector of directory entry names, as returned by procfs_get_contents().
Convert at most NENTRIES of them to dirent structures, put them in
@@ -142,7 +165,7 @@ static int putentries (char *contents, size_t contents_len,
int nentries,
d->d_fileno = 42; /* XXX */
d->d_namlen = namlen;
d->d_reclen = reclen;
- d->d_type = DT_UNKNOWN;
+ d->d_type = entry_type(contents);
memcpy (d->d_name, contents, namlen + 1);
if (pad)
memset(d->d_name + namlen + 1, 0, pad);
--
2.47.1
- [PATCH] procfs: set d_type on returned direntries,
dnietoc <=