Week 10 Project 3 An Introduction to File

  • Slides: 46
Download presentation
Week 10 Project 3: An Introduction to File Systems Classes COP 4610 / CGS

Week 10 Project 3: An Introduction to File Systems Classes COP 4610 / CGS 5765 Florida State University 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 q n Setting up your environment Mounting file systems Project

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

Environment Setup Get ready for Project 3! 4

Environment Setup Get ready for Project 3! 4

Project 3 Environment n Must develop inside Linux environment with root access q n

Project 3 Environment n Must develop inside Linux environment with root access q n Use Debian virtual machine or lab machine from project 2 I will be grading your projects inside of my copy of the class virtual machine 5

Project Environment n Kernel version no longer matters q n Can go back to

Project Environment n Kernel version no longer matters q n Can go back to the default 2. 6. 26 version if you trust it more Entire project will be in userspace, not kernel! q Please use debuggers, they will save you time n n gdb, ddd, others… Programming language is still C 6

Running out of room? n n You must have at least 64 MB free

Running out of room? n n You must have at least 64 MB free plus room for your source code To see how much room you have left inside your machine, issue the following command: $> df -h 7

df -h n /dev/sda is root file system mounted on “/” q Has 2.

df -h n /dev/sda is root file system mounted on “/” q Has 2. 2 GB currently available 8

Cleaning up space n If you need to clean up some more space q

Cleaning up space n If you need to clean up some more space q q Issue ‘make clean’ inside of your 2. 6. 32 kernel source Delete the 2. 6. 26 kernel source 9

Mounting File Systems 10

Mounting File Systems 10

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 11

‘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 12

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. 13

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 14

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… 15

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 16

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 17

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 18

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 19

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 20

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

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

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 22

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

FAT 32 Manipulation Utility only recognizes the following built-in commands: n n n open close create rm size n n n cd ls mkdir rmdir read write 23

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 24

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! 25

File System Image n Sometimes you may want to check that you haven’t corrupted

File System Image n Sometimes you may want to check that you haven’t corrupted your file system image, or that you can add or write files successfully q q Mount your file system image with the OS FAT 32 driver Just like the file system image is a device 26

File System Image Mount Example / /mnt /boot /home /lib files… /user files… fat

File System Image Mount Example / /mnt /boot /home /lib files… /user files… fat 32. img 27

File System Image Mount Example / /mnt File that contains a raw image of

File System Image Mount Example / /mnt File that contains a raw image of a file system /boot /home /lib files… /user files… fat 32. img 28

File System Image Mount Example / /mnt /boot /home /lib files… /user files… Mount

File System Image Mount Example / /mnt /boot /home /lib files… /user files… Mount image onto /mnt to read files in image fat 32. img 29

File System Image Mount Example $> sudo mount -o loop fat 32. img /mnt

File System Image Mount Example $> sudo mount -o loop fat 32. img /mnt $> cd /mnt n n n fat 32. img is your image file /mnt is your mounting directory Once the file is mounted, you can go into the /mnt directory and issue all your normal file system commands like: q ls, cat, cd, … 30

General FAT 32 Data Structures 31

General FAT 32 Data Structures 31

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 32

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? 37

Endian Big or little? 37

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

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 December 3 rd, 2010 at 11: 59 pm (Friday before finals week) q q q No extensions Can use remainder of slack days Cannot be more than 3 days late n Monday, December 6 th is absolute last day to turn in 44

Project 3 Partners n n Raise your hand if you are looking for a

Project 3 Partners n n Raise your hand if you are looking for a partner… Also use the discussion board 45

Until Next Time n n n Set up your environment Download the image file

Until Next Time n n n Set up your environment Download the image file Practice mounting the image file with the OS FAT 32 drivers q n Make sure you can cd into /mnt and read/write to the files Read over the FAT 32 Specification 46