Project 3 An Introduction to File Systems CS

  • Slides: 35
Download presentation
Project 3: An Introduction to File Systems CS 3430 Operating Systems University of Northern

Project 3: An Introduction to File Systems CS 3430 Operating Systems University of Northern Iowa 1

Introduction n The goal of project 3 is to understand q q q n

Introduction n The goal of project 3 is to understand q q q n basic file system design and implementation file system testing data serialization/de-serialization At the end of the project, you will feel like a file system expert! 2

Outline n Background q n Mounting file systems Project 3 q q Specification Downloading

Outline n Background q n Mounting file systems Project 3 q q Specification Downloading and testing file system image General FAT 32 data structures Endian-ness 3

Mounting File Systems 4

Mounting File Systems 4

Unix File Hierarchy n All files accessible in a Unix system are arranged in

Unix File Hierarchy n All files accessible in a Unix system are arranged in one big tree q q n n Also called the file hierarchy Tree is rooted (starts) at / These files can be spread out over several devices The mount command serves to attach the file system found on some device to the big file tree 5

‘mount’ command n n mount <device> <mount directory> Typing ‘mount’ without arguments shows you

‘mount’ command n n mount <device> <mount directory> Typing ‘mount’ without arguments shows you what is mounted and where Second example attaches a device or partition to a directory q Must have root privileges 6

Mount Example Mount point / /mnt /dev/sda 1 /boot /home /lib files… The device

Mount Example Mount point / /mnt /dev/sda 1 /boot /home /lib files… The device sda partition 1 is mounted at “/”. All files and dirs below “/” come from this device. 7

Mount Example n Type command ‘mount’ without any arguments to see what is mounted

Mount Example n Type command ‘mount’ without any arguments to see what is mounted and where Root “/” file system mounted 8

Mount Example / /mnt /boot /home /lib files… /dev/sda 1 /dev/sdb 1 Now suppose

Mount Example / /mnt /boot /home /lib files… /dev/sda 1 /dev/sdb 1 Now suppose we attach a thumb drive and want our thumb drive files accessible under /mnt… 9

File Hierarchy Example / Mount point /mnt /boot /home /lib files… Files from the

File Hierarchy Example / Mount point /mnt /boot /home /lib files… Files from the thumb drive are now accessible under /mnt /dev/sda 1 /dev/sdb 1 10

Mount Example n The ‘mount’ command can dynamically attach new devices to new mount

Mount Example n The ‘mount’ command can dynamically attach new devices to new mount points 11

Mount Example n The ‘mount’ command can dynamically attach new devices to new mount

Mount Example n The ‘mount’ command can dynamically attach new devices to new mount points Thumb drive mounted here 12

Un-mount Command n umount <dir> n In our example where thumb drive was mounted

Un-mount Command n umount <dir> n In our example where thumb drive was mounted at /mnt, we can issue q $> umount /mnt q Must have root privileges n This means you can play with the mount command on your virtual machine, but not on the class server 13

Figuring out names of devices n n /etc/fstab – Has list of devices and

Figuring out names of devices n n /etc/fstab – Has list of devices and file systems that get auto-mounted on boot ‘dmesg’ command shows output when plugging in a dynamic device 14

Project 3 More than you wanted to know about FAT 32. . 15

Project 3 More than you wanted to know about FAT 32. . 15

Project 3 n You will create a user-space utility to manipulate a FAT 32

Project 3 n You will create a user-space utility to manipulate a FAT 32 file system image q n n No more kernel programming! Utility must understand a few basic commands to allow simple file system manipulation Utility must not corrupt the file system and should be robust 16

FAT 32 Manipulation Utility only recognizes the following built-in readonly commands: n n info

FAT 32 Manipulation Utility only recognizes the following built-in readonly commands: n n info open close size n n n cd ls read 17

File System Image n Manipulation utility will work on a preconfigured FAT 32 file

File System Image n Manipulation utility will work on a preconfigured FAT 32 file system image q n Actually a file File system image will have raw FAT 32 data structures inside q Just like looking at the raw bytes inside of a disk partition 18

File System Image n Your FAT 32 manipulation utility will have to q q

File System Image n Your FAT 32 manipulation utility will have to q q Open the FAT 32 file system image Read parts of the FAT 32 file system image and interpret the raw bytes inside to service your utility’s file system commands… …just like a file system! 19

General FAT 32 Data Structures 20

General FAT 32 Data Structures 20

Terminology n n Byte – 8 bits of data, the smallest addressable unit in

Terminology n n Byte – 8 bits of data, the smallest addressable unit in modern processors Sector – Smallest addressable unit on a storage device. Usually this is 512 bytes Cluster – FAT 32 -specific term. A group of sectors representing a chunk of data FAT – Stands for file allocation table and is a map of files to data 21

FAT 32 Disk Layout n 3 main regions… Reserved Region Track Sector FAT Region

FAT 32 Disk Layout n 3 main regions… Reserved Region Track Sector FAT Region Data Region Disk arm

Reserved Region n Reserved Region – Includes the boot sector, the extended boot sector,

Reserved Region n Reserved Region – Includes the boot sector, the extended boot sector, the file system information sector, and a few other reserved sectors Reserved Region Boot Sector FS Information Sector FAT Region Additional Reserved Sectors (Optional) Data Region

FAT Region n FAT Region – A map used to traverse the data region.

FAT Region n FAT Region – A map used to traverse the data region. Contains mappings from cluster locations to cluster locations Reserved Region FAT Region File Allocation Table #1 Data Region Copy of File Allocation Table #1

Data Region n Data Region – Using the addresses from the FAT region, contains

Data Region n Data Region – Using the addresses from the FAT region, contains actual file/directory data Reserved Region FAT Region Data until end of partition

Endian Big or little? 26

Endian Big or little? 26

Machine Endianness The endianness of a given machine determines in what order a group

Machine Endianness The endianness of a given machine determines in what order a group of bytes are handled (ints, shorts, longs) n q q n Big-endian – most significant byte first Little-endian – least significant byte first This is important to understand for this project, since FAT 32 is always formatted as little-endian

FAT 32 Endianness n The following are a few cases where endianness matters in

FAT 32 Endianness n The following are a few cases where endianness matters in your project: q q Reading in integral values from the FAT 32 image Reading in shorts from a FAT 32 image Combining multiple shorts to form a single integer from the FAT 32 image Interpreting directory entry attributes

Endian Example (English Version) n n Imagine you can only communicate three letters at

Endian Example (English Version) n n Imagine you can only communicate three letters at a time, and your word is “RAPID” Big-endian q q q n 1. RAP 2. ID Word = RAPID Little-endian q q q 1. PID 2. RA Word = PIDRA (come again? )

Endian Example (data version) n n short value = 15; /* 0 x 000

Endian Example (data version) n n short value = 15; /* 0 x 000 F */ char bytes[2]; memcpy(bytes, &value, sizeof(short)); In little-endian: q q n bytes[0] = 0 x 0 F bytes[1] = 0 x 00 In big-endian: q q bytes[0] = 0 x 00 bytes[1] = 0 x 0 F

Endian Example (data version 2) n n int value = 1337; /* 0 x

Endian Example (data version 2) n n int value = 1337; /* 0 x 00 CC 07 C 9 */ char bytes[4]; memcpy(bytes, &value, sizeof(int)); In little-endian: n In big-endian: q q bytes[0] = 0 x. C 9 bytes[1] = 0 x 07 bytes[2] = 0 x. CC bytes[3] = 0 x 00 q q bytes[0] = 0 x 00 bytes[1] = 0 x. CC bytes[2] = 0 x 07 bytes[3] = 0 x 09

Visualizing Example 2 Value = 1337 (0 x 00 CC 07 C 9) index

Visualizing Example 2 Value = 1337 (0 x 00 CC 07 C 9) index 0 1 2 3 little endian 0 x. C 9 0 x 07 0 x. CC 0 x 00 big endian 0 x 00 0 x. CC 0 x 07 0 x. C 9

Helper Resources and Programs n Look at the resources page to see how to

Helper Resources and Programs n Look at the resources page to see how to do file I/O in C q n Look at how to compile python and java programs on the Linux server q n Will have to read and seek around in the image file. If your project does not compile or run on the Linux sever, the most it can earn is 50% Parameter passing program q In C, but other languages are very similar 33

Additional Project 3 Information n n Like other projects, may work in teams or

Additional Project 3 Information n n Like other projects, may work in teams or alone Project deadline is April 30 th q q No final project demo – I will just grade them myself Optional halfway demo is still open 34

Next Steps n Take a look at the fat 32 specification file from Microsoft

Next Steps n Take a look at the fat 32 specification file from Microsoft q n Somewhat confusing – just like the real world (haha) Take a look at the image file 35