/*
* 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 (c) 2011 Gary Mills
*
* Copyright (c) 1999,2000 by Sun Microsystems, Inc.
* All rights reserved.
*/
/*
* fsck_pcfs -- routines for manipulating the BPB (BIOS parameter block)
* of the file system.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <libintl.h>
#include "pcfs_common.h"
#include "fsck_pcfs.h"
#include "pcfs_bpb.h"
extern off64_t FirstClusterOffset;
extern off64_t PartitionOffset;
extern int32_t BytesPerCluster;
extern int32_t TotalClusters;
extern int32_t LastCluster;
extern int32_t RootDirSize;
extern short FATEntrySize;
extern bpb_t TheBIOSParameterBlock;
extern int IsFAT32;
extern int Verbose;
static void
computeFileAreaSize(void)
{
/*
*/
/*
* First we'll find total number of sectors in the file area...
*/
else
sizeof (struct pcdir);
/*
* Good old FAT12 or FAT16
*/
/*
* Compute this for later - when we actually pull in a copy
* of the FAT
*/
} else {
/*
* FAT32
* I'm unsure if this is always going to work. At one
* point during the creation of this program and mkfs_pcfs
* it seemed that Windows had created an fs where it had
* rounded big_sectors_per_fat up to a cluster boundary.
* Later, though, I encountered a problem where I wasn't
* finding the root directory because I was looking in the
* wrong place by doing that same roundup. So, for now,
* I'm backing off on the cluster boundary thing and just
* believing what I am told.
*/
/*
* Compute this for later - when we actually pull in a copy
* of the FAT
*/
}
/*
* Now change sectors to clusters. The computed value for
* TotalClusters is persistent for the remainder of execution.
*/
dataSectors -= overhead;
/*
* Also need to compute last cluster and offset of the first cluster
*/
/*
* XXX this should probably be more sophisticated
*/
if (IsFAT32)
FATEntrySize = 32;
else {
if (TotalClusters <= DOS_F12MAXC)
FATEntrySize = 12;
else
FATEntrySize = 16;
}
if (Verbose) {
gettext("Disk has a file area of %d "
"allocation units,\neach with %d sectors = %llu "
"bytes.\n"), TotalClusters,
}
}
/*
* XXX - right now we aren't attempting to fix anything that looks bad,
* instead we just give up.
*/
void
{
/*
* The BPB is the first sector of the file system
*/
exit(7);
}
if (Verbose)
gettext("Reading BIOS parameter block\n"));
exit(2);
}
gettext("Bad signature on BPB. Giving up.\n"));
exit(2);
}
#ifdef _BIG_ENDIAN
#else
sizeof (TheBIOSParameterBlock.bpb));
sizeof (TheBIOSParameterBlock.ebpb));
#endif
/*
* In general, we would expect the bytes per sector to
* equal 256 (BPSEC). I personally have yet to see a file
* system where this isn't true but apparently some weird media
* have different sector sizes. So we'll accept a couple of
* other small multiples of 256 as valid sizes.
*/
gettext("Bogus bytes per sector value. Giving up.\n"));
exit(2);
}
1, 128))) {
gettext("Bogus sectors per cluster value. Giving up.\n"));
exit(6);
}
#ifdef _BIG_ENDIAN
#else
sizeof (TheBIOSParameterBlock.bpb32));
#endif
IsFAT32 = 1;
}
if (!IsFAT32) {
sizeof (struct pcdir)) %
gettext("Bogus number of root entries. "
"Giving up.\n"));
exit(2);
}
} else {
gettext("Bogus number of root entries. "
"Giving up.\n"));
exit(2);
}
}
/*
* In general, we would expect the number of FATs field to
* equal 2. Our mkfs and Windows have this as a default
* value. I suppose someone could override the default,
* though, so we'll sort of arbitrarily accept any number
* between 1 and 4 inclusive as reasonable values.
*
* XXX: Warn, but continue, if value is suspicious? (>2?)
*/
gettext("Bogus number of FATs. Giving up.\n"));
exit(2);
}
}