The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Linux::Ext2::Attributes - Linux ext2/3/4 filesystem attributes.

SYNOPSIS

  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");

DESCRIPTION

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.

SUBROUTINES

set_attrs

  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.

METHODS

new

  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.

load

  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.

save

  $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.

set

  $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.

flags

  my $attribs_i = $attribs->flags()

Return the attributes as a bitwise OR'd integer (e.g. 148).

string

  my $attribs_s = $attribs->string()

Return the attributes as a string of characters (e.g. "icA").

strip

  $attribs->strip()

Unset any read-only/system flags and return self.

immutable

  $attribs->immutable()
  $attribs->immutable(true/false value)

Get and/or set the state of the immutable flag. Returns the current/new value.

append_only

  $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.

flag

  $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.

FLAGS

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.

COPYRIGHT AND LICENSE

Copyright (C) 2012,2013 Daniel Collins <solemnwarning@solemnwarning.net>

This library is free software; you may redistribute it and/or modify it under the same terms as Perl itself.