Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!ccut!wnoc-tyo-news!toumon!wucc!ytsuji From: ytsuji@wucc.waseda.ac.jp (Y.Tsuji) Newsgroups: comp.sys.atari.st Subject: Re: Can GCC treat printer like Summary: file descriptor for raw devices Message-ID: <5614@wucc.waseda.ac.jp> Date: 8 May 91 22:13:50 GMT References: <1912@do.maus.de> Distribution: world,comp Organization: The Centre for Informatics, WASEDA Univ. Lines: 28 It's up to you whether to make use of the TOS Fopen() or not when you implement your own open() in your own C library. For ordinary files, the value returned will be similar to what other OS (i.e. unix) expects, but when it comes to raw devices (/dev/tty,/dev/lpt,/dev/fd0 etc), you need to be a bit inventive. What I have done is this: (1) for keyboard/monitor, parallel port, and RS232C port, the returned value by Fopen will be respected but not used. Instead values 128, 129,130 will be given. (The returned value of fffe etc will be kept internally). (2) for other devices e.g. disk drives and midi ports, the same trick will be applied. drive A will be assigned 256, drive B 257 etc. However, as drives are block devices, read/write and lseek can be done only in units of 512. And we must keep a file pointer for each device. There is no way of knowing the basic features of the device as read/write is normally done to disks that are physically formatted but may lack boot sector info. I simply followed the nomenclature of minix. At any event, I needed a file descriptor table internally that keeps info to be given to stat() and fstat(). That table also keeps the name of the file descriptor (I sometimes needed to know the name of the file from the file descriptor). Read/write of raw device is necessary in such cases as reformatter(re-initialises the boot sector,FATs and directory) and TAR. Another thing I needed to use my brain a bit is giving i-node numbers( real id number of files). I think I better keep this secret to myself so as not to bore you to death. Dr Y. Tsuji ytsuji@cfi.waseda.ac.jp