STIOC_CREATE_PARTITION
This IOCTL creates partitions on tapes that support partitioning. The data structure that is used
for this IOCTL
is
#define IDP_PARTITION (1)
#define SDP_PARTITION (2)
#define FDP_PARTITION (3)
struct tape_partition {
unchar type;
unchar number_of_partitions;
unchar size_unit;
ushort size[MAX_PARTITIONS];
char reserved[32];
};
Type is the type of partition, whether
IDP_PARTITION (initiator defined partition),
SDP_PARTITION (select data partition), or
FDP_PARTITION (fixed data partition). The behavior of these options is
described in the SCSI reference for your tape drive.
- number_of_partitions is the number of partitions the user wants to create.
- size_unit is as defined in the STIOC_QUERY_PARTITION section.
- size is an array of requested sizes, in size_units, one array element per partition.
An example of the STIOC_CREATE_PARTITION IOCTL
is
int stioc_create_partition()
{
int rc = 0, i = 0, char_cap = 0, short_cap = 0;
struct tape_partition crt;
char* input = NULL;
char_cap = pow(2, sizeof(char) * BITS_PER_BYTE) - 1;
short_cap = pow(2, sizeof(short) * BITS_PER_BYTE) - 1;
input = malloc(DEF_BUF_SIZE / 16);
if(!input) {
rc = ENOMEM;
goto EXIT_LABEL;
} /* if */
memset(input, '\0', DEF_BUF_SIZE / 16);
memset(&crt, '\0', sizeof(struct tape_partition));
while(atoi(input) < IDP_PARTITION || atoi(input) > FDP_PARTITION + 1) {
printf("%d) IDP_PARTITION\n", IDP_PARTITION);
printf("%d) SDP_PARTITION\n", SDP_PARTITION);
printf("%d) FDP_PARTITION\n", FDP_PARTITION);
printf("%d) Cancel\n", FDP_PARTITION + 1);
printf("\nPlease select: ");
fgets(input, DEF_BUF_SIZE / 16, stdin);
if(atoi(input) == FDP_PARTITION + 1) {
rc = 0;
goto EXIT_LABEL;
} /* if */
} /* while */
crt.type = atoi(input);
memset(input, '\0', DEF_BUF_SIZE / 16);
while(input[0] < '1' || input[0] > '9') {
printf("Enter desired number of partitions (0 to cancel): ");
fgets(input, DEF_BUF_SIZE / 16, stdin);
if(input[0] == '0') {
rc = 0;
goto EXIT_LABEL;
} /* if */
if(atoi(input) > MAX_PARTITIONS) {
printf("Please select number <= %d\n", MAX_PARTITIONS);
input[0] = '\0';
} /* if */
} /* while */
crt.number_of_partitions = atoi(input);
if(crt.type == IDP_PARTITION && crt.number_of_partitions > 1) {
memset(input, '\0', DEF_BUF_SIZE / 16);
while(input[0] < '0' || input[0] > '9') {
printf("Enter size unit (0 to cancel): ");
fgets(input, DEF_BUF_SIZE / 16, stdin);
if(input[0] == '0') {
rc = 0;
goto EXIT_LABEL;
} /* if */
if(atoi(input) > char_cap) {
printf("Please select number <= %d\n", char_cap);
input[0] = '\0';
} /* if */
} /* while */
crt.size_unit = atoi(input);
for(i = 0; i < crt.number_of_partitions; i++) {
memset(input, '\0', DEF_BUF_SIZE / 16);
while(input[0] != '-' &&
(input[0] < '0' || input[0] > '9')) {
printf("Enter size[%d] (0 to cancel, < 0 for "\
"remaining space on cartridge): ", i);
fgets(input, DEF_BUF_SIZE / 16, stdin);
if(input[0] == '0') {
rc = 0;
goto EXIT_LABEL;
} /* if */
if(atoi(input) > short_cap) {
printf("Please select number <= %d\n",
short_cap);
input[0] = '\0';
} /* if */
} /* while */
if(input[0] == '-' && atoi(&input[1]) > 0)
crt.size[i] = 0xFFFF;
else crt.size[i] = atoi(input);
} /* for */
} /* if */
printf("Issuing IOCTL...\n");
rc = ioctl(fd, STIOC_CREATE_PARTITION, &crt);
if(rc) {
printf("Create partition failed: %d\n", rc);
goto EXIT_LABEL;
} /* if */
EXIT_LABEL:
if(input) free(input);
return rc;
} /* stioc_create_partition() */