LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-27-2011, 12:07 PM   #1
warrior
LQ Newbie
 
Registered: May 2011
Posts: 5

Rep: Reputation: Disabled
Lightbulb Hardware in linux


Hi there,

i would like to understand a bit better about how linux treat a piece of hardware as a file and why ?? What is the benefit of treating a hardware as a file?From this files what kind of useful info can you extract and how to do that..??

Last edited by warrior; 05-27-2011 at 12:08 PM.
 
Old 05-27-2011, 01:22 PM   #2
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
not just Linux, but all *NIX operating systems treat hardware like a file. The how is that the driver creates a special file called a device node that appears in the /dev file-system. The why is if I recall correctly mostly to make things easier for programmers to access the devices since they can use standard file in/out methods rather then have to access the device drivers directly, at least that's what I remember being told by my instructor when I was taking an intro Linux course.
 
1 members found this post helpful.
Old 05-27-2011, 02:00 PM   #3
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by frieza View Post
The why is if I recall correctly mostly to make things easier for programmers to access the devices since they can use standard file in/out methods rather then have to access the device drivers directly
Exactly. For example, to make a raw image of your disk, you don't need to write a program that calls the kernel. You can just use a normal command-line command that works on files.
 
1 members found this post helpful.
Old 05-27-2011, 10:36 PM   #4
warrior
LQ Newbie
 
Registered: May 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
thanks for the info.it helps me a lot.And would you share some more info about the benefits of treating a device as a file ??
 
Old 05-28-2011, 12:11 AM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Well, if you turn the question around, you would ask "how else would you access a device"? The semantics of accessing devices which are abstracted as files just works well. For most devices, you need to make them do something, or more accurately, tell them to do something. This is a lot like writing to a file, so why not write to a device? Similarly, when you need to get some data or status information from a device, you ask it to give it to you by reading from the device.

For years, OSes defined a fairly standard API for access to files: open(), read(), write(), close(), and a few other calls. Since this API was already understood, and a lot of the underlying code and mechanisms could be shared between IO and the filesystem, I'm sure it just made sense to the creators of Unix to extend the metaphor to device access.

The concept does lend itself very nicely to extension of support for new or different hardware. The standard API is well known, so implementing drivers becomes easier. To fit a new driver into an existing architecture, you simply create a new device node in the filesystem, and and the underlying driver works in ways similar to all of the other drivers. Application code can then be written to use various types of devices according to run-time conditions, in contrast to hardwiring the application to a particular piece of hardware.

The concept of ownership and privilege borrowed from the filesystem can also be used to provide appropriate access to devices. I'm sure there are other good reasons, but these are probably the key issues.

--- rod.
 
1 members found this post helpful.
Old 05-28-2011, 06:37 AM   #6
warrior
LQ Newbie
 
Registered: May 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
thanks a lot....
 
  


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



LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:05 PM.

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