ident_pcfs.c revision 18c2aff776a775d34a4c9893a4c72e0434d68e36
/*
* 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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <rmmount.h>
#include <errno.h>
/*
* We call it a pcfs file system iff:
* The "media type" descriptor in the label == the media type
* descriptor that's supposed to be the first byte
* of the FAT.
* The second byte of the FAT is 0xff.
* The third byte of the FAT is 0xff.
*
* Assumptions:
*
* 1. I don't really know how safe this is, but it is
* mentioned as a way to tell whether you have a dos disk
* in my book (Advanced MSDOS Programming, Microsoft Press).
* Actually it calls it an "IBM-compatible disk" but that's
* good enough for me.
*
* 2. The FAT is right after the reserved sector(s), and both
* the sector size and number of reserved sectors must be gotten
* from the boot sector.
*/
static bool_t find_dos_part(int);
/*ARGSUSED*/
{
/*
* pcfs is always clean... at least there's no way to tell if
* it isn't!
*/
/* try no offset first (i.e. a floppy?) */
if (ident_fs_offset(fd, 0L))
return (TRUE);
return (find_dos_part(fd));
}
static int
{
}
static int
{
}
/*
* find DOS partitions offset *iff* there's no Solaris partition *at all*
*/
static bool_t
find_dos_part(int fd)
{
union {
} mbr_u;
int i, extended_part, loop;
/* seek to start of disk (assume it works) */
return (FALSE);
}
/* try to read */
return (FALSE);
}
/* get pointer to master boot struct and validate */
/* not an FDISK table */
return (FALSE);
}
/*
* and also DOSOS12/FDISK_WINDOWS/FDISK_EXT and FDISK_FAT95 entries.
*/
extended_part = -1;
for (i = 0; i < FD_NUMPART; i++) {
if (ident_fs_offset(fd,
return (TRUE);
}
if (extended_part < 0)
extended_part = i;
/* oh oh -- not suposed to be solaris here! */
return (FALSE);
}
/* continue looking */
}
if (extended_part < 0)
return (FALSE);
lastseek = 0;
/*
* No sure how many extended dos partition we can really allocate.
* 512 would be enough?
*/
break;
!= (diskblk * PC_SECSIZE)) {
return (FALSE);
}
return (FALSE);
}
/* Not a valid extended partition */
return (FALSE);
}
for (i = 0; i < FD_NUMPART; i++) {
continue;
return (TRUE);
}
continue;
}
}
}
return (FALSE);
}
static bool_t
{
/* go to start of image */
}
/* read the boot sector (plus some) */
}
/* no need to go farther if magic# is wrong */
}
/* calculate where FAT starts */
}
/* if offset is too large we probably have garbage */
unsigned long fat_sec_off; /* offset of FAT sector */
unsigned int fat_sub_off; /* offset w/in sector */
/* we need to read another sector to get the FAT */
/* get sec# for FAT */
/* seek to FAT sec# */
}
/* read the new sector */
}
/* now lets check if we got a good FAT */
}
} else {
}
}
return (result);
}