Avoid double fetch and temporary hex encoding for NTFS attributes
ClosedPublic

Authored by bruns on Mar 22 2020, 4:29 AM.

Details

Summary

The attrib is a DWORD (32 bit unsigned int) in the Windows APIs (see
WIN32_FILE_ATTRIBUTE_DATA), and exported as a 4 byte array by ntfs-3g.
As the size is known, there is no need to query it. As each file has
the "archive" flag set on creation, i.e. the first getxattr call typically
never returns 0, this cuts the number of syscalls by half.

Skip the temporary hex encoding of the value, it is pointless to hex-
encode the value and immediately after parse it again.

Test Plan
  1. touch foo
  2. getfattr -n system.ntfs_attrib_be -e hex foo
  3. dolphin ./
  4. setfattr -n system.ntfs_attrib_be -v 0x00000022
  5. refresh dolphin

Diff Detail

Repository
R241 KIO
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
bruns created this revision.Mar 22 2020, 4:29 AM
Restricted Application added a project: Frameworks. · View Herald TranscriptMar 22 2020, 4:29 AM
Restricted Application edited subscribers, added: kde-frameworks-devel; removed: Frameworks. · View Herald Transcript
bruns requested review of this revision.Mar 22 2020, 4:29 AM

Indeed the hex roundtrip was very unnecessary, well spotted.

src/ioslaves/file/file_unix.cpp
880–882

Given that the value of n isn't used, any reason why this doesn't iterate upwards instead, as the old code was doing? I just find it more usual and readable.

bruns added inline comments.Mar 22 2020, 12:35 PM
src/ioslaves/file/file_unix.cpp
880–882

To make sure n and length have the same type. Otherwise an int and a ssize_t, or whatever getxattr* return, are compared.

dfaure accepted this revision.Mar 22 2020, 12:46 PM

Oh, I see.
Not obvious that this is the reason.
for (decltype(length) n = 0; n < length; ++n) might be more obvious, although maybe also not very common. I'll let you decide which one you prefer, and push.

This revision is now accepted and ready to land.Mar 22 2020, 12:46 PM
This revision was automatically updated to reflect the committed changes.