In Linux world, I learnt that there is corresponding file that user space program communicates with, in order to actually communicate with any hardware device , for example, below are the files for devices,
CD and DVD drives :
PATA hard disks:
My understanding is,
In Linux world(unlike windows), apart from file storage, file system is also used for IO communication.
So, device driver for any corresponding hardware device actually populates the data in such files(say
/dev/sd*) which is actually the data sent/received from/to device. This enables user space program to read/write from/to devices using these files. for example, below is the user space program using C,
int fd; struct termios *oldser,*newser,*oldter,*newter; oldser=(struct termios *)malloc(sizeof(struct termios)); newser=(struct termios *)malloc(sizeof(struct termios)); oldter=(struct termios *)malloc(sizeof(struct termios)); newter=(struct termios *)malloc(sizeof(struct termios)); fd=openSerial("/dev/ttyS1"); setSerial(fd,oldser,newser); /* next stop echo and buffering for stdin */ tcgetattr(0,oldter); tcgetattr(0,newter); /* get working stdtio */
When you say, Everything is file or process,
Does that mean my above understanding on performing IO using file in Linux kernel(or UNIX)? Please correct me.