Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

developerWorks Community:

  • Close [x]

IBM AIX device driver development

A tutorial on AIX device driver framework and related APIs

Gautam Raut (, Senior Software Engineer, IBM
Gautam Raut works as a Senior Software Engineer for the Andrew File System (AFS) Team at the IBM Software Labs in Pune, India. He works with kernel and user-level debugging of dumps and crashes, as well as reported bugs on the Linux and AIX platforms. He has also worked on various AFS-specific AIX kernel components. Gautam holds M.S. in Computer Science from the University of Pune. He is a Linux enthusiast who spends his spare time exploring the Linux kernel on his Fedora 8 box.

Summary:  This tutorial illustrates the IBM® AIX® device driver framework and related application programming interfaces (APIs). Here, we shall discuss about the device switch structure, API to register device switch methods, major and minor number management, and moving data from kernel to user space.

Date:  28 Mar 2013
Level:  Intermediate PDF:  A4 and Letter (244 KB | 15 pages)Get Adobe® Reader®

Activity:  20933 views

Example of a configuration application for a given device driver


#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/errno.h>
#include <sys/sysmacros.h>
#include <sys/sysconfig.h>
#include <sys/device.h>
#include <sys/mode.h>
#include <odmi.h>
#include <cf.h>
#include <sys/cfgodm.h>
#include <sys/cfgdb.h>

int main()
   struct cfg_load ext_load; /* to load kernel extension */
   struct cfg_dd ddcfg; /* to invoke driver config() */
   char c, str[80];
   int rc;
   int major, minor = 0;
   dev_t devno;

   rc = odm_initialize();

   printf("\n Enter choice, (l)oad, (u)nload \n");
   while((c = getchar()) < 'a' && c > 'z');

   switch(c) {
      case 'l':
          ext_load.path = "sample_driver";
          ext_load.libpath = NULL;
          ext_load.kmid = 0;

          &ext_load, sizeof(struct cfg_load))) {
             printf("Error in loading extension\n");
             exit (1);
             printf("Extension Successfully loaded, kmid is %d\n", ext_load.kmid);

          major = genmajor("sample_driver");
          printf("Major number: %d\n", major);
          devno = makedev64(major, minor);
          ddcfg.kmid = ext_load.kmid;
          ddcfg.devno = devno;
          ddcfg.cmd = CFG_INIT;
          ddcfg.ddsptr = NULL;
          ddcfg.ddslen = 0;

          if (rc = sysconfig(SYS_CFGDD,
             &ddcfg, sizeof(ddcfg))) {
             printf("Error in configuring device %d %d\n", rc, errno);
             exit (1);

          for(minor = 0; minor <=2; minor++) {
             devno = makedev64(major, minor);
             sprintf(str, "/dev/drvdd%d", minor);
             if (mknod(str, 0666 | _S_IFCHR, devno) == -1){
               printf("Error while creating device %s\n", str);
               exit (1);

    case 'u':
         ext_load.path = " sample_driver";
         ext_load.libpath = NULL;
         ext_load.kmid = 0;

         if(sysconfig(SYS_QUERYLOAD, &ext_load,
         sizeof(struct cfg_load)))
            printf("Error while querying\n");

         if(sysconfig(SYS_KULOAD, &ext_load,
         sizeof(struct cfg_load)))
            printf("Error in unloading extension\n");
            printf("Extension Successfully unloaded\n");

         printf("Incorrect option\n");
        return 0;

11 of 15 | Previous | Next


Zone=AIX and UNIX, Linux
TutorialTitle= IBM AIX device driver development