bugfindutils - Bugs: bug #46791, wishlist: no option to find...

 
 

bug #46791: wishlist: no option to find devices for major/minor

Submitter:  Andreas Metzler <ametzler>
Submitted:  Sat 02 Jan 2016 01:24:08 PM UTC
   
 
Category:  find Severity:  1 - Wish
Item Group:  None Status:  None
Privacy:  Public Assigned to:  berny
Originator Name:  Marc Haber Open/Closed:  Open
Release:  4.6.0 Fixed Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 06 Jan 2025 09:56:00 PM UTC, comment #5: 

I see that adding such predicates is almost trivial, as the implementation has
just to evaluate the already known value of 'struct stat' member 'rdev', and we
already deal with major/minor numbers in -ls,-fls (although not in -printf).

I also don't see that this would add much risks or bloat, so it may fit quite
well into find(1).
As such, I'm hereby re-opening this one for discussion.

As for the user interface, I'd rather avoid messy parsing of the "x:y" syntax,
and instead use the gear we already have for other numerical comparisons
(-inum, -gid, -uid, -size, -links) which additionally allows the comparison
with +N (COMP_GT), -N (COMP_LT) and exactly N (COMP_EQ).


# Search the device with number '1:3'.
$ find /dev -major 1 -minor 3 -exec ls -logd '{}' +
crw-rw-rw- 1 1, 3 Jan  5 23:14 /dev/null

# Search all devices with major number <2.
$ find /dev -major -2 -exec ls -logd '{}' +
crw-rw-rw- 1 1,  7 Jan  5 23:14 /dev/full
crw-r--r-- 1 1, 11 Jan  5 23:14 /dev/kmsg
crw-r----- 1 1,  1 Jan  5 23:14 /dev/mem
crw-rw-rw- 1 1,  3 Jan  5 23:14 /dev/null
crw-r----- 1 1,  4 Jan  5 23:14 /dev/port
crw-rw-rw- 1 1,  8 Jan  5 23:14 /dev/random
crw-rw-rw- 1 1,  9 Jan  5 23:14 /dev/urandom
crw-rw-rw- 1 1,  5 Jan  5 23:14 /dev/zero

# Search for all devices with minor number >300.
$ find /dev -type c -minor +300 -exec ls -logd '{}' +
crw-rw-r-- 1 189, 384 Jan  5 23:14 /dev/bus/usb/004/001
crw-rw-r-- 1 189, 385 Jan  5 23:14 /dev/bus/usb/004/002
crw-rw-r-- 1 189, 386 Jan  5 23:14 /dev/bus/usb/004/003


I prototyped that as new predicate names '-major N -minor N',
but I'm not strictly opposed to use more descriptive yet longer names
like '-devmajor N -devminor N' or even '-rdev_major N -rdev_minor N'
to emphasize that this test is limited to char+block devices.

I'm not sure one would rather like to see a combined '-rdev' test, as
e.g. one wouldn't really search with '-rdev 259' for '/dev/null', would one?

Missing at this point: doc (man+texi), tests.

FWIW: the suggested '-major N -minor N' even works for '0:0' devices
found in '/run/systemd/inaccessible/' on my system.

Opinions, objections, ...?

(file #56745)

Bernhard Voelker <berny>
Group administrator
Tue 24 Dec 2024 08:19:49 AM UTC, comment #4: 

That debian bug report is 18 years old and didn't get much love.

You could instead use my rawhide (rh) program (an alternative to find(1)). It is mentioned in the debian bug report you refer to. rh can include major/minor device numbers in its search criteria. For example, if you want to find all mountpoints to a specific device (named "/dev/specific" here), then something like this should do the trick:

    rh / 'dev == "/dev/specific".dev'

Note that "dev" combines "major" and "minor" which could alternatively be used separately. "dev" combines them into a single number in whatever way makes sense for the current platform (struct stat's st_dev field).

But that would find all paths on that device (not just the mountpoint). If you want to only find the mountpoint, you would need to include "prune" or (more probably) "trim":

    rh / 'dev == "/dev/specific".dev && trim'

Rawhide is at:

    https://raf.org/rawhide
    https://github.com/raforg/rawhide
    https://codeberg.org/raforg/rawhide

raf <raf>
Tue 24 Dec 2024 05:40:07 AM UTC, comment #3: 

Quoting Chris Dunlop on https://bugs.debian.org/397434

Just to add a voice...

My use case is to search for all the alternate paths to a specific device.

I was quite surprised to discover that find doesn't support searching by
major:minor, to the naive eye it looks like something that fits directly into
the existing options that search on the stat structure.

I can of course use multiple tools (e.g. find + awk) to do what I need
but it would be nice if "find" were able to do this directly.

tl;dr...

Whilst a ATA security erase is in progress on a device (e.g. hdparm
--security-erase), all other open()s of the device go into an unkillable sleep
(wchan:blkdev) until the security erase completes - this can take many minutes
to >24 hours (e.g. 20T HDD).

This means anything that performs device scans will go into an unkillable
sleep for the duration, e.g. various utilities from LVM2 like "pvs" and "lvs".
I have regular operations that require such scans and blocking for an hour,
let alone 24 hours, is problematic.

LVM2 scans /dev, /sys/dev/block and /sys/block for all block devices and tries
to open them, subject to a configurable "device filter" that can filter
devices by filesystem path name.

So I need to find all the paths to a specific major:minor to reject those
paths using the LVM2 device filter.

An alternate "coding required" solution would be for LVM2 to utilise
major:minor in it's device filter. This in fact would be the best solution to
this specific problem (other than secure erase not blocking) and I'll see if
it's possible to have this added to LVM2.

Andreas Metzler <ametzler>
Sun 26 May 2024 12:19:55 PM UTC, comment #2: 

No response in 7y, closing.

James Youngman <jay>
Group administrator
Sun 03 Jan 2016 06:35:03 PM UTC, comment #1: 

I commented upstream.  The feature request needs a more thoughtful justification to convince me to spend time on this feature in particular (instead of other enhancements to findutils, for example).

James Youngman <jay>
Group administrator
Sat 02 Jan 2016 01:24:08 PM UTC, original submission:  

Hello,
this is a re-submission of http://savannah.gnu.org/support/?105661

Marc Haber writes in http://bugs.debian.org/397434
-----------------
find does not have the ability to find device nodes with given
major/minor number. It should.

Greetings
Marc

Andreas Metzler <ametzler>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #56745:  0001-FIXME-find-add-major-and-minor-predicate-to-search-f.patch added by berny (10KiB - text/x-patch - [PATCH] [POC/RFC] find: add -major and -minor predicate to search for device numbers)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by berny (Updated the item)
  • -email is unavailable- added by raf (Posted a comment)
  • -email is unavailable- added by jay (Posted a comment)
  •  

    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.

     

    Follow 11 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2025-01-06 berny Attached File- Added 0001-FIXME-find-add-major-and-minor-predicate-to-search-f.patch, #56745
        StatusObsolete None
        Assigned tojay berny
        Open/ClosedClosed Open
    2024-05-26 jay StatusNeed Info Obsolete
        Open/ClosedOpen Closed
    2016-01-03 jay Severity3 - Normal 1 - Wish
        StatusNone Need Info
        Assigned toNone jay
        ReleaseNone 4.6.0
    2016-01-02 ametzler Carbon-CopyRemoved 20807 -

    Back to the top

    Powered by Savane 3.14-430a.
    Corresponding source code