T
Tomasz Chmielewski
I want to check if a given block device is already used by the system
(i.e. device is mounted, used for swap, part of a RAID array etc.).
In short, it can be done with:
use Fcntl qw(O_RDONLY O_EXCL);
my $path = "/dev/sda";
sysopen(FH, $path, O_RDONLY | O_EXCL) or die $!;
If /dev/sda is really used, the script will die with
"Device or resource busy" error message (depending on locales).
Low level, it can be seen as:
open("/dev/sda", O_RDONLY|O_EXCL|O_LARGEFILE) = -1 EBUSY (Device or resource busy)
The script will also die if the file does not exist - looking
low level it would be:
open("/dev/blah", O_RDONLY|O_EXCL|O_LARGEFILE) = -1 ENOENT (No such file or directory)
I want the script to take a specified action depending on
the error (EBUSY, ENOENT, etc.).
How can I read these values?
(i.e. device is mounted, used for swap, part of a RAID array etc.).
In short, it can be done with:
use Fcntl qw(O_RDONLY O_EXCL);
my $path = "/dev/sda";
sysopen(FH, $path, O_RDONLY | O_EXCL) or die $!;
If /dev/sda is really used, the script will die with
"Device or resource busy" error message (depending on locales).
Low level, it can be seen as:
open("/dev/sda", O_RDONLY|O_EXCL|O_LARGEFILE) = -1 EBUSY (Device or resource busy)
The script will also die if the file does not exist - looking
low level it would be:
open("/dev/blah", O_RDONLY|O_EXCL|O_LARGEFILE) = -1 ENOENT (No such file or directory)
I want the script to take a specified action depending on
the error (EBUSY, ENOENT, etc.).
How can I read these values?