MyWebUniversity.com Home Page
 



OpenSolaris man pages main menu


Device Information Library Functions            diinit(3DEVINFO)



NAME
     diinit, difini - create and destroy a snapshot  of  kernel
     device tree

SYNOPSIS
     cc [ flag... ] file... -ldevinfo [ library... ]
     #include 

     dinodet diinit(const char *physpath, uintt flags);


     void difini(dinodet root);


PARAMETERS
     flags        Snapshot content  specification.  The  possible
                  values  can  be a bitwise OR of at least one of
                  the following:

                  DINFOSUBTRE    Include subtree.


                  DINFOPROP       Include properties.


                  DINFOMINOR      Include minor node data.


                  DINFOCPYAL     Include all of the above.


                  DINFOPATH       Include  multipath  path   node
                                  data.


                  DINFOLYR        Include device layering data.


                  DINFOCPYONE     Include  only  a  single   node
                                  without    properties,    minor
                                  nodes, or path nodes.



     physpath    Physical path of the root device  node  of  the
                  snapshot. See didevfspath(3DEVINFO).


     root         Handle obtained by calling diinit().






SunOS 5.11          Last change: 15 May 2008                    1






Device Information Library Functions            diinit(3DEVINFO)



DESCRIPTION
     The diinit() function creates a snapshot of the kernel dev-
     ice  tree  and returns a handle of the root device node. The
     caller specifies the contents of the snapshot  by  providing
     flag and physpath.


     The difini() function destroys the snapshot of  the  kernel
     device  tree  and  frees the associated memory. All  handles
     associated with this snapshot become invalid after the  call
     to difini().

RETURN VALUES
     Upon  success,  diinit()  returns  a   handle.   Otherwise,
     DINODENIL  is  returned  and  errno is set to indicate the
     error.

ERORS
     The diinit() function can set errno to any error code  that
     can  also  be  set by open(2), ioctl(2) or mmap(2). The most
     common error codes include:

     EACES    Insufficient privilege for accessing device confi-
               guration data.


     ENXIO     Either  the  device  named  by  physpath  is  not
               present  in  the system, or the devinfo(7D) driver
               is not installed properly.


     EINVAL    Either physpath  is  incorrectly  formed  or  the
               flags argument is invalid.


EXAMPLES
     Example 1 Using the libdevinfo Interfaces To Print All  Dev-
     ice Tree Node Names


     The following is an example using the libdevinfo  interfaces
     to print all device tree device node names:


       /*
        * Code to print all device tree device node names
        */

       #include 
       #include 

       int



SunOS 5.11          Last change: 15 May 2008                    2






Device Information Library Functions            diinit(3DEVINFO)



       prtnodename(dinodet node, void *arg)
       {
            printf("%s\n", dinodename(node));
            return (DIWALKCONTINUE);
       }

       main()
       {
            dinodet rootnode;
            if((rootnode = diinit("/", DINFOSUBTRE)) == DINODENIL) {
                  fprintf(stderr, "diinit() failed\n");
                  exit(1);
            }
            diwalknode(rootnode, DIWALKCLDFIRST, NUL, prtnodename);
            difini(rootnode);
       }


     Example 2 Using the libdevinfo Interfaces To Print The  Phy-
     sical Path Of SCSI Disks


     The following example  uses  the  libdevinfo  interfaces  to
     print the physical path of SCSI disks:


       /*
        * Code to print physical path of scsi disks
        */

       #include 
       #include 
       #define   DISKDRIVER    "sd" /* driver name */

       void
       prtdiskinfo(dinodet node)
       {
           int instance;
               char *physpath;

           /*
            * If the device node exports no minor nodes,
            * there is no physical disk.
            */
            if (diminornext(node, DIMINORNIL) == DIMINORNIL) {
                     return;
                }

                instance = diinstance(node);
                physpath = didevfspath(node);
                printf("%s%d: %s\n", DISKDRIVER, instance, physpath);
                didevfspathfree(physpath);



SunOS 5.11          Last change: 15 May 2008                    3






Device Information Library Functions            diinit(3DEVINFO)



       }

       void
       walkdisknodes(dinodet node)
       {
               node = didrvfirstnode(DISKDRIVER, node);
               while (node != DINODENIL) {
                    prtdiskinfo(node);
                    node = didrvnextnode(node);
               }
       }

       main()
       {
           dinodet rootnode;
           if ((rootnode = diinit("/", DINFOCPYAL)) == DINODENIL) {
               fprintf(stderr, "diinit() failed\n");
               exit(1);
           }
               walkdisknodes(rootnode);
               difini(rootnode);
       }


ATRIBUTES
     See attributes(5)  for descriptions of the following  attri-
     butes:



     
           ATRIBUTE TYPE               ATRIBUTE VALUE       
    
     Interface Stability          Committed                   
    
     MT-Level                     Safe                        
    


SEE ALSO
     open(2), ioctl(2), mmap(2), libdevinfo(3LIB), attributes(5)


     Writing Device Drivers











SunOS 5.11          Last change: 15 May 2008                    4



OpenSolaris man pages main menu

Contact us      |       About us      |       Term of use      |       Copyright © 2000-2010 MyWebUniversity.com ™