Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 09-23-2011, 04:58 AM   #1
Registered: Apr 2010
Location: bangalore,india
Distribution: ubuntu 9.10,CentOS 5
Posts: 120

Rep: Reputation: 16
problem opening a file from inside program.

I created a char file in my home directory with following command :

 mknod myi2c c 256 0
then changed permissions on it using :
chmod a+rw myi2c

Now i try to open the device file using following code

int main(){

int fd , ret ;
fd = open("/home/sccc/myi2c",O_RDWR) ;
if(fd < 0){
perror("myi2c open error :");
printf("myi2c opened : fd = %d\n",fd );

return 0;
it throws an error :
myi2c open error :: No such file or directory

please point out where am i going wrong.
Old 09-23-2011, 07:12 AM   #2
Senior Member
Registered: Dec 2002
Location: England
Distribution: Used to use Mandrake/Mandriva
Posts: 2,794

Rep: Reputation: 116Reputation: 116
Special files are created by the mknod(1) command and come in two flavors: block and character. Block devices can only be read from or written to one block (for example, 1024 bytes) at a time and are usually associated with disk drives, whereas character devices operate one character at a time. Since an asynchronous serial port always transmits or receives one character at a time, they are always character devices.

Special files also have major and minor numbers. The major number identifies to the operating system which device driver will service system calls on behalf of the special file,[5] and the minor number identifies to the device driver one of the possibly several hardware devices that it manages on behalf of which it must act. For example, a multiport serial card would be managed by a single device driver but provides several serial ports. Each serial port would have a correpsonding special file with the same major number but a unique minor number. The minor number enables the device driver to distinguish which serial port has been opened, read from, written to, etc.
5. Since major numbers identify device drivers, there has to be a convention specifying which number corresponds to each device driver. This can be found in the file /usr/src/linux/Documentation/devices.txt.
Did you choose the right major and minor numbers? What device/driver's servicing this file?

Last edited by Proud; 09-23-2011 at 07:13 AM.
Old 09-23-2011, 08:36 AM   #3
Registered: Apr 2010
Location: bangalore,india
Distribution: ubuntu 9.10,CentOS 5
Posts: 120

Original Poster
Rep: Reputation: 16
Originally Posted by Proud View Post you choose the right major and minor numbers? What device/driver's servicing this file?
thanks for the pointer.I 'll check that .


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How to detect opening of a file using a C program? pulkit_m Programming 10 07-21-2011 02:10 PM
Problem for Opening any file with VIM ? raviteja_s Linux - Newbie 1 10-02-2010 03:35 AM
Long file names on Linux file server jumbled when opening on 16-bit PC program. brandonhughesj General 3 03-04-2009 07:53 AM
Text file default opening program - have set, and it still ignores me! sandaili Linux - Newbie 1 09-09-2008 02:12 PM
problem with opening file function in c++ tinieprotonjam Programming 2 02-14-2007 09:48 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:32 AM.

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