add directory study

This commit is contained in:
gohigh
2024-02-19 00:25:23 -05:00
parent b1306b38b1
commit f3774e2f8c
4001 changed files with 2285787 additions and 0 deletions

Binary file not shown.

View File

@@ -0,0 +1,341 @@
How it Works -- Partition Tables
Version 1c
by Hale Landis (landis@sugs.tware.com)
THE "HOW IT WORKS" SERIES
This is one of several How It Works documents. The series
currently includes the following:
* How It Works -- CHS Translation
* How It Works -- Master Boot Record
* How It Works -- DOS Floppy Boot Sector
* How It Works -- OS2 Boot Sector
* How It Works -- Partition Tables
PARTITION SECTOR/RECORD/TABLE BASICS
FDISK creates all partition records (sectors). The primary
purpose of a partition record is to hold a partition table. The
rules for how FDISK works are unwritten but so far most FDISK
programs (DOS, OS/2, WinNT, etc) seem to follow the same basic
idea.
First, all partition table records (sectors) have the same
format. This includes the partition table record at cylinder 0,
head 0, sector 1 -- what is known as the Master Boot Record
(MBR). The last 66 bytes of a partition table record contain a
partition table and a 2 byte signature. The first 446 bytes of
these sectors usually contain a program but only the program in
the MBR is ever executed (so extended partition table records
could contain something other than a program in the first 466
bytes). See "How It Works -- The Master Boot Record".
Second, extended partitions are "nested" inside one another and
extended partition table records form a "linked list". I will
attempt to show this in a diagram below.
PARTITION TABLE ENTRY FORMAT
Each partition table entry is 16 bytes and contains things like
the start and end location of a partition in CHS, the start in
LBA, the size in sectors, the partition "type" and the "active"
flag. Warning: older versions of FDISK may compute incorrect
LBA or size values. And note: When your computer boots itself,
only the CHS fields of the partition table entries are used
(another reason LBA doesn't solve the >528MB problem). The CHS
fields in the partition tables are in L-CHS format -- see "How It
Works -- CHS Translation".
There is no central clearing house to assign the codes used in
the one byte "type" field. But codes are assigned (or used) to
define most every type of file system that anyone has ever
implemented on the x86 PC: 12-bit FAT, 16-bit FAT, HPFS, NTFS,
etc. Plus, an extended partition also has a unique type code.
Note: I know of no complete list of all the type codes that have
been used to date. However, I try to include such a list in a
future version of this document.
The 16 bytes of a partition table entry are used as follows:
+--- Bit 7 is the active partition flag, bits 6-0 are zero.
|
| +--- Starting CHS in INT 13 call format.
| |
| | +--- Partition type byte.
| | |
| | | +--- Ending CHS in INT 13 call format.
| | | |
| | | | +-- Starting LBA.
| | | | |
| | | | | +-- Size in sectors.
| | | | | |
v <--+---> v <--+--> v v
0 1 2 3 4 5 6 7 8 9 A B C D E F
DH DL CH CL TB DL CH CL LBA..... SIZE....
80 01 01 00 06 0e be 94 3e000000 0c610900 1st entry
00 00 81 95 05 0e fe 7d 4a610900 724e0300 2nd entry
00 00 00 00 00 00 00 00 00000000 00000000 3rd entry
00 00 00 00 00 00 00 00 00000000 00000000 4th entry
Bytes 0-3 are used by the small program in the Master Boot Record
to read the first sector of an active partition into memory. The
DH, DL, CH and CL above show which x86 register is loaded when
the MBR program calls INT 13H AH=02H to read the active
partition's boot sector. See "How It Works -- Master Boot
Record".
These entries define the following partitions:
1) The first partition, a primary partition DOS FAT, starts at
CHS 0H,1H,1H (LBA 3EH) and ends at CHS 294H,EH,3EH with a size
of 9610CH sectors.
2) The second partition, an extended partition, starts at CHS
295H,0H,1H (LBA 9614AH) and ends at CHS 37DH,EH,3EH with a
size of 34E72H sectors.
3) The third and fourth table entries are unused.
PARTITION TABLE RULES
Keep in mind that there are NO written rules and NO industry
standards on how FDISK should work but here are some basic rules
that seem to be followed by most versions of FDISK:
1) In the MBR there can be 0-4 "primary" partitions, OR, 0-3
primary partitions and 0-1 extended partition entry.
2) In an extended partition there can be 0-1 "secondary"
partition entries and 0-1 extended partition entries.
3) Only 1 primary partition in the MBR can be marked "active" at
any given time.
4) In most versions of FDISK, the first sector of a partition
will be aligned such that it is at head 0, sector 1 of a
cylinder. This means that there may be unused sectors on the
track(s) prior to the first sector of a partition and that
there may be unused sectors following a partition table
sector.
For example, most new versions of FDISK start the first
partition (primary or extended) at cylinder 0, head 1, sector
1. This leaves the sectors at cylinder 0, head 0, sectors
2...n as unused sectors. This same layout may be seen on the
first track of an extended partition. See example 2 below.
Also note that software drivers like Ontrack's Disk Manager
depend on these unused sectors because these drivers will
"hide" their code there (in cylinder 0, head 0, sectors
2...n). This is also a good place for boot sector virus
programs to hang out.
5) The partition table entries (slots) can be used in any order.
Some versions of FDISK fill the table from the bottom up and
some versions of FDISK fill the table from the top down.
Deleting a partition can leave an unused entry (slot) in the
middle of a table.
6) And then there is the "hack" that some newer OS's (OS/2 and
Linux) use in order to place a partition spanning or passed
cylinder 1024 on a system that does not have a CHS translating
BIOS. These systems create a partition table entry with the
partition's starting and ending CHS information set to all
FFH. The starting and ending LBA information is used to
describe the location of the partition. The LBA can be
converted back to a CHS -- most likely a CHS with more than
1024 cylinders. Since such a CHS can't be used by the system
BIOS, these partitions can not be booted or accessed until the
OS's kernel and hard disk device drivers are loaded. It is
not known if the systems using this "hack" follow the same
rules for the creation of these type of partitions.
There are NO written rules as to how an OS scans the partition
table entries so each OS can have a different method. For DOS,
this means that different versions could assign different drive
letters to the same FAT file system partitions.
PARTITION NESTING
What do I mean when I say the partitions are "nested" within each
other? Lets look at this example:
M = Master Boot Record (and any unused sectors
on the same track)
E = Extended partition record (and any unused sectors
on the same track)
pri = a primary partition (first sector is a "boot" sector)
sec = a secondary partition (first sector is a "boot" sector)
|<----------------the entire disk-------------->|
| |
|M |
| |
| E<---rest of 1st ext part---------->|
| |
| E<---rest of 2nd ext part---->|
The first extended partition is described in the MBR and it
occupies the entire disk following the primary partition. The
second extended partition is described in the first extended
partition record and it occupies the entire disk following the
first secondary partition.
PARTITION TABLE LINKING
What do I mean when I say the partition records (tables) form a
"linked" list? This means that the MBR has an entry that
describes (points to) the first extended partition, the first
extended partition table has an entry that describes (points to)
the second extended partition table, and so on. There is, in
theory, no limited to out long this linked list is. When you ask
FDISK to show the DOS "logical drives" it scans the linked list
looking for all of the DOS FAT type partitions that may exist.
Remember that in an extended partition table, only two entries of
the four can be used (rule 2 above).
And one more thing... Within a partition, the layout of the file
system data varies greatly. However, the first sector of a
partition is expected to be a "boot" sector. A DOS FAT file
system has: a boot sector, first FAT sectors, second FAT
sectors, root directory sectors and finally the file data area.
See "How It Works -- OS2 Boot Sector".
EXAMPLE 1
A disk containing four DOS FAT partitions (C, D, E and F):
|<---------------------the entire disk------------------->|
| |
|M<---C:---> |
| |
| E<---D:---><-rest of 1st ext part------------>|
| |
| E<---E:---><-rest of 2nd ext part->|
| |
| E<---------F:---------->|
EXAMPLE 2
So here is an example of a disk with two primary partitions, one
DOS FAT and one OS/2 HPFS, plus an extended partition with
another DOS FAT:
|<------------------the entire disk------------------>|
| |
|M |
| |
| |
| |
| E|
Or in more detail ('n' is the highest cylinder, head or sector
number number allowed in the indicated field of the CHS)...
+-------------------------------------+
CHS=0,0,1 | Master Boot Record containing |
| partition table search program and |
| a partition table |
| +---------------------------------+ |
| | DOS FAT partition description | | points to CHS=0,1,1
| +---------------------------------+ | points to CHS=a
| | OS/2 HPFS partition description | |
| +---------------------------------+ |
| | unused table entry | |
| +---------------------------------+ |
| | extended partition entry | | points to CHS=b
| +---------------------------------+ |
+-------------------------------------+
CHS=0,0,2 | the rest of "track 0" -- this is | :
to | where the software drivers such as | : normally
CHS=0,0,n | Ontrack's Disk Manager or Micro | : unused
| House's EZ Drive are located. | :
+-------------------------------------+
CHS=0,1,1 | Boot sector for the DOS FAT | :
| partition | : a DOS FAT
+-------------------------------------+ : file
CHS=0,1,2 | rest of the DOS FAT partition | : system
to | (FAT table, root directory and | :
CHS=x-1,n,n | user data area) | :
+-------------------------------------+
CHS=x,0,1 | Boot sector for the OS/2 HPFS | :
| file system partition | : an OS/2
+-------------------------------------+ : HPFS file
CHS=x,0,2 | rest of the OS/2 HPFS file system | : system
to | partition | :
CHS=y-1,n,n | | :
+-------------------------------------+
CHS=y,0,1 | Partition record for the extended |
| partition containing a partition |
| record program (never executed) and |
| a partition table |
| +---------------------------------+ |
| | DOS FAT partition description | | points to CHS=b+1
| +---------------------------------+ |
| | unused table entry | |
| +---------------------------------+ |
| | unused table entry | |
| +---------------------------------+ |
| | unused table entry | |
| +---------------------------------+ |
+-------------------------------------+
CHS=y,0,2 | the rest of the first track of the | : normally
to | extended partition | : unused
CHS=y,0,n | | :
+-------------------------------------+
CHS=y,1,1 | Boot sector for the DOS FAT | :
| partition | : a DOS FAT
+-------------------------------------+ : file
CHS=y,1,2 | rest of the DOS FAT partition | : system
to | (FAT table, root directory and | :
CHS=n,n,n | user data area) | :
+-------------------------------------+
EXAMPLE 3
Here is a partition record from an extended partition (the first
sector of an extended partition). Note that it contains no
program code. It contains only the partition table and the
signature data.
OFFSET 0 1 2 3 4 5 6 7 8 9 A B C D E F *0123456789ABCDEF*
000000 00000000 00000000 00000000 00000000 *................*
000010 TO 0001af SAME AS ABOVE
0001b0 00000000 00000000 00000000 00000001 *................*
0001c0 8195060e fe7d3e00 0000344e 03000000 *.....}>...4N....*
0001d0 00000000 00000000 00000000 00000000 *................*
0001e0 00000000 00000000 00000000 00000000 *................*
0001f0 00000000 00000000 00000000 000055aa *..............U.*
NOTES
Thanks to yue@heron.Stanford.EDU (Kenneth C. Yue) for pointing
out that in V0 of this document I did not properly describe the
unused sectors normally found around the partition table sectors.
/end/
--
\\===============\\=======================\\
\\ Hale Landis \\ 303-548-0567 \\
// Niwot, CO USA // landis@sugs.tware.com //
//===============//=======================//

View File

@@ -0,0 +1,68 @@
Values for operating system indicator:
00h empty
01h DOS 12-bit FAT
02h XENIX root file system
03h XENIX /usr file system (obsolete)
04h DOS 16-bit FAT (up to 32M)
05h DOS 3.3+ extended partition
06h DOS 3.31+ Large File System (16-bit FAT, over 32M)
07h QNX
07h OS/2 HPFS
07h Windows NT NTFS
07h Advanced Unix
08h AIX bootable partition, SplitDrive
09h AIX data partition
09h Coherent filesystem
0Ah OS/2 Boot Manager
0Ah OPUS
0Ah Coherent swap partition
10h OPUS
11h OS/2 Boot Manager hidden 12-bit FAT partition
12h Compaq Diagnostics partition
14h (resulted from using Novell DOS 7.0 FDISK to delete Linux Native part)
14h OS/2 Boot Manager hidden sub-32M 16-bit FAT partition
16h OS/2 Boot Manager hidden over-32M 16-bit FAT partition
17h OS/2 Boot Manager hidden HPFS partition
18h AST special Windows swap file
24h NEC MS-DOS 3.x
3Ch PowerQuest PartitionMagic recovery partition
40h VENIX 80286
42h SFS (Secure File System) by Peter Gutmann
50h Disk Manager, read-only partition
51h Disk Manager, read/write partition
51h Novell???
52h CP/M
52h Microport System V/386
56h GoldenBow VFeature
61h SpeedStor
63h Unix SysV/386, 386/ix
63h Mach, MtXinu BSD 4.3 on Mach
63h GNU HURD
64h Novell NetWare
65h Novell NetWare (3.11)
70h DiskSecure Multi-Boot
75h PC/IX
80h Minix v1.1 - 1.4a
81h Minix v1.4b+
81h Linux
81h Mitac Advanced Disk Manager
82h Linux Swap partition
83h Linux native file system (ext2fs/xiafs)
84h OS/2-renumbered type 04h partition (related to hiding DOS C: drive)
93h Amoeba file system
94h Amoeba bad block table
A5h FreeBSD
B7h BSDI file system (secondarily swap)
B8h BSDI swap partition (secondarily file system)
C1h DR-DOS 6.0 LOGIN.EXE-secured 12-bit FAT partition
C4h DR-DOS 6.0 LOGIN.EXE-secured 16-bit FAT partition
C6h DR-DOS 6.0 LOGIN.EXE-secured Huge partition
C7h Cyrnix Boot
DBh CP/M, Concurrent CP/M, Concurrent DOS
DBh CTOS (Convergent Technologies OS)
E1h SpeedStor 12-bit FAT extended partition
E4h SpeedStor 16-bit FAT extended partition
F2h DOS 3.3+ secondary
F4h SpeedStor
FEh LANstep
FFh Xenix bad block table

View File

@@ -0,0 +1,99 @@
<title>Operating Systems: Partition Tables</title>
<body BGCOLOR=#FFFFFF TEXT=#000000>
<center><font face=Verdana size=7><b>Partition Tables</b></font></center>
<HR><p>
This article is about the partitioning scheme that MS-DOS uses to keep track
of it's partitions. This is the standard that all PC operation systems must
use to be allowed to share hard disk resources with other operating systems.
<p>
Send me any questions, comments, or corrections.
<i><a href="mailto:sabre@nondot.org">Chris Lattner</a></i><p>
<HR Align=Center Width=400><br>
DOS keeps track of partitions with a "Master Partition Table" that it keeps
at offset 1BEh in the disk's boot sector. It contains four 16 byte
entries, one for each partition. Each entry is divided into ten fields that
contain all of the information necessary to describe a partition on the
hard drive, including: <p>
<ul>
<li>Whether this partition is the one that got booted from.<br>
<li>The Head, Sector, and Cylinder where the partition starts.<br>
<li>The Head, Sector, and Cylinder where the partition ends.<br>
<li>The operating system that owns it.<br>
<li>The number of sectors that are before this partition.<br>
<li>The length of the partition in sectors.<br>
</ul>
See: <strong><a href="#Fig_1">Figure 1</a></strong><p>
Now the astute reader may say: "Wait a minute! On my machine I run DOS/Windows
and OS/2. I have 5 DOS partitions. How can this be!"<p>
Microsoft's solution to this problem was to invent the "Extended DOS"
partition. If you go into FDISK, you will see that you have a "Primary" DOS
partition, and an "Extended" DOS partition (Plus whatever else you have).
You can also type in "UNFORMAT /PARTN /L" to get a list of all of your partitions.
This clearly shows the chain format used. <p>
<H2><HR Align=Center Width=400>
<A NAME="Fig_1">Figure 1</H2>
<CENTER>
<TABLE BORDER CellPadding=10 WIDTH="50%">
<TR ALIGN=CENTER>
<TD></TD><TD ColSpan=3> Start </TD><TD></TD><TD ColSpan=3> End </TD>
</TR>
<TR ALIGN=CENTER>
<TD>BI</TD>
<TD>H</TD><TD>S</TD><TD>C</TD>
<TD>SI</TD>
<TD>H</TD><TD>S</TD><TD>C</TD>
<TD ColSpan=4>SB</TD><TD ColSpan=4>NS</TD>
</TR>
<TR ALIGN=CENTER>
<TD>0h</TD><TD>1h</TD><TD>2h</TD><TD>3h</TD><TD>4h</TD><TD>5h</TD><TD>6h</TD><TD>7h</TD>
<TD>8h</TD><TD>9h</TD><TD>Ah</TD><TD>Bh</TD><TD>Ch</TD><TD>Dh</TD><TD>Eh</TD><TD>Fh</TD>
</TR>
</TABLE>
</CENTER><p>
This is repeated four times (one for each partition). Offsets are:
1BEh, 1CEh, 1DEh, and 1EEh. At offset 1FEh, AA55h signifies that the disk
is bootable. The BIOS reads it in and executes it. See my article on <strong>
<a href="http://www.nondot.org/sabre/os/files/Booting/BootSector.html">Boot Sectors</a></strong>.<br>
<h3>Key:</H3>
<ul>
BI: Boot indication. 0 = Not booted from. 80h = Booted from. <br>
H: Head. Starting/Ending head number for the partition. <br>
S: Sector. Starting/Ending sector number for the partition. This field
also holds bits 8 and 9 of the cylinder in standard DOS format. <br>
C: Cylinder. Lower 8 bits of the Starting/Ending cylinder number for
the partition. <br>
SI: System Indicator:
<ul>
00h = Unused <br>
01h = DOS 12 bit FAT (0 - 16 megs) <br>
02h = XENIX root file system <br>
03h = XENIX /usr file system (obsolete) <br>
04h = DOS 16 bit FAT (16 - 32 megs) <br>
05h = Extended DOS partition <br>
06h = DOS 16 bit FAT (32 megs and up) <br>
07h = OS/2 High Performance File System <br>
07h = Windows NT (NTFS) <br>
07h = Advanced Unix <br>
0Ah = OS/2 Boot Manager <br>
<li>For more, consult Ralf Brown's Interrupt list: INT 19 <br>
</ul>
SB (DWORD): Number of sectors before this partition. <br>
NS (DWORD): Number of sectors in this partition. <br>
</ul>
<p><hr><FONT SIZE=4><TABLE ALIGN=RIGHT BORDER=0><TR><TD><center>
Copyright &copy; 1994-8 <i><a href="mailto:sabre@nondot.org">Chris Lattner</a></i><br>
Last modified: Monday, 21-May-2001 13:25:25 CDT </center></TD></TR></TABLE>

View File

@@ -0,0 +1,7 @@
<html>
<head>
<meta http-equiv="refresh" content="0;url=/Linux.old/sabre/os/articles">
</head>
<body lang="zh-CN">
</body>
</html>