Basic Driver Completion

To complete the process of creating a basic device driver the fops table needs the open, close, read and write references completed.

This can be done in the module_init function.

Following this the driver needs to be added to the Kernel Configuration and Build System.

A modified module_init function is shown here

  static int __init scmd_init(void){                                 
      int ret;
      int i;
 
      /* set up the initial data */                  
      for ( i = 0 ; i < SCMD_SIZE ; i++ ) {          
          scmd_data[i] = '0'+i;                       
      }                                              
 
      //SET_MODULE_OWNER(&scmd_driver_fops); //not now in 2.6 kernels
 
      scmd_driver_fops.read = scmd_read;
      scmd_driver_fops.write = scmd_write;
      scmd_driver_fops.open = scmd_open;
      scmd_driver_fops.release = scmd_close;
 
 
      ret = register_chrdev(scmd_major, SCMD_DEV,                    
                                      &scmd_driver_fops);            
      printk(" Driver scmd_basic registered .. ret %d \n",ret);      
      if ( ret > 0 ) {                                               
          scmd_major = ret;                                          
       ret = 0;                                                          
      }                                                              
      return ret;                                                    
  }