Re: DEVFS oddity

From: Maxime Henrion <mux_at_freebsd.org>
Date: Fri, 13 Feb 2004 19:50:17 +0100
Lukas Ertl wrote:
> Hi,
> 
> I've came across an oddity in devfs.  The size of a symlink is the length
> of the "symbolic name", not the one of the target.
> 
> Consider:
> 
> $ ls -la /dev/ | grep ^l
> lrwxr-xr-x   1 root  wheel    3 13 Feb 16:01 dvd_at_ -> acd0
> lrwxr-xr-x   1 root  wheel    4 13 Feb 17:01 kbd0_at_ -> atkbd0
> lrwxr-xr-x   1 root  wheel    3 13 Feb 16:01 log_at_ -> /var/run/log
> lrwxr-xr-x   1 root  wheel    4 13 Feb 17:01 net1_at_ -> net/fxp0
> lrwxr-xr-x   1 root  wheel    4 13 Feb 17:01 net2_at_ -> net/lo0
> lrwxr-xr-x   1 root  wheel    4 13 Feb 16:02 net3_at_ -> net/ndis0
> lrwxr-xr-x   1 root  wheel    6 13 Feb 17:01 stderr_at_ -> fd/2
> lrwxr-xr-x   1 root  wheel    5 13 Feb 17:01 stdin_at_ -> fd/0
> lrwxr-xr-x   1 root  wheel    6 13 Feb 17:01 stdout_at_ -> fd/1
> lrwxr-xr-x   1 root  wheel    7 13 Feb 17:01 urandom_at_ -> random
> 
> against:
> 
> $ ls -l /sys
> lrwxr-xr-x  1 root  wheel  11 13 Feb 12:12 /sys_at_ -> usr/src/sys
> 
> Is this considered a bug or a feature? :-)

I believe it is a bug.

The very simple patch below should fix this (untested).

%%
Index: devfs_vnops.c
===================================================================
RCS file: /space2/ncvs/src/sys/fs/devfs/devfs_vnops.c,v
retrieving revision 1.68
diff -u -p -r1.68 devfs_vnops.c
--- devfs_vnops.c	2 Jan 2004 19:02:28 -0000	1.68
+++ devfs_vnops.c	13 Feb 2004 18:48:36 -0000
_at__at_ -224,7 +224,7 _at__at_ devfs_getattr(ap)
 	vap->va_gid = de->de_gid;
 	vap->va_mode = de->de_mode;
 	if (vp->v_type == VLNK)
-		vap->va_size = de->de_dirent->d_namlen;
+		vap->va_size = strlen(de->de_symlink);
 	else if (vp->v_type == VDIR)
 		vap->va_size = vap->va_bytes = DEV_BSIZE;
 	else
%%

Cheers,
Maxime
Received on Fri Feb 13 2004 - 09:50:17 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:43 UTC