check_usage - checks whether a disk partition is in use
#include <sys/disklabel.h> #include <overlap.h>
int check_usage(
const char *special,
int option );
Filesystem Library (libfilsys.a)
Shared Filesystem Library (libfilsys.so)
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.
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.
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.
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); }
Commands: disklabel(8)
Functions: set_usage(3)
check_usage(3)
[ Back ] |