ix_altsctr.c revision 052b6e8a13e1fb4be51ba482db6bb2e9833fa717
/*
* 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 2005 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.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <ctype.h>
#include <fcntl.h>
#include <malloc.h>
#include <stdio.h>
#include <string.h>
#include "badsec.h"
#define FAILURE 0
#define SUCCESS 1
#define CMD_READ 0
#define CMD_WRITE 1
struct badsec_lst *badsl_chain;
int badsl_chain_cnt;
struct badsec_lst *gbadsl_chain;
int gbadsl_chain_cnt;
extern int alts_fd;
static void chk_badsec (void);
static void init_altsctr (void);
void wr_altsctr (void);
static void get_badsec (void);
static int count_badsec (void);
static void gen_alts_ent (void);
static void assign_altsctr(void);
static void expand_map (void);
static void compress_map (void);
static int ent_merge(
int lcnt1,
int lcnt2);
static void print_altsctr(void);
/*
*/
int
{
if (init_flag)
get_badsec();
gen_alts_ent();
compress_map();
return(SUCCESS);
}
/*
* read_altsctr( ptr to alternate sector partition )
* -- read the alternate sector partition tables
*/
static void
{
int ret;
/* allocate buffer for the alts partition table (sector size) */
exit(50);
}
/* allocate buffer for the alts partition map (sector size) */
/* buffers include the disk image bit map */
/* and the incore transformed char map */
exit(51);
}
exit(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
*/
{
init_altsctr();
}
else {
chk_badsec();
else
init_altsctr();
}
}
}
/*
* checking duplicate bad sectors or bad sectors in ALTSCTR partition
*/
static void
chk_badsec(void)
{
int cnt;
int status;
/* if bad sector is within the ATLSCTR partition */
exit(53);
}
exit(54);
}
exit(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) {
}
}
}
}
/*
* initialize the alternate partition tables
*/
static void
init_altsctr(void)
{
int cnt;
ap->ap_ent_secsiz = 0;
if (badsec == altsp_srtsec) {
exit(56);
}
}
}
/* allocate the alts_map on disk skipping possible bad sectors */
perror("Unable to allocate alternate map on disk: ");
exit(57);
}
}
/*
* read the alternate partition tables from disk
*/
int
int badok;
{
/* get alts partition table info */
if (badok)
return(FAILURE);
perror("Unable to read alternate sector partition: ");
exit(58);
}
if (badok)
return(FAILURE);
exit(69);
}
/* get the alts map */
if (badok)
return(FAILURE);
perror("Unable to read alternate sector partition map: ");
exit(59);
}
/* transform the disk image bit-map to incore char map */
expand_map();
ap->ap_ent_secsiz = 0;
} else {
if (badok)
return(FAILURE);
exit(60);
}
if (badok)
return(FAILURE);
perror("Unable to read alternate sector entry table: ");
exit(61);
}
}
return(SUCCESS);
}
/*
* update the new alternate partition tables on disk
*/
void
wr_altsctr(void)
{
return;
perror("Unable to write alternate sector partition: ");
exit(62);
}
perror("Unable to write alternate sector partition map: ");
exit(63);
}
perror("Unable to write alternate sector entry table: ");
exit(64);
}
}
}
/*
* get a list of bad sector
*/
static void
get_badsec(void)
{
int cnt;
struct badsec_lst *blc_p;
int i;
cnt = count_badsec();
if (!cnt) {
ap->ap_gbadcnt = 0;
}
else {
"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
count_badsec(void)
{
struct badsec_lst *blc_p;
if (!badsl_chain)
else {
;
}
return(badsl_chain_cnt);
}
/*
* generate alternate entry table by merging the existing and
* the new entry list.
*/
static void
gen_alts_ent(void)
{
int ent_used;
if (ap->ap_gbadcnt == 0)
return;
ap->ap_gbadcnt = 0;
/* assign alternate sectors to the bad sectors */
/* allocate the alts_entry on disk skipping possible bad sectors */
perror("Unable to allocate alternate entry table on disk: ");
exit(65);
}
}
/*
* assign alternate sectors for bad sector mapping
*/
static void
assign_altsctr(void)
{
int i;
int j;
int cluster;
continue;
continue;
alts_ind =
fprintf(stderr, "Unable to allocate alternates for bad starting sector %ld.\n", (ap->ap_entp)[i].bad_start);
exit(65);
}
for (j=0; j<cluster; j++) {
}
}
}
/*
* transform the disk image alts bit map to incore char map
*/
static void
expand_map(void)
{
int i;
}
}
/*
* transform the incore alts char map to the disk image bit map
*/
static void
compress_map(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 int
{
int i;
int total;
int first_ind;
total = 0;
continue;
}
total++;
return(first_ind);
}
return(0);
}
/*
* bubble sort the entry table into ascending order
*/
static void
{
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 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 i;
int ind;
int interval;
int mystatus = -1;
ind=i;
/*
printf("ind= %d, intv= %d; ",ind, interval);
*/
} 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;
int j;
for (i=0; i<cnt; i++) {
exit(66);
/*
if (!numsec) {
(ap->ap_entp)[i].good_start = 0;
return(mystatus);
}
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 */
}
/*
* print_altsec () -- print alternate sector information
*/
int
{
read_altsctr(part, 0);
return(SUCCESS);
}
static void
print_altsctr(void)
{
int i;
int totalloc;
int avail;
/* find # of available alternate sectors */
if ((ap->ap_memmapp)[i])
totalloc++;
}
/*
* - partition table - partition map
* - entry table
*/
- ap->ap_map_sectot;
printf("\nBad Sector Start\tAlternate Sector Start\t\tCount\n");
printf("\t%ld\t ->\t\t%ld\t\t\t %ld\n",
}
}
static int
{
int rc;
return(FAILURE);
switch (ioflag)
{
case CMD_READ:
break;
case CMD_WRITE:
break;
default:
break;
}
if (rc == -1)
return(FAILURE);
return(SUCCESS);
}