GNU bug report logs - #19508
[PATCH] diff: compare major, minor numbers of block/character special files

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: diffutils; Reported by: Ondřej Svoboda <ondrej@HIDDEN>; Keywords: patch; dated Sun, 4 Jan 2015 21:24:02 UTC; Maintainer for diffutils is bug-diffutils@HIDDEN.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 12 Mar 2016 14:17:09 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Mar 12 09:17:09 2016
Received: from localhost ([127.0.0.1]:45858 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1aekLt-0000Le-If
	for submit <at> debbugs.gnu.org; Sat, 12 Mar 2016 09:17:09 -0500
Received: from eggs.gnu.org ([208.118.235.92]:37913)
 by debbugs.gnu.org with esmtp (Exim 4.84)
 (envelope-from <SRS0-6hPm=PI=svobodasoft.cz=ondrej@HIDDEN>)
 id 1aekLr-0000LQ-Bv
 for submit <at> debbugs.gnu.org; Sat, 12 Mar 2016 09:17:07 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <SRS0-6hPm=PI=svobodasoft.cz=ondrej@HIDDEN>)
 id 1aekLl-0004Uz-0e
 for submit <at> debbugs.gnu.org; Sat, 12 Mar 2016 09:17:02 -0500
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled
 version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:35379)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <SRS0-6hPm=PI=svobodasoft.cz=ondrej@HIDDEN>)
 id 1aekLk-0004Uv-TX
 for submit <at> debbugs.gnu.org; Sat, 12 Mar 2016 09:17:00 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:57105)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <SRS0-6hPm=PI=svobodasoft.cz=ondrej@HIDDEN>)
 id 1aekLj-0003FF-Lz
 for bug-diffutils@HIDDEN; Sat, 12 Mar 2016 09:17:00 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <SRS0-6hPm=PI=svobodasoft.cz=ondrej@HIDDEN>)
 id 1aekLg-0004RS-Ee
 for bug-diffutils@HIDDEN; Sat, 12 Mar 2016 09:16:59 -0500
Received: from kolbaba.stable.cz ([88.86.120.223]:50906)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <SRS0-6hPm=PI=svobodasoft.cz=ondrej@HIDDEN>)
 id 1aekLg-0004Pa-5F
 for bug-diffutils@HIDDEN; Sat, 12 Mar 2016 09:16:56 -0500
Received: from localhost (kolbaba.miton.cz [127.0.0.1])
 by kolbaba.stable.cz (Postfix) with ESMTP id E543623FC3
 for <bug-diffutils@HIDDEN>; Sat, 12 Mar 2016 15:16:54 +0100 (CET)
X-Virus-Scanned: amavisd-new at kolbaba.stable.cz
Received: from kolbaba.stable.cz ([127.0.0.1])
 by localhost (kolbaba.stable.cz [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 4xjk0+DuOMYv for <bug-diffutils@HIDDEN>;
 Sat, 12 Mar 2016 15:16:53 +0100 (CET)
Received: from [192.168.0.15] (155.198.broadband11.iol.cz [90.178.198.155])
 by kolbaba.stable.cz (Postfix) with ESMTPSA id 6255B22F14
 for <bug-diffutils@HIDDEN>; Sat, 12 Mar 2016 15:16:53 +0100 (CET)
Subject: Re: [bug-diffutils] bug#19508: bug#19508: [PATCH] diff: compare
 major, minor numbers of block/character special files
To: bug-diffutils@HIDDEN
References: <54A9A7E6.8020305@HIDDEN> <56E41FEC.6050300@HIDDEN>
From: =?UTF-8?Q?Ond=c5=99ej_Svoboda?= <ondrej@HIDDEN>
Message-ID: <56E424D1.3040904@HIDDEN>
Date: Sat, 12 Mar 2016 15:16:49 +0100
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101
 Thunderbird/38.6.0
MIME-Version: 1.0
In-Reply-To: <56E41FEC.6050300@HIDDEN>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 2001:4830:134:3::11
X-Spam-Score: -4.0 (----)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -4.0 (----)

Please see the follow-up on testing below.

On 12.3.2016 14:55, Ond=C5=99ej Svoboda wrote:
> Hi everybody,
>
> I rebased the patch on current master and tested it (as root) like this=
:
>
> # mkdir /tmp/a /tmp/b
> # mknod /tmp/a/block1 b 1 2; mknod /tmp/b/block1 b 1 2
> # mknod /tmp/a/block2 b 2 3; mknod /tmp/b/block2 b 2 4
> # mknod /tmp/a/block3 b 3 4; mknod /tmp/b/block3 b 5 4
> # mknod /tmp/a/char1 c 1 2; mknod /tmp/b/char1 c 1 2
> # mknod /tmp/a/char2 c 2 3; mknod /tmp/b/char2 c 2 4
> # mknod /tmp/a/char3 c 3 4; mknod /tmp/b/char3 c 5 4
>
> # LC_ALL=3DC ls -l /tmp/a
> total 0
> brw-r--r-- 1 root root 1, 2 Mar 12 14:51 block1
> brw-r--r-- 1 root root 2, 3 Mar 12 14:51 block2
> brw-r--r-- 1 root root 3, 4 Mar 12 14:51 block3
> crw-r--r-- 1 root root 1, 2 Mar 12 14:51 char1
> crw-r--r-- 1 root root 2, 3 Mar 12 14:51 char2
> crw-r--r-- 1 root root 3, 4 Mar 12 14:51 char3
>
> # LC_ALL=3DC ls -l /tmp/b
> total 0
> brw-r--r-- 1 root root 1, 2 Mar 12 14:51 block1
> brw-r--r-- 1 root root 2, 4 Mar 12 14:51 block2
> brw-r--r-- 1 root root 5, 4 Mar 12 14:51 block3
> crw-r--r-- 1 root root 1, 2 Mar 12 14:51 char1
> crw-r--r-- 1 root root 2, 4 Mar 12 14:51 char2
> crw-r--r-- 1 root root 5, 4 Mar 12 14:51 char3
>
> # LC_ALL=3DC diff -s -r /tmp/a /tmp/b
> Files /tmp/a/block1 and /tmp/b/block1 are identical
> File /tmp/a/block2 is a block special file while file /tmp/b/block2 is=20
> a block special file
> File /tmp/a/block3 is a block special file while file /tmp/b/block3 is=20
> a block special file
> Files /tmp/a/char1 and /tmp/b/char1 are identical
> File /tmp/a/char2 is a character special file while file /tmp/b/char2=20
> is a character special file
> File /tmp/a/char3 is a character special file while file /tmp/b/char3=20
> is a character special file
>
> # LC_ALL=3DC /usr/local/bin/diff -s -r /tmp/a /tmp/b
> Files /tmp/a/block1 and /tmp/b/block1 are identical
> Block special files /tmp/a/block2 and /tmp/b/block2 differ: 2,3 (2,4)
> Block special files /tmp/a/block3 and /tmp/b/block3 differ: 3,4 (5,4)
> Files /tmp/a/char1 and /tmp/b/char1 are identical
> Character special files /tmp/a/char2 and /tmp/b/char2 differ: 2,3 (2,4)
> Character special files /tmp/a/char3 and /tmp/b/char3 differ: 3,4 (5,4)
>
> The reason why diff compared block1 as identical perhaps because it=20
> descended to diff_2_files, I would know if I stepped through the code=20
> which I currently don't have much time to do.

# touch /tmp/b/*

# LC_ALL=3DC ls -l /tmp/b
total 0
brw-r--r-- 1 root root 1, 2 Mar 12 15:09 block1
brw-r--r-- 1 root root 2, 4 Mar 12 15:09 block2
brw-r--r-- 1 root root 5, 4 Mar 12 15:09 block3
crw-r--r-- 1 root root 1, 2 Mar 12 15:09 char1
crw-r--r-- 1 root root 2, 4 Mar 12 15:09 char2
crw-r--r-- 1 root root 5, 4 Mar 12 15:09 char3

# LC_ALL=3DC diff -s -r /tmp/a /tmp/b
File /tmp/a/block1 is a block special file while file /tmp/b/block1 is a=20
block special file
File /tmp/a/block2 is a block special file while file /tmp/b/block2 is a=20
block special file
File /tmp/a/block3 is a block special file while file /tmp/b/block3 is a=20
block special file
File /tmp/a/char1 is a character special file while file /tmp/b/char1 is=20
a character special file
File /tmp/a/char2 is a character special file while file /tmp/b/char2 is=20
a character special file
File /tmp/a/char3 is a character special file while file /tmp/b/char3 is=20
a character special file

# LC_ALL=3DC /usr/local/bin/diff -s -r /tmp/a /tmp/b :(
Files /tmp/a/block1 and /tmp/b/block1 are identical
Block special files /tmp/a/block2 and /tmp/b/block2 differ: 2,3 (2,4)
Block special files /tmp/a/block3 and /tmp/b/block3 differ: 3,4 (5,4)
Files /tmp/a/char1 and /tmp/b/char1 are identical
Character special files /tmp/a/char2 and /tmp/b/char2 differ: 2,3 (2,4)
Character special files /tmp/a/char3 and /tmp/b/char3 differ: 3,4 (5,4)

After changing the modification datetime, both block1 and char1 compared=20
differently with diffutils 3.3-2 (on Arch Linux) while they were found=20
to be the same with the patched diff from master.

> Please share your comments!
>
> Cheers,
> Ondra





Information forwarded to bug-diffutils@HIDDEN:
bug#19508; Package diffutils. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 12 Mar 2016 13:56:14 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Mar 12 08:56:14 2016
Received: from localhost ([127.0.0.1]:45854 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1aek1d-0008Ja-L1
	for submit <at> debbugs.gnu.org; Sat, 12 Mar 2016 08:56:13 -0500
Received: from eggs.gnu.org ([208.118.235.92]:34549)
 by debbugs.gnu.org with esmtp (Exim 4.84)
 (envelope-from <SRS0-6hPm=PI=svobodasoft.cz=ondrej@HIDDEN>)
 id 1aek1b-0008JM-9f
 for submit <at> debbugs.gnu.org; Sat, 12 Mar 2016 08:56:12 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <SRS0-6hPm=PI=svobodasoft.cz=ondrej@HIDDEN>)
 id 1aek1U-0007Ej-Sf
 for submit <at> debbugs.gnu.org; Sat, 12 Mar 2016 08:56:06 -0500
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled
 version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:34382)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <SRS0-6hPm=PI=svobodasoft.cz=ondrej@HIDDEN>)
 id 1aek1U-0007Ef-PY
 for submit <at> debbugs.gnu.org; Sat, 12 Mar 2016 08:56:04 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:53752)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <SRS0-6hPm=PI=svobodasoft.cz=ondrej@HIDDEN>)
 id 1aek1T-0000vP-Bc
 for bug-diffutils@HIDDEN; Sat, 12 Mar 2016 08:56:04 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <SRS0-6hPm=PI=svobodasoft.cz=ondrej@HIDDEN>)
 id 1aek1Q-0007DL-4Z
 for bug-diffutils@HIDDEN; Sat, 12 Mar 2016 08:56:03 -0500
Received: from kolbaba.stable.cz ([88.86.120.223]:55589)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <SRS0-6hPm=PI=svobodasoft.cz=ondrej@HIDDEN>)
 id 1aek1P-0007D6-RK
 for bug-diffutils@HIDDEN; Sat, 12 Mar 2016 08:56:00 -0500
Received: from localhost (kolbaba.miton.cz [127.0.0.1])
 by kolbaba.stable.cz (Postfix) with ESMTP id 661D4226C0
 for <bug-diffutils@HIDDEN>; Sat, 12 Mar 2016 14:55:58 +0100 (CET)
X-Virus-Scanned: amavisd-new at kolbaba.stable.cz
Received: from kolbaba.stable.cz ([127.0.0.1])
 by localhost (kolbaba.stable.cz [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id mcDDeqhB6Glh for <bug-diffutils@HIDDEN>;
 Sat, 12 Mar 2016 14:55:57 +0100 (CET)
Received: from [192.168.0.15] (155.198.broadband11.iol.cz [90.178.198.155])
 by kolbaba.stable.cz (Postfix) with ESMTPSA id D84CD209D0
 for <bug-diffutils@HIDDEN>; Sat, 12 Mar 2016 14:55:56 +0100 (CET)
Subject: [bug-diffutils] bug#19508: [PATCH] diff: compare major, minor numbers
 of block/character special files
To: bug-diffutils@HIDDEN
References: <54A9A7E6.8020305@HIDDEN>
From: =?UTF-8?Q?Ond=c5=99ej_Svoboda?= <ondrej@HIDDEN>
Message-ID: <56E41FEC.6050300@HIDDEN>
Date: Sat, 12 Mar 2016 14:55:56 +0100
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101
 Thunderbird/38.6.0
MIME-Version: 1.0
In-Reply-To: <54A9A7E6.8020305@HIDDEN>
Content-Type: multipart/mixed; boundary="------------060105090405050203080107"
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 2001:4830:134:3::11
X-Spam-Score: -4.0 (----)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -4.0 (----)

This is a multi-part message in MIME format.
--------------060105090405050203080107
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi everybody,

I rebased the patch on current master and tested it (as root) like this:

# mkdir /tmp/a /tmp/b
# mknod /tmp/a/block1 b 1 2; mknod /tmp/b/block1 b 1 2
# mknod /tmp/a/block2 b 2 3; mknod /tmp/b/block2 b 2 4
# mknod /tmp/a/block3 b 3 4; mknod /tmp/b/block3 b 5 4
# mknod /tmp/a/char1 c 1 2; mknod /tmp/b/char1 c 1 2
# mknod /tmp/a/char2 c 2 3; mknod /tmp/b/char2 c 2 4
# mknod /tmp/a/char3 c 3 4; mknod /tmp/b/char3 c 5 4

# LC_ALL=C ls -l /tmp/a
total 0
brw-r--r-- 1 root root 1, 2 Mar 12 14:51 block1
brw-r--r-- 1 root root 2, 3 Mar 12 14:51 block2
brw-r--r-- 1 root root 3, 4 Mar 12 14:51 block3
crw-r--r-- 1 root root 1, 2 Mar 12 14:51 char1
crw-r--r-- 1 root root 2, 3 Mar 12 14:51 char2
crw-r--r-- 1 root root 3, 4 Mar 12 14:51 char3

# LC_ALL=C ls -l /tmp/b
total 0
brw-r--r-- 1 root root 1, 2 Mar 12 14:51 block1
brw-r--r-- 1 root root 2, 4 Mar 12 14:51 block2
brw-r--r-- 1 root root 5, 4 Mar 12 14:51 block3
crw-r--r-- 1 root root 1, 2 Mar 12 14:51 char1
crw-r--r-- 1 root root 2, 4 Mar 12 14:51 char2
crw-r--r-- 1 root root 5, 4 Mar 12 14:51 char3

# LC_ALL=C diff -s -r /tmp/a /tmp/b
Files /tmp/a/block1 and /tmp/b/block1 are identical
File /tmp/a/block2 is a block special file while file /tmp/b/block2 is a 
block special file
File /tmp/a/block3 is a block special file while file /tmp/b/block3 is a 
block special file
Files /tmp/a/char1 and /tmp/b/char1 are identical
File /tmp/a/char2 is a character special file while file /tmp/b/char2 is 
a character special file
File /tmp/a/char3 is a character special file while file /tmp/b/char3 is 
a character special file

# LC_ALL=C /usr/local/bin/diff -s -r /tmp/a /tmp/b
Files /tmp/a/block1 and /tmp/b/block1 are identical
Block special files /tmp/a/block2 and /tmp/b/block2 differ: 2,3 (2,4)
Block special files /tmp/a/block3 and /tmp/b/block3 differ: 3,4 (5,4)
Files /tmp/a/char1 and /tmp/b/char1 are identical
Character special files /tmp/a/char2 and /tmp/b/char2 differ: 2,3 (2,4)
Character special files /tmp/a/char3 and /tmp/b/char3 differ: 3,4 (5,4)

The reason why diff compared block1 as identical perhaps because it 
descended to diff_2_files, I would know if I stepped through the code 
which I currently don't have much time to do.

Please share your comments!

Cheers,
Ondra

--------------060105090405050203080107
Content-Type: text/x-patch;
 name="0001-diff-compare-major-minor-numbers-of-block-character-.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="0001-diff-compare-major-minor-numbers-of-block-character-.pa";
 filename*1="tch"

From 36f26c15551d5c32d3197b3f0008a96fe3440240 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ond=C5=99ej=20Svoboda?= <ondrej@HIDDEN>
Date: Sun, 21 Sep 2014 18:06:38 +0200
Subject: [PATCH] diff: compare major, minor numbers of block/character special
 files

This deals with situation such as

  File dev1/block1 is a block special file while file dev2/block1 is
  a block special file

in case the major and minor numbers are identical.
If stat.st_rdev does not match, a message is given:

  Block special files dev1/block1 and dev2/block1 differ: 1,2 (3,2)
---
 src/diff.c | 23 +++++++++++++++++++++++
 src/diff.h |  1 +
 src/util.c |  9 +++++++++
 3 files changed, 33 insertions(+)

diff --git a/src/diff.c b/src/diff.c
index 9bc1d96..110b8e1 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -1318,6 +1318,29 @@ compare_files (struct comparison const *parent,
 	      status = EXIT_FAILURE;
 	    }
 	}
+      else if ((S_ISBLK (cmp.file[0].stat.st_mode)
+	        && S_ISBLK (cmp.file[1].stat.st_mode))
+	       || (S_ISCHR (cmp.file[0].stat.st_mode)
+	           && S_ISCHR (cmp.file[1].stat.st_mode)))
+	{
+	  if (cmp.file[0].stat.st_rdev != cmp.file[1].stat.st_rdev)
+	    {
+	      char major_minor0[20], major_minor1[20];
+	      format_major_minor (major_minor0, cmp.file[0].stat.st_rdev);
+	      format_major_minor (major_minor1, cmp.file[1].stat.st_rdev);
+
+	      const char *message = S_ISBLK (cmp.file[0].stat.st_mode) ?
+			"Block special files %s and %s differ: %s (%s)\n" :
+			"Character special files %s and %s differ: %s (%s)\n";
+	      message5 (message,
+			file_label[0] ? file_label[0] : cmp.file[0].name,
+			file_label[1] ? file_label[1] : cmp.file[1].name,
+			major_minor0, major_minor1);
+
+	      /* This is a difference.  */
+	      status = EXIT_FAILURE;
+	    }
+	}
       else
 	{
 	  /* We have two files that are not to be compared.  */
diff --git a/src/diff.h b/src/diff.h
index 0983e7c..12ed085 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -391,6 +391,7 @@ extern void begin_output (void);
 extern void debug_script (struct change *);
 extern void fatal (char const *) __attribute__((noreturn));
 extern void finish_output (void);
+extern void format_major_minor (char *buffer, const dev_t st_rdev);
 extern void message (char const *, char const *, char const *);
 extern void message5 (char const *, char const *, char const *,
                       char const *, char const *);
diff --git a/src/util.c b/src/util.c
index d7b8925..85a47d3 100644
--- a/src/util.c
+++ b/src/util.c
@@ -26,6 +26,7 @@
 #include <xalloc.h>
 #include "xvasprintf.h"
 #include <signal.h>
+#include <sys/types.h>
 
 /* Use SA_NOCLDSTOP as a proxy for whether the sigaction machinery is
    present.  */
@@ -1577,3 +1578,11 @@ debug_script (struct change *sp)
 
   fflush (stderr);
 }
+
+/* Format a device number as major,minor. */
+
+void
+format_major_minor (char *buffer, const dev_t st_rdev)
+{
+  sprintf (buffer, "%u,%u", (major (st_rdev)), (minor (st_rdev)));
+}
-- 
2.7.2


--------------060105090405050203080107--




Information forwarded to bug-diffutils@HIDDEN:
bug#19508; Package diffutils. Full text available.

Message received at 19508 <at> debbugs.gnu.org:


Received: (at 19508) by debbugs.gnu.org; 11 Feb 2015 23:40:30 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Feb 11 18:40:30 2015
Received: from localhost ([127.0.0.1]:40386 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1YLgtR-00059j-RQ
	for submit <at> debbugs.gnu.org; Wed, 11 Feb 2015 18:40:30 -0500
Received: from kolbaba.stable.cz ([88.86.120.103]:44103)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <ondrej@HIDDEN>) id 1YLgtP-00059U-Au
 for 19508 <at> debbugs.gnu.org; Wed, 11 Feb 2015 18:40:28 -0500
Received: from localhost (kolbaba.miton.cz [127.0.0.1])
 by kolbaba.stable.cz (Postfix) with ESMTP id D571420977
 for <19508 <at> debbugs.gnu.org>; Thu, 12 Feb 2015 00:40:21 +0100 (CET)
X-Virus-Scanned: amavisd-new at kolbaba.stable.cz
Received: from kolbaba.stable.cz ([127.0.0.1])
 by localhost (kolbaba.stable.cz [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id ZM1KmTGDZyc3 for <19508 <at> debbugs.gnu.org>;
 Thu, 12 Feb 2015 00:40:18 +0100 (CET)
Received: from [10.0.0.8] (38.211.broadband18.iol.cz [109.81.211.38])
 by kolbaba.stable.cz (Postfix) with ESMTPSA id C37C520C8C;
 Thu, 12 Feb 2015 00:40:16 +0100 (CET)
Message-ID: <54DBE85F.5080803@HIDDEN>
Date: Thu, 12 Feb 2015 00:40:15 +0100
From: =?UTF-8?B?T25kxZllaiBTdm9ib2Rh?= <ondrej@HIDDEN>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
 rv:31.0) Gecko/20100101 Thunderbird/31.4.0
MIME-Version: 1.0
To: 19508 <at> debbugs.gnu.org, Paul Eggert <eggert@HIDDEN>
Subject: Re: [bug-diffutils] bug#19508: [PATCH] diff: compare major, minor
 numbers of block/character special files
References: <54A9A7E6.8020305@HIDDEN>
In-Reply-To: <54A9A7E6.8020305@HIDDEN>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 19508
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: 0.0 (/)

Paul, this is the first patch in the series (and is succeeded by the 
fifo one), I am sorry for the confusion.

Could you please give it a look?

Thanks :-)
Ondra Svoboda

On 4.1.2015 21:51, Ondřej Svoboda wrote:
> This deals with situation such as
>
>   File dev1/block1 is a block special file while file dev2/block1 is
>   a block special file
>
> in case the major and minor numbers are identical.
> If stat.st_rdev does not match, a message is given:
>
>   Block special files dev1/block1 and dev2/block1 differ: 1,2 (3,2)
> ---
>  src/diff.c | 23 +++++++++++++++++++++++
>  src/diff.h |  1 +
>  src/util.c |  9 +++++++++
>  3 files changed, 33 insertions(+)
>
> diff --git a/src/diff.c b/src/diff.c
> index ff28377..a3e1b6f 100644
> --- a/src/diff.c
> +++ b/src/diff.c
> @@ -1276,6 +1276,29 @@ compare_files (struct comparison const *parent,
>            status = EXIT_FAILURE;
>          }
>      }
> +      else if ((S_ISBLK (cmp.file[0].stat.st_mode)
> +            && S_ISBLK (cmp.file[1].stat.st_mode))
> +           || (S_ISCHR (cmp.file[0].stat.st_mode)
> +               && S_ISCHR (cmp.file[1].stat.st_mode)))
> +    {
> +      if (cmp.file[0].stat.st_rdev != cmp.file[1].stat.st_rdev)
> +        {
> +          char major_minor0[20], major_minor1[20];
> +          format_major_minor (major_minor0, cmp.file[0].stat.st_rdev);
> +          format_major_minor (major_minor1, cmp.file[1].stat.st_rdev);
> +
> +          const char *message = S_ISBLK (cmp.file[0].stat.st_mode) ?
> +            "Block special files %s and %s differ: %s (%s)\n" :
> +            "Character special files %s and %s differ: %s (%s)\n";
> +          message5 (message,
> +            file_label[0] ? file_label[0] : cmp.file[0].name,
> +            file_label[1] ? file_label[1] : cmp.file[1].name,
> +            major_minor0, major_minor1);
> +
> +          /* This is a difference.  */
> +          status = EXIT_FAILURE;
> +        }
> +    }
>        else
>      {
>        /* We have two files that are not to be compared.  */
> diff --git a/src/diff.h b/src/diff.h
> index 465e4bc..098e75f 100644
> --- a/src/diff.h
> +++ b/src/diff.h
> @@ -390,3 +390,4 @@ extern void print_script (struct change *, struct 
> change * (*) (struct change *)
>  extern void setup_output (char const *, char const *, bool);
>  extern void translate_range (struct file_data const *, lin, lin,
>                               long int *, long int *);
> +extern void format_major_minor (char *buffer, const dev_t st_rdev);
> diff --git a/src/util.c b/src/util.c
> index 2d6d3fc..4773003 100644
> --- a/src/util.c
> +++ b/src/util.c
> @@ -24,6 +24,7 @@
>  #include <system-quote.h>
>  #include <xalloc.h>
>  #include "xvasprintf.h"
> +#include <sys/types.h>
>   char const pr_program[] = PR_PROGRAM;
>  @@ -907,3 +908,11 @@ debug_script (struct change *sp)
>     fflush (stderr);
>  }
> +
> +/* Format a device number as major,minor. */
> +
> +void
> +format_major_minor (char *buffer, const dev_t st_rdev)
> +{
> +  sprintf (buffer, "%u,%u", (major (st_rdev)), (minor (st_rdev)));
> +}





Information forwarded to bug-diffutils@HIDDEN:
bug#19508; Package diffutils. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 4 Jan 2015 21:23:15 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Jan 04 16:23:15 2015
Received: from localhost ([127.0.0.1]:36662 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1Y7sdm-0000Sh-Nr
	for submit <at> debbugs.gnu.org; Sun, 04 Jan 2015 16:23:15 -0500
Received: from eggs.gnu.org ([208.118.235.92]:33322)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <ondrej@HIDDEN>) id 1Y7s9l-00088R-6H
 for submit <at> debbugs.gnu.org; Sun, 04 Jan 2015 15:52:14 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <ondrej@HIDDEN>) id 1Y7s9j-0007vI-RK
 for submit <at> debbugs.gnu.org; Sun, 04 Jan 2015 15:52:12 -0500
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled
 version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:49889)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <ondrej@HIDDEN>) id 1Y7s9j-0007vE-P0
 for submit <at> debbugs.gnu.org; Sun, 04 Jan 2015 15:52:11 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:35008)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <ondrej@HIDDEN>) id 1Y7s9i-0005Gh-L0
 for bug-diffutils@HIDDEN; Sun, 04 Jan 2015 15:52:11 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <ondrej@HIDDEN>) id 1Y7s9b-0007rV-MM
 for bug-diffutils@HIDDEN; Sun, 04 Jan 2015 15:52:10 -0500
Received: from kolbaba.stable.cz ([88.86.120.103]:58998)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <ondrej@HIDDEN>) id 1Y7s9b-0007qs-Fy
 for bug-diffutils@HIDDEN; Sun, 04 Jan 2015 15:52:03 -0500
Received: from localhost (kolbaba.miton.cz [127.0.0.1])
 by kolbaba.stable.cz (Postfix) with ESMTP id 01A6E2026E
 for <bug-diffutils@HIDDEN>; Sun,  4 Jan 2015 21:52:00 +0100 (CET)
X-Virus-Scanned: amavisd-new at kolbaba.stable.cz
Received: from kolbaba.stable.cz ([127.0.0.1])
 by localhost (kolbaba.stable.cz [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 9cnBxWDPXufa for <bug-diffutils@HIDDEN>;
 Sun,  4 Jan 2015 21:51:56 +0100 (CET)
Received: from [192.168.0.15] (155.198.broadband11.iol.cz [90.178.198.155])
 by kolbaba.stable.cz (Postfix) with ESMTPSA id CD40520942
 for <bug-diffutils@HIDDEN>; Sun,  4 Jan 2015 21:51:56 +0100 (CET)
Message-ID: <54A9A7E6.8020305@HIDDEN>
Date: Sun, 04 Jan 2015 21:51:50 +0100
From: =?UTF-8?B?T25kxZllaiBTdm9ib2Rh?= <ondrej@HIDDEN>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
 rv:31.0) Gecko/20100101 Thunderbird/31.3.0
MIME-Version: 1.0
To: bug-diffutils@HIDDEN
Subject: [PATCH] diff: compare major, minor numbers of block/character special
 files
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address
 (bad octet value).
X-Received-From: 2001:4830:134:3::11
X-Spam-Score: -5.0 (-----)
X-Debbugs-Envelope-To: submit
X-Mailman-Approved-At: Sun, 04 Jan 2015 16:23:12 -0500
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -5.0 (-----)

This deals with situation such as

   File dev1/block1 is a block special file while file dev2/block1 is
   a block special file

in case the major and minor numbers are identical.
If stat.st_rdev does not match, a message is given:

   Block special files dev1/block1 and dev2/block1 differ: 1,2 (3,2)
---
  src/diff.c | 23 +++++++++++++++++++++++
  src/diff.h |  1 +
  src/util.c |  9 +++++++++
  3 files changed, 33 insertions(+)

diff --git a/src/diff.c b/src/diff.c
index ff28377..a3e1b6f 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -1276,6 +1276,29 @@ compare_files (struct comparison const *parent,
  	      status = EXIT_FAILURE;
  	    }
  	}
+      else if ((S_ISBLK (cmp.file[0].stat.st_mode)
+	        && S_ISBLK (cmp.file[1].stat.st_mode))
+	       || (S_ISCHR (cmp.file[0].stat.st_mode)
+	           && S_ISCHR (cmp.file[1].stat.st_mode)))
+	{
+	  if (cmp.file[0].stat.st_rdev != cmp.file[1].stat.st_rdev)
+	    {
+	      char major_minor0[20], major_minor1[20];
+	      format_major_minor (major_minor0, cmp.file[0].stat.st_rdev);
+	      format_major_minor (major_minor1, cmp.file[1].stat.st_rdev);
+
+	      const char *message = S_ISBLK (cmp.file[0].stat.st_mode) ?
+			"Block special files %s and %s differ: %s (%s)\n" :
+			"Character special files %s and %s differ: %s (%s)\n";
+	      message5 (message,
+			file_label[0] ? file_label[0] : cmp.file[0].name,
+			file_label[1] ? file_label[1] : cmp.file[1].name,
+			major_minor0, major_minor1);
+
+	      /* This is a difference.  */
+	      status = EXIT_FAILURE;
+	    }
+	}
        else
  	{
  	  /* We have two files that are not to be compared.  */
diff --git a/src/diff.h b/src/diff.h
index 465e4bc..098e75f 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -390,3 +390,4 @@ extern void print_script (struct change *, struct 
change * (*) (struct change *)
  extern void setup_output (char const *, char const *, bool);
  extern void translate_range (struct file_data const *, lin, lin,
                               long int *, long int *);
+extern void format_major_minor (char *buffer, const dev_t st_rdev);
diff --git a/src/util.c b/src/util.c
index 2d6d3fc..4773003 100644
--- a/src/util.c
+++ b/src/util.c
@@ -24,6 +24,7 @@
  #include <system-quote.h>
  #include <xalloc.h>
  #include "xvasprintf.h"
+#include <sys/types.h>
   char const pr_program[] = PR_PROGRAM;
  @@ -907,3 +908,11 @@ debug_script (struct change *sp)
     fflush (stderr);
  }
+
+/* Format a device number as major,minor. */
+
+void
+format_major_minor (char *buffer, const dev_t st_rdev)
+{
+  sprintf (buffer, "%u,%u", (major (st_rdev)), (minor (st_rdev)));
+}
-- 
2.2.1





Acknowledgement sent to Ondřej Svoboda <ondrej@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-diffutils@HIDDEN. Full text available.
Report forwarded to bug-diffutils@HIDDEN:
bug#19508; Package diffutils. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 25 Nov 2019 12:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.