Multiple open calls to a character file

Multiple open calls to a character file

Post by Nicholas Thaye » Wed, 21 Mar 2001 09:57:16



Hello,
    I've hooked a peripheral scsi device up to my Ultra30, performed
'probe-scsi-all' at the boot prompt, and then booted the machine with
'boot -r', which created the character device file for me.  My
application then talks through this device file to the scsi device by
calling 'open', performing the appropriate scsi operation, and a
subsequent 'close' when the command is done.  My problem is that I want
to call 'open' on that device file multiple times without issuing a
'close'.  The first 'open' is always successful, but I can't figure out
how to make the 'open' return a valid file descriptor (> -1) on
subsequent 'open' calls.

Thanks for your help,
Nicholas

 
 
 

Multiple open calls to a character file

Post by Bruce Adle » Thu, 22 Mar 2001 02:12:18



> Hello,
>     I've hooked a peripheral scsi device up to my Ultra30, performed
> 'probe-scsi-all' at the boot prompt, and then booted the machine with
> 'boot -r', which created the character device file for me.  My
> application then talks through this device file to the scsi device by
> calling 'open', performing the appropriate scsi operation, and a
> subsequent 'close' when the command is done.  My problem is that I want
> to call 'open' on that device file multiple times without issuing a
> 'close'.  The first 'open' is always successful, but I can't figure out
> how to make the 'open' return a valid file descriptor (> -1) on
> subsequent 'open' calls.

You're probably doing something wrong. But it's kind of pointless
for anyone to try to guess what you're doing wrong if you don't say
exactly what the error code is or exactly what code sequences you're
trying. In fact you haven't even specified what kind of SCSI device
and what pathname you're trying to open so it's not even safe to
assume that whatever device driver you're opening supports multiple
opens.

 
 
 

1. Open multiple files with open() from stdin.PLEASE HELP

Please help me.
Im having problems opening multiple files from stdin.
Mainly large files,(/usr/bin).

All I want to do is pipe ls from command line into program.

Here is test version of myprogram:

/*header files*/
#include<sys/types.h>
#include<sys/stat.h>
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#include<ctype.h>

/*prototypes*/
int fd;

main(int argc,char *argv[])
{
 char file[80];
 int fd;

 while(fscanf(stdin,"%s",file) != EOF)
 {
  if ((fd=open(file,O_RDONLY))==-1)
   fprintf(stdout,"error opening file %s *** %d\n",file,fd);
  else
   fprintf(stdout,"ok opening file %s *** %d\n",file,fd);
  close(fd);
 }

 return 0;
**********************************

when I open files in my local directory(which contains small text files)
works
ok: #ls | myprogram

but any other directory, returns -1 when trying to open a file.
ls /usr/bin | myprogram  (cannot open files)

Please help,

Thank you very much.

2. RedHat4 vs Slackware96?

3. how to read a text file and write it into a new file character by character?

4. How do I set up a local printer?

5. Need help in opening a character special file....

6. OS5 with Digi Portserver II

7. Character string substitution for multiple files

8. Securing Linux For Web/FTP Serving

9. Solution: multiple Apache log files, multiple args to env=, multiple conditions to CustomLog directive

10. Character string substitution with multiple files

11. Need help for opening a character special file....

12. How to replace specific characters in filenames on multiple files

13. OpenWin Filemgr: 'cannot open file: too many files open' ?