LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-23-2011, 04:58 AM   #1
avee137
Member
 
Registered: Apr 2010
Location: bangalore,india
Distribution: ubuntu 9.10,CentOS 5
Posts: 120

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


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

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

Now i try to open the device file using following code
Code:
#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>
#include<sys/types.h>
#include<sys/stat.h>


int main(){

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

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

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

Rep: Reputation: 116Reputation: 116
http://frank.harvard.edu/~coldwell/t...pecial%20Files
Quote:
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.
Quote:
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
avee137
Member
 
Registered: Apr 2010
Location: bangalore,india
Distribution: ubuntu 9.10,CentOS 5
Posts: 120

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by Proud View Post
http://frank.harvard.edu/~coldwell/t...pecial%20FilesDid you choose the right major and minor numbers? What device/driver's servicing this file?
thanks for the pointer.I 'll check that .
 
  


Reply


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

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

All times are GMT -5. The time now is 08:32 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration