File I/O, Command Line Parameters, Endian-ness

Slides:



Advertisements
Similar presentations
1 Week 11 FAT32 Boot Sector, Locating Files and Dirs Classes COP4610 / CGS5765 Florida State University.
Advertisements

Utilizing the GDB debugger to analyze programs Background and application.
The Assembly Language Level
Assembly 01. Outline Binary vs. Text Files Compiler vs. Assembler Mnemonic Assembly Process Development Process Debugging Example 1 this analogy will.
Recap – Intro to Project 3 and FAT32
Lab6 – Debug Assembly Language Lab
IT Systems What Number? EN230-1 Justin Champion C208 –
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
1 Computers and Representations Ascii vs. Binary Files Over the last few million years, Earth has experienced numerous ice ages when vast regions of the.
CS 206 Introduction to Computer Science II 04 / 29 / 2009 Instructor: Michael Eckmann.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
Week 10 Project 3: An Introduction to File Systems
Homework Reading Programming Assignments
Data Representation Prepared by Dr P Marais (Modified by D Burford)
1 Project 3: An Introduction to File Systems CS3430 Operating Systems University of Northern Iowa.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Introduction to Unix (CA263) File Editing By Tariq Ibn Aziz.
Computer Organization 1 Instruction Fetch and Execute.
OPERATING SYSTEMS Frans Sanen.  Analyze a FAT file system manually  FAT12 first and simplest version  Still used on smaller disks (e.g. floppies) 
NTFS Filing System CHAPTER 9. New Technology File System (NTFS) Started with Window NT in 1993, Windows XP, 2000, Server 2003, 2008, and Window 7 also.
Files in Python The Basics. Why use Files? Very small amounts of data – just hardcode them into the program A few pieces of data – ask the user to input.
1 FAT32 Boot Sector, Locating Files and Dirs Operating Systems CS3430 Sarah Diesburg.
Today… Strings: –String Methods Demo. Raising Exceptions. os Module Winter 2016CISC101 - Prof. McLeod1.
Hex Editing using HxD Nick Fogal & Lindsay Shaffer.
1 Chapter 1: Introduction Appendix A: Binary and Hexadecimal Tutorial Assembly Language for Intel-Based Computers, 3rd edition Kip R. Irvine.
Chapter 3: Mastering Editors Chapter 3 Mastering Editors (Emacs)
COMPUTER ORGANIZATION 4 TH LECTURE. ASCII Code  ASCII ( American Standard Code for Information Interchange).  Input and output devices that communicate.
UMBC CMSC 421 Spring 2017 The FAT Filesystem.
Efficient Drive forensics – and it’s free!
The Machine Model Memory
Distributed Computing Systems
FAT32 Directory Entries and Operations Guide
Topics Introduction to Repetition Structures
FAT32 Directory Entries and Operations Guide
A “Walk Through” Experiment
Slide design: Dr. Mark L. Hornick
Guide To UNIX Using Linux Third Edition
Session #5 File I/O Bit Masks, Fields & Bit Manipulations
How does it do that? Introducing Computer Software
Project 3: An Introduction to File Systems
Python Lesson 12 Mr. Kalmes.
Using Tweak to Study Ccrypt
CS 301 Fall 2001 – Chapter 3 Slides by Prof. Hartman, following “IBM PC Assembly Language Programming” by Peter Abel 9/17/2018.
LING 408/508: Computational Techniques for Linguists
Strings, Line-by-line I/O, Functions, Call-by-Reference, Call-by-Value
File Managements.
Chapter 17 Binary I/O Dr. Clincy - Lecture.
Slide design: Dr. Mark L. Hornick
Python Lessons 13 & 14 Mr. Kalmes.
Passing Parameters by value
Data Representation Conversion 05/12/2018.
Winter 2018 CISC101 12/5/2018 CISC101 Reminders
Chapter Four UNIX File Processing.
Project 3: An Introduction to File Systems
Lecture 9: Radix-64 Tutorial
Homework Applied for cs240? (If not, keep at it!) 8/10 Done with HW1?
File Analysis with MicroSoft DEBUG
FAT32 Directory Entries and Operations Guide
Understanding Hex “I hope you have the worst headache of your life, then you will begin to understand” ~unknown.
Sector 25 from the Root Directory (in 32 byte chunks)
Slide design: Dr. Mark L. Hornick
Lab 4: Introduction to Scripting
Module 6 Working with Files and Directories
CS2911 Week 2, Class 3 Today Return Lab 2 and Quiz 1
Quick Tutorial on MPICH for NIC-Cluster
Python Lessons 13 & 14 Mr. Husch.
Recap – Intro to Project 3 and FAT32
Chapter 5 File Systems -Compiled for MCA, PU
SPL – PS1 Introduction to C++.
File I/O, Command Line Parameters, Endian-ness
Presentation transcript:

File I/O, Command Line Parameters, Endian-ness Operating Systems CS3430 Sarah Diesburg

Outline File I/O in C Passing arguments on the command line Starter C code More on serialization (hexedit, endian, safe functions)

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

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

Alternatively… $>java fat32_reader fat32.img /] $>python3 fat32_reader fat32.img $>python2 fat32_reader fat32.img

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

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

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)

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)

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?

Hexedit

Hexedit Line numbers in hex

Hexedit Content in hex

Content in printable ASCII Hexedit Content in printable ASCII

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

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

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? 0x0000040 or 0x40000000?

Endianness Why are characters in order (readable) if some numbers are not?

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)

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!