*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->Tru64 Unix man pages -> check_usage (3)              
Title
Content
Arch
Section
 

check_usage(3)

Contents


NAME    [Toc]    [Back]

       check_usage - checks whether a disk partition is in use

SYNOPSIS    [Toc]    [Back]

       #include <sys/disklabel.h> #include <overlap.h>

       int check_usage(
               const char *special,
               int option );

LIBRARY    [Toc]    [Back]

       Filesystem Library (libfilsys.a)

       Shared Filesystem Library (libfilsys.so)

PARAMETERS    [Toc]    [Back]

       Points  to  a special device file.  Specifies the scope of
       usage checking. Valid values are: Checks the usage of  the
       specified   partition   and  all  overlapping  partitions.
       Checks the usage of the specified partition only.

DESCRIPTION    [Toc]    [Back]

       The check_usage()  function  checks  whether  the  special
       device  file  is  in  use,  that is, whether it contains a
       valid file system, is part of LSM, or is being used  by  a
       database or for swap space.

       If  the  option  OV_CHECK_ALL  is  set, check_usage() also
       checks to ensure that the range of blocks to be used  does
       not  overlap with blocks already in use or marked to be in
       use by an overlapping partition.

       If the option OV_CHECK_EXACT is  set,  usage  checking  is
       limited to the specified partition only.

       The  check_usage()  function  checks  whether  the special
       device file is in use by comparing  it  with  all  mounted
       file  systems  (both UFS and AdvFS), swap devices, and LSM
       disks. It also reads the disk label to  check  the  fstype
       field  of the specified partition and any overlapping partitions.
 If any partition is marked as being in  use,  the
       appropriate error is returned.

       Before allocating a partition, an application should check
       that none of the overlapping partitions is in use. When an
       application  uses  a  partition, it should mark its use by
       setting the fstype field in the partition map in the  disk
       label.

       See  <sys/disklabel.h>  for  a  list of the supported file
       system types that can be set using the  set_usage()  function.

RETURN VALUES    [Toc]    [Back]

       The  check_usage()  function  returns the values described
       here. Logical names for the return values  are  listed  in
       parentheses.  Checks succeeded. The range of blocks is not
       open or marked for use. Note that for the  mount  command,
       you  get  a  warning  message  if  the  fstype  is  set to
       FS_UNUSED; it should be  set  to  FS_BSDFFS.   Either  the
       specified  special device file or an overlapping partition
       is open or marked for use.  Either the special device file
       name  is invalid or the device cannot be opened.  Overlapping
 partitions are marked for use, that is, they  have  a
       value  set for fstype.  Note that the command disklabel -s
       can be used to unset any partitions  that  should  not  be
       marked  for  use.  The specified partition and overlapping
       partitions have the fstype field set.  The disk  label  is
       not  present  or  is  corrupted. You should install a disk
       label and set the fstype field of any partitions that  are
       in  use.  You  should correct any changes to the partition
       layout before trying to use the newfs command on a  partition.
   An error was encountered during the checks. Either
       /etc/fdmns or /etc/fdmns/domain for an in-use domain  does
       not  exist or is corrupted.  An error was encountered during
 the checks. The special device file for an in-use swap
       device does not exist.  This indicates a failure in updating
 the disk label.  The specified partition is set to  an
       fstype,  which  is the return value. Refer to <sys/disklabel.h>
 for information on valid fstype values.

EXAMPLES    [Toc]    [Back]

       The   following   function   illustrates   the   use    of
       check_usage()  and  possible  error messages that could be
       printed based on the return values from check_usage().

       #define   DKTYPENAMES    #include    <stdio.h>    #include
       <sys/disklabel.h> #include <overlap.h>

       #define STR_ERR_OPEN \
           "Error: %s is open and in use.\n"

       #define STR_ERR_OPEN_OVERLAP \
           "Error:  Partition  overlapping  %s  is  open  and  in
       use.\n"

       #define STR_ERR_INVALID_DEV \
           "Error:  %s  is  an  invalid  device  or   cannot   be
       opened.\n"

       #define STR_ERR_DEFAULT_FSTYPE \
           "Error:  %s  is  marked in the disk label as in use by
       %s.\n"

       #define STR_WARN_FSTYPE_OVERLAP \
           "Warning: partition(s) which overlaps %s are marked in
       use.\n"

       #define STR_WARN_MULT_OVERLAP \
           "Warning:  %s  and overlapping partition(s) are marked
       in use.\n"

       #define STR_WARN_INVAL_DISKLBL \
           "Warning: the disklabel for %s does not  exist  or  is
       corrupted.\n"

       int get_usage(char *special) {
           int    ret;

           /*
            * Check if the specific partition and any
            * overlapping partition is in use.
            */
           ret = check_usage(special, OV_CHECK_ALL);

           if (ret == 0) {
               /*
                * Specified partition is available for use.
                */
               return (0);
           } else {
                /*
                 * Specified partition has a valid fstype.
                 */
               if ( (ret > 0) && (ret <= FSMAXTYPES) ) {
                   fprintf(stderr, STR_ERR_DEFAULT_FSTYPE,
                       special, fstypenames[ret]);
                   return(-1);
               }
           }
           /*
            * Print appropriate error messages for the rest of
            * the return values.
            */
           switch (ret) {

           case OV_ERR_OPEN_OVERLAP:
               /*
                * Check if the specified partition is open.
                */
               ret = check_usage(special, OV_CHECK_EXACT);
               if (ret == OV_ERR_OPEN_OVERLAP)
                   fprintf(stderr, STR_ERR_OPEN, special);
               else
                   fprintf(stderr,   STR_ERR_OPEN_OVERLAP,   special);

               break;
           case OV_ERR_INVALID_DEV:
               fprintf(stderr, STR_ERR_INVALID_DEV, special);
               break;
           case OV_ERR_INVALID_DSKLBL:
               fprintf(stderr, STR_WARN_INVAL_DISKLBL, special);
               break;
           case OV_ERR_FSTYPE_OVERLAP:
               fprintf(stderr, STR_WARN_FSTYPE_OVERLAP, special);
               break;
           case OV_ERR_MULT_FSTYPE_OVERLAP:
               fprintf(stderr, STR_WARN_MULT_OVERLAP, special);
               break;
           }
           return (-1); }

SEE ALSO    [Toc]    [Back]

      
      
       Commands: disklabel(8)

       Functions: set_usage(3)



                                                   check_usage(3)
[ Back ]
 Similar pages
Name OS Title
set_usage Tru64 checks whether a disk partition is in use and sets the fstype of the partition in the disk label
opendisk NetBSD open a disk partition
installboot OpenBSD installs a bootstrap on an FFS disk or partition
installboot OpenBSD installs a bootstrap on an FFS disk or partition
mediainit HP-UX initialize disk or partition DDS tape
vn_isdisk FreeBSD checks if a vnode represents a disk
verify Tru64 Checks the AdvFS on-disk metadata structures
cfdisk Linux Curses based disk partition table manipulator for Linux
disklabel Tru64 Reads and writes a disk pack label and formats disk partitions
createlabel Tru64 creates a disk label structure for a disk device
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service