File Systems. It is a simple C program that prints ``hello world'' and then exits. The header describes it as an ELF image with two physical headers (e_phnum.

Slides:



Advertisements
Similar presentations
Programs in Memory Bryce Boe 2012/08/29 CS32, Summer 2012 B.
Advertisements

C Language.
Part IV: Memory Management
One Dimensional Arrays
ITEC 352 Lecture 27 Memory(4). Review Questions? Cache control –L1/L2  Main memory example –Formulas for hits.
Basic Algorithms on Arrays. Learning Objectives Arrays are useful for storing data in a linear structure We learn how to process data stored in an array.
7. Physical Memory 7.1 Preparing a Program for Execution
Search and Recursion pt. 2 CS221 – 2/25/09. How to Implement Binary Search Take a sorted data-set to search and a key to search for Start at the mid-point.
Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
File System Implementation: beyond the user’s view A possible file system layout on a disk.
Representing Block and Record Addresses Rajhdeep Jandir ID: 103.
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Memory Management - 2 CS 342 – Operating Systems Ibrahim Korpeoglu Bilkent.
File Systems Implementation
CS 104 Introduction to Computer Science and Graphics Problems
Chapter 5: Loops and Files.
Chapter 9 Virtual Memory Produced by Lemlem Kebede Monday, July 16, 2001.
Chapter 6 C Arrays Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc. Arrays are data structures.
File System Implementation
Overview scope - determines when an identifier can be referenced in a program storage class - determines the period of time during which that identifier.
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
OBJECT MODULE FORMATS. The object module format we have employed as an educational device is called OMF (relocatable object format). It’s one of the earliest.
High-Level Programming Languages: C++
1Fall 2008, Chapter 11 Disk Hardware Arm can move in and out Read / write head can access a ring of data as the disk rotates Disk consists of one or more.
Chapter 11: File System Implementation Hung Q. Ngo KyungHee University Spring 2009
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 8: Main Memory.
CSIS 123A Lecture 6 Strings & Dynamic Memory. Introduction To The string Class Must include –Part of the std library You can declare an instance like.
MIPS coding. SPIM Some links can be found such as:
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
8.4 paging Paging is a memory-management scheme that permits the physical address space of a process to be non-contiguous. The basic method for implementation.
Programming With C.
Recursion Textbook chapter Recursive Function Call a recursive call is a function call in which the called function is the same as the one making.
IT253: Computer Organization Lecture 3: Memory and Bit Operations Tonga Institute of Higher Education.
1 C++ Syntax and Semantics, and the Program Development Process.
Topic 2d High-Level languages and Systems Software
1 File Systems: Consistency Issues. 2 File Systems: Consistency Issues File systems maintains many data structures  Free list/bit vector  Directories.
CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11: :30 AM.
CSC 211 Data Structures Lecture 13
80386DX.
Page 111/15/2015 CSE 30341: Operating Systems Principles Chapter 11: File System Implementation  Overview  Allocation methods: Contiguous, Linked, Indexed,
Files & File system. A Possible File System Layout Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved
CS 241 Section Week #9 (11/05/09). Topics MP6 Overview Memory Management Virtual Memory Page Tables.
Solutions for the First Quiz COSC 6360 Spring 2014.
The Goal: illusion of large, fast, cheap memory Fact: Large memories are slow, fast memories are small How do we create a memory that is large, cheap and.
CE Operating Systems Lecture 17 File systems – interface and implementation.
I MPLEMENTING FILES. Contiguous Allocation:  The simplest allocation scheme is to store each file as a contiguous run of disk blocks (a 50-KB file would.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Memory Management Overview.
Loops and Files. 5.1 The Increment and Decrement Operators.
CSCI 156: Lab 11 Paging. Our Simple Architecture Logical memory space for a process consists of 16 pages of 4k bytes each. Your program thinks it has.
Addressing Modes. Register Addressing Immediate Addressing Base Addressing Indexed Addressing PC-Relative Addressing.
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
Operating Systems A Biswas, Dept. of Information Technology.
Memory Management 백 일 우
Program Execution in Linux David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
File System Implementation
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Chapter 8 Main Memory.
Program Execution in Linux
Copyright © 2011, Elsevier Inc. All rights Reserved.
Review.
System Structure B. Ramamurthy.
Computer Architecture
So far… Text RO …. printf() RW link printf Linking, loading
Outline Allocation Free space management Memory mapped files
Memory Management Overview
Virtual Memory CSCI 380: Operating Systems Lecture #7 -- Review and Lab Suggestions William Killian.
Virtual Memory: Systems CSCI 380: Operating Systems
Program Execution in Linux
CSCI 380: Operating Systems William Killian
Memory Management (Ch 4: )
Presentation transcript:

File Systems

It is a simple C program that prints ``hello world'' and then exits. The header describes it as an ELF image with two physical headers (e_phnum is 2) starting 52 bytes (e_phoff) from the start of the image file. The first physical header describes the executable code in the image. It goes at virtual address 0x and there is bytes of it. This is because it is a statically linked image which contains all of the library code for the printf() call to output ``hello world''. The entry point for the image, the first instruction for the program, is not at the start of the image but at virtual address 0x (e_entry). The code starts immediately after the second physical header. This physical header describes the data for the program and is to be loaded into virtual memory at address 0x8059BB8. This data is both readable and writeable. You will notice that the size of the data in the file is 2200 bytes (p_filesz) whereas its size in memory is 4248 bytes. This because the first 2200 bytes contain pre-initialized data and the next 2048 bytes contain data that will be initialized by the executing code. Linux Executable Binary File Executable File on Disk

It's important to note that PE files are not just mapped into memory as a single memory- mapped file. Instead, the Windows loader looks at the PE file and decides what portions of the file to map in. This mapping is consistent in that higher offsets in the file correspond to higher memory addresses when mapped into memory. The offset of an item in the disk file may differ from its offset once loaded into memory. However, all the information is present to allow you to make the translation from disk offset to memory offset (see Figure 1). Windows Executable Binary File Portable Executable File on Disk Process Running Executable In Memory

int binarySearch(int size, int value) { // lower bound index of the interval that may contain value int lower=0; // upper bound index of interval that may contain value int upper=size-1; // middle of interval int middle=0; // Search array using smaller and smaller index intervals until // - the value is found // - the interval is smaller than zero // Each iteration of the while loop, halve the interval while (lower <= upper) { // The middle of the interval is halfway between the lower and // upper bounds of the interval. middle = (lower + upper) / 2; // Get the middle value from file int theMiddleValue = getValueFromBinFileRandom(middle); // Return the array index if value found if (value == theMiddleValue) { cout << "Found " << endl; return middle; } // If value is less than middle, then shift the upper bound // of the interval to the left. else if (value < theMiddleValue) { upper = middle -1; } // If value is greater than middle, then shift the lower bound // of the interval to the right. else if (value > theMiddleValue) { lower = middle + 1; } // If we get here, then the array doesn't contain the value. // Return index of -1. cout << "Not Found" << endl; return -1; } int getValueFromBinFileRandom(int index) { int result; char *byteView = (char *) &result; ifstream infile; infile.open("sortedarray.bin"); infile.seekg(index*sizeof(int),ios::beg); infile.get(byteView[0]); infile.get(byteView[1]); infile.get(byteView[2]); infile.get(byteView[3]); infile.close(); return result; } 5ms per search int getValueFromBinFileSequential(int index) { int result; char *byteView = (char *) &result; ifstream infile; infile.open("sortedarray.bin"); for (int i=0; i<index; i++) { infile.get(byteView[0]); infile.get(byteView[1]); infile.get(byteView[2]); infile.get(byteView[3]); } infile.close(); return result; } 7500 ms per search

File Attributes

Accessing mode bits in st_mode requires two different masks. S_IFMT for the file type information and S_IAMB for the access mode. if ((info.st_mode & S_IFMT) == S_IFDIR) { cout << “Directory!” << endl; } else { cout << “Not a Directory!” << endl; } Members of stat data structure from stat() Decoding the st_mode member

int binarySearch(int array[], int size, int value) { // lower bound index of the interval that may contain value int lower=0; // upper bound index of interval that may contain value int upper=size-1; // middle of interval int middle=0; // Search array using smaller and smaller index intervals until // - the value is found // - the interval is smaller than zero // Each iteration of the while loop, halve the interval while (lower <= upper) { // The middle of the interval is halfway between the lower and // upper bounds of the interval. middle = (lower + upper) / 2; // Get the middle value from file int theMiddleValue = array[middle]; // Return the array index if value found if (value == theMiddleValue) { cout << "Found " << endl; return middle; } // If value is less than middle, then shift the upper bound // of the interval to the left. else if (value < theMiddleValue) { upper = middle -1; } // If value is greater than middle, then shift the lower bound // of the interval to the right. else if (value > theMiddleValue) { lower = middle + 1; } // If we get here, then the array doesn't contain the value. // Return index of -1. cout << "Not Found" << endl; return -1; } int main() { int size=MAX_SIZE; int sum = 0; // // HOW TO MEMORY MAP A FILE // // STEP ONE: Open the file using primitive open system call // int fd = open("sortedarray.bin",O_RDONLY); // // STEP TWO: Use mmap() system call to map file to an array // int* array = (int *) mmap(0,MAX_SIZE*sizeof(int), PROT_READ, MAP_SHARED, fd, 0); // // STEP THREE: Use the array normally // cout << "First file entry is: " << array[0] << endl; cout << "Performing search test..." << endl; for (int i=0; i<100; i++) { int start = clock(); int value = rand() % MAX_SIZE; binarySearch(array,size,value); int stop = clock(); sum = sum + stop-start; } cout << "Search array of size " << size << " took " << sum/100.0 << " ms" << endl; // // STEP FOUR: Unmap the file and close // munmap(array,MAX_SIZE*sizeof(int)); close(fd); return 0; } Memory Mapped File Example 0.04ms per search

Disk Drive Anatomy

Disk Platter, 7 Tracks, 25 Sectors/Track

Cylinder Skew

Files: Contiguous Allocation

Directories: Storage

Block Size: Tradeoff between Space and Time for 2KB Files

Free Block Management: Linked List vs. Bitmap