From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Thu, 18 Jan 2001 00:29:06 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Thu, 18 Jan 2001 00:28:57 -0500 Received: from snark.tuxedo.org ([207.106.50.26]:31238 "EHLO snark.thyrsus.com") by vger.kernel.org with ESMTP id ; Thu, 18 Jan 2001 00:28:52 -0500 Date: Thu, 18 Jan 2001 00:28:12 -0500 From: "Eric S. Raymond" To: Linux Kernel List Subject: Documenting stat(2) Message-ID: <20010118002812.A19810@thyrsus.com> Reply-To: esr@thyrsus.com Mail-Followup-To: "Eric S. Raymond" , Linux Kernel List Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i Organization: Eric Conspiracy Secret Labs X-Eric-Conspiracy: There is no conspiracy Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org I'm trying to pin down and document the behavior of the size field in stat(2) on Linux and under various stat emulations on Windows and the Mac. What I find out will be documented where it will do some good (in particular I'll send a stat.2 man page patch to Andries Brouwer). Here is what I think I know about stat(2) that isn't in the Linux man pages: * For a plain file or directory (S_IFREG or S_IFDIR), the st_size field reports the size of the file in bytes. * For a symlink (S_IFLNK) it reports the size of the link file, not the size of the file the link points to. * For a socket or FIFO (S_IFSOCK, S_IFIFO) it reports the count of bytes waiting to be read. * For a block special device (S_IFBLK) it returns 0. I don't know what it should be expected to return for terminal or other special devices. My guess is number of characters waiting in clists. Can anyone verify, correct, or expand on the above? Reply to esr@thyrsus.com, please, and thanks in advance. (Among other things, this may turn into a substantial improvement in the documented capabilities of Perl and Python.) -- Eric S. Raymond The spirit of resistance to government is so valuable on certain occasions, that I wish it always to be kept alive. It will often be exercised when wrong, but better so than not to be exercised at all. I like a little rebellion now and then. It is like a storm in the Atmosphere. -- Thomas Jefferson, letter to Abigail Adams, 1787 - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org Please read the FAQ at http://www.tux.org/lkml/ From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Thu, 18 Jan 2001 01:46:45 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Thu, 18 Jan 2001 01:46:35 -0500 Received: from neon-gw.transmeta.com ([209.10.217.66]:8970 "EHLO neon-gw.transmeta.com") by vger.kernel.org with ESMTP id ; Thu, 18 Jan 2001 01:46:22 -0500 To: linux-kernel@vger.kernel.org From: torvalds@transmeta.com (Linus Torvalds) Subject: Re: Documenting stat(2) Date: 17 Jan 2001 22:46:11 -0800 Organization: Transmeta Corporation Message-ID: <9463fj$gsq$1@penguin.transmeta.com> In-Reply-To: <20010118002812.A19810@thyrsus.com> Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org In article <20010118002812.A19810@thyrsus.com>, Eric S. Raymond wrote: > >* For a socket or FIFO (S_IFSOCK, S_IFIFO) it reports the count of bytes >waiting to be read. Don't depend on it. That's pretty much implementation-defined: use the FIONREAD ioctl to fetch available info from pipes, sockets, ttys etc. Some versions of Linux will _not_ give the size of the pipe from stat(), if I remember correctly. And as far as I know, no version of Linux will have st_size mean anything at all for sockets (pipes, yes. Both named and unnamed - at least with the current implementation. But not sockets. How could, it, anyway, as a socket name is nothing but a bind entry, and can have many sockets associated with it?). >* For a block special device (S_IFBLK) it returns 0. Again, this is not something you should depend on. Older Linuxes tried to return the size of the block device, again if my memory serves me. >I don't know what it should be expected to return for terminal or >other special devices. My guess is number of characters waiting >in clists. Nope. Use FIONREAD for that. Linux will normally return 0. >Can anyone verify, correct, or expand on the above? Reply to >esr@thyrsus.com, please, and thanks in advance. Basically, the _only_ think you should depend on is that st_size contains: - for regular files, the size of the file in bytes - for symlinks, the length of the symlink. That's it. Anybody who tries to use anything else is nonportable, and is almost guaranteed to not work reliably even on just different versions of Linux, never mind anything else. Linus - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org Please read the FAQ at http://www.tux.org/lkml/ From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Thu, 18 Jan 2001 02:06:01 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Thu, 18 Jan 2001 02:05:43 -0500 Received: from w240.z209220232.was-dc.dsl.cnc.net ([209.220.232.240]:61444 "EHLO yendi.dmeyer.net") by vger.kernel.org with ESMTP id ; Thu, 18 Jan 2001 02:05:29 -0500 Date: Thu, 18 Jan 2001 02:05:28 -0500 From: dmeyer@dmeyer.net To: linux-kernel@vger.kernel.org Subject: Documenting stat(2) Message-ID: <20010118020528.A16871@jhereg.dmeyer.net> Reply-To: dmeyer@dmeyer.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2i Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org In article <9463fj$gsq$1@penguin.transmeta.com> you write: > Basically, the _only_ think you should depend on is that st_size > contains: > - for regular files, the size of the file in bytes > - for symlinks, the length of the symlink. I don't think this is right - for a symlink, stat should return the size of the file; lstat should return the size of the symlink. -- David M. Meyer dmeyer@dmeyer.net - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org Please read the FAQ at http://www.tux.org/lkml/ From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Thu, 18 Jan 2001 06:53:36 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Thu, 18 Jan 2001 06:53:27 -0500 Received: from mirasta.antefacto.net ([193.120.245.10]:52996 "EHLO nt1.antefacto.com") by vger.kernel.org with ESMTP id ; Thu, 18 Jan 2001 06:53:11 -0500 Message-ID: <3A66D93C.8090500@AnteFacto.com> Date: Thu, 18 Jan 2001 11:53:32 +0000 From: Padraig Brady User-Agent: Mozilla/5.0 (X11; U; Linux 2.4.0-ac4 i686; en-US; 0.7) Gecko/20010105 X-Accept-Language: en MIME-Version: 1.0 To: dmeyer@dmeyer.net CC: linux-kernel@vger.kernel.org Subject: Re: Documenting stat(2) In-Reply-To: <20010118020528.A16871@jhereg.dmeyer.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org dmeyer@dmeyer.net wrote: > In article <9463fj$gsq$1@penguin.transmeta.com> you write: > >> Basically, the _only_ think you should depend on is that st_size >> contains: >> - for regular files, the size of the file in bytes >> - for symlinks, the length of the symlink. > > I don't think this is right - for a symlink, stat should return the > size of the file; lstat should return the size of the symlink. Nope stat should return the details of the symlink whereas lstat should return the details of the symlink target. But there is another ambiguity when stating symlinks. In the current implementation the length of the symlink (name) is the same as the symlink file size. Will this always be the case? If not then the above statement is wrong. i.e. >> - for symlinks, the length of the symlink. should be >> - for symlinks, the symlink file size in bytes (currently the >> length of the symlink). Padraig. - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org Please read the FAQ at http://www.tux.org/lkml/ From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Thu, 18 Jan 2001 07:57:51 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Thu, 18 Jan 2001 07:57:32 -0500 Received: from felix.convergence.de ([212.84.236.131]:4877 "EHLO convergence.de") by vger.kernel.org with ESMTP id ; Thu, 18 Jan 2001 07:57:21 -0500 Date: Thu, 18 Jan 2001 13:56:35 +0100 From: Felix von Leitner To: Linux Kernel List Cc: "Eric S. Raymond" Subject: Re: Documenting stat(2) Message-ID: <20010118135635.A12276@convergence.de> Mail-Followup-To: Linux Kernel List , "Eric S. Raymond" In-Reply-To: <20010118002812.A19810@thyrsus.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.12i In-Reply-To: <20010118002812.A19810@thyrsus.com>; from esr@thyrsus.com on Thu, Jan 18, 2001 at 12:28:12AM -0500 Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Thus spake Eric S. Raymond (esr@thyrsus.com): > Here is what I think I know about stat(2) that isn't in the > Linux man pages: > * For a symlink (S_IFLNK) it reports the size of the link file, not the > size of the file the link points to. I think you confuse stat and lstat here. Felix - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org Please read the FAQ at http://www.tux.org/lkml/ From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Thu, 18 Jan 2001 10:55:03 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Thu, 18 Jan 2001 10:54:53 -0500 Received: from w240.z209220232.was-dc.dsl.cnc.net ([209.220.232.240]:4357 "EHLO yendi.dmeyer.net") by vger.kernel.org with ESMTP id ; Thu, 18 Jan 2001 10:54:36 -0500 Date: Thu, 18 Jan 2001 10:54:31 -0500 From: dmeyer@dmeyer.net To: linux-kernel@vger.kernel.org Subject: Re: Documenting stat(2) Message-ID: <20010118105430.A4461@jhereg.dmeyer.net> Reply-To: dmeyer@dmeyer.net In-Reply-To: <20010118020528.A16871@jhereg.dmeyer.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2i X-Newsgroups: local.linux.kernel In-Reply-To: <3A66D93C.8090500@AnteFacto.com> Organization: dmeyer.net Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org In article <3A66D93C.8090500@AnteFacto.com> you write: > Nope stat should return the details of the symlink > whereas lstat should return the details of the symlink target. Not according to my manpages. From stat(2): stat stats the file pointed to by file_name and fills in buf. lstat is identical to stat, only the link itself is stated, not the file that is obtained by tracing the links. Actually, the Solaris manpage is clearer: The lstat() function obtains file attributes similar to stat(), except when the named file is a symbolic link; in that case lstat() returns information about the link, while stat() returns information about the file the link refer- ences. and a short test program: #include #include #include main() { struct stat buf; stat("stattest.c",&buf); printf("stat original file: %d\n",buf.st_size); symlink("stattest.c","a_symlink"); stat("a_symlink",&buf); printf("stat symlink: %d\n",buf.st_size); lstat("a_symlink",&buf); printf("lstat symlink: %d\n",buf.st_size); } jhereg|dmeyer|~/dl> ./stattest stat original file: 358 stat symlink: 358 lstat symlink: 10 stat clearly is giving the size of the target, and lstat the size of the link. -- David M. Meyer dmeyer@dmeyer.net - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org Please read the FAQ at http://www.tux.org/lkml/ From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Thu, 18 Jan 2001 14:45:36 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Thu, 18 Jan 2001 14:45:26 -0500 Received: from mail-out.chello.nl ([213.46.240.7]:26466 "EHLO amsmta05-svc.chello.nl") by vger.kernel.org with ESMTP id ; Thu, 18 Jan 2001 14:45:13 -0500 Date: Thu, 18 Jan 2001 21:52:02 +0100 (CET) From: Igmar Palsenberg To: Padraig Brady cc: dmeyer@dmeyer.net, linux-kernel@vger.kernel.org Subject: Re: Documenting stat(2) In-Reply-To: <3A66D93C.8090500@AnteFacto.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org > Nope stat should return the details of the symlink > whereas lstat should return the details of the symlink target. It's the other way around according to the manpage, and my code also says it's the other way around. It's logical the way it is.. I use lstat to check if a config file is a symlink, and if it is, it refuses to open it. Igmar - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org Please read the FAQ at http://www.tux.org/lkml/ From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Thu, 18 Jan 2001 20:00:46 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Thu, 18 Jan 2001 20:00:37 -0500 Received: from phoenix.nanospace.com ([209.213.199.19]:52490 "HELO phoenix.nanospace.com") by vger.kernel.org with SMTP id ; Thu, 18 Jan 2001 20:00:26 -0500 Date: Thu, 18 Jan 2001 17:00:23 -0800 From: Mike Castle To: linux-kernel@vger.kernel.org Subject: Re: Documenting stat(2) Message-ID: <20010118170023.A3694@thune.yy.com> Reply-To: Mike Castle Mail-Followup-To: Mike Castle , linux-kernel@vger.kernel.org In-Reply-To: <3A66D93C.8090500@AnteFacto.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.6i In-Reply-To: ; from maillist@chello.nl on Thu, Jan 18, 2001 at 09:52:02PM +0100 Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 18, 2001 at 09:52:02PM +0100, Igmar Palsenberg wrote: > I use lstat to check if a config file is a symlink, and if it is, it > refuses to open it. Nice race condition. mrc -- Mike Castle Life is like a clock: You can work constantly dalgoda@ix.netcom.com and be right all the time, or not work at all www.netcom.com/~dalgoda/ and be right at least twice a day. -- mrc We are all of us living in the shadow of Manhattan. -- Watchmen - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org Please read the FAQ at http://www.tux.org/lkml/ From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Fri, 19 Jan 2001 05:19:30 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Fri, 19 Jan 2001 05:19:20 -0500 Received: from Cantor.suse.de ([194.112.123.193]:2832 "HELO Cantor.suse.de") by vger.kernel.org with SMTP id ; Fri, 19 Jan 2001 05:19:07 -0500 To: Padraig Brady Cc: linux-kernel@vger.kernel.org Subject: Re: Documenting stat(2) In-Reply-To: <20010118020528.A16871@jhereg.dmeyer.net> <3A66D93C.8090500@AnteFacto.com> X-Yow: I wonder if I should put myself in ESCROW!! From: Andreas Schwab Date: 19 Jan 2001 11:18:56 +0100 In-Reply-To: <3A66D93C.8090500@AnteFacto.com> Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.0.96 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Padraig Brady writes: |> dmeyer@dmeyer.net wrote: |> |> > In article <9463fj$gsq$1@penguin.transmeta.com> you write: |> > |> >> Basically, the _only_ think you should depend on is that st_size |> >> contains: |> >> - for regular files, the size of the file in bytes |> >> - for symlinks, the length of the symlink. |> > I don't think this is right - for a symlink, stat should return the |> > size of the file; lstat should return the size of the symlink. |> |> Nope stat should return the details of the symlink |> whereas lstat should return the details of the symlink target. Nope, check the facts. Andreas. -- Andreas Schwab "And now for something SuSE Labs completely different." Andreas.Schwab@suse.de SuSE GmbH, Schanzäckerstr. 10, D-90443 Nürnberg - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org Please read the FAQ at http://www.tux.org/lkml/ From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Sat, 20 Jan 2001 13:33:27 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Sat, 20 Jan 2001 13:33:08 -0500 Received: from mail-out.chello.nl ([213.46.240.7]:14404 "EHLO amsmta01-svc.chello.nl") by vger.kernel.org with ESMTP id ; Sat, 20 Jan 2001 13:32:57 -0500 Date: Sat, 20 Jan 2001 20:39:52 +0100 (CET) From: Igmar Palsenberg To: Mike Castle cc: linux-kernel@vger.kernel.org Subject: Re: Documenting stat(2) In-Reply-To: <20010118170023.A3694@thune.yy.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 18 Jan 2001, Mike Castle wrote: > On Thu, Jan 18, 2001 at 09:52:02PM +0100, Igmar Palsenberg wrote: > > I use lstat to check if a config file is a symlink, and if it is, it > > refuses to open it. > > Nice race condition. Agree, but still better then opening things that are actually a symlink. Now would someone probably say : use the O_NOWFOLLOW option, but since I do other checks that wouldn't be an option. > mrc Igmar - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org Please read the FAQ at http://www.tux.org/lkml/