NAME
File::ExtAttr - Perl extension for accessing extended attributes of files
SYNOPSIS
use File::ExtAttr ':all';
use IO::File;
# Manipulate the extended attributes of files.
setfattr('foo.txt', 'user.colour', 'red') || die;
my $colour = getfattr('bar.txt', 'user.colour');
if (defined($colour))
{
print $colour;
delfattr('bar.txt', 'user.colour');
}
# Manipulate the extended attributes of a file via a file handle.
my $fh = new IO::File('<foo.txt') || die;
setfattr($fh, 'user.colour', 'red') || die;
$fh = new IO::File('<bar.txt') || die;
$colour = getfattr($fh, 'user.colour');
if (defined($colour))
{
print $colour;
delfattr($fh, 'user.colour');
}
DESCRIPTION
File::ExtAttr is a Perl module providing access to the extended attributes of files.
Extended attributes are metadata associated with a file. Examples are access control lists (ACLs) and other security parameters. But users can add their own key=value pairs.
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, OpenBSD).
Extended attributes may also not be supported by your filesystem or require special options to be enabled for a particular filesystem (e.g. "mount -o user_xattr /dev/hda1 /some/path").
NOTE: The API is not stable. It may change as part of supporting multiple operating systems.
METHODS
- getfattr([$filename | $filehandle], $attrname)
-
Return the value of the attribute named
$attrname
for the file named$filename
or referenced by the open filehandle$filehandle
(which should be an IO::Handle).If no attribute is found, returns
undef
. Otherwise gives a warning. - setfattr([$filename | $filehandle], $attrname, $attrval, [$flags])
-
Set the attribute named
$attrname
with the value$attrval
for the file named$filename
or referenced by the open filehandle$filehandle
(which should be an IO::Handle).$flags
allows control of whether the attribute should be created or should replace an existing attribute's value. The valueFile::ExtAttr::XATTR_CREATE
will cause setfattr to fail if the attribute already exists. The valueFile::ExtAttr::XATTR_REPLACE
will cause setfattr to fail if the attribute does not already exist. If$flags
is omitted, then the attribute will be created if necessary or silently replaced.If the attribute could not be set, a warning is given.
- delfattr([$filename | $filehandle], $attrname)
-
Delete the attribute named
$attrname
for the file named$filename
or referenced by the open filehandle$filehandle
(which should be an IO::Handle).Returns true on success, otherwise false and a warning is given.
EXPORT
None by default.
You can request that getfattr
, setfattr
and delfattr
be exported using the tag ":all".
Exportable constants
None
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.
Various low-level APIs exist for manipulating extended attributes:
- Linux
- OpenBSD
- FreeBSD
- NetBSD
-
http://netbsd.gw.com/cgi-bin/man-cgi?extattr_get_file+2+NetBSD-current
- Mac OS X
- Solaris
-
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
AUTHOR
Kevin M. Goess, <kgoess@ensenda.com>
Richard Dawe, <rich@phekda.gotadsl.co.uk>
COPYRIGHT AND LICENSE
Copyright (C) 2005 by Kevin M. Goess
Copyright (C) 2005, 2006 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.