Re: [PATCH v2] kbuild: Use ls(1) instead of stat(1) to obtain file size

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2018-03-20, Masahiro Yamada <yamada.masahiro@xxxxxxxxxxxxx> wrote:
> 2018-03-19 9:54 GMT+09:00 Michael Forney <mforney@xxxxxxxxxxx>:
>> From: Michael Forney <forney@xxxxxxxxxx>
>>
>> stat(1) is not standardized and different implementations have their own
>> (conflicting) flags for querying the size of a file.
>>
>> ls(1) provides the same information (value of st.st_size) in the 5th
>> column, except when the file is a character or block device. This output
>> is standardized[0]. The -n option turns on -l, which writes lines
>> formatted like
>>
>>   "%s %u %s %s %u %s %s\n", <file mode>, <number of links>,
>>       <owner name>, <group name>, <size>, <date and time>,
>>       <pathname>
>>
>> but instead of writing the <owner name> and <group name>, it writes the
>> numeric owner and group IDs (this avoids /etc/passwd and /etc/group
>> lookups as well as potential field splitting issues).
>>
>> The <size> field is specified as "the value that would be returned for
>> the file in the st_size field of struct stat".
>>
>> To avoid duplicating logic in several locations in the tree, create
>> scripts/file-size.sh and update callers to use that instead of stat(1).
>>
>> [0]
>> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html#tag_20_73_10
>>
>> Signed-off-by: Michael Forney <forney@xxxxxxxxxx>
>> ---
>> Changes in v2:
>> * Use a wrapper script instead of calling ls(1) directly.
>> * Also replace a couple of other instances of `stat -c '%s'`.
>> * Update description with justification of ls(1) usage.
>>
>
> Applied to linux-kbuild. Thanks!

Thanks, Masahiro!

However, I just realized that we probably need to revert the change to
tools/testing/selftests/efivarfs/efivarfs.sh since it is called
through a separate Makefile system that does not have $CONFIG_SHELL
and $srctree defined.

Sorry for the mistake.
--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux&nblp;USB Development]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite Secrets]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux