/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* copyright (c) 1990, 1991 UNIX System Laboratories, Inc.
* copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T
* All rights reserved.
*/
/*
* Copyrighted as an unpublished work.
* (c) Copyright INTERACTIVE Systems Corporation 1986, 1988, 1990
* All rights reserved.
*/
#include <ctype.h>
#include <fcntl.h>
#include <malloc.h>
#include <stdio.h>
#include <string.h>
#include "badsec.h"
#include "global.h"
#include "ctlr_ata.h"
#include "misc.h"
#define SUCCESS 0
#define CMD_READ 0
int badsl_chain_cnt = 0;
int gbadsl_chain_cnt = 0;
/* alts tables */
/* prototypes */
int updatebadsec(struct dkl_partition *, int);
int read_altsctr(struct dkl_partition *);
static int chk_badsec();
static int init_altsctr();
static int get_altsctr();
int wr_altsctr();
static void get_badsec();
static int count_badsec();
static int gen_alts_ent();
static int assign_altsctr();
static void expand_map();
static void compress_map();
static int altsmap_getbit(blkaddr_t);
static void ent_compress(struct alts_ent *, int);
struct alts_ent *, int);
static int chk_bad_altsctr(blkaddr_t);
/*
*/
int
int init_flag;
struct dkl_partition *part;
{
if (init_flag)
get_badsec();
(void) read_altsctr(part);
(void) gen_alts_ent();
compress_map();
return (SUCCESS);
}
/*
* read_altsctr( ptr to alternate sector partition )
* -- read the alternate sector partition tables
*/
int
struct dkl_partition *part;
{
/* allocate buffer for the alts partition table (sector size) */
"Unable to malloc alternate partition table.\n");
return (50);
}
/* allocate buffer for the alts partition map (sector size) */
/* buffers include the disk image bit map */
/* and the incore transformed char map */
"Unable to malloc incore alternate partition map.\n");
return (51);
}
NBPSCTR);
"Unable to malloc alternate partition map.\n");
return (52);
}
/* clear the buffers to zero */
/*
* if add alternate partition flag is set, then install the partition
* otherwise read the alts partition info from disk
* if failed, then assume the first installation
*/
{
"WARNING: Manually initializing alternate table.\n");
(void) init_altsctr();
} else {
if (get_altsctr() == SUCCESS)
(void) chk_badsec();
else
(void) init_altsctr();
}
}
return (SUCCESS);
}
/*
* checking duplicate bad sectors or bad sectors in ALTSCTR partition
*/
static int
{
int cnt;
int status;
/* if bad sector is within the ATLSCTR partition */
"Alternate partition information table is bad.\n");
return (53);
}
"Alternate partition map is bad.\n");
return (54);
}
"Alternate partition entry table is bad.\n");
return (55);
}
} else {
}
} else {
/*
* binary search for bad sector in the alts entry table
*/
/*
* if the bad sector had already been remapped(found in alts_entry)
* then ignore the bad sector
*/
if (status != -1) {
}
}
}
return (SUCCESS);
}
/*
* initialize the alternate partition tables
*/
static int
{
int cnt;
ap->ap_ent_secsiz = 0;
if (badsec == altsp_srtsec) {
"First sector of alternate partition is bad.\n");
return (56);
}
}
}
/* allocate the alts_map on disk skipping possible bad sectors */
perror("Unable to allocate alternate map on disk: ");
return (57);
}
(void) wr_altsctr();
return (SUCCESS);
}
/*
* read the alternate partition tables from disk
*/
static int
{
int status = 0;
/* get alts partition table info */
0, NULL);
perror("Unable to read alternate sector partition: ");
return (58);
}
return (mystatus);
/* get the alts map */
perror("Unable to read alternate sector partition map: ");
return (59);
}
/* transform the disk image bit-map to incore char map */
expand_map();
ap->ap_ent_secsiz = 0;
} else {
"Unable to malloc alternate sector entry table.\n");
return (60);
}
0, NULL);
perror("Unable to read alternate sector entry table: ");
return (61);
}
}
return (SUCCESS);
}
/*
* update the new alternate partition tables on disk
*/
int
{
int status;
return (0);
if (status) {
(void) printf("ata_rdwr status = %d need = %d\n",
perror("Unable to write with ata_rdwr the alt sector part: ");
return (62);
}
perror("Unable to write alternate sector partition map: ");
return (63);
}
perror("Unable to write alternate sector entry table: ");
return (64);
}
}
return (0);
}
/*
* get a list of bad sector
*/
static void
{
int cnt;
int i;
cnt = count_badsec();
if (!cnt) {
ap->ap_gbadcnt = 0;
} else {
err_print("get_badsec: unable to malloc %d bytes\n",
fullabort();
}
"Ignoring bad sector %ld which is in first track of the drive.\n", curbad);
continue;
}
"Ignoring bad sector %ld which is past the end of the drive.\n", curbad);
continue;
}
cnt++;
}
}
}
}
/*
* count number of bad sector on list
* merging the bad sector list from surface analysis and the
* one given through the command line
*/
static int
{
if (!badsl_chain)
else {
;
}
return (badsl_chain_cnt);
}
/*
* generate alternate entry table by merging the existing and
* the new entry list.
*/
static int
gen_alts_ent() {
if (ap->ap_gbadcnt == 0)
return (0);
err_print("get_alts_ent: unable to malloc %d bytes\n",
ap->ap_ent_secsiz);
fullabort();
}
ap->ap_gbadcnt = 0;
/* assign alternate sectors to the bad sectors */
(void) assign_altsctr();
/* allocate the alts_entry on disk skipping possible bad sectors */
perror("Unable to allocate alternate entry table on disk: ");
return (65);
}
return (0);
}
/*
* assign alternate sectors for bad sector mapping
*/
static int
{
uint_t i;
uint_t j;
continue;
continue;
alts_ind =
"Unable to allocate alternates for bad starting sector %u.\n",
return (65);
}
for (j = 0; j < cluster; j++) {
}
}
return (SUCCESS);
}
/*
* transform the disk image alts bit map to incore char map
*/
static void
{
int i;
}
}
/*
* transform the incore alts char map to the disk image bit map
*/
static void
{
int i;
int bytesz;
char mask = 0;
int maplen = 0;
if (bytesz < 0) {
bytesz = 7;
mask = 0;
}
}
/*
* if partition size != multiple number of bytes
* then record the last partial byte
*/
if (bytesz != 7)
}
/*
* given a bad sector number, search in the alts bit map
* and identify the sector as good or bad
*/
static int
{
return (ALTS_BAD);
return (ALTS_GOOD);
}
/*
* allocate a range of sectors from the alternate partition
*/
static blkaddr_t
int cnt;
int dir;
{
blkaddr_t i;
total = 0;
continue;
}
total++;
return (first_ind);
}
return (NULL);
}
/*
* bubble sort the entry table into ascending order
*/
static void
int cnt;
{
int flag;
int i, j;
for (i = 0; i < cnt-1; i++) {
flag = 1;
for (j = cnt-1; j > i; j--) {
} else {
flag = 0;
}
}
if (flag) break;
}
}
/*
* compress all the contiguous bad sectors into a single entry
* in the entry table. The entry table must be sorted into ascending
* before the compression.
*/
static void
int cnt;
{
int keyp;
int movp;
int i;
for (i = 0; i < cnt; i++) {
continue;
continue;
break;
}
}
}
/*
* merging two entry tables into a single table. In addition,
* all empty slots in the entry table will be removed.
*/
static int
int lcnt1;
int lcnt2;
{
int i;
j1++;
continue;
}
j2++;
continue;
}
else
}
continue;
}
continue;
}
return (i);
}
/*
* binary search for bad sector in the alternate entry table
*/
static int
int cnt;
{
int i;
int ind;
int interval;
if (!cnt)
return (mystatus);
ind = i;
} else {
interval >>= 1;
if (!interval) break;
} else {
/* if key is larger than the last element then break */
}
}
}
return (mystatus);
}
/*
* check for bad sector in assigned alternate sectors
*/
static int
{
int i;
/*
* daddr_t intv[3];
*/
for (i = 0; i < cnt; i++) {
"Bad sector %ld is an assigned alternate sector.\n", badsec);
return (66);
/*
* if (!numsec) {
* (ap->ap_entp)[i].good_start = 0;
* return (FAILURE);
* }
* intv[0] = badsec - (ap->ap_entp)[i].good_start;
* intv[1] = 1;
* intv[2] = (ap->ap_entp)[i].good_start + numsec - badsec;
*/
}
}
/* the bad sector has already been identified as bad */
return (SUCCESS);
}