Operating System - HP-UX
1833187 Members
3206 Online
110051 Solutions
New Discussion

Re: can you tell me the difference of character device file and block device file?

 
SOLVED
Go to solution
常有慈悲心
Regular Advisor

can you tell me the difference of character device file and block device file?

why use :pvcreate /dev/rdsk/c2t5d0
but use: vgcreate vg01 /dev/dsk/c2t5d0

can you tell me the rule of use c device file
or b device file?
9 REPLIES 9
RAC_1
Honored Contributor

Re: can you tell me the difference of character device file and block device file?

I will try to explain.

pvcreate prepares the disk to be used as LVM disk. vgcreate understand only blocks. So block device must be used.

Anil
There is no substitute to HARDWORK
Nicolas Dumeige
Esteemed Contributor

Re: can you tell me the difference of character device file and block device file?

Hello,

When dealing with IO, the device can read and write without buffer, one caracter at a time - aka caracter device - or using a buffer feed with various caracter, a block of data - aka block device.

Cheers

Nicolas
All different, all Unix
Muthukumar_5
Honored Contributor

Re: can you tell me the difference of character device file and block device file?

character device file uses data's by character by character stream

block device files are uing data's by byte by byte stream

You can detect a file is weather character or block using it's permissions as,
b--------- -- block device
c--------- -- character device

Easy to suggest when don't know about the problem!
Cheryl Griffin
Honored Contributor
Solution

Re: can you tell me the difference of character device file and block device file?

As a general rule of thumb any command that deals with the disk at a physical level, you will use the character device (rdsk).

For instance diskinfo, pvcreate.

The vgcreate, vgextend command is not at the physical level, so you would use the block device (dsk).
"Downtime is a Crime."
常有慈悲心
Regular Advisor

Re: can you tell me the difference of character device file and block device file?

but newfs -F vxfs /dev/vg00/rlvol9 ?
why also use character file?
Geoff Wild
Honored Contributor

Re: can you tell me the difference of character device file and block device file?

Because newfs is a front-end to the mkfs command - which layouts a filesystem on the disk/logical volume ( a character (raw) special device).

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Bill Hassell
Honored Contributor

Re: can you tell me the difference of character device file and block device file?

Think of the character or raw device files as just dumb disks with a bunch of data sectors. The blocked device files use a driver that understands files (well, inodes) and routes that data through a buffer cache for performance. But when you are manipulating the unformatted disk (ie, pvcreate or newfs) there is no filesystem at all. Don't worry too much about the differences--the commands will tell whether a raw or blocked device file is required. Some commands don't care (not many) and automatically track down the right device file.


Bill Hassell, sysadmin
Saravanan_11
Occasional Advisor

Re: can you tell me the difference of character device file and block device file?


Block devices uses a buffering mechanism. So they can choose by which order to respond for requests.
This is important in the case of storage devices, where it's faster to read or write sectors which are close to each other, rather than those which are further apart.

Character devices are not using buffering mechanism to interact with the kernel.

Another one more difference is that block devices can only accept input and return output in blocks (whose size can vary according to the device), whereas character devices are allowed to use as many or as few bytes as they like.

We can determine the type of device by using , ls -l of that device.

example

# ll /dev | grep brw
brw-r----- 1 bin sys 255 0xffffff Jun 15 05:43 root
# ll /dev | grep crw
crw------- 1 root sys 1 0x000080 Apr 16 07:08 GSPdiag1
crw-rw-rw- 1 root root 72 0x000013 Jul 29 08:29 arp
#

-Saravanan
Jose Mosquera
Honored Contributor

Re: can you tell me the difference of character device file and block device file?

Hi,

As you know, there are tow main types of device files: block and character, represented by the character b and c, respectively. All I/O devices can be classified as block or character. Then:

Block device files transfer data using the system buffers to speed up I/O transfer.
Storage devices such as tape drives, hard and floppy disks, and magneto-optic drives can use block device files.

Character device files transfer data blocks of varying sizes one character at a time without using the system's I/O buffers. The user program does its own buffering. Typically the following devices use character device files: terminals, printers, plottters, digitizers, magnetic tape drives, cartridge tape drives, and disk mass storage devices. Chracter I/O tranfer is also called raw I/O transfer, and sometimes characters devices are called raw devices.

Disk drives generally need both block and character device files. The file system access ordinary files and directories with block device files, using the buffer cache for speed. A database can use a character device file to access an area of the disk that the file system does not use. File system integrity is checked using fsck through the character device file, since fsck requires low-level control of teh device.

For complementary info pls check man pages of the fsck and newfs commands.

Rgds.