bugfindutils - Bugs: bug #64088, find should support file attribute...

 
 

bug #64088: find should support file attribute flags (immutable, append-only, fscrypt, etc.)

Submitter:  None
Submitted:  Fri 21 Apr 2023 10:55:41 PM UTC
   
 
Category:  find Severity:  3 - Normal
Item Group:  None Status:  None
Privacy:  Public Assigned to:  None
Originator Name:  Andreas Dilger Originator Email:  -email is unavailable-
Open/Closed:  Open Release:  None
Fixed Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sat 03 Jun 2023 03:18:02 AM UTC, comment #2: 

original submission:

>     ioctl(fd, FS_IOC_GETFLAGS, &flags);


On some other systems, it's easier. FreeBSD, OpenBSD, NetBSD, and macOS (probably all BSDs) have an st_flags field in their stat structure, and these attributes/flags are there. But which flags are available differ between systems. The symbols for them are defined in <sys/stat.h>, and the user-facing names (and some aliases) are listed in the respective manual entries for chflags(1).

raf <raf>
Sun 23 Apr 2023 12:08:09 AM UTC, comment #1: 

Another method (Linux only) is to use the functions in libe2p which is part of the libext2fs-dev package on Debian.

I've written a find-alternative called "rawhide" that can search for these attributes (and project and version numbers) using fgetflags(), fgetproject() and fgetversion() from that library.

I was going to suggest copying the code from rawhide but with libe2p, it's just a single function call for each. But you might want to copy the underlying code from libe2p itself if you want to avoid the dependency.

As for the %e, that's a great choice. That's what rawhide uses for the same purpose. I'd hate to see the %-notation for find and rawhide get out of sync.

raf <raf>
Fri 21 Apr 2023 10:55:41 PM UTC, original submission:  

It should be possible to use find to locate files and directories with or without specific file attribute flags, such as append-only, immutable, nodump, fscrypt, verity, dax, projinherit, etc.

Some of these flags are Linux-specific, or filesystem-specific, but some of them are available on multiple OSes and filesystems (e.g. append-only, immutable, nodump).   On Linux the file attributes are available via the "statx(3)" syscall so there is no extra overhead to fetching them, otherwise if statx(3) is not available they can be accessed on multiple filesystems (ext2, ext4, XFS, btrfs, etc.) via:

    long flags;

    ioctl(fd, FS_IOC_GETFLAGS, &flags);

This allows finding e.g. files that meet specific security or administrative requirements (e.g. should be immutable, encrypted, have project quotas, etc.).

I would suggest to use "[!] -attr [^]ATTR[,[^]ATTR]" to find files with/without the named attributes. [^] means files do NOT have the named attribute, which allows specifying a mix of attributes that are or are not set on a single file, as opposed to unlisted attributes that are ignored.

It should also be possible to print a comma-separated list of file attribute names (or hex number for unknown attributes) with "-printf", possibly "%e" could be used (vs. "%x" for -xattr which is different), since it is unused by both "find" and "stat(1)".

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by raf (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    No changes have been made to this item

    Back to the top

    Powered by Savane 3.12.
    Corresponding source code