f_format.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* f_format.c :
* This file contains the format functions for floppy plug-in for
* library libsm.so.
*/
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <locale.h>
#include <errno.h>
#include <stdlib.h>
#include "f_defines.h"
/*
* extern functions
*/
extern void my_perror(char *err_string);
/*
* local functions
*/
struct fd_char save_fdchar,
struct dk_allmap save_allmap);
static int32_t
{
int32_t i;
/* for verify buffers */
/* FDRAW ioctl command structures for seeking and formatting */
FDRAW_SEEK, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,
0
};
0x4D, 0, 2, 0, 0x54, (char)0xA5, 0, 0, 0, 0,
6,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, /* nbytes */
0 /* addr */
};
if (format_flags == SM_FORMAT_HD) {
H_flag = 1;
} else if (format_flags == SM_FORMAT_DD) {
D_flag = 1;
} else if (format_flags == SM_FORMAT_ED) {
E_flag = 1;
} else if (format_flags == SM_FORMAT_MD) {
M_flag = 1;
} else {
DPRINTF("Invalid operation \n");
return (-1);
}
/*
* restore drive to default geometry and characteristics
* (probably not implemented on sparc)
*/
PERROR("DKIOCINFO failed.");
exit(3);
}
/* get the default partititon maps */
PERROR("DKIOCGAPART failed.");
return (-1);
}
/* Save the original default partition maps */
/* find out the characteristics of the default diskette */
PERROR("FDIOGCHAR failed.");
return (-1);
}
/* Save the original characteristics of the default diskette */
/*
* The user may only format the entire diskette.
* formatting partion a or b is not allowed
*/
* DEV_BSIZE;
if (size_of_part != size_of_dev) {
DPRINTF("The entire diskette must be formatted\n");
return (-1);
}
/* find out the geometry of the drive */
PERROR("DKIOCGGEOM failed.");
return (-1);
}
#ifdef sparc
#endif
drive_size = 5;
else
drive_size = 3;
/*
* set proper density flag in case we're formating to default
* characteristics because no density switch was input
*/
/* XXX */
switch (fdchar.fdc_transfer_rate) {
case 1000:
E_flag++;
break;
case 500:
default:
/*
* default to HD even though High density and
*/
H_flag++;
break;
#ifndef sparc
case 250:
D_flag++;
break;
#endif
}
}
if (H_flag) {
transfer_rate = 500;
num_cyl = 80;
sec_size = 512;
if (drive_size == 5) {
spt = 15;
} else {
spt = 18;
}
gap = 0x54;
} else if (D_flag) {
transfer_rate = 250;
if (drive_size == 5) {
/*
* formatting a 360KB DD diskette in
* a 1.2MB drive is not a good idea
*/
transfer_rate = 300;
}
num_cyl = 40;
gap = 0x50;
} else {
num_cyl = 80;
gap = 0x54;
}
sec_size = 512;
spt = 9;
} else if (M_flag) {
#ifdef sparc
transfer_rate = 500;
#else
/*
* density diskette spun at 300 rpm instead of 360 rpm
*/
transfer_rate = 417;
#endif
num_cyl = 77;
sec_size = 1024;
spt = 8;
gap = 0x74;
} else if (E_flag) {
transfer_rate = 1000;
num_cyl = 80;
sec_size = 512;
spt = 36;
gap = 0x54;
}
/*
* Medium density diskettes have 1024 byte blocks. The dk_map
* structure in dklabel.h assumes the blocks size is DEVBSIZE (512)
* bytes. The dkl_nblk field is in terms of DEVBSIZE byte blocks
* while the spt variable is in terms of the true block size on
* the diskette.
*/
}
#ifndef sparc
PERROR("drive not capable of requested density");
return (-1);
}
#endif
/*
* -- CAUTION --
* The SPARC fd driver is using a non-zero value in
* fdc_medium to indicate the 360 rpm, 77 track,
*
* The x86 fd driver uses fdc_medium as the diameter
* indicator, either 3 or 5. It should not be modified.
*/
#ifdef sparc
#endif
PERROR("FDIOSCHAR (density selection) failed");
/* restore the default characteristics */
return (-1);
}
PERROR("DKIOCSAPART failed");
/* restore the default characteristics */
return (-1);
}
}
PERROR("car't malloc verify buffer");
/* restore the default characteristics */
return (-1);
}
/*
* for those systems that support this ioctl, they will
* return whether or not a diskette is in the drive.
*/
if (chgd & FDGC_CURRENT) {
gettext("no diskette in drive \n"));
/* restore the default characteristics */
return (-1);
}
if (chgd & FDGC_CURWPROT) {
gettext("Media is write protected\n"));
/* restore the default characteristics */
return (-1);
}
}
PERROR("Could not malloc format header buffer");
return (-1);
}
/*
* do the format, a track at a time
*/
start_cyl = 0;
start_head = 0;
} else {
return (-1);
}
}
/*
* This is not the optimal ioctl to format the floppy.
* The device driver should do do the work,
* instead of this program mucking with a lot
* of low-level, device-dependent code.
*/
gettext(" seek to cyl %d failed\n"),
cyl);
/* restore the default characteristics */
return (-1);
}
/*
* Assume that the fd driver has issued a SENSE_INT
* command to complete the seek operation.
*/
for (i = 1; i <= spt; i++) {
*p++ = (uchar_t)i; /* sector # */
}
/*
* ASSUME the fd driver is going to set drive-select
* bits in the second command byte
*/
"format of cyl %d head %d failed\n"),
/* restore the default characteristics */
return (-1);
}
/*CSTYLED*/
"diskette is write protected\n"));
/*
* restore the default
* characteristics
*/
return (-1);
}
"format of cyl %d head %d failed\n"),
/* restore the default characteristics */
return (-1);
}
}
/*
* do a quick verify
*/
PERROR(" bad seek to format verify, ");
/* restore the default characteristics */
return (-1);
}
PERROR("Could not read format data");
/* restore the default characteristics */
return (-1);
}
}
}
PERROR("seek to blk 0 failed");
/* restore the default characteristics */
return (-1);
}
return (0);
}
/*
* Restore the default characteristics of the floppy diskette.
* Fdformat changes the characteristics in the process of formatting.
* If fdformat fails while in the process of doing the format, fdformat
* should clean up after itself and reset the driver back to the original
* state.
*/
static void
struct fd_char save_fdchar,
struct dk_allmap save_allmap)
{
/*
* When this function is called, fdformat is failing anyways,
* so the errors are not processed.
*/
/*
* Before looking at the diskette's characteristics, format_floppy()
* sets the x86 floppy driver to the default characteristics.
* restore drive to default geometry and
* characteristics. This ioctl isn't implemented on
* sparc.
*/
}
struct format_track ft;
/* Check for valid handle */
DPRINTF("Null Handle\n");
return (-1);
}
DPRINTF("Invalid signature in handle.\n");
"Signature expected=0x%x, found=0x%x\n",
return (-1);
}
DPRINTF("Invalid file handle.\n");
return (-1);
}
DPRINTF("Format floppy called \n");
}
{
/* Check for valid handle */
DPRINTF("Null Handle\n");
return (-1);
}
DPRINTF("Invalid signature in handle.\n");
"Signature expected=0x%x, found=0x%x\n",
return (-1);
}
DPRINTF("Invalid file handle.\n");
return (-1);
}
#ifdef DEBUG
}
#endif /* DEBUG */
}