| 1 | # Copyright (c) 2024-2025 Philipp Schafft <lion@cpan.org> | ||
| 2 | |||
| 3 | # licensed under Artistic License 2.0 (see LICENSE file) | ||
| 4 | |||
| 5 | # ABSTRACT: generic module for extracting information from filesystems | ||
| 6 | |||
| 7 | |||
| 8 | package File::Information::Filesystem; | ||
| 9 | |||
| 10 | use v5.10; | ||
| 11 | use strict; | ||
| 12 | use warnings; | ||
| 13 | |||
| 14 | use parent 'File::Information::Base'; | ||
| 15 | |||
| 16 | use Carp; | ||
| 17 | |||
| 18 | our $VERSION = v0.16; | ||
| 19 | |||
| 20 | my @_copy_properties = ( | ||
| 21 | qw(dos_device dos_path), | ||
| 22 | qw(mountpoint fs_type), | ||
| 23 | qw(linux_mount_options linux_superblock_options), | ||
| 24 | ); | ||
| 25 | |||
| 26 | my %_properties = ( | ||
| 27 | dev_disk_by_uuid => {rawtype => 'uuid'}, | ||
| 28 | dev_disk_by_label => {}, | ||
| 29 | dev_name => {}, | ||
| 30 | dev_mapper_name => {}, | ||
| 31 | (map {$_ => {}} | ||
| 32 | @_copy_properties, | ||
| 33 | ), | ||
| 34 | ); | ||
| 35 | |||
| 36 | my %_known_paths = ( | ||
| 37 | '/dev/disk/by-uuid' => 'uuid', | ||
| 38 | '/dev/disk/by-label' => 'label', | ||
| 39 | '/dev/mapper' => 'mapper', | ||
| 40 | '/dev' => 'dev', | ||
| 41 | ); | ||
| 42 | |||
| 43 | sub _new { | ||
| 44 | my ($pkg, %opts) = @_; | ||
| 45 | my $self = $pkg->SUPER::_new(%opts, properties => \%_properties); | ||
| 46 | my $pv = ($self->{properties_values} //= {})->{current} //= {}; | ||
| 47 | |||
| 48 | croak 'No stat or dirstat is given' unless defined($self->{stat}) || defined($self->{dirstat}); | ||
| 49 | croak 'No paths is given' unless defined $self->{paths}; | ||
| 50 | |||
| 51 | foreach my $key (keys %{$self->{paths}}) { | ||
| 52 | my $known = $_known_paths{$key} or next; | ||
| 53 | foreach my $value (@{$self->{paths}{$key}}) { | ||
| 54 | if ($known eq 'uuid') { | ||
| 55 | if ($value =~ __PACKAGE__->SUPER::RE_UUID) { | ||
| 56 | $pv->{dev_disk_by_uuid} = {raw => $value}; | ||
| 57 | } | ||
| 58 | } elsif ($known eq 'label') { | ||
| 59 | $pv->{dev_disk_by_label} = {raw => $value}; | ||
| 60 | } elsif ($known eq 'dev') { | ||
| 61 | $pv->{dev_name} //= {raw => $value}; | ||
| 62 | } elsif ($known eq 'mapper') { | ||
| 63 | $pv->{dev_mapper_name} //= {raw => $value}; | ||
| 64 | } | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | # Simple keys: | ||
| 69 | foreach my $key (@_copy_properties) { | ||
| 70 | if (defined $self->{$key}) { | ||
| 71 | $pv->{$key} = {raw => $self->{$key}}; | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 | return $self; | ||
| 76 | } | ||
| 77 | |||
| 78 | # ---------------- | ||
| 79 | |||
| 80 | sub _default_device_search_paths { | ||
| 81 | return state $defaults = [qw(/dev /dev/disk/by-id /dev/mapper), keys %_known_paths]; | ||
| 82 | } | ||
| 83 | |||
| 84 | 1; | ||
| 85 | |||
| 86 | __END__ | ||
| 87 | |||
| 88 | =pod | ||
| 89 | |||
| 90 | =encoding UTF-8 | ||
| 91 | |||
| 92 | =head1 NAME | ||
| 93 | |||
| 94 | File::Information::Filesystem - generic module for extracting information from filesystems | ||
| 95 | |||
| 96 | =head1 VERSION | ||
| 97 | |||
| 98 | version v0.16 | ||
| 99 | |||
| 100 | =head1 SYNOPSIS | ||
| 101 | |||
| 102 | use File::Information; | ||
| 103 | |||
| 104 | my File::Information::Filesystem $filesystem = $instance->for_link($path)->filesystem; | ||
| 105 | |||
| 106 | my File::Information::Filesystem $filesystem = $instance->for_handle($path)->filesystem; | ||
| 107 | |||
| 108 | B<Note:> This package inherits from L<File::Information::Base>. | ||
| 109 | |||
| 110 | This module represents a filesystem. A filesystem is the the stroage structure for inodes, hardlinks and maybe other types of objects. | ||
| 111 | |||
| 112 | =head1 METHODS | ||
| 113 | |||
| 114 | =head1 AUTHOR | ||
| 115 | |||
| 116 | Philipp Schafft <lion@cpan.org> | ||
| 117 | |||
| 118 | =head1 COPYRIGHT AND LICENSE | ||
| 119 | |||
| 120 | This software is Copyright (c) 2024-2025 by Philipp Schafft <lion@cpan.org>. | ||
| 121 | |||
| 122 | This is free software, licensed under: | ||
| 123 | |||
| 124 | The Artistic License 2.0 (GPL Compatible) | ||
| 125 | |||
| 126 | =cut |