Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 9 Jun 2009 11:18:07 +0200
From:      Thomas Backman <serenity@exscape.org>
To:        Ivan Voras <ivoras@freebsd.org>
Cc:        freebsd-current@freebsd.org
Subject:   Re: FS utils treates directories as files?
Message-ID:  <60F36765-E4FA-4A2D-AD6B-E7881537F6DA@exscape.org>
In-Reply-To: <h0l8gb$57r$1@ger.gmane.org>
References:  <B7437F9F-A8BF-4F49-AAE4-9B93B62B6223@exscape.org> <h0l8gb$57r$1@ger.gmane.org>

next in thread | previous in thread | raw e-mail | index | archive | help

On Jun 9, 2009, at 11:03 AM, Ivan Voras wrote:

> Thomas Backman wrote:
>> FreeBSD 8.0-CURRENT r193521 (Jun 5), bash:
>> [root@chaos /usr/ports]# file /
>> /: directory
>> [root@chaos /usr/ports]# cat /
>> =EF=BF=BDg=EF=BF=BD=EF=BF=BD=3D[root@chaos /usr/ports]#
>> [root@chaos /usr/ports]# cat /usr/ports/mail
>> =EF=BF=BD
>
> This is the traditional behaviour because yes, directories are just
> simply ordinary files with a special bit set to distinguish them. =20
> Other
> systems might have modified "cat" to check if directories are files =20=

> but
> it's not standard.
>
> You can easily check this yourself. The following small program should
> work on every unix-ish system:
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <sys/fcntl.h>
>
> int main() {
> 	int fd, i;
> 	char buf[512];
> =09
> 	fd =3D open(".", O_RDONLY);
> 	read(fd, buf, 512);
> 	for (i =3D 0; i < 512; i++)
> 		printf("%4d ", buf[i]);
> }

Yes, I realize that, and actually added a stat() call to cat to check =20=

for directories... before I realized it was true for other utils as =20
well.
I still think it's weird, though, and that the utils should check (as =20=

long as they return gibberish; less /etc on my GNU/Linux system =20
actually shows a readable list of files - it seems as if less /etc =3D=3D =
=20
ls -al /etc | less). Is there *any* use for this behaviour, or is it =20
simply there because nobody has added a check?

Regards,
Thomas=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?60F36765-E4FA-4A2D-AD6B-E7881537F6DA>