File::ExtAttr(3pm)
π¦ NAME π¦
okay so bestie, meet File::ExtAttr β a Perl extension for accessing extended attributes of files. literally what it says on the tin, no gatekeeping π
β¨ SYNOPSIS β¨
here's the whole vibe, copy-paste ready:
use File::ExtAttr ':all';
use IO::File;
# Manipulate the extended attributes of files.
setfattr('foo.txt', 'colour', 'red') || die;
my $colour = getfattr('bar.txt', 'colour');
if (defined($colour))
{
print $colour;
delfattr('bar.txt', 'colour');
}
# Manipulate the extended attributes of a file via a file handle.
my $fh = new IO::File('<foo.txt') || die;
setfattr($fh, 'colour', 'red') || die;
$fh = new IO::File('<bar.txt') || die;
$colour = getfattr($fh, 'colour');
if (defined($colour))
{
print $colour;
delfattr($fh, 'colour');
}
# List attributes in the default namespace.
print "Attributes of bar.txt:\n";
foreach (listfattr($fh))
{
print "\t$_\n";
}
# Examine attributes in a namespace-aware manner.
my @namespaces = listfattrns($fh);
foreach my $ns (@namespaces)
{
print "Attributes in namespace '$ns': ";
my @attrs = listfattr($fh, { namespace => $ns });
print join(',', @attrs)."\n";
}
πΈ DESCRIPTION πΈ
So File::ExtAttr is a Perl module that gives you access to the extended attributes of files. π«Ά
Extended attributes are literally metadata that's attached to a file. Like, the examples are access control lists (ACLs) and other security parameters. But also?? users can just add their own key=value pairs. iconic behaviour honestly π
β οΈ Heads up bestie: extended attributes may not be supported by your operating system. This module is aimed at Linux, Unix or Unix-like operating systems (e.g.: Mac OS X, FreeBSD, NetBSD, Solaris).
And it's not just your OS that has beef β extended attributes may also not be supported by your filesystem, or they might need special options enabled for a particular filesystem. E.g.:
mount -o user_xattr /dev/hda1 /some/path
π» Supported OSes
- Linux
- Mac OS X
- FreeBSD 5.0 and later
- NetBSD 4.0 and later
- Solaris 10 and later
π« Unsupported OSes
- OpenBSD
π Namespaces
Some implementations of extended attributes support namespacing. In those implementations, the attribute is referred to by namespace and attribute name. iykyk.
- Linux β The primary namespaces are
"user"for user programs;"security","system"and"trusted"for file security/access-control. See <http://www.die.net/doc/linux/man/man5/attr.5.html> for more details.
Namespaces on Linux are described by a string, but only certain values are supported by filesystems. In general "user", "security", "system" and "trusted" are supported, by others may be supported -- e.g.: "os2" on JFS. File::Extattr will be able to access any of these.
- FreeBSD, NetBSD β *BSD have two namespaces:
"user"and"system".
Namespaces on *BSD are described by an integer. File::ExtAttr will only be able to access attributes in "user" and "system".
- Mac OS X β OS X has no support for namespaces.
- Solaris β Solaris has no support for namespaces.
π© Flags
The functions take a hash reference as their final parameter, which can specify flags to modify the behaviour of the functions. The flags specific to a function are documented in the function's description. periodt.
All functions support a "namespace" flag. E.g.:
use File::ExtAttr ':all';
use IO::File;
# Manipulate the extended attributes of files.
setfattr('foo.txt', 'colour', 'red') || die;
my $colour = getfattr('bar.txt', 'colour', { namespace => 'user');
If no namespace is specified, the default namespace will be used. On Linux and *BSD the default namespace will be "user". π
π METHODS π
getfattr([$filename | $filehandle], $attrname, [\%flags])β Return the value of the attribute named$attrnamefor the file named$filenameor referenced by the open filehandle$filehandle(which should be anIO::Handleor subclass thereof).
If no attribute is found, returns "undef". Otherwise gives a warning.
setfattr([$filename | $filehandle], $attrname, $attrval, [\%flags])β Set the attribute named$attrnamewith the value$attrvalfor the file named$filenameor referenced by the open filehandle$filehandle(which should be anIO::Handleor subclass thereof).
%flags allows control of whether the attribute should be created or should replace an existing attribute's value. If the key "create" is true, setfattr will fail if the attribute already exists. If the key "replace" is true, setfattr will fail if the attribute does not already exist. If neither is specified, then the attribute will be created (if necessary) or silently replaced.
If the attribute could not be set, a warning is issued.
π Note that"create"cannot be implemented in a race-free manner on *BSD. If your code relies on the"create"behaviour, it may be insecure on *BSD. be careful bestie, fr fr.
delfattr([$filename | $filehandle], $attrname, [\%flags])β Delete the attribute named$attrnamefor the file named$filenameor referenced by the open filehandle$filehandle(which should be anIO::Handleor subclass thereof).
Returns true on success, otherwise false and a warning is issued.
listfattr([$filename | $filehandle], [\%flags])β Return an array of the attributes on the file named$filenameor referenced by the open filehandle$filehandle(which should be anIO::Handleor subclass thereof).
Returns undef on failure and $! will be set.
listfattrns([$filename | $filehandle], [\%flags])β Return an array containing the namespaces of attributes on the file named$filenameor referenced by the open filehandle$filehandle(which should be anIO::Handleor subclass thereof).
Returns undef on failure and $! will be set.
π¦ EXPORT π¦
None by default. π
You can request that getfattr, setfattr, delfattr and listfattr be exported using the tag ":all". slay.
Exportable constants
None β¨
π BUGS π
You cannot set empty attributes on Mac OS X 10.4 and earlier. And like, that's a bug in Darwin, rather than File::ExtAttr. not us, not our problem, we're just the messenger bestie π
π SEE ALSO π
The latest version of this software should be available from its home page: <http://sourceforge.net/projects/file-extattr/>
OS2::ExtAttr provides access to extended attributes on OS/2.
Eiciel, <http://rofi.pinchito.com/eiciel/>, is an access control list (ACL) editor for GNOME; the ACLs are stored in extended attributes. cute.
Various low-level APIs exist for manipulating extended attributes:
- Linux
- OpenBSD β OpenBSD 3.7 supported extended attributes, although support was never built into the default GENERIC kernel. Its support was documented in the
"extattr"man page:
Support was removed in OpenBSD 3.8 -- see the CVS history for the include file "sys/extattr.h". π
<http://www.openbsd.org/cgi-bin/cvsweb/src/sys/sys/Attic/extattr.h>
- FreeBSD β FreeBSD >= 5.0 supports extended attributes.
- NetBSD β NetBSD >= 3.0 supports extended attributes, but you'll need to use NetBSD >= 4.0 to get UFS filesystem support for them.
<http://netbsd.gw.com/cgi-bin/man-cgi?extattr_get_file+2+NetBSD-current>
<http://www.netbsd.org/Changes/changes-4.0.html#ufs>
- Mac OS X
- Solaris
attropen(3C),fsattr(5)- <http://docsun.cites.uiuc.edu/sun_docs/C/solaris_9/SUNWaman/hman3c/attropen.3c.html>
- <http://docsun.cites.uiuc.edu/sun_docs/C/solaris_9/SUNWaman/hman5/fsattr.5.html>
- Solaris also has extensible system attributes, which are used by Solaris's CIFS support on ZFS, and have a confusingly similar name to extended file attributes. These system attributes are stored in extended file attributes called
SUNWattr_roandSUNWattr_rw. See PSARC 2007/315 for more details:
<http://opensolaris.org/os/community/arc/caselog/2007/315/spec-final-txt/>
π AUTHOR π
Kevin M. Goess, <kgoess@ensenda.com>
Richard Dawe, <richdawe@cpan.org>
π COPYRIGHT AND LICENSE π
Copyright (C) 2005 by Kevin M. Goess
Copyright (C) 2005, 2006, 2007, 2008 by Richard Dawe
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.5 or, at your option, any later version of Perl 5 you may have available.
and that's the whole thing babes π«Ά this little drop came to you from the User Contributed Perl Documentation section of the manual, churned out by perl v5.42.3, dated 2026-08-20 β go forth and set some attributes, you absolute icon πβ¨ππ¦
π¦ where this page comes from
- ubuntu stonking: libfile-extattr-perl 1.09-7build1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms