Computer Systems. Assembly Language for x86 Processors 6th Edition, Kip Irvine

Similar documents
makes floppy bootable o next comes root directory file information ATTRIB command used to modify name

Segmentation with Paging. Review. Segmentation with Page (MULTICS) Segmentation with Page (MULTICS) Segmentation with Page (MULTICS)

Guide to Computer Forensics and Investigations Fourth Edition. Chapter 6 Working with Windows and DOS Systems

Hard facts. Hard disk drives

Advanced Operating Systems

Long-term Information Storage Must store large amounts of data Information stored must survive the termination of the process using it Multiple proces

File Directories Associated with any file management system and collection of files is a file directories The directory contains information about

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

Machine Language and System Programming

Preview. COSC350 System Software, Fall

File System Case Studies. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

File Systems. What do we need to know?

File System Case Studies. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

CS609 Final Term Subjective Paper Solved with references March (2014)

Introduction. Secondary Storage. File concept. File attributes

File System. Preview. File Name. File Structure. File Types. File Structure. Three essential requirements for long term information storage

Chapter 11: File System Implementation. Objectives

Hard Disk Organization. Vocabulary

Typical File Extensions File Structure

Chapter Two File Systems. CIS 4000 Intro. to Forensic Computing David McDonald, Ph.D.

CS370 Operating Systems

Da-Wei Chang CSIE.NCKU. Professor Hao-Ren Ke, National Chiao Tung University Professor Hsung-Pin Chang, National Chung Hsing University

Assembly Language for Intel-Based Computers, 4 th Edition

DOS INT 21h - DOS Function Codes

IT ESSENTIALS V. 4.1 Module 5 Fundamental Operating Systems

There is a general need for long-term and shared data storage: Files meet these requirements The file manager or file system within the OS

Summer 2003 Lecture 26 07/24/03

What does a file system do?

Windows File System. File allocation table (FAT) NTFS - New Technology File System. used in Windows 95, and MS-DOS

Secondary Storage (Chp. 5.4 disk hardware, Chp. 6 File Systems, Tanenbaum)

ECE 598 Advanced Operating Systems Lecture 14

File Systems Forensics

File System Management

bytes per disk block (a block is usually called sector in the disk drive literature), sectors in each track, read/write heads, and cylinders (tracks).

File Management. Ezio Bartocci.

CS609 FINAL TERM CURRENT 2014 SUBJECTIVE PAPERS

COMP091 Operating Systems 1. File Systems

Table 12.2 Information Elements of a File Directory

CS370 Operating Systems

NTFS Recoverability. CS 537 Lecture 17 NTFS internals. NTFS On-Disk Structure

Chapter. Chapter. Magnetic and Solid-State Storage Devices

Operating Systems. Operating Systems Professor Sina Meraji U of T

Lesson 09: SD Card Interface

Initial Bootloader. On power-up, when a computer is turned on, the following operations are performed:

File Systems. Martin Děcký. DEPARTMENT OF DISTRIBUTED AND DEPENDABLE SYSTEMS

Chapter 4. File Systems. Part 1

A file system is a clearly-defined method that the computer's operating system uses to store, catalog, and retrieve files.

Introduction to OS. File Management. MOS Ch. 4. Mahmoud El-Gayyar. Mahmoud El-Gayyar / Introduction to OS 1

UNIX File Systems. How UNIX Organizes and Accesses Files on Disk

CSCE Introduction to Computer Systems Spring 2019

The FAT File System. 1. FAT Overview. 2. Boot Sector, FAT, Root Directory, and Files The FAT F 䤀耄 le System

File System Case Studies. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

File System: Interface and Implmentation

Files. File Structure. File Systems. Structure Terms. File Management System. Chapter 12 File Management 12/6/2018

File Systems. Information Server 1. Content. Motivation. Motivation. File Systems. File Systems. Files

FILE SYSTEMS. CS124 Operating Systems Winter , Lecture 23

File Management. Chapter 12

CS609 Final Term Solved MCQs with References Without Repetitions 14/02/2013

OPERATING SYSTEMS CS136

Chapter 12: File System Implementation

CS370 Operating Systems

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 13: 16-Bit MS-DOS Programming

Lecture 13: I/O I/O. Interrupts. How?

FILE SYSTEM IMPLEMENTATION. Sunu Wibirama

CS3600 SYSTEMS AND NETWORKS

CHAPTER 11: IMPLEMENTING FILE SYSTEMS (COMPACT) By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

CS333 Intro to Operating Systems. Jonathan Walpole

Example Implementations of File Systems

Microsoft File Allocation Table

Chapter 6. File Systems

File System Interpretation

Hard Drive Technologies

SMD149 - Operating Systems - File systems

Outlook. File-System Interface Allocation-Methods Free Space Management

File System. Computadors Grau en Ciència i Enginyeria de Dades. Xavier Verdú, Xavier Martorell

Acronis Disk Director 11 Home. Quick Start Guide

8/31/2015 BITS BYTES AND FILES. What is a bit. Representing a number. Technically, it s a change of voltage

412 Notes: Filesystem

Ρουτίνες Λειτουργίας (DOS function calls)

Che-Wei Chang Department of Computer Science and Information Engineering, Chang Gung University

Time Left. sec(s) Quiz Start Time: 12:13 AM. Question # 5 of 10 ( Start time: 12:18:29 AM ) Total Marks: 1

A+ Guide to Hardware: Managing, Maintaining, and Troubleshooting, 5e. Chapter 6 Supporting Hard Drives

C13: Files and Directories: System s Perspective

Project 3 Help Document

Older geometric based addressing is called CHS for cylinder-head-sector. This triple value uniquely identifies every sector.

CS4500/5500 Operating Systems File Systems and Implementations

File Systems. File system interface (logical view) File system implementation (physical view)

File System NTFS. Section Seven. NTFS, EFS, Partitioning, and Navigating Folders

Figure 1-1 Example of File System Layout

CSE 4482 Computer Security Management: Assessment and Forensics. Computer Forensics: Working with Windows and DOS Systems

File System Implementation. Sunu Wibirama

UNIT 4 Device Management

Microprocessors (A) DOS Services

Chapter 11: Implementing File Systems

COMP 530: Operating Systems File Systems: Fundamentals

File Shredders. and, just what is a file?

File System Concepts File Allocation Table (FAT) New Technology File System (NTFS) Extended File System (EXT) Master File Table (MFT)

THOMAS RUSSELL, Information Technology Teacher

A+ Guide to Managing and Maintaining your PC, 6e. Chapter 8 Hard Drives

Chapter 12: File System Implementation

Transcription:

Computer Systems Assembly Language for x86 Processors 6th Edition, Kip Irvine Chapter 15: Disk Fundamentals Yonsei University Department of Computer Science Jaekyung Kim(kimjk@cs.yonsei.ac.kr) (c) Pearson Education, 2010. All rights reserved. You may modify and copy this slide show for your personal use, or for use in the classroom, as long as this copyright statement, the author's name, and the title are not changed.

370 Chapter Overview Disk Storage Systems File Systems Disk Directory Reading and Writing Disk Sectors (7305h) System-Level File Functions

371 Disk Storage Systems Tracks, Cylinders, and Sectors Disk Partitions (Volumes)

372 Tracks and Sectors Physical disk geometry - a way of describing the disk s structure to make it readable by the system BIOS Track - concentric circle containing data Sector - part of a track track sector

373 Cylinders and Seeking Cylinder - all tracks readable from one head position Seek - move read/write heads between tracks rotating spindle head 0 head 1 platter movement

374 Disk Formatting Physical formatting aka low-level formatting Usually done at the factory. Must be done before logical formatting Defines the tracks, sectors, and cylinders Logical formatting Permits disk to be accessed using sequentially numbered logical sectors Installs a file system (ex: NTFS) May install an operating system

375 Fragmentation A fragmented file is one whose sectors are no longer located in contiguous areas of the disk. causes read/write heads to skip slower file access possible read/write errors

376 Translation Translation - conversion of physical disk geometry to a sequence of logical sector numbers Performed by a hard disk controller (firmware) Logical sector numbers are numbered sequentially, have no direct mapping to hardware

Disk Partitions Logical units that divide a physical hard disk Also called volumes Primary partition Up to four permitted Each may boot a different OS Extended partition Maximum of one permitted May be divided into multiple logical partitions, each with a different drive letter Primary and Extended Up to three primary and one extended Computer Systems Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010. 377

378 Logical Partitions Created from an extended partition No limit on the number Each has a separate drive letter Usually contain data Can be bootable (ex: Linux)

379 Disk Partition Table Located in the disk's Master Boot Record (MBR), following a block of executable code Four entries, one for each possible partition Each entry contains the following fields: state (non-active, bootable) type of partition (BigDOS, Extended,...) beginning head, cylinder, & sector numbers ending head, cylinder, & sector numbers offset of partition from MBR number of sectors in the partition See also: www.datarescue.com/laboratory/partition.htm

Cascading Partition Tables Drive C Boot, BigDOS Primary partition NA, Extended links to NA, BigDOS NA, BigDOS Drive D Drive E Logical partitions (D, E) Boot = bootable (system) NA = non active BigDOS = over 32 MB Computer Systems Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010. 380

Dual-Boot Example System 98 and Win2000-A are bootable partitions One is called the system partition when active DATA_1 and BACKUP are logical partitions Their data can be shared by both operating systems Computer Systems Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010. 381

382 Master Boot Record (MBR) The MBR contains the following elements: Disk partititon table A program that jumps to the boot sector of the system partition

383 What's Next Disk Storage Systems File Systems Disk Directory Reading and Writing Disk Sectors (7305h) System-Level File Functions

384 File Systems Directory, File, Cluster Relationships Clusters FAT12 FAT16 FAT32 NTFS Primary Disk Areas

385 File System This is what it does for you: Keeps track of allocated and free space Maintains directories and filenames Tracks the sector location of each file and directory

386 Directory, File, Cluster, Sector Relationships File System lists a Filename stored in Directory maps to Cluster chain stored in File Allocation Table maps to Logical sectors map to Physical sectors

387 Cluster (1 of 2) Smallest unit of space used by a file Consists of one or more adjacent sectors Size depends on both the type of file system in use and the disk partition size A file is a linked sequence of clusters. Example: sector 1 2 3 4 Cluster 1 5 6 7 8 Cluster 2

388 Cluster (2 of 2) A file always uses at least one cluster A high percentage of space may be wasted Example: 8,200-byte file requires three 4K clusters: File size: 8,200 bytes 4,096 used 4,096 used 8 bytes used, 4,088 empty Cluster 1 Cluster 2 Cluster 3

389 FAT12 Designed for diskettes Each FAT entry is 12 bits Very little fault tolerance two copies of the FAT (cluster table) Optimal storage for small files 512-byte clusters

390 FAT16 MS-DOS format for hard disks 16-bit FAT entries Large cluster size when disk > 1 GB inneficient for small files Max 2 GB size under MS-DOS Little or no recovery from read/write errors

391 FAT32 Supports long filenames Supported by all version of MS-Windows from Windows 95 onward (except Windows NT) 32-bit FAT entries 32 GB maximum volume size Improved recovery from read/write errors

392 NTFS Supported by Windows NT, 2000, and XP Handles large volumes can span multiple hard drives Efficient cluster size (4K) on large volumes Unicode filenames Permissions on files & folders Share folders across network Built-in compression and encryption Track changes in a change journal Disk quotas for individuals or groups Robust error recovery Disk mirroring

393 Primary Disk Areas A disk or volume is divided into predefined areas and assigned specific logical sectors. Example: 1.44 MB diskette Boot record (sector 0) File allocation table (sectors 1 18) Root directory (sectors 19 32) Data area (sectors 33 2,879)

394 Your turn... 1. A 1.44 MB diskette has 512 bytes per cluster. Suppose a certain file begins in cluster number 5. Which logical disk sector contains the beginning of the file? (Hint: see page 503). 2. Suppose a certain hard drive has 4 KB per cluster, and we know that the data area begins in sector 100. If a particular file begins in cluster 10, which logical sectors are used by the cluster? (answers on next panel...)

395 Answers 1. The data area begins in Sector 33. Each cluster = 1 sector, so the file begins in sector 33 + 5 = sector 38. 2. The hard drive has 8 sectors per cluster. The starting cluster number of the file is 100 + (8 * 10) = 180. Therefore, sectors 180 187 are used by the file's first cluster.

396 Boot Record (1 of 2) Fields in a typical MS-DOS boot record: Jump to boot code (JMP instruction) Manufacturer name, version number Bytes per sector Sectors per cluster Number of reserved sectors (preceding FAT #1) Number of copies of FAT Maximum number of root directory entries Number of disk sectors for drives under 32 MB Media descriptor byte Size of FAT, in sectors Sectors per track

397 Boot Record (2 of 2) (continued) Number of drive heads Number of hidden sectors Number of disk sectors for drives over 32 MB Drive number (modified by MS-DOS) Reserved Extended boot signature (always 29h) Volume ID number (binary) Volume label File-system type (ASCII) Start of boot program and data

398 What's Next Disk Storage Systems File Systems Disk Directory Reading and Writing Disk Sectors (7305h) System-Level File Functions

399 Keeping Track of Files MS-DOS Directory Structure Long Filenames in MS-Windows File Allocation Table

400 MS-DOS Directory Structure (1 of 2)

MS-DOS Directory Structure (2 of 2) Time field equals 4DBDh (9:45:58), and the Date field equals 247Ah (March 26, 1998). Attribute is normal: Filename Extension Attribute 4D 41 49 4E 20 20 20 20-43 50 50 20 00 22 E8 80 A5 24 A5 24 00 00 BD 4D - 7A 24 20 00 EE 04 00 00 MAIN CPP."...$.$...Mz$... Time Date Starting Cluster File size Computer Systems Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010. 401

402 Date and Time Fields Date stamp field: 15 0 year month day Time stamp field: 15 0 hours minutes seconds

Your turn... What time value is represented here? 0 1 1 1 0 0 0 0 0 1 0 1 0 1 0 0 hours minutes seconds Computer Systems Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010. 403

File Attribute Values (reserved, 0) (reserved, 0) archive bit subdirectory volume label system file hidden file read-only file What type of file has attribute 00100111...? Computer Systems Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010. 404

405 Long Filenames in Windows Filename: ABCDEFGHIJKLMNOPQRSTUV.TXT first long entry last long entry attribute (long entry) 01A0 42 4E 00 4F 00 50 00 51 00 52 00 0F 00 27 53 00 BN.O.P.Q.R...'S. 01B0 54 00 55 00 56 00 2E 00 54 00 00 00 58 00 54 00 T.U.V...T...X.T. 01C0 01 41 00 42 00 43 00 44 00 45 00 0F 00 27 46 00.A.B.C.D.E...'F. 01D0 47 00 48 00 49 00 4A 00 4B 00 00 00 4C 00 4D 00 G.H.I.J.K...L.M. 01E0 41 42 43 44 45 46 7E 31 54 58 54 20 00 AF 78 62 ABCDEF~1TXT..xb 01F0 2F 2B 30 2B 00 00 59 B9 30 2B 02 00 52 01 00 00 /+0+..Y.0+..R... create date last access date last modified time last modified date first cluster file size create time

406 File Allocation Table (1 of 2) A map of all clusters on the disk, showing their ownership by specific files Each entry corresponds to a cluster number Each cluster contains one or more sectors Each file is represented in the FAT as a linked list, called a cluster chain. Three types of FAT's, named after the length of each FAT entry: FAT-12 FAT-16 FAT-32

407 File Allocation Table (2 of 2) Each entry contains an n-bit integer that identifies the next entry. (n=12,16, or 32) Two cluster chains are shown in the following diagram, one for File1, and another for File2: File1: starting cluster number = 1, size = 7 clusters 2 3 4 8 9 10 eof 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 File2: starting cluster number = 5, size = 5 clusters 6 7 11 12 eof 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

408 What's Next Disk Storage Systems File Systems Disk Directory Reading and Writing Disk Sectors (7305h) System-Level File Functions

409 Reading and Writing Disk Sectors (7305h) INT 21h, Function 7305h (absolute disk read and write) Reads and writes logical disk sectors Runs only in 16-bit Real-address mode Does not work under Windows 2000, XP, Vista, Windows 7 Tight security!

DISKIO Structure Used by Function 7305h: DISKIO STRUCT startsector DWORD 0 ; starting sector number numsectors WORD 1 ; number of sectors bufferofs WORD buffer ; buffer offset bufferseg WORD @DATA ; buffer segment DISKIO ENDS Computer Systems Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010. 410

Example Example: Read one or more sectors from drive C:.data buffer BYTE 512 DUP(?) diskstruct DISKIO <>.code mov ax,7305h ; absolute Read/Write mov cx,0ffffh ; always this value mov dl,3 ; drive C mov bx,offset diskstruct mov si,0 ; read sector int 21h Computer Systems Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010. 411

412 Sector Display Program Pseudocode: Ask for starting sector number and drive number do while (keystroke <> ESC) Display heading Read one sector If MS-DOS error then exit Display one sector Wait for keystroke Increment sector number end do View the source code

413 What's Next Disk Storage Systems File Systems Disk Directory Reading and Writing Disk Sectors (7305h) System-Level File Functions

414 System-Level File Functions Common Disk-Related Functions Get Disk Free Space Create Subdirectory Remove Subdirecrory Set Current Directory Get Current Directory

415 Common Disk-Related Functions

416 ExtGetDskFreSpcStruc Structure (1 of 2) Structure data returned by Fucntion 7303h: StructSize: A return value that represents the size of the ExtGetDskFreSpcStruc structure, in bytes. Level: Always 0. SectorsPerCluster: The number of sectors inside each cluster. BytesPerSector: The number of bytes in each sector. AvailableClusters: The number of available clusters. TotalClusters: The total number of clusters in the volume.

417 ExtGetDskFreSpcStruc (2 of 2) AvailablePhysSectors: The number of physical sectors available in the volume, without adjustment for compression. TotalPhysSectors: The total number of physical sectors in the volume, without adjustment for compression. AvailableAllocationUnits: The number of available allocation units in the volume, without adjustment for compression. TotalAllocationUnits: The total number of allocation units in the volume, without adjustment for compression. Rsvd: Reserved member.

418 Function 7303h Get Disk Free Space AX = 7303h ES:DI points to a ExtGetDskFreSpcStruc CX = size of the ExtGetDskFreSpcStruc variable DS:DX points to a null-terminated string containing the drive name View the DiskSpc.asm program

419 Create Subdirectory.data pathname BYTE "\ASM",0.code mov ah,39h mov dx,offset pathname int 21h jc DisplayError.. DisplayError: ; create subdirectory

420 Remove Subdirecrory.data pathname BYTE 'C:\ASM',0.code mov ah,3ah mov dx,offset pathname int 21h jc DisplayError.. DisplayError: ; remove subdirectory

421 Set Current Directory.data pathname BYTE "C:\ASM\PROGS",0.code mov ah,3bh mov dx,offset pathname int 21h jc DisplayError.. DisplayError: ; set current directory

422 Get Current Directory.data pathname BYTE 64 dup(0).code mov ah,47h mov dl,0 mov si,offset pathname int 21h jc DisplayError.. DisplayError: ; path stored here by MS-DOS ; get current directory path ; on default drive

423 Your turn... Write a program that creates a hidden, read-only directory named secret. Create a hidden file inside the new directory named $$temp. Try to remove the directory by calling Function 3Ah. Display the error code returned by MS-DOS.

424 Summary Disk controller: acts as a broker between the hardware and the operating system Disk characteristics composed of tracks, cylinders, sectors average seek time, data transfer rate Formatting & logical characteristics master boot record, contains disk partition table clusters logical storage units file allocation table used by some systems directory root directory, subdirectories