Bug 19756 – Add extended attributes support to std.file

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-03-20T11:53:00Z
Last change time
2024-12-01T16:34:53Z
Assigned to
No Owner
Creator
Vladimir Panteleev
Depends on
21306
Moved to GitHub: phobos#9771 →

Comments

Comment #0 by dlang-bugzilla — 2019-03-20T11:53:00Z
Many operating systems and filesystems support adding short, arbitrarily-named attributes to files. The way this is done is OS-specific. std.file should provide a cross-platform interface to set, query, enumerate, and remove these attributes. The following supported OSes support extended attributes: - Linux (getxattr family of functions, already in Druntime) - FreeBSD (VOP_GETEXTATTR family) - OSX (getxattr but a different API) - Windows apparently supports extended attributes in FAT, HPFS, and NTFS. I found some sample PowerShell code to access them here: https://gist.github.com/jaredcatkinson/f1cd44a8605e05c2661bdeca558c03e1 However, it seems to be using kernel mode APIs and I'm not sure how that's done from userspace. More research is needed. Windows seems to have a protected "$Kernel." namespace which is similar to the "system." namespace in the Linux kernel. Note that alternate data streams (a different feature present in some filesystems) is occasionally used for metadata on Windows, see e.g. "Zone.Identifier" which is used to control whether to prompt users when opening files downloaded from the Internet. I have an implementation of a D wrapper around the Linux APIs here: https://github.com/cybershadow/ae/blob/master/sys/file.d (search for XAttr) The interface should be suitable for other platforms as well.
Comment #1 by alphaglosined — 2019-03-20T14:44:48Z
I found out a few details for Windows. To list all extended attributes use FindFirstStreamW and FindNextStreamW providing the file name. To read or write attributes, use standard file IO functions but use the file name in the format of: "filename:attribute:$DATA". Note that ":$DATA" will be appended if gotten from e.g. FindFirstStreamW. DigitalMars libc will not work for interacting with the attributes. But MSVC's will. I would recommend using WriteFile and ReadFile from WinAPI instead of using the libc abstraction. To delete an attribute you can use CreateFileW (on close). Note: if you delete the stream "filename::$DATA" the file will be deleted. We also need to create fileapi.h as part of the Windows bindings. Its missing and contains the two main functions with their related declarations. While we are at it, it might be a good idea to extend std.mmap to be able to use these attributes as a source of a file (if possible).
Comment #2 by dlang-bugzilla — 2019-03-20T14:46:31Z
I think those are the alternate data streams I mentioned. NTFS extended attributes ("EA") are different. See e.g. the documentation for ZwQueryEaFile.
Comment #3 by robert.schadek — 2024-12-01T16:34:53Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/9771 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB