open_mode

Pattara Kiatisevi pkiatisevi at student.ei.uni-stuttgart.de
Mon Feb 11 14:15:29 UTC 2002


Thank you for fast response. At first, I did use the O_WRONLY flag but I
couldn't find the definition of O_WRONLY anywhere in the RTEMS source
(hmm, maybe I missed it somehow) so I happened to see

#define LIBIO_FLAGS_WRITE         0x0004  /* writing */

in the libio.h so I tried directly the value of "4" :-p

So it works now (with O_WRONLY) but I have to define it manually in my
application code (#define O_WRONLY 1). A better way is possible?

Regards,
Pattara

On Mon, 11 Feb 2002, Joel Sherrill wrote:

>
>
> Pattara Kiatisevi wrote:
> >
> > Hi,
> >
> > I'm working further on my sound driver in the sound_open() function.
> > >From application code I do:
> >
> > audio_fd = open("/dev/dsp", 4, 1)
>
> I think it was bogus to pass a 4 as the flags arg to open.
> You should use the constants O_RDONLY, O_WRONLY, O_RDWR per
> POSIX and ISO C. In this particular case, a 4 does not appear
> to map to anything.  From sys/fcntl.h
>
> #define O_RDONLY        0               /* +1 == FREAD */
> #define O_WRONLY        1               /* +1 == FWRITE */
> #define O_RDWR          2               /* +1 == FREAD|FWRITE */
>
> Also passing the 3rd parameter is bogus because you are not
> creating the file /dev/dsp.  Even if you did, using a 1 is
> also not cool and you should use the appropriate S_ constants.
>
>
>
> > And then in the driver code:
> >
> > rtems_device_driver sound_open(
> >   rtems_device_major_number major,
> >   rtems_device_minor_number minor,
> >   void                    * arg
> > )
> > {
> >   rtems_libio_open_close_args_t *args = arg;
> >
> >   /* Only write-only mode is supported now */
> >   printf("args->flags is 0x%4X\n", args->flags);
> >   printf("args->mode is 0x%4X\n", args->mode);
> >   if ( args->flags == 0x0004 ) {
> >     printf("/dev/dsp opened...\n");
> >     return RTEMS_SUCCESSFUL;
> >   } else {
> >     return RTEMS_NOT_IMPLEMENTED;
> >   }
> >
> > Hmm, but amazing (to me) is that the debugged output said:
> >
> > args->flags is 0x 103
> > args->mode is 0x   1
> > /dev/dsp: Permission denied
> >
> > Hmm, the flag I sent was "4" or "0x0004" but how could it become 0x103?
> > Anybody has idea?
>
> It is a bad idea to use numeric constants.  POSIX defined symbols for
> a reason. :)
>
> > Thank you,
> > Pattara}
> >
> > The best things in life are free. - B.G. DeSilva (1927)
> > ----------------------------------------------------------------------
> > Ott Pattara Kiatisevi                              T L W G
> > M.Sc. INFOTECH Student, Stuttgart, Germany      http://linux.thai.net/
> > ----------------------------------------------------------------------
>
> --
> Joel Sherrill, Ph.D.             Director of Research & Development
> joel at OARcorp.com                 On-Line Applications Research
> Ask me about RTEMS: a free RTOS  Huntsville AL 35805
>    Support Available             (256) 722-9985
>
>




More information about the users mailing list