open_mode
Joel Sherrill
joel.sherrill at OARcorp.com
Mon Feb 11 13:10:58 UTC 2002
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