[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: wc -c /proc /sys handling
From: |
Jim Meyering |
Subject: |
Re: wc -c /proc /sys handling |
Date: |
Thu, 22 Dec 2016 10:16:27 -0800 |
On Thu, Dec 22, 2016 at 7:25 AM, Pádraig Brady <address@hidden> wrote:
> On 21/03/16 18:42, Jim Meyering wrote:
>> On Mon, Mar 21, 2016 at 8:57 AM, Pádraig Brady <address@hidden> wrote:
>>> I was wondering if we should not penalize all normal files,
>>> to handle the /proc and /sys approximate st_size edge case?
>>> I.E. only do the seek to last block of file + read() when st_size %
>>> PAGE_SIZE == 0 ?
>>>
>>> I did a quick check of /proc and /sys sizes:
>>>
>>> $ find /proc/ /sys/ -type f -printf "%p\t%s\n" 2>/dev/null |
>>> tr ' ' _ | sort -k2,2n | uniq -f1 -c
>>>
>>> 121494 /proc/100/attr/current 0
>> ...
>>> 19610 /proc/bus/pci/00/1b.0 4096
>> ...
>>> In all cases where st_size % PAGE_SIZE != 0, it would be the same or better
>>> to take the st_size.
>>> In most cases it was the same. There are a couple of cases with larger sizes
>>> where it would
>>> have been better to take the st_size rather than reading, I.E.:
>>>
>>> /sys/devices/pci0000:00/0000:00:1a.0/usb3/3-1/3-1.4/descriptors
>>> st_size = 65553, available bytes = 195, wc -c = 65552
>>> /sys/devices/pci0000:00/0000:00:02.0/rom
>>> st_size = 131072, available bytes = 0, wc -c = 127007 (EINVAL)
>>> /sys/devices/pci0000:00/0000:00:02.0/resource0
>>> st_size = 4194304, available bytes = 0, wc -c = 4191231 (EIO)
>>>
>>> Also related to this is that we currently need read access to any file
>>> we want to wc -c, whereas with this we wouldn't. Well we would for %
>>> PAGE_SIZE files,
>>> but we probably should fall back to st_size on EPERM in any case?
>>
>> Good ideas. I agree and like the proposal.
>> Not actually reading makes the results more conceptually consistent
>> with the usual (non-special) case of files listed on the command line.
>
> Patch attached.
Thank you. That looks fine modulo a test comment nit: s/where/where we/?
+# Ensure we handle cases where don't read()