Advanced Linux Sound Architecture - Driver: File operations

Next Previous Contents

## 3. File operations

File operations related structures and functions are in include/driver.h header file. Basic structure for registering file operations for minor number is snd_minor_t. Minor constants are in include/minors.h header file.

## 3.1 Variables and functions

Functions list:

- int snd_register_minor( unsigned short minor, snd_minor_t *reg )
  - minor minor number
  - reg pointer to registration structure with file operations
  - returns negative value when error occured
- int snd_unregister_minor( unsigned short minor )
  - minor minor number
  - returns negative value when error occured

Note: Devices (minor numbers) are registered only if device is present in the system. It isn't preffered do some pre-registration from some middle-level code for each possible devices per interface.

## 3.2 Examples

> `

>     static snd_minor_t snd_pcm_reg = {
>       "digital audio",

>       NULL,                         /* unregister */

>       NULL,                         /* lseek */
>       snd_pcm_read,                 /* read */
>       snd_pcm_write,                /* write */
>       snd_pcm_open,                 /* open */
>       snd_pcm_release,              /* release */
>     #ifdef SND_POLL
>       snd_pcm_poll,                 /* poll */
>     #else
>       snd_pcm_select,               /* select */
>     #endif
>       snd_pcm_ioctl,                /* ioctl */
>       NULL,                         /* mmap */
>     };

>     ...
>       if ( (err = snd_register_minor( SND_MINOR_PCM + device, &snd_pcm_reg )) < 0 )
>         return err;
>     ...
>       snd_unregister_minor( SND_MINOR_PCM + device );

> `

Next Previous Contents