Module Name: src Committed By: christos Date: Fri Jan 14 18:28:28 UTC 2022
Modified Files: src/sys/miscfs/procfs: procfs_vnops.c Log Message: Put the appropriate DT_ constant in the dirent structure depending on the file type. To generate a diff of this commit: cvs rdiff -u -r1.224 -r1.225 src/sys/miscfs/procfs/procfs_vnops.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/miscfs/procfs/procfs_vnops.c diff -u src/sys/miscfs/procfs/procfs_vnops.c:1.224 src/sys/miscfs/procfs/procfs_vnops.c:1.225 --- src/sys/miscfs/procfs/procfs_vnops.c:1.224 Tue Jan 11 17:55:54 2022 +++ src/sys/miscfs/procfs/procfs_vnops.c Fri Jan 14 13:28:28 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: procfs_vnops.c,v 1.224 2022/01/11 22:55:54 christos Exp $ */ +/* $NetBSD: procfs_vnops.c,v 1.225 2022/01/14 18:28:28 christos Exp $ */ /*- * Copyright (c) 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc. @@ -105,7 +105,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: procfs_vnops.c,v 1.224 2022/01/11 22:55:54 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: procfs_vnops.c,v 1.225 2022/01/14 18:28:28 christos Exp $"); #include <sys/param.h> #include <sys/atomic.h> @@ -223,6 +223,7 @@ int procfs_print(void *); int procfs_pathconf(void *); int procfs_getpages(void *); +static uint8_t fttodt(file_t *); static int atoi(const char *, size_t); /* @@ -1410,7 +1411,7 @@ procfs_readdir(void *v) d.d_fileno = PROCFS_FILENO(pfs->pfs_pid, PFSfd, i - 2); d.d_namlen = snprintf(d.d_name, sizeof(d.d_name), "%lld", (long long)(i - 2)); - d.d_type = VREG; + d.d_type = fttodt(fp); if ((error = uiomove(&d, UIO_MX, uio)) != 0) break; if (cookies) @@ -1748,3 +1749,31 @@ atoi(const char *b, size_t len) return p; } + +/** + * convert DTYPE_XXX to corresponding DT_XXX + * matching what procfs_loadvnode() does. + */ +static uint8_t +fttodt(file_t *fp) +{ + switch (fp->f_type) { + case DTYPE_VNODE: + switch (fp->f_vnode->v_type) { + case VREG: return DT_REG; + case VDIR: return DT_LNK; /* symlink */ + case VBLK: return DT_BLK; + case VCHR: return DT_CHR; + case VLNK: return DT_LNK; + case VSOCK: return DT_SOCK; + case VFIFO: return DT_FIFO; + default: return DT_UNKNOWN; + } + case DTYPE_PIPE: return DT_FIFO; + case DTYPE_SOCKET: return DT_SOCK; + case DTYPE_KQUEUE: /*FALLTHROUGH*/ + case DTYPE_MISC: /*FALLTHROUGH*/ + case DTYPE_SEM: return DT_LNK; /* symlinks */ + default: return DT_UNKNOWN; + } +}