Skip to content

Add API to access "extended file attributes" (xattr, EA) #49604

Open
@heinrich-ulbricht

Description

@heinrich-ulbricht

Background and Motivation

The API currently lacks support to create, read, update and delete "extended file attributes". What are extended file attributes? Citation from the Wikipedia article:

Extended file attributes are file system features that enable users to associate computer files with metadata not interpreted by the filesystem, whereas regular attributes have a purpose strictly defined by the filesystem (such as permissions or records of creation and modification times).

On *nix based systems they are called xattr, on Windows E xtended A ttributes (EA).

MacOS documentation: https://ss64.com/osx/xattr.html
Linux documentation: https://man7.org/linux/man-pages/man7/xattr.7.html
Windows documentation (?): https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/a82e9105-2405-4e37-b2c3-28c773902d85?redirectedfrom=MSDN ($EA and $EA_INFORMATION)
Hints to usage of EA on Windows: https://superuser.com/q/396692/93905

My use case specifically is storing an ID for files that is not visible for the user but links those files to external cloud sources those files were generated (and need to be updated) from. Internet Explorer seems to store the "downloaded from Internet" information there, Antivirus vendors store scan information, Dropbox used those properties in the past as well - there definitely are use cases.

Extended file attributes are a lightweight, cross-platform way of storing file metadata that cannot be tinkered with (at least not easily) by the user. Platform/file system support seems to be good. There are even recent developments like Linux NFS support for xattr: User Xattr Support Finally Landing For NFS In Linux 5.9 To cite one comment: "I've been wanting this for years!" ;)

Proposed API

As extension to System.IO.File?

namespace System.IO
{
    public static class File
    {
        public static FileExtendedAttributes GetExtendedAttributes(string path);
    }
}

(Note: Like the existing File.GetAttributes API)

(Note: It's also possible to set those attributes on directories.)

Usage Examples

try
{
    // here FileExtendedAttributes behaves like a Dictionary<string, string> - although binary values should be possible as well
    FileExtendedAttributes extendedAttributes = File.GetExtendedAttributes("Program.cs");
    extendedAttributes.Add("key", "value");
    Debug.WriteLine(string.Join(", ", extendedAttributes.Keys)); // "key"
    Debug.WriteLine(string.Join(", ", extendedAttributes.Values)); // "value"
    extendedAttributes.Remove("key");
}
catch (NotSupportedException)
{
    // not supported by the underlying platform, file system or kernel
}

Alternative Designs

The API design should reflect existing implementations from other languages and/or platforms. If this proposal is deemed worthy of being pursued further then we would have to look deeper into existing designs.

Risks

Effort for a rarely-used (?) feature.

Short-sighted design; searching for files based on those property values could be desirable. How could this be designed in contrast to existing designs?

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-System.IOneeds-further-triageIssue has been initially triaged, but needs deeper consideration or reconsideration

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions