Special Device Files

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.