St_dev and st_rdev:
The storage devices of each file system are represented by the Primary and Secondary device numbers.
The data type used by the device number is the basic system data type dev_t.
The main device ID identifies the device driver, which is sometimes coded as a peripheral board for communications with it; the secondary device number identifies a specific sub-device.
For example, a disk drive often contains several file systems.
File Systems on the same disk drive usually have the same primary device number, but their secondary device numbers are different.
We can usually use two macros, major and minor, to access the master and secondary device numbers. Most implementations define these two macros.
In Linux, macro major and minor are defined in the header file <sys/sysmacros. h>, which is included in <sys/type. h>.
# Include "apue. H"
// # Ifdef Solaris
// # Include <sys/mkdev. h>
// # Endif
# Include <sys/sysmacros. h>
Int main (INT argc, char * argv [])
{
Int I;
Struct stat Buf;
For (I = 1; I <argc; I ++)
{
Printf ("% s:", argv [I]);
If (STAT (argv [I], & BUF) <0)
{Err_ret ("stat error ");
Continue;
}
Printf ("Dev = % d/% d", Major (BUF. st_dev), minor (BUF. st_dev ));
If (s_ischr (BUF. st_mode) | s_isblk (BUF. st_dev ))
{
Printf ("(% s) rdev = % d/% d ",
(S_ischr (BUF. st_mode ))? "Character": "Block ",
Major (BUF. st_rdev), minor (BUF. st_rdev ));
}
Printf ("\ n ");
}
Exit (0 );
}
Special Device Files