Top Banner
© Microsoft Corporation 1 Windows Kernel Internals NTFS David B. Probert, Ph.D. Windows Kernel Development Microsoft Corporation
25

Windows Kernel Internals NTFS - University of Tokyo Kernel Internals NTFS David B. Probert, Ph.D. Windows Kernel Development Microsoft Corporation © Microsoft Corporation 2 Basic

May 01, 2018

Download

Documents

vokhuong
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Windows Kernel Internals NTFS - University of Tokyo Kernel Internals NTFS David B. Probert, Ph.D. Windows Kernel Development Microsoft Corporation © Microsoft Corporation 2 Basic

© Microsoft Corporation 1

Windows Kernel InternalsNTFS

David B. Probert, Ph.D.Windows Kernel Development

Microsoft Corporation

Page 2: Windows Kernel Internals NTFS - University of Tokyo Kernel Internals NTFS David B. Probert, Ph.D. Windows Kernel Development Microsoft Corporation © Microsoft Corporation 2 Basic

© Microsoft Corporation 2

Basic Design Points

• Aries Logging• Meta-data via Cache Manager• Self describing meta-data• B-trees for fast index lookup• Multiple user data streams

Page 3: Windows Kernel Internals NTFS - University of Tokyo Kernel Internals NTFS David B. Probert, Ph.D. Windows Kernel Development Microsoft Corporation © Microsoft Corporation 2 Basic

© Microsoft Corporation 3

Disk Basics

• Volume exported via device object• Addressed by byte offset and length• Enforced on sector boundaries• NTFS allocation unit - clusters• Round size down to clusters

Page 4: Windows Kernel Internals NTFS - University of Tokyo Kernel Internals NTFS David B. Probert, Ph.D. Windows Kernel Development Microsoft Corporation © Microsoft Corporation 2 Basic

© Microsoft Corporation 4

NTFS Knows Files

• Partition is collection of files• Common routines for all meta-data• Utilizes MM and Cache Manager• No specific on-disk locations

Page 5: Windows Kernel Internals NTFS - University of Tokyo Kernel Internals NTFS David B. Probert, Ph.D. Windows Kernel Development Microsoft Corporation © Microsoft Corporation 2 Basic

© Microsoft Corporation 5

Some System Files

• $Bitmap• $BadClus• $Boot• . (root directory)• $Logfile• $Volume

Page 6: Windows Kernel Internals NTFS - University of Tokyo Kernel Internals NTFS David B. Probert, Ph.D. Windows Kernel Development Microsoft Corporation © Microsoft Corporation 2 Basic

© Microsoft Corporation 6

MFT File

• Data is entirely File Records• File Records are fixed size• Every file on volume has a File Record• File records are recycled• Reserved area for system files

Page 7: Windows Kernel Internals NTFS - University of Tokyo Kernel Internals NTFS David B. Probert, Ph.D. Windows Kernel Development Microsoft Corporation © Microsoft Corporation 2 Basic

© Microsoft Corporation 7

File Records

• ‘Base’ file record for each file• Header followed by ‘Attributes’• Additional file records as needed• Update Sequence Array• ID by offset and sequence number

Page 8: Windows Kernel Internals NTFS - University of Tokyo Kernel Internals NTFS David B. Probert, Ph.D. Windows Kernel Development Microsoft Corporation © Microsoft Corporation 2 Basic

© Microsoft Corporation 8

File D:¥Letters (File ID 0x200)

A B C D E F G H I J K L M N O P Q R S T U V

File ¥$Mft

A B C D E F

100200

2000

280200

J K L M N O G H I P Q R S T U V

P Q R S T A B C D E F

Physical Disk

L MG H I U V J K N O

Page 9: Windows Kernel Internals NTFS - University of Tokyo Kernel Internals NTFS David B. Probert, Ph.D. Windows Kernel Development Microsoft Corporation © Microsoft Corporation 2 Basic

© Microsoft Corporation 9

File Basics

• Timestamps• File attributes (DOS + NTFS)• Filename (+ hard links)• Data streams• ACL• Indexes

Page 10: Windows Kernel Internals NTFS - University of Tokyo Kernel Internals NTFS David B. Probert, Ph.D. Windows Kernel Development Microsoft Corporation © Microsoft Corporation 2 Basic

© Microsoft Corporation 10

File Building Blocks

• File Records• Ntfs Attributes• Allocated clusters

Page 11: Windows Kernel Internals NTFS - University of Tokyo Kernel Internals NTFS David B. Probert, Ph.D. Windows Kernel Development Microsoft Corporation © Microsoft Corporation 2 Basic

© Microsoft Corporation 11

File Record Header

• USA Header• Sequence Number• First Attribute Offset• First Free Byte and Size• Base File Record• IN_USE bit

Page 12: Windows Kernel Internals NTFS - University of Tokyo Kernel Internals NTFS David B. Probert, Ph.D. Windows Kernel Development Microsoft Corporation © Microsoft Corporation 2 Basic

© Microsoft Corporation 12

NTFS Attributes

• Type code and optional name• Resident or non-resident• Header followed by value• Sorted within file record• Common code for operations

Page 13: Windows Kernel Internals NTFS - University of Tokyo Kernel Internals NTFS David B. Probert, Ph.D. Windows Kernel Development Microsoft Corporation © Microsoft Corporation 2 Basic

© Microsoft Corporation 13

MFT File Record

$STANDARD_INFORMATION (Time Stamps, DOS Attributes)

$FILE_NAME - VeryLongFileName.Txt

$FILE_NAME - VERYLO~1.TXT

$DATA (Default Data Stream)

$DATA - “VeryLongFileName.Txt:A named stream”

$END (Available for attribute growth or new attribute)

Page 14: Windows Kernel Internals NTFS - University of Tokyo Kernel Internals NTFS David B. Probert, Ph.D. Windows Kernel Development Microsoft Corporation © Microsoft Corporation 2 Basic

© Microsoft Corporation 14

Attribute Header

• Length• Form• Name and name length• Flags (Compressed, Encrypted, Sparse)

Page 15: Windows Kernel Internals NTFS - University of Tokyo Kernel Internals NTFS David B. Probert, Ph.D. Windows Kernel Development Microsoft Corporation © Microsoft Corporation 2 Basic

© Microsoft Corporation 15

Resident Attributes

• Data follows attribute header• ‘Allocation Size’ on 8-byte boundary• May grow or shrink• Convert to non-resident

Page 16: Windows Kernel Internals NTFS - University of Tokyo Kernel Internals NTFS David B. Probert, Ph.D. Windows Kernel Development Microsoft Corporation © Microsoft Corporation 2 Basic

© Microsoft Corporation 16

Non-Resident Attributes

• Data stored in allocated disk clusters• May describe sub-range of stream• Sizes and stream properties• Mapping pairs for on-disk runs

Page 17: Windows Kernel Internals NTFS - University of Tokyo Kernel Internals NTFS David B. Probert, Ph.D. Windows Kernel Development Microsoft Corporation © Microsoft Corporation 2 Basic

© Microsoft Corporation 17

Some Attribute Types$STANDARD_INFORMATION $FILE_NAME $SECURITY_DESCRIPTOR $DATA $INDEX_ROOT $INDEX_ALLOCATION $BITMAP $EA

Page 18: Windows Kernel Internals NTFS - University of Tokyo Kernel Internals NTFS David B. Probert, Ph.D. Windows Kernel Development Microsoft Corporation © Microsoft Corporation 2 Basic

© Microsoft Corporation 18

Mapping Pairs

• Stored in a byte optimal format• Represents allocation and holes• Each pair is relative to prior run• Used to represent compression/sparse

Page 19: Windows Kernel Internals NTFS - University of Tokyo Kernel Internals NTFS David B. Probert, Ph.D. Windows Kernel Development Microsoft Corporation © Microsoft Corporation 2 Basic

© Microsoft Corporation 19

Indexes

• File name and view indexes• Indexes are B-trees• Entries stored at each level• Intermediate nodes have down pointers• $INDEX_ROOT• $INDEX_ALLOCATION• $BITMAP

Page 20: Windows Kernel Internals NTFS - University of Tokyo Kernel Internals NTFS David B. Probert, Ph.D. Windows Kernel Development Microsoft Corporation © Microsoft Corporation 2 Basic

© Microsoft Corporation 20

Index Implementation

• Top level - $INDEX_ROOT• Index buckets - $INDEX_ALLOCATION• Available buckets - $BITMAP

Page 21: Windows Kernel Internals NTFS - University of Tokyo Kernel Internals NTFS David B. Probert, Ph.D. Windows Kernel Development Microsoft Corporation © Microsoft Corporation 2 Basic

© Microsoft Corporation 21

$INDEX_ROOT

E J R end

A B CG I N P QZunused data

A B C G I N P Q Z

$INDEX_ALLOCATION

$BITMAP

0x36 (00110110)

Page 22: Windows Kernel Internals NTFS - University of Tokyo Kernel Internals NTFS David B. Probert, Ph.D. Windows Kernel Development Microsoft Corporation © Microsoft Corporation 2 Basic

© Microsoft Corporation 22

$ATTRIBUTE_LIST

• Needed for multi-file record file• Entry for each attribute in file• Resident or non-resident form• Must be in base file record

Page 23: Windows Kernel Internals NTFS - University of Tokyo Kernel Internals NTFS David B. Probert, Ph.D. Windows Kernel Development Microsoft Corporation © Microsoft Corporation 2 Basic

© Microsoft Corporation 23

Attribute List (example)

• Base Record -0x200

• 0x10 - Standard• 0x20 - Attribute List• 0x30 - FileName• 0x80 - Default Data• 0x80 - Data1 “Owner”

• Aux Record -0x180

• 0x30 - FileName• 0x80 - Data “Author”• 0x80 - Data0 “Owner”• 0x80 - Data “Writer”

Page 24: Windows Kernel Internals NTFS - University of Tokyo Kernel Internals NTFS David B. Probert, Ph.D. Windows Kernel Development Microsoft Corporation © Microsoft Corporation 2 Basic

© Microsoft Corporation 24

Attribute List (example cont.)

Code FR VCN Name (Not Present)0x10 0x200 $Standard0x30 0x200 $Filename0x30 0x180 $Filename0x80 0x200 0 $Data0x80 0x180 0 “Author” $Data0x80 0x180 0 “Owner” $Data0x80 0x200 40 “Owner” $Data0x80 0x180 “Writer” $Data

Page 25: Windows Kernel Internals NTFS - University of Tokyo Kernel Internals NTFS David B. Probert, Ph.D. Windows Kernel Development Microsoft Corporation © Microsoft Corporation 2 Basic

© Microsoft Corporation 25

Discussion