FreeBSD device files

Source: Internet
Author: User

For each hardware device, the system kernel has a corresponding device driver responsible for processing it. In Unix, device files are used to represent hardware devices, and each device driver is abstracted as a device file, giving the application a consistent file interface that facilitates communication between the application and the operating system. All the device files are placed in the/dev directory.

$ ls -l /dev/rfd0 /dev/fd0
brw-r----- 9 root operator 2, 0 Nov 12 13:32 /dev/fd0
crw-r----- 9 root operator 9, 0 Nov 12 13:32 /dev/rfd0

In the list above you can see where the file size was originally displayed, and now display two comma-delimited digits instead. This is the two important serial numbers that the system uses to represent the device, the first main device number (major), which indicates the serial number of the hardware driver used by the device in the system, and the second from the device number (minor). Hardware drivers use it to differentiate between different devices and how to handle them. The main device number is represented by a 8-bit FreeBSD and 24 digits from the device number. In fact, the name of the device file is not important, it is important that the two device numbers, the operating system uses it to determine the hardware driver, and the hardware driver to communicate.

Disk and block device files

Under Unix There are two types of devices, block devices and character devices, where block devices are used primarily for random access purposes, disks are represented for this type of device, and character devices are used for sequential access purposes, such as tape or terminal equipment.

The name of the disk device is mentioned in the previous chapter, the disk device is represented by the disk name, the serial number of the disk, the ordinal of the partition, and the ordinal of the FreeBSD sub partition, for example, in the device WD0S1A, WD is the driver, then the device serial number, 0 is the first device for the driver, and the Unix The habit begins counting from 0, the third part of the partition number is S1, note that this is the first partition, because the S1 is ranked from 1 down, and the general Unix habit is different, because the concept of partitioning is a DOS concept, so here also use the order corresponding to DOS, The last A is the order of the FreeBSD, and each UFS base partition can have 8 sub partitions, which are used for different purposes, such as wd0s1a for the root file system, wd0s1b for the swap partition, and wd0s1c for the entire hard disk partition wd0s1. Therefore, fd0c can be used to access the entire floppy disk fd0, wcd0c for access to the entire disc wcd0.

A traditional name, such as wd0a, can be used to represent a child partition on the first UFS partition, such as WD0S1A. Typically, a single hard disk has only one UFS partition, so you can identify the partition directly using the traditional name.

When using the LS command list, the system uses C (character) to identify a character device file, using B (block) to identify blocks of device files.

$ ls -l /dev/*wd0s1
crw-r----- 1 root operator 3, 131072 Oct 31 19:59 /dev/rwd0s1
brw-r----- 1 root operator 0, 131072 Oct 31 19:59 /dev/wd0s1

Although the hard disk device is a block device, it is used for random access purposes. But it can also be accessed sequentially, in the same way as raw. Use raw way to access the hard disk, you need a corresponding character type of device files, corresponding to the WD0S1 hard disk device character type hard disk device for RWD0S1, the first letter in the device name uses R to indicate the raw way of the hard disk access.

Because the device file represents the entire device, you can directly access the hardware device by using the FreeBSD standard command to manipulate the device files directly in raw mode. This way, you can do a lot of useful work, but this is also very dangerous, for example, the hard disk device files will damage the entire hard disk data. Fortunately, most direct access to the device is to read the appropriate data operations, without the need to write to the disk device.

When a device is not available, its corresponding device file is not properly accessed, so direct access to the device file can determine if the corresponding device is truly normal. For example, to determine the connection to the first serial port, the mouse on the ttyd0 is working properly, using the command "cat </dev/ttyd 0" To view the input data on the TTYD0, if the connected mouse and work properly, then the screen will be moved at the same time the display of clutter received data. If there is no response, the mouse is not working correctly. But it could also be that other programs took over the device, such as the system running moused. If moused controls the mouse port, then "Cat </dev/sysmouse" will give an answer.

Cat or other commands, do not control the specific number of data received, more efficient system tool is DD, it can accurately input a certain amount of data output. For example: # dd if=/dev/rwd0 of=mbr count=1 bs=512

This will read data from the previous unit in the hard drive wd0 in 512 bytes, and be saved to a file with the name MBR, which is typically the primary boot sector on the hard disk wd0.

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.