LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-17-2003, 01:09 PM   #1
Mohsen
Member
 
Registered: Feb 2003
Location: Iran
Distribution: Solaris 10
Posts: 201

Rep: Reputation: 30
/dev


I'm curious to know what's the difference(s) between simple files (directories, text files, links) and those who are in /dev. mc shows two numbers instead of their size, is there any attribute flag on them? Where can I find something about them?
 
Old 09-17-2003, 03:01 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
The linux kernel controls the hardware drivers as modules or linked-in. It's part of the UNIX philosphy that "everything is a file". Through files in /dev the kernel provides an interface for programs to access hardware.

The files in /dev are special because they are not normal files, even though they live in the filesystem. All files in the filesystem have a inode, which contains information about it: last-modified time, creation time, where the contents of the file are on the disk, so it also knows the size of the file.

The files in /dev have some of these inode attributes used for different purpose: instead of the size of the file they have numbers by which the kernel recognizes them, so it knows which driver to use when a file in /dev is accessed by some program. The kernel also uses these numbers to decide which modules to load automatically when a program reads/writes to a /dev file.

Because of this the files need to be created by the special utility "mknod". Most distributions provide a script in /dev called "MAKEDEV" that calls mknod and which is easier to use.

When you ls -l normal files, the first character on each lines indicates that the file is a directory 'd', a named pipe 'p', a regular file '-', etc. In /dev the files have 'c' for character devices and 'b' for block devices.

So they are the link between the kernel and programs for devices.
Programs refer to the hardware devices by their filename, and the kernel by numbers in the inode of the file, which would normally indicate the filesize.

There are some files in /dev that are not (directly) referring to hardware, but are handled by the kernel the same way (as devices):

/dev/zero contains infinite zero-bytes
/dev/random for infinite random bytes
/dev/tty for the current terminal
/dev/null which eats everything written to it, and is always empty
/dev/full that acts like a full disk.

Last edited by Hko; 09-17-2003 at 03:13 PM.
 
Old 09-19-2003, 12:40 AM   #3
Mohsen
Member
 
Registered: Feb 2003
Location: Iran
Distribution: Solaris 10
Posts: 201

Original Poster
Rep: Reputation: 30
Thanks
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
I cannot access EITHER CD drive! And there's no /dev/hdc or /dev/hdd or /dev/cdrom! Dmalic Linux - Hardware 13 11-18-2005 07:11 PM
ln: creating symbolic link `/dev/dvd' to `/dev/hdc': Permission denied qazwsx27 Fedora 3 06-14-2005 02:09 PM
How can I boot either one of my hard drives /dev/hda or /dev/hdb, I have RH9 and FC2 omogunkristi Linux - General 1 06-21-2004 05:11 AM
Sandisk USB card Reader not linking /dev/sg0 to /dev/sda acidraven Linux - Hardware 1 06-19-2004 03:56 PM
mounting 2 ide-scsi devices /dev/cdrom and /dev/cdrom1 issue penguin123 Linux - Hardware 3 09-26-2003 08:36 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration