Linux::Ext2::Attributes - Manipulate Linux extended filesystem attributes.
use Linux::Ext2::Attributes qw(set_attrs :flags); set_attrs("somefile", "i"); my $attribs = Linux::Ext2::Attributes->load("somefile"); my $attribs_i = $attribs->flags; # 16 my $attribs_s = $attribs->string; # "i" $attribs->set("-i"); $attribs->save("somefile");
Linux::Ext2::Attributes provides an object-oriented interface for manipulating Linux extended filesystem attributes and a chattr-like function.
Only regular files/directories can have attributes.
set_attrs($file, $attribs) set_attrs($file, EXT2_IMMUTABLE_FL | EXT2_NOATIME_FL) set_attrs($file, "iA") set_attrs($file, "-a+iA")
Set the attributes on a filename or open file. The attributes may be an instance of Linux::Ext2::Attributes, an integer of bitwise OR'd flags or a string based on the format used by the chattr program.
Not all attributes of a file may be changed. Any read-only attributes on a file will remain unchanged.
Returns true on success, false on error.
my $attribs = Linux::Ext2::Attributes->new() my $attribs = Linux::Ext2::Attributes->new($value)
Return a new instance of Linux::Ext2::Attributes containing no flags or an arbitrary set.
my $attribs = Linux::Ext2::Attributes->load("filename") my $attribs = Linux::Ext2::Attributes->load($filehandle) my $attribs = Linux::Ext2::Attributes->load(\*FILE)
Get the attributes of a filename or open file. Returns an instance of Linux::Ext2::Attributes on success, undef on error.
$attribs->save("filename") $attribs->save($filehandle) $attribs->save(\*FILE)
Set the attributes of a filename or open file. Returns true on success, false on failure.
$attribs->set($attribs) $attribs->set(EXT2_IMMUTABLE_FL | EXT2_NOATIME_FL) $attribs->set("iA") $attribs->set("-a+iA")
Replace or modify the stored flags value. Takes the same attributes as set_attrs.
my $attribs_i = $attribs->flags()
Return the attributes as a bitwise OR'd integer (e.g. 148).
my $attribs_s = $attribs->string()
Return the attributes as a string of characters (e.g. "icA").
$attribs->strip()
Unset any read-only/system flags and return self.
$attribs->immutable() $attribs->immutable(true/false value)
Get and/or set the state of the immutable flag. Returns the current/new value.
$attribs->append_only() $attribs->append_only(true/false value)
Get and/or set the state of the append only flag. Returns the current/new value.
$attribs->flag(EXT3_JOURNAL_DATA_FL) $attribs->flag("j", true/false value)
Get and/or set the state of an arbitrary flag. Returns the current/new value.
The following flag constants are defined and may be imported using the :flags tag. Not all of them may be modified by the user or are currently implemented in the Linux kernel. For more information see the chattr man page.
EXT2_NOATIME_FL (A) - Do not update atime on access. EXT2_APPEND_FL (a) - File may only be appended to. EXT2_COMPRBLK_FL (B) - One or more compressed clusters. EXT2_COMPR_FL (c) - Compress file on disk. EXT2_DIRSYNC_FL (D) - Directory changes are synchronous. EXT2_NODUMP_FL (d) - Not backed up by dump. EXT2_ECOMPR_FL (E) - Compression error. EXT4_EXTENTS_FL (e) - File is using extents for block mapping. EXT4_HUGE_FILE_FL (h) - File is (or was) larger than 2TB. EXT2_INDEX_FL (I) - Directory is indexed using hashed trees. EXT2_IMMUTABLE_FL (i) - File may not be modified. EXT3_JOURNAL_DATA_FL (j) - Journal file data as well as metadata. EXT2_SECRM_FL (s) - File will be securely deleted when unlinked. EXT2_SYNC_FL (S) - Changes to this file are written synchronously. EXT2_TOPDIR_FL (T) - Directory is at the top of a hierarchy. EXT2_NOTAIL_FL (t) - Disable tail merging. EXT2_UNRM_FL (u) - Keep file for undeletion. EXT2_NOCOMP_FL (X) - Don't compress file. EXT2_DIRTY_FL (Z) - Compressed file is dirty.
The ioctl numbers are hardcoded into the module as they're different under 32/64-bit kernels and both are tried.
Daniel Collins, solemnwarning@solemnwarning.net
To install Linux::Ext2::Attributes, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Linux::Ext2::Attributes
CPAN shell
perl -MCPAN -e shell install Linux::Ext2::Attributes
For more information on module installation, please visit the detailed CPAN module installation guide.