GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Figure out extended attributes on BSDs · Issue #57187 · python/cpython

Figure out extended attributes on BSDs #57187

New issue
Copy link
New issue
Copy link
Open
Open
Figure out extended attributes on BSDs#57187
Copy link
Labels
OS-freebsdOS-macextension-modulesC modules in the Modules dirC modules in the Modules dirtype-featureA feature request or enhancementA feature request or enhancement

Description

@benjaminp
benjaminp
opened on Sep 14, 2011
Issue body actions
BPO 12978
Nosy @etrepum, @ronaldoussoren, @benjaminp, @ned-deily, @hynek, @koobs, @worr
PRs
  • gh-57187: Add support for extended attributes on FreeBSD #1690
  • Files
  • initial_freebsd_xattrs.patch
  • extattrs.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2011-09-14.15:35:25.624>
    labels = ['3.8']
    title = 'Figure out extended attributes on BSDs'
    updated_at = <Date 2018-10-10.23:45:24.855>
    user = 'https://github.com/benjaminp'

    bugs.python.org fields:

    activity = <Date 2018-10-10.23:45:24.855>
    actor = 'ned.deily'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = []
    creation = <Date 2011-09-14.15:35:25.624>
    creator = 'benjamin.peterson'
    dependencies = []
    files = ['39095', '40946']
    hgrepos = []
    issue_num = 12978
    keywords = ['patch']
    message_count = 12.0
    messages = ['144028', '144035', '155505', '155756', '165551', '165578', '193732', '241392', '247000', '247308', '254089', '327502']
    nosy_count = 10.0
    nosy_names = ['nicholas.riley', 'bob.ippolito', 'ronaldoussoren', 'benjamin.peterson', 'ned.deily', 'Arfrever', 'hynek', 'koobs', 'worr', 'billyfoster']
    pr_nums = ['1690']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue12978'
    versions = ['Python 3.8']

    Linked PRs

    • gh-57187: add xattr support for FreeBSD and macOS #103994

    Activity

    1. benjaminp commented on Sep 14, 2011

      @benjaminp
      benjaminp
      on Sep 14, 2011
      ContributorAuthor
      More actions

      Extended attribute support currently exists in the os module for Linux. BSD's (including OSX) have a similar (but of course incompatible) interface. They should be exposed through the same functions. For example,

      os.getxattr("myfile", "user.whatever")

      should call on the C level

      getxattr("myfile", "user.whatever", value, sizeof(value), 0, 0);

    2. ned-deily commented on Sep 14, 2011

      @ned-deily
      ned-deily
      on Sep 14, 2011
      Member
      More actions

      Have you looked at Bob Ippolito's xattr module which has been out for some time and wraps Linux, OS X, BSD, and Solaris extended attributes?

      http://pypi.python.org/pypi/xattr

    3. nicholasriley commented on Mar 12, 2012

      @nicholasriley
      nicholasrileymannequin
      on Mar 12, 2012
      Mannequin
      More actions

      I've spent a few hours looking at xattr and the Linux/OS X (10.4+) implementations. Bob Ippolito's xattr module implements the OS X xattr interface on Linux, Solaris (9+) and FreeBSD. Linux and OS X are pretty close; FreeBSD and Solaris are substantially different from either and the Solaris implementation is somewhat incomplete/broken.

      The OS X differences from Linux are:

      • Instead of l* functions, the XATTR_NOFOLLOW option

      • XATTR_NOSECURITY and XATTR_NODEFAULT are in the headers but essentially unavailable as the kernel code always returns EINVAL for them.

      • XATTR_SHOWCOMPRESSION to expose the HFS compression stuff, which I can't imagine many people needing

      • XATTR_MAXNAMELEN (but no equivalent to XATTR_SIZE_MAX). Linux has a corresponding XATTR_NAME_MAX, which we should probably expose too.

      • XATTR_FINDERINFO_NAME and XATTR_RESOURCEFORK_NAME for some standard attribute names. I would imagine these are worth exposing.

      I don't see any problems supporting the currently exposed Linux API on OS X (I could probably find a usable value for XATTR_SIZE_MAX), but it's unclear if that is the right way to go forward.

      Suggestions?

    4. benjaminp commented on Mar 14, 2012

      @benjaminp
      benjaminp
      on Mar 14, 2012
      ContributorAuthor
      More actions

      2012/3/12 Nicholas Riley <[email protected]>:

      Nicholas Riley <[email protected]> added the comment:

      I've spent a few hours looking at xattr and the Linux/OS X (10.4+) implementations.  Bob Ippolito's xattr module implements the OS X xattr interface on Linux, Solaris (9+) and FreeBSD.  Linux and OS X are pretty close; FreeBSD and Solaris are substantially different from either and the Solaris implementation is somewhat incomplete/broken.

      The OS X differences from Linux are:

      • Instead of l* functions, the XATTR_NOFOLLOW option

      • XATTR_NOSECURITY and XATTR_NODEFAULT are in the headers but essentially unavailable as the kernel code always returns EINVAL for them.

      • XATTR_SHOWCOMPRESSION to expose the HFS compression stuff, which I can't imagine many people needing

      • XATTR_MAXNAMELEN (but no equivalent to XATTR_SIZE_MAX).  Linux has a corresponding XATTR_NAME_MAX, which we should probably expose too.

      • XATTR_FINDERINFO_NAME and XATTR_RESOURCEFORK_NAME for some standard attribute names.  I would imagine these are worth exposing.

      I don't see any problems supporting the currently exposed Linux API on OS X  (I could probably find a usable value for XATTR_SIZE_MAX), but it's unclear if that is the right way to go forward.

      Suggestions?

      Thanks for looking into this. I think the best approach at the moment
      is try to wrap these differences under the LInux API. It seems the
      biggest one will just be adding XATTR_NOFOLLOW for the l* calls.

    5. koobs commented on Jul 15, 2012

      @koobs
      koobs
      on Jul 15, 2012
      More actions

      FreeBSD (at least on 7.x, 8.x and 9.x) has the following syscalls available in its API:

      extattr_{get,set,list,delete}_{fd,file,link}

      And also has: EXTATTR_MAXNAMELEN

      http://www.freebsd.org/cgi/man.cgi?query=extattr&sektion=2&manpath=FreeBSD+9.0-RELEASE

    6. koobs commented on Jul 16, 2012

      @koobs
      koobs
      on Jul 16, 2012
      More actions

      And to clarify the no-follow-symlinks case on FreeBSD:

      extattr_{get,set,list,delete}_link "system calls behave in the same way as their _file counterparts, except that they do not follow sym-links." as per the man page.

    7. ronaldoussoren commented on Jul 26, 2013

      @ronaldoussoren
      ronaldoussoren
      on Jul 26, 2013
      Contributor
      More actions

      The OSX API also has a "position" argument for both getting and setting extended attributes. The position should be 0 for normal attributes, and can have other values when accessing the resource fork of a file.

    8. worr commented on Apr 18, 2015

      @worr
      worrmannequin
      on Apr 18, 2015
      Mannequin
      More actions

      Here's an initial attempt at implementing extended attribute support. Let me know if there's any interest.

      There's currently one deficiency, which is that the namespace isn't prepended to the attribute name when calling lsxattr.

      Let me know if my approach is good, so I can continue fixing lsxattr. All other unit tests pass.

    9. billyfoster commented on Jul 20, 2015

      @billyfoster
      billyfostermannequin
      on Jul 20, 2015
      Mannequin
      More actions

      Is there any chance of getting this finalized? I have been using William Orr's patch as a workaround for months now, but it would be nice to not have to manually apply it each version bump...

    10. ned-deily commented on Jul 25, 2015

      @ned-deily
      ned-deily
      on Jul 25, 2015
      Member
      More actions

      There certainly is interest in supporting extended attributes on additional platforms. Thanks for the patch, William, and the positive comments, Billy. Since this probably falls into the category of new feature, it should be targeted for 3.6, now that 3.5 is in feature-freeze and nearing release. The gating factor is getting a core developer to review and champion it.

    11. worr commented on Nov 5, 2015

      @worr
      worrmannequin
      on Nov 5, 2015
      Mannequin
      More actions

      After a considerable amount of rework, I've gotten something worth submitting. All unit tests pass, and it handles some of the more unfortunate differences between FreeBSD's extended attribute syscalls and Linux's.

      One of the bigger changes is that I reworked the calls to getxattr and listxattr. These used to be called with a small buffer, and if the size of the extended attribute(s) exceeded the buffer length, we'd throw out that buffer and start again with a buffer of the maximum possible attribute size allocated.

      I threw this out, and opted for always making two calls - one to get the size of the buffer, and one to actually get the contents (or list of attributes). This works the same for both FreeBSD and Linux. FreeBSD's extattr_get_* and extattr_list_* unfortunately only return the number of bytes read, *not* the number of bytes in the attribute value or the list. That means that there's no real way to determine if we've read less data than there is in the attribute.

      This passes the unit tests (on FreeBSD 10.1). I'd be interested to see results from other users and comments.

    12. ned-deily commented on Oct 10, 2018

      @ned-deily
      ned-deily
      on Oct 10, 2018
      Member
      More actions

      On 2018-10-02, worr asked on the python-dev mailing list:

      Can I get a review for #46031[PR 1690]? It fixes bpo-12978 and
      has been sitting for a handful of years now. This adds
      support for os.*xattr on DragonflyBSD, FreeBSD and NetBSD.

    13. ned-deily
      added
      3.8 (EOL)end of lifeend of life
      on Oct 10, 2018
    14. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    15. sorcio commented on Apr 28, 2023

      @sorcio
      sorcio
      on Apr 28, 2023
      Contributor
      More actions

      I wanted to pick this up, and port the PR to current Python and add support for macOS.

      There are some platform differences, and I need help deciding how to proceed. Some of these were discussed above, but let me summarize.

      1. Syscall interface on FreeBSD is substantially different. Previous work in the PR already takes care of this by wrapping the FreeBSD extattr_ API to make it closer to the Linux API. If this approach is accepted, no decision to be taken here.

      2. macOS interface is very similar to the one implemented by Linux. I decided to ignore the position argument (i.e. always pass 0), but it can be added later. So not much would need to change on the Python interface—but see the other issues.

      3. Linux uses ENODATA to signal an unset attribute. BSDs use ENOATTR. One issue here is that cross-platform code can't use errno in (ENODATA, ENOATTR) because on some platforms they are not both defined. I can see a few options:

        1. Leave it to users to check for the right error codes. This could break some code that uses if hasattr(os, 'getxattr') kind of guards and suddenly starts working on more platforms that are incompatible. One such example is in the stdlib (shutil).

        2. Make macOS/FreeBSD raise OSError with errno set to ENODATA to match the current behavior. On FreeBSD, this would mean exporting a fake ENODATA since it's not defined. Might introduce compatibility bugs in the future, if those systems decide to use ENODATA for something different. I'm not a fan of changing the meaning of constants, but this option would have the least compatibility impact with existing code, and is in line with the idea of reproducing the Linux API.

        3. Add a new exception class which inherits from OSError. Existing code would still work on Linux, and cross-platform code would need to migrate to catch the new exception. Probably my favorite option, if acceptable.

      4. macOS requires attribute names to be UTF-8, and returns an error (EINVAL) if it doesn't get valid UTF-8. Currently Python accepts either bytes, str, or a path-like. path_converter converts any string or path-like using the file system encoding, which (as far as I understand) might not be UTF-8. Probably we should not use the same converter for macOS. Should we disallow bytes on macOS? What about path-likes? Edit: disregard this, file system encoding is always UTF-8 on macOS (correct me if I'm wrong) so no issue here.

      5. Linux defines a XATTR_SIZE_MAX (max byte size of an attribute value) which is not defined in either FreeBSD or macOS. But both of them might enforce a file-system-specific limit. In the FreeBSD case, it's unclear to me if the limit is ever exposed to user code. macOS has a pathconf/fpathconf API to query the limit for a specific path, and has some special cases1. Either way, if we want to preserve compatibility, we need to make up a value for the constant.

      1. Linux also has XATTR_NAME_MAX (number of chars in an attribute name). This is currently not exposed by Python, but probably it should. macOS has an equivalent XATTR_MAXNAMELEN. FreeBSD has EXTATTR_MAXNAMELEN, but with the proposed solution (the one implemented in the PR) the semantics would be slightly different because it only applies to the attribute name without the namespace qualifier; might be good enough.

      I will prepare an updated PR. Meanwhile, I appreciate any input on these points.

      Footnotes

      1. «As a special case, the resource fork can have much larger size, and some file system specific extended attributes can have smaller and preset size; for example, Finder Info is always 32 bytes», PATHCONF(2) ↩

    16. arhadthedev
      added
      OS-freebsd
      type-featureA feature request or enhancementA feature request or enhancement
      extension-modulesC modules in the Modules dirC modules in the Modules dir
      and removed
      3.8 (EOL)end of lifeend of life
      on Apr 29, 2023
    17. ezio-melotti
      added
      OS-mac
      on Apr 29, 2023
    18. serhiy-storchaka
      added this to OS issues 💻on Jul 3, 2026
    19. github-project-automation
      moved this to Todo in OS issues 💻on Jul 3, 2026
    20. dehildum commented on Sep 21, 2026

      @dehildum
      dehildum
      on Sep 21, 2026
      More actions

      Bumping this to keep the issue live. I would like to see this resolved as I need to get/set extended attributes on macOS and the work arounds are slow.

      I see that a PR resolving this problem was completed three years ago, but never merged.

      By the way, the label type-feature is probably inappropriate, this omission should probably be considered a bug as this is a standard POSIX feature that should be supported universally in os.py.

    21. zzffeggs commented on Sep 21, 2026

      @zzffeggs
      zzffeggs
      on Sep 21, 2026 via email
      More actions
      Well noted.
      …
      On Mon, Sep 21, 2026 at 10:08 PM dehildum ***@***.***> wrote: *dehildum* left a comment (python/cpython#57187) <#57187 (comment)> Bumping this to keep the issue live. I would like to see this resolved as I need to get/set extended attributes on macOS and the work arounds are slow. I see that a PR resolving this problem was completed three years ago, but never merged. — Reply to this email directly, view it on GitHub <#57187?email_source=notifications&email_token=CI24R3PMSFJSOH4WIFNYU6T5QGKFVA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKNZWG42TGOJZHAZKM4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSWGM33PORSXEX3DNRUWG2Y#issuecomment-5767539982>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/CI24R3NG7C2H6JQZ3FMMZQT5QGKFVAVCNFSNUABEKJSXA33TNF2G64TZHM4DCNJZHA4TMMJ3JFZXG5LFHMYTCOJYHA3TGMBQHGQXMAQ> . Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS <https://github.com/notifications/mobile/ios/CI24R3MJXUDEJVDD2637W3L5QGKFVA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKNZWG42TGOJZHAZKM4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSVGM33PORSXEX3JN5ZQ> and Android <https://github.com/notifications/mobile/android/CI24R3KAVYH74B6WJ2ECSED5QGKFVA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKNZWG42TGOJZHAZKM4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSXGM33PORSXEX3BNZSHE33JMQ>. Download it today! You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      OS-freebsdOS-macextension-modulesC modules in the Modules dirC modules in the Modules dirtype-featureA feature request or enhancementA feature request or enhancement

      Projects

      • OS issues 💻
        Status
        Todo
        Show more project fields

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.