From: "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com>
To: Konstantin Bukin <kbukin@gmail.com>
Cc: mtk.manpages@gmail.com, linux-man@vger.kernel.org,
Alejandro Colomar <colomar.6.4.3@gmail.com>,
"Dmitry V. Levin" <ldv@altlinux.org>
Subject: Re: [PATCH] stat.2: fixed inode printing in example program
Date: Mon, 14 Sep 2020 11:30:19 +0200 [thread overview]
Message-ID: <edd2b0d9-253b-9fd3-688f-7324a4939b71@gmail.com> (raw)
In-Reply-To: <20200913194041.14349-1-kbukin@gmail.com>
Hello Konstantin,
On 9/13/20 9:40 PM, Konstantin Bukin wrote:
> inode numbers are expected to be positive. Casting them to a signed type
> may result in printing negative values. E.g. running example program on
> the following file:
>
> $ ls -li test.txt
> 9280843260537405888 -r--r--r-- 1 kbukin hardware 300 Jul 21 06:36 test.txt
>
> resutls in the following output:
>
> $ ./example test.txt
> ID of containing device: [0,480]
> File type: regular file
> I-node number: -9165900813172145728
> Mode: 100444 (octal)
> Link count: 1
> Ownership: UID=2743 GID=30
> Preferred I/O block size: 32768 bytes
> File size: 300 bytes
> Blocks allocated: 8
> Last status change: Tue Jul 21 06:36:50 2020
> Last file access: Sat Sep 12 14:13:38 2020
> Last file modification: Tue Jul 21 06:36:50 2020
>
> Such erroneous reporting happens for inode values greater than maximum
> value which can be stored in signed long. Printing inode as unsigned
> long long fixes the issue.
> ---
> man2/stat.2 | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/man2/stat.2 b/man2/stat.2
> index 7e5417480..82eaefcda 100644
> --- a/man2/stat.2
> +++ b/man2/stat.2
> @@ -681,7 +681,7 @@ main(int argc, char *argv[])
> default: printf("unknown?\en"); break;
> }
>
> - printf("I\-node number: %ld\en", (long) sb.st_ino);
> + printf("I\-node number: %llu\en", (unsigned long long) sb.st_ino);
>
> printf("Mode: %lo (octal)\en",
> (unsigned long) sb.st_mode);
Thanks for your patches and problem report. But, it seems best to
go with Alejandro's suggestion to use uintmax_t + %ju. See the
patch that Alejandro has sent.
Thanks,
Michael
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
next prev parent reply other threads:[~2020-09-14 9:30 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-13 15:04 [PATCH] stat.2: fixed inode printing in example program Konstantin Bukin
2020-09-13 15:16 ` Dmitry V. Levin
2020-09-13 17:24 ` Konstantin Bukin
2020-09-13 17:38 ` Dmitry V. Levin
2020-09-13 18:04 ` Alejandro Colomar
2020-09-13 18:16 ` Konstantin Bukin
2020-09-13 18:30 ` Alejandro Colomar
2020-09-13 18:42 ` Konstantin Bukin
2020-09-13 18:46 ` Alejandro Colomar
2020-09-13 19:12 ` Konstantin Bukin
2020-09-13 19:39 ` Konstantin Bukin
2020-09-13 19:40 ` Konstantin Bukin
2020-09-14 9:30 ` Michael Kerrisk (man-pages) [this message]
2020-09-13 18:04 ` Konstantin Bukin
-- strict thread matches above, loose matches on Subject: below --
2020-09-13 18:29 Konstantin Bukin
2020-09-13 18:43 ` Alejandro Colomar
2020-09-13 19:32 ` Konstantin Bukin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=edd2b0d9-253b-9fd3-688f-7324a4939b71@gmail.com \
--to=mtk.manpages@gmail.com \
--cc=colomar.6.4.3@gmail.com \
--cc=kbukin@gmail.com \
--cc=ldv@altlinux.org \
--cc=linux-man@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox