Day21 A. Young W. Lim Wed. Young W. Lim Day21 A Wed 1 / 13

Similar documents
Excuse the ads! We need some help to keep our site up.

Day05 A. Young W. Lim Sat. Young W. Lim Day05 A Sat 1 / 14

Day06 A. Young W. Lim Wed. Young W. Lim Day06 A Wed 1 / 26

CMPSC 311- Introduction to Systems Programming Module: Input/Output

Day06 A. Young W. Lim Mon. Young W. Lim Day06 A Mon 1 / 16

Day02 A. Young W. Lim Sat. Young W. Lim Day02 A Sat 1 / 12

Day14 A. Young W. Lim Thr. Young W. Lim Day14 A Thr 1 / 14

Day14 A. Young W. Lim Tue. Young W. Lim Day14 A Tue 1 / 15

Play with FILE Structure Yet Another Binary Exploitation Technique. Abstract

Day08 A. Young W. Lim Mon. Young W. Lim Day08 A Mon 1 / 27

Goals of this Lecture

I/O Management! Goals of this Lecture!

I/O Management! Goals of this Lecture!

Stack Tutorial. Young W. Lim Sat. Young W. Lim Stack Tutorial Sat 1 / 15

Procedure Calls. Young W. Lim Mon. Young W. Lim Procedure Calls Mon 1 / 29

Procedure Calls. Young W. Lim Sat. Young W. Lim Procedure Calls Sat 1 / 27

GAS Tutorial - 6. Expression

Arrays. Young W. Lim Wed. Young W. Lim Arrays Wed 1 / 19

Stack Debugging. Young W. Lim Thr. Young W. Lim Stack Debugging Thr 1 / 12

Link 3. Symbols. Young W. Lim Mon. Young W. Lim Link 3. Symbols Mon 1 / 42

Arrays. Young W. Lim Mon. Young W. Lim Arrays Mon 1 / 17

Link 4. Relocation. Young W. Lim Wed. Young W. Lim Link 4. Relocation Wed 1 / 22

Access. Young W. Lim Fri. Young W. Lim Access Fri 1 / 18

Access. Young W. Lim Sat. Young W. Lim Access Sat 1 / 19

SOFTWARE ARCHITECTURE 2. FILE SYSTEM. Tatsuya Hagino lecture URL.

GDB Tutorial. Young W. Lim Thr. Young W. Lim GDB Tutorial Thr 1 / 24

2. HW/SW Co-design. Young W. Lim Thr. Young W. Lim 2. HW/SW Co-design Thr 1 / 21

GDB Tutorial. Young W. Lim Fri. Young W. Lim GDB Tutorial Fri 1 / 24

GAS Tutorial - 4. Sections & Relocation

File Systems: Consistency Issues

Systems Programming. 08. Standard I/O Library. Alexander Holupirek

Control. Young W. Lim Mon. Young W. Lim Control Mon 1 / 16

Link 7. Dynamic Linking

GDB Tutorial. Young W. Lim Tue. Young W. Lim GDB Tutorial Tue 1 / 32

Stack Debugging. Young W. Lim Sat. Young W. Lim Stack Debugging Sat 1 / 40

Main Points. File layout Directory layout

Link 4. Relocation. Young W. Lim Thr. Young W. Lim Link 4. Relocation Thr 1 / 26

Process Management! Goals of this Lecture!

CSE 333 SECTION 3. POSIX I/O Functions

File (1A) Young Won Lim 11/25/16

Unix File and I/O. Outline. Storing Information. File Systems. (USP Chapters 4 and 5) Instructor: Dr. Tongping Liu

Pointers (1A) Young Won Lim 11/1/17

HyperGeometric Distribution

Motivation. Operating Systems. File Systems. Outline. Files: The User s Point of View. File System Concepts. Solution? Files!

Link 7.A Static Linking

ENG120. Misc. Topics

Applications of Structures (1A) Young Won Lim 12/8/17

Accessing Files in C. Professor Hugh C. Lauer CS-2303, System Programming Concepts

Accessibility (1A) Young Won Lim 8/22/13

How do we define pointers? Memory allocation. Syntax. Notes. Pointers to variables. Pointers to structures. Pointers to functions. Notes.

File Systems. CS170 Fall 2018

Link 8.A Dynamic Linking

CS370 Operating Systems

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

CS370 Operating Systems

Applications of Pointers (1A) Young Won Lim 12/26/17

Summer June 15, 2010

CS246 Spring14 Programming Paradigm Files, Pipes and Redirection

File Management 1/34

File Management. Information Structure 11/5/2013. Why Programmers Need Files

FCFS: On-Disk Design Revision: 1.8

Applications of Structures (1A) Young Won Lim 12/4/17

CS370 Operating Systems

TDDB68 Concurrent Programming and Operating Systems. Lecture: File systems

File Systems: Fundamentals

Outline. OS Interface to Devices. System Input/Output. CSCI 4061 Introduction to Operating Systems. System I/O and Files. Instructor: Abhishek Chandra

V. File System. SGG9: chapter 11. Files, directories, sharing FS layers, partitions, allocations, free space. TDIU11: Operating Systems

UNIX input and output

File Systems: Fundamentals

UNIX Files. How UNIX Sees and Uses Files

File-System Interface. File Structure. File Concept. File Concept Access Methods Directory Structure File-System Mounting File Sharing Protection

Link 2. Object Files

Class (1A) Young Won Lim 9/8/14

we are here I/O & Storage Layers Recall: C Low level I/O Recall: C Low Level Operations CS162 Operating Systems and Systems Programming Lecture 18

Input and Output System Calls

Fundamental File Processing Operations 2. Fundamental File Processing Operations

I/O OPERATIONS. UNIX Programming 2014 Fall by Euiseong Seo

Logic Haskell Exercises

we are here Page 1 Recall: How do we Hide I/O Latency? I/O & Storage Layers Recall: C Low level I/O

Type (1A) Young Won Lim 2/17/18

ECE 650 Systems Programming & Engineering. Spring 2018

CS240: Programming in C

PROGRAMMAZIONE I A.A. 2017/2018

ECE 598 Advanced Operating Systems Lecture 18

I/O OPERATIONS. UNIX Programming 2014 Fall by Euiseong Seo

Algorithms Bubble Sort (1B) Young Won Lim 4/5/18

File Systems. ECE 650 Systems Programming & Engineering Duke University, Spring 2018

CSE 333 SECTION 3. POSIX I/O Functions

File System Implementation

Standard File Pointers

CSI 402 Systems Programming LECTURE 4 FILES AND FILE OPERATIONS

Chapter 11 File Processing

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

Lecture 3. Introduction to Unix Systems Programming: Unix File I/O System Calls

Outline. File Systems. File System Structure. CSCI 4061 Introduction to Operating Systems

Section 11: File Systems and Reliability, Two Phase Commit

CSci 4061 Introduction to Operating Systems. Input/Output: High-level

Disk divided into one or more partitions

Pointers (1A) Young Won Lim 1/9/18

Pointers (1A) Young Won Lim 1/5/18

Transcription:

Day21 A Young W. Lim 2017-12-06 Wed Young W. Lim Day21 A 2017-12-06 Wed 1 / 13

Outline 1 Based on 2 File Processing Files and Streams Young W. Lim Day21 A 2017-12-06 Wed 2 / 13

Based on "C How to Program", Paul Deitel and Harvey Deitel I, the copyright holder of this work, hereby publish it under the following licenses: GNU head Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled GNU Free Documentation License. CC BY SA This file is licensed under the Creative Commons Attribution ShareAlike 3.0 Unported License. In short: you are free to share and make derivative works of the file under the conditions that you appropriately attribute it, and that you distribute it only under a license compatible with this one. Young W. Lim Day21 A 2017-12-06 Wed 3 / 13

Files, Streams, and Programs views each file as a sequential stream of bytes when a file is opened, a stream is associated with it stream provide communication channels between files and programs Young W. Lim Day21 A 2017-12-06 Wed 4 / 13

Standard Streams three files and their associated streams are opened automatically when program execution begins standard input (stdin) to read data from the keyboard standard output (stdout) to print data on a screen standard error (stderr) to print error messages Young W. Lim Day21 A 2017-12-06 Wed 5 / 13

FILE structure a FILE structure contains information used to process the file includes a file descriptor typedef struct {... } FILE; opening a file returns a pointer to this FILE structure in C library s (GNU libc) source code. typedef struct _IO_FILE FILE; Young W. Lim Day21 A 2017-12-06 Wed 6 / 13

_IO_FILE structure definition (1) struct _IO_FILE { int _flags; /* High-order word is _IO_MAGIC; rest is flags. */ #define _IO_file_flags _flags /* The following pointers correspond to the C++ streambuf protocol. */ /* Note: Tk uses the _IO_read_ptr and _IO_read_end fields directly. */ char* _IO_read_ptr; /* Current read pointer */ char* _IO_read_end; /* End of get area. */ char* _IO_read_base; /* Start of putback+get area. */ char* _IO_write_base; /* Start of put area. */ char* _IO_write_ptr; /* Current put 3 pointer. */ char* _IO_write_end; /* End of put3 area. */ char* _IO_buf_base; /* Start of reserve area. */ char* _IO_buf_end; /* End of reserve area. */ /* The following fields are used to support backing up and undo. */ char *_IO_save_base; /* Pointer to start of non-current get area. */ char *_IO_backup_base; /* Pointer to first valid character of backup area */ char *_IO_save_end; /* Pointer to end of non-current get area. */ struct _IO_marker *_markers; struct _IO_FILE *_chain; Young W. Lim Day21 A 2017-12-06 Wed 7 / 13

_IO_FILE structure definition (2) int _fileno; #if 0 int _blksize; #else int _flags2; #endif _IO_off_t _old_offset; /* This used to be _offset but it s too small. */ #define HAVE_COLUMN /* temporary */ 3 /* 1+column number of pbase(); 0 is unknown. */ 3 unsigned short _cur_column; signed char _vtable_offset; char _shortbuf[1]; /* char* _save_gptr; char* _save_egptr; */ _IO_lock_t *_lock; #ifdef _IO_USE_OLD_IO_FILE }; Young W. Lim Day21 A 2017-12-06 Wed 8 / 13

accessing file descriptor from a FILE pointer member _fileno : file descriptor fileno() returns a file descriptor #include <stdio.h> int main(void) { FILE *fp; fp = fopen("t.c", "r"); printf("%d\n", fileno(fp)); 3 3 printf("%d\n", fp->_fileno); } Young W. Lim Day21 A 2017-12-06 Wed 9 / 13

file descriptor, file, inode tables a file descriptor table file descriptor a handle used to access a file or an i/o resource fd=0 (stdin), fd=1 (stdout), fd=2 (stderr) an index into an array (the open file table) a file table contains mode information (read, write, append... ) contains index into inode table (Linux) an inode table describes the actual underlying files from http://www.linfo.org/inode.html Young W. Lim Day21 A 2017-12-06 Wed 10 / 13

inode inode stores all the information about a file or a directory metadata: size, ownership, access permissions, timestamps, a reference counter file type except its name and and its actual data each file has inode number unique throughout the filesystem file name -> inode number -> inode table entry -> inode from http://www.linfo.org/inode.html Young W. Lim Day21 A 2017-12-06 Wed 11 / 13

inode pointer structure Unix File System (UFS) and Linux ext3 cases use inode pointer structure to list the addresses of a file s data blocks an inode has its metadata and 15 pointers 12 pointers to direct blocks (*) 1 singly indirect pointer (**) 1 doubly indirect pointer (***) 1 triply indirect pointer (****) from https://en.wikipedia.org/wiki/inode_pointer_structure Young W. Lim Day21 A 2017-12-06 Wed 12 / 13

Opening a file a FILE structure contains information used to process the file includes a file descriptor a file descriptor an index into an array : the open file table each array element contains a file control block a file control block (FCB) OS uses to administer a particular file opening a file returns a pointer to FILE structure Young W. Lim Day21 A 2017-12-06 Wed 13 / 13