Download presentation
Presentation is loading. Please wait.
Published byMargaret Jacobs Modified over 6 years ago
1
File I/O, Command Line Parameters, Endian-ness
Operating Systems CS3430 Sarah Diesburg
2
Outline File I/O in C Passing arguments on the command line
Starter C code More on serialization (hexedit, endian, safe functions)
3
File I/O in C Two resources:
A C language file I/O tutorial (link also found on class Resources page) Take a look at endian_test.c Linked on today session webpage
4
Starting our Utility $>./fat32_reader fat32.img /]
Fat32_reader is name of our utility Should return a different prompt (like “/]”) to symbolize that user is inside utility
5
Alternatively… $>java fat32_reader fat32.img /] $>python3 fat32_reader fat32.img $>python2 fat32_reader fat32.img
6
Passing in Command Line Parameters
Can be done with any language Usually uses an argv[] and argc passed into main Let’s look at a C example: args.c
7
Main Structure of our Utility
Our utility will Prompt the user for a command Perform the command (or quit) Repeat Need a main loop and a way to compare input to commands fat32_reader.c - C starter code
8
Additional Reserved Sectors (Optional)
Reserved Region Reserved Region – Includes the boot sector, the extended boot sector, the file system information sector, and a few other reserved sectors Reserved Region FAT Data Boot Sector FS Information Sector Additional Reserved Sectors (Optional)
9
Additional Reserved Sectors (Optional)
Beginning Project 3 Start by reading boot sector fat32 information As you work, it might make sense to first take a look at the raw file system image Hexedit to the rescue! Reserved Region FAT Data Boot Sector FS Information Sector Additional Reserved Sectors (Optional)
10
Hexedit To install (run once): To run: $> hexedit [filename]
$> sudo apt-get update $> sudo apt-get install hexedit To run: $> hexedit [filename] View files in hexadecimal or ASCII Why wouldn’t you want to view the file system image file in your regular editor?
11
Hexedit
12
Hexedit Line numbers in hex
13
Hexedit Content in hex
14
Content in printable ASCII
Hexedit Content in printable ASCII
15
Hexadecimal Hints Hex is base 16 – one hexadecimal can represent 0-15
It takes 4 binary bits to represent values 0-15 0000 = 0 1111 = 15
16
Hexadecimal Hints If it takes 4 bits to represent one hexadecimal number, it takes 8 bits to represent two hexadecimal numbers 8 bits = 1 byte Two hex numbers together symbolize one byte That’s why hex numbers are in groups of two
17
Endianness FAT32 is represented in little endian byte order
Reading left to right, you encounter least-significant byte first What 32-bit number is this? 0x or 0x ?
18
Endianness Why are characters in order (readable) if some numbers are not?
19
Endianness You must account for little endianness across bytes when reading in numbers of size larger than one byte Characters are only one byte, no re-ordering necessary Use only safe functions when reading, to make sure to adjust for the endian-ness of your architecture Ex. le8toh(num), le16toh(num), le32toh(num)
20
Important Boot Sector Information
Size of each region BPB_BytesPerSec BPB_SecPerClus BPB_RsvdSecCnt BPB_NumFATS BPB_FATSz32 Root directory (first directory in tree) BPB_RootClus Warning: this list is not exhaustive!
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.