in reply to Meaning of stat's 'rdev' value.
For a regular file st_rdev is 0, for a device file (e.g. /dev/tty) it holds the major and minor device numbers (assuming a POSIX like system) which can derived by masking and shifting appropriately. You can see how this is done in the source of File::Stat::Bits. The following is derived from that module:
If you want to recreate the st_rdev from the output of the stat command you want to get the values for the major and minor device type and combine them using the dev_join from File::Stat::Bits.my $tty_rdev = (stat('/dev/dsp0'))[6]; print major($tty_rdev), " ", minor($tty_rdev),"\n"; sub MAJOR_MASK () { 03777400 } sub MAJOR_SHIFT () { 0000010 } sub MINOR_MASK () { 037774000377 } sub MINOR_SHIFT () { 0000000 } sub major { my $dev = shift; return defined MAJOR_MASK ? ($dev & MAJOR_MASK) >> MAJOR_SHIFT : u +ndef; } sub minor { my $dev = shift; return defined MINOR_MASK ? ($dev & MINOR_MASK) >> MINOR_SHIFT : u +ndef; }
I'm not clear however why you want to use the external command rather than the builtin stat.
/J\
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Meaning of stat's 'rdev' value.
by palamedes (Novice) on Sep 06, 2006 at 14:51 UTC | |
|
Re^2: Meaning of stat's 'rdev' value.
by stonecolddevin (Parson) on Sep 06, 2006 at 15:09 UTC | |
by mr_mischief (Monsignor) on Sep 06, 2006 at 15:25 UTC | |
by gellyfish (Monsignor) on Sep 06, 2006 at 15:37 UTC |