- 論壇徽章:
- 0
|
/* $OpenBSD: part.c,v 1.42 2006/06/09 17:01:47 deraadt Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include err.h>
#include util.h>
#include stdio.h>
#include string.h>
#include unistd.h>
#include sys/fcntl.h>
#include sys/types.h>
#include sys/stat.h>
#include sys/disklabel.h>
#include machine/param.h>
#include "disk.h"
#include "misc.h"
#include "mbr.h"
磁盤的分區(qū)表結(jié)構(gòu)說明如下:
字節(jié)
說明
0
是否是活動(dòng)分區(qū):0x80表示活動(dòng)分區(qū),0x00表示普通分區(qū)
1
分區(qū)起始磁頭號(hào)
2,3
2字節(jié)低6位表示起始扇區(qū)號(hào),2字節(jié)高兩位+3字節(jié)表示柱面號(hào)
4
分區(qū)文件系統(tǒng)標(biāo)志
5,6,7
分區(qū)結(jié)束柱面號(hào),磁頭號(hào),扇區(qū)號(hào),意義同1,2,3相同
8,9,10,11
邏輯起始扇區(qū)號(hào),表示在這個(gè)分區(qū)之前的扇區(qū)數(shù)
12,13,14,15
表示這個(gè)分區(qū)占用的扇區(qū)個(gè)數(shù)
void
PRT_parse(disk_t *disk, void *prt, off_t offset, off_t reloff,
prt_t *partn)
{
unsigned char *p = prt;
off_t off;
partn->flag = *p++;
partn->shead = *p++;
partn->ssect = (*p) & 0x3F;
partn->scyl = ((*p 2) & 0xFF00) | (*(p+1));
p += 2;
partn->id = *p++;
partn->ehead = *p++;
partn->esect = (*p) & 0x3F;
partn->ecyl = ((*p 2) & 0xFF00) | (*(p+1));
p += 2;
if ((partn->id == DOSPTYP_EXTEND) || (partn->id == DOSPTYP_EXTENDL))
off = reloff;
else
off = offset;
partn->bs = getlong(p) + off;
partn->ns = getlong(p+4);
PRT_fix_CHS(disk, partn);
}
本文來自ChinaUnix博客,如果查看原文請(qǐng)點(diǎn):http://blog.chinaunix.net/u/31277/showart_243344.html |
|