GNU bug report logs - #18621
[BUG] wc -c incorrectly counts bytes in /sys

Previous Next

Package: coreutils;

Reported by: George Shuklin <george.shuklin <at> gmail.com>

Date: Fri, 3 Oct 2014 15:13:01 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#18621: closed ([BUG] wc -c incorrectly counts bytes in /sys)
Date: Tue, 07 Oct 2014 23:53:02 +0000
[Message part 1 (text/plain, inline)]
Your message dated Tue, 07 Oct 2014 16:51:47 -0700
with message-id <54347C93.9020906 <at> cs.ucla.edu>
and subject line Re: bug#18621: [BUG] wc -c incorrectly counts bytes in /sys
has caused the debbugs.gnu.org bug report #18621,
regarding [BUG] wc -c incorrectly counts bytes in /sys
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
18621: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=18621
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: George Shuklin <george.shuklin <at> gmail.com>
To: bug-coreutils <at> gnu.org
Subject: [BUG] wc -c incorrectly counts bytes in /sys
Date: Fri, 03 Oct 2014 17:47:19 +0300
There is many sysfs (linux) attributes which reported as '4k files' but 
contains just a few bytes.

wc file and wc -c shows different sizes.

Example:

$cat /sys/kernel/vmcoreinfo
1b74c00 1024

$hexdump -Cv /sys/kernel/vmcoreinfo
00000000  31 62 37 34 63 30 30 20  31 30 32 34 0a           |1b74c00 1024.|
0000000d

$ls -la /sys/kernel/vmcoreinfo
-r--r--r-- 1 root root 4096 Oct  3 17:40 /sys/kernel/vmcoreinfo


Here wc output:

$ wc /sys/kernel/vmcoreinfo
   1    2   13 /sys/kernel/vmcoreinfo

and wc -c:

$ wc -c /sys/kernel/vmcoreinfo
4096 /sys/kernel/vmcoreinfo

4096 is not 13, and manual page for wc says that third number is byte count.

I think problem is in  cnt(const char *file)  function:

	if (dochar || domulti) {
		if (fstat(fd, &sb)) {
			warn("%s: fstat", file);
			(void)close(fd);
			return (1);
		}
		if (S_ISREG(sb.st_mode)) {
			(void)printf(" %7lld", (long long)sb.st_size);
			tcharct += sb.st_size;
			(void)close(fd);
			return (0);
		}
	}




[Message part 3 (message/rfc822, inline)]
From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Jim Meyering <jim <at> meyering.net>, Pádraig Brady
 <P <at> draigbrady.com>
Cc: George Shuklin <george.shuklin <at> gmail.com>, 18621-done <at> debbugs.gnu.org
Subject: Re: bug#18621: [BUG] wc -c incorrectly counts bytes in /sys
Date: Tue, 07 Oct 2014 16:51:47 -0700
[Message part 4 (text/plain, inline)]
Paul Eggert wrote:

> The attached patch still needs a changelog entry and test cases.

I wrote those up and pushed the attached patch; this should fix the bug so I'm 
closing the bug report.

[0001-wc-don-t-miscount-sys-and-similar-file-systems.patch (text/plain, attachment)]

This bug report was last modified 10 years and 289 days ago.

Previous Next


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