From unknown Sat Aug 16 15:59:33 2025 X-Loop: help-debbugs@gnu.org Subject: bug#13927: stat --printf %t, %T flags (major and minor device types) don't work on mount points Resent-From: Tyler Hobbs Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Mon, 11 Mar 2013 20:45:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 13927 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: 13927@debbugs.gnu.org X-Debbugs-Original-To: bug-coreutils@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.13630346492320 (code B ref -1); Mon, 11 Mar 2013 20:45:02 +0000 Received: (at submit) by debbugs.gnu.org; 11 Mar 2013 20:44:09 +0000 Received: from localhost ([127.0.0.1]:46870 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UF9Zp-0000bM-82 for submit@debbugs.gnu.org; Mon, 11 Mar 2013 16:44:09 -0400 Received: from eggs.gnu.org ([208.118.235.92]:34845) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UF9Y6-0000YU-1e for submit@debbugs.gnu.org; Mon, 11 Mar 2013 16:42:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UF9X3-0004IO-MN for submit@debbugs.gnu.org; Mon, 11 Mar 2013 16:41:21 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,HTML_MESSAGE autolearn=unavailable version=3.3.2 Received: from lists.gnu.org ([208.118.235.17]:49843) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UF9X3-0004IG-Jx for submit@debbugs.gnu.org; Mon, 11 Mar 2013 16:41:17 -0400 Received: from eggs.gnu.org ([208.118.235.92]:46191) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UF9Wz-0003LW-IO for bug-coreutils@gnu.org; Mon, 11 Mar 2013 16:41:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UF9Ww-0004HG-EU for bug-coreutils@gnu.org; Mon, 11 Mar 2013 16:41:13 -0400 Received: from mail-la0-x231.google.com ([2a00:1450:4010:c03::231]:45528) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UF9Vh-0002gW-S9 for bug-coreutils@gnu.org; Mon, 11 Mar 2013 16:39:54 -0400 Received: by mail-la0-f49.google.com with SMTP id fs13so4333717lab.22 for ; Mon, 11 Mar 2013 13:39:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type:x-gm-message-state; bh=gPaFB9U6bfhxL1saKZCRQzvsic1AY/TX7XUPY1KI6Qs=; b=JkvYwO0FnZvGUAfiZfvu3SCJGCL0VJ3NfMvW2QdmSbMIPu/ltfP8WlNhmWBScbd83N L2G8RwbBpKf9CxNC+NGcUvAwhOxbHWbiZmRoJt/nusPWVHSuXtbHF0paxpMGgySuniNU iLUPoIFM9Pf/l+G/UuGpTnK7VBnttDpTYxDHdOCtcsByVKe3RCiVX4ChahOwS3YDlNqe 3GrZF7VXWLnWEv3TizQFOXk7A3/07vxfu13yOLfwTjf3+eqCnjE6C8WVaoeNKrrzaZKC L4aJ7MKmSdrVwqc2XcDfzWeRxsxPqd5RuKs88qsEbzWF+Gi1sOUEkLmaN86I7s8pGLgN ExbQ== MIME-Version: 1.0 X-Received: by 10.112.54.6 with SMTP id f6mr5096159lbp.104.1363034392128; Mon, 11 Mar 2013 13:39:52 -0700 (PDT) Received: by 10.112.71.198 with HTTP; Mon, 11 Mar 2013 13:39:51 -0700 (PDT) Date: Mon, 11 Mar 2013 15:39:51 -0500 Message-ID: From: Tyler Hobbs Content-Type: multipart/alternative; boundary=bcaec5540070c298e404d7ac2cfb X-Gm-Message-State: ALoCoQnd9eh2m8PdrnmtvrPRK8cvOdOnPetT/IxHmhRpI3QP1ghVVnaHktKoKhZExcLI0v/xZTN0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 208.118.235.17 X-Spam-Score: -3.5 (---) X-Mailman-Approved-At: Mon, 11 Mar 2013 16:44:08 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -6.2 (------) --bcaec5540070c298e404d7ac2cfb Content-Type: text/plain; charset=ISO-8859-1 If I run stat --printf='%D', the result is "10ca70", which is correct. However, if I run stat --printf='%t %T' /mountpoint, the result is erroneously "0 0". If I instead run stat against the device directly (stat --printf='%t %T' /dev/xvdx), I get the correct result of "ca 170". I believe the proper fix is to replace (in stat.c): out_uint_x (pformat, prefix_len, major (statbuf->st_rdev)); with: out_uint_x (pformat, prefix_len, major (statbuf->st_dev)); That is, use statbuf->st_dev instead of st_rdev, which is what the %d and %D directives use. I'm using coreutils 8.9, compiled from source, and this is the output of uname -a: Linux ip-10-39-122-238 2.6.32-276.el6.x86_64 #1 SMP Tue May 29 17:38:19 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux Thanks for your time. - Tyler --bcaec5540070c298e404d7ac2cfb Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
If I run stat --printf=3D'%D', the result is "= ;10ca70", which is correct.=A0 However, if I run stat --printf=3D'= %t %T' /mountpoint, the result is erroneously "0 0".=A0 If I = instead run stat against the device directly (stat --printf=3D'%t %T= 9; /dev/xvdx), I get the correct result of "ca 170".

I believe the proper fix is to replace (in stat.c):

=A0 out_uint= _x (pformat, prefix_len, major (statbuf->st_rdev));

with:

= =A0 out_uint_x (pformat, prefix_len, major (statbuf->st_dev));

Th= at is, use statbuf->st_dev instead of st_rdev, which is what the %d and = %D directives use.


I'm using coreutils 8.9, compiled from source, and this is the = output of uname -a:

Linux ip-10-39-122-238 2.6.32-276.el6.x86_64 #1 = SMP Tue May 29 17:38:19 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux

Thanks for your time.
- Tyler
--bcaec5540070c298e404d7ac2cfb-- From unknown Sat Aug 16 15:59:33 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.428 (Entity 5.428) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Tyler Hobbs Subject: bug#13927: closed (Re: bug#13927: stat --printf %t, %T flags (major and minor device types) don't work on mount points) Message-ID: References: <513F32EA.5000104@draigBrady.com> X-Gnu-PR-Message: they-closed 13927 X-Gnu-PR-Package: coreutils Reply-To: 13927@debbugs.gnu.org Date: Tue, 12 Mar 2013 13:54:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1363096442-14144-1" This is a multi-part message in MIME format... ------------=_1363096442-14144-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #13927: stat --printf %t, %T flags (major and minor device types) don't wor= k on mount points which was filed against the coreutils package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 13927@debbugs.gnu.org. --=20 13927: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D13927 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1363096442-14144-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 13927-done) by debbugs.gnu.org; 12 Mar 2013 13:53:02 +0000 Received: from localhost ([127.0.0.1]:48211 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UFPdV-0003ej-Pp for submit@debbugs.gnu.org; Tue, 12 Mar 2013 09:53:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26304) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UFPdE-0003eD-FB for 13927-done@debbugs.gnu.org; Tue, 12 Mar 2013 09:52:59 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r2CDpf6O005386 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 12 Mar 2013 09:51:41 -0400 Received: from [10.36.116.79] (ovpn-116-79.ams2.redhat.com [10.36.116.79]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r2CDpcFp004563 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 12 Mar 2013 09:51:40 -0400 Message-ID: <513F32EA.5000104@draigBrady.com> Date: Tue, 12 Mar 2013 13:51:38 +0000 From: =?ISO-8859-1?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: Tyler Hobbs Subject: Re: bug#13927: stat --printf %t, %T flags (major and minor device types) don't work on mount points References: In-Reply-To: X-Enigmail-Version: 1.5.1 Content-Type: multipart/mixed; boundary="------------010801010109060004080507" X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-Spam-Score: -4.2 (----) X-Debbugs-Envelope-To: 13927-done Cc: 13927-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -6.9 (------) This is a multi-part message in MIME format. --------------010801010109060004080507 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id r2CDpf6O005386 On 03/11/2013 08:39 PM, Tyler Hobbs wrote: > If I run stat --printf=3D'%D', the result is "10ca70", which is correct. > However, if I run stat --printf=3D'%t %T' /mountpoint, the result is > erroneously "0 0". If I instead run stat against the device directly (= stat > --printf=3D'%t %T' /dev/xvdx), I get the correct result of "ca 170". >=20 > I believe the proper fix is to replace (in stat.c): >=20 > out_uint_x (pformat, prefix_len, major (statbuf->st_rdev)); >=20 > with: >=20 > out_uint_x (pformat, prefix_len, major (statbuf->st_dev)); >=20 > That is, use statbuf->st_dev instead of st_rdev, which is what the %d a= nd > %D directives use. >=20 >=20 > I'm using coreutils 8.9, compiled from source, and this is the output o= f > uname -a: >=20 > Linux ip-10-39-122-238 2.6.32-276.el6.x86_64 #1 SMP Tue May 29 17:38:19= EDT > 2012 x86_64 x86_64 x86_64 GNU/Linux >=20 > Thanks for your time. > - Tyler >=20 So %t and %T are only currently defined for device special files, allowing one to distinguish between the represented device and the device of the inode storing the representation (the special file). $ stat -c '%T%t %D' /dev/sda /dev 08 5 00 5 Now %t and %T returning 0 for non special device nodes is not that useful. I suppose in this case we might use st_rdev only for block and char speci= als, and switch to st_dev otherwise. However... st_rdev is not always 0 I notice that st_rdev is not 0 on FreeBSD 9 for files. I don't know what it represents, but it's non random so may be significan= t. Also the man page I have here says that on XENIX named special file subtypes are distinguished by st_rdev values Also is it useful to get low level access like this to the backing device major and minor for normal files from a shell script? So I think we'll just improve this through documentation. Hopefully the attached clarifies things. thanks, P=E1draig. --------------010801010109060004080507 Content-Type: text/x-patch; name="stat-rdev.patch" Content-Disposition: attachment; filename="stat-rdev.patch" Content-Transfer-Encoding: 7bit >From 2a887d28aacb6135cdacb9c8776385b8e4d6ab38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Tue, 12 Mar 2013 13:43:08 +0000 Subject: [PATCH] doc: clarify stat the meaning of --format="%t %T" * src/stat.c (usage): Mention sthat the values are only defined for character and block special files. * doc/coreutils.texi (stat invication): Likewise. Also mention st_rdev. Reported in http://bugs.gnu.org/13927 --- doc/coreutils.texi | 9 +++++++-- src/stat.c | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/doc/coreutils.texi b/doc/coreutils.texi index c6b3b32..8f1df45 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -11631,8 +11631,8 @@ The valid @var{format} directives for files with @option{--format} and @item %N - Quoted file name with dereference if symbolic link @item %o - Optimal I/O transfer size hint @item %s - Total size, in bytes -@item %t - Major device type in hex -@item %T - Minor device type in hex +@item %t - Major device type in hex (see below) +@item %T - Minor device type in hex (see below) @item %u - User ID of owner @item %U - User name of owner @item %w - Time of file birth, or @samp{-} if unknown @@ -11645,6 +11645,11 @@ The valid @var{format} directives for files with @option{--format} and @item %Z - Time of last change as seconds since Epoch @end itemize +The @samp{%t} and @samp{%T} formats operate on the st_rdev member of +the stat(2) structure, and are only defined for character and block +special files. On some systems or file types, st_rdev may be used to +represent other quantities. + The @samp{%W}, @samp{%X}, @samp{%Y}, and @samp{%Z} formats accept a precision preceded by a period to specify the number of digits to print after the decimal point. For example, @samp{%.3X} outputs the diff --git a/src/stat.c b/src/stat.c index 2326698..a1938a7 100644 --- a/src/stat.c +++ b/src/stat.c @@ -1393,8 +1393,8 @@ The valid format sequences for files (without --file-system):\n\ %N quoted file name with dereference if symbolic link\n\ %o optimal I/O transfer size hint\n\ %s total size, in bytes\n\ - %t major device type in hex\n\ - %T minor device type in hex\n\ + %t major device type in hex, for character/block device special files\n\ + %T minor device type in hex, for character/block device special files\n\ "), stdout); fputs (_("\ %u user ID of owner\n\ -- 1.7.7.6 --------------010801010109060004080507-- ------------=_1363096442-14144-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 11 Mar 2013 20:44:09 +0000 Received: from localhost ([127.0.0.1]:46870 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UF9Zp-0000bM-82 for submit@debbugs.gnu.org; Mon, 11 Mar 2013 16:44:09 -0400 Received: from eggs.gnu.org ([208.118.235.92]:34845) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UF9Y6-0000YU-1e for submit@debbugs.gnu.org; Mon, 11 Mar 2013 16:42:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UF9X3-0004IO-MN for submit@debbugs.gnu.org; Mon, 11 Mar 2013 16:41:21 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,HTML_MESSAGE autolearn=unavailable version=3.3.2 Received: from lists.gnu.org ([208.118.235.17]:49843) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UF9X3-0004IG-Jx for submit@debbugs.gnu.org; Mon, 11 Mar 2013 16:41:17 -0400 Received: from eggs.gnu.org ([208.118.235.92]:46191) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UF9Wz-0003LW-IO for bug-coreutils@gnu.org; Mon, 11 Mar 2013 16:41:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UF9Ww-0004HG-EU for bug-coreutils@gnu.org; Mon, 11 Mar 2013 16:41:13 -0400 Received: from mail-la0-x231.google.com ([2a00:1450:4010:c03::231]:45528) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UF9Vh-0002gW-S9 for bug-coreutils@gnu.org; Mon, 11 Mar 2013 16:39:54 -0400 Received: by mail-la0-f49.google.com with SMTP id fs13so4333717lab.22 for ; Mon, 11 Mar 2013 13:39:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type:x-gm-message-state; bh=gPaFB9U6bfhxL1saKZCRQzvsic1AY/TX7XUPY1KI6Qs=; b=JkvYwO0FnZvGUAfiZfvu3SCJGCL0VJ3NfMvW2QdmSbMIPu/ltfP8WlNhmWBScbd83N L2G8RwbBpKf9CxNC+NGcUvAwhOxbHWbiZmRoJt/nusPWVHSuXtbHF0paxpMGgySuniNU iLUPoIFM9Pf/l+G/UuGpTnK7VBnttDpTYxDHdOCtcsByVKe3RCiVX4ChahOwS3YDlNqe 3GrZF7VXWLnWEv3TizQFOXk7A3/07vxfu13yOLfwTjf3+eqCnjE6C8WVaoeNKrrzaZKC L4aJ7MKmSdrVwqc2XcDfzWeRxsxPqd5RuKs88qsEbzWF+Gi1sOUEkLmaN86I7s8pGLgN ExbQ== MIME-Version: 1.0 X-Received: by 10.112.54.6 with SMTP id f6mr5096159lbp.104.1363034392128; Mon, 11 Mar 2013 13:39:52 -0700 (PDT) Received: by 10.112.71.198 with HTTP; Mon, 11 Mar 2013 13:39:51 -0700 (PDT) Date: Mon, 11 Mar 2013 15:39:51 -0500 Message-ID: Subject: stat --printf %t, %T flags (major and minor device types) don't work on mount points From: Tyler Hobbs To: bug-coreutils@gnu.org Content-Type: multipart/alternative; boundary=bcaec5540070c298e404d7ac2cfb X-Gm-Message-State: ALoCoQnd9eh2m8PdrnmtvrPRK8cvOdOnPetT/IxHmhRpI3QP1ghVVnaHktKoKhZExcLI0v/xZTN0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 208.118.235.17 X-Spam-Score: -3.5 (---) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Mon, 11 Mar 2013 16:44:08 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -6.2 (------) --bcaec5540070c298e404d7ac2cfb Content-Type: text/plain; charset=ISO-8859-1 If I run stat --printf='%D', the result is "10ca70", which is correct. However, if I run stat --printf='%t %T' /mountpoint, the result is erroneously "0 0". If I instead run stat against the device directly (stat --printf='%t %T' /dev/xvdx), I get the correct result of "ca 170". I believe the proper fix is to replace (in stat.c): out_uint_x (pformat, prefix_len, major (statbuf->st_rdev)); with: out_uint_x (pformat, prefix_len, major (statbuf->st_dev)); That is, use statbuf->st_dev instead of st_rdev, which is what the %d and %D directives use. I'm using coreutils 8.9, compiled from source, and this is the output of uname -a: Linux ip-10-39-122-238 2.6.32-276.el6.x86_64 #1 SMP Tue May 29 17:38:19 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux Thanks for your time. - Tyler --bcaec5540070c298e404d7ac2cfb Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
If I run stat --printf=3D'%D', the result is "= ;10ca70", which is correct.=A0 However, if I run stat --printf=3D'= %t %T' /mountpoint, the result is erroneously "0 0".=A0 If I = instead run stat against the device directly (stat --printf=3D'%t %T= 9; /dev/xvdx), I get the correct result of "ca 170".

I believe the proper fix is to replace (in stat.c):

=A0 out_uint= _x (pformat, prefix_len, major (statbuf->st_rdev));

with:

= =A0 out_uint_x (pformat, prefix_len, major (statbuf->st_dev));

Th= at is, use statbuf->st_dev instead of st_rdev, which is what the %d and = %D directives use.


I'm using coreutils 8.9, compiled from source, and this is the = output of uname -a:

Linux ip-10-39-122-238 2.6.32-276.el6.x86_64 #1 = SMP Tue May 29 17:38:19 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux

Thanks for your time.
- Tyler
--bcaec5540070c298e404d7ac2cfb-- ------------=_1363096442-14144-1--