ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem
|
|
- Damon McKenzie
- 5 years ago
- Views:
Transcription
1 ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem Risto Järvinen September 21, 2015
2 Lecture contents Filesystem concept. System call API. Buffered I/O API. Filesystem conventions. Additional stuff. Terminals. Stevens: ch3-5 and ch18(=terminals). Kerrisk: parts of ch4-5, ch13-14 and ch62(=terminals). ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 2/43
3 Filesystem concept Abstraction for storage devices. Mounted on any block device, a storage device that stores an array of data blocks. Also network filesystems (NFS, CIFS/SMB, various). Filesystems are connected in a hierarchy. "/" root, start of the hierarchy. "/abc/def/ghi" pathname. Files, directories, devices, are all stored as names in the hierarcy. ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 3/43
4 Types of files Regular files. Pipes, named. Directories. Device files. Symbolic links. Sockets. ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 4/43
5 File API Basic operations: Open, initiates access to a file. Read, copies data from file to process memory. Write, copies data from process memory to file. Seek, changes location where file is read/written. Close, ends access to file. Files are opened via pathname, then accessed via file descriptor. File descriptor is an index in the descriptor table maintained by the OS for the process. Stdin/stdout/stderr are defined to be the first three file descriptors, with indexes 0, 1 and 2. ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 5/43
6 Opening files # include <sys / types. h> #include <sys / s t a t. h> #include < f c n t l. h> i nt open ( const char pathname, i nt f l a g s ) ; i nt open ( const char pathname, i nt flags, mode_t mode ) ; i nt creat ( const char pathname, mode_t mode ) ; Primary flags: O_RDONLY, O_WRONLY, O_RDWR. Optional flags: O_APPEND, O_CREAT, O_EXCL, O_TRUNC, O_NOCTTY, O_NONBLOCK. Synchronous I/O: O_DSYNC, O_RSYNC, O_SYNC. creat() is like open() with O_WRONLY O_CREAT O_TRUNC. ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 6/43
7 Reading and writing ssize_t read ( int fd, void buf, size_t count ) ; ssize_t w r i t e ( int fd, const void buf, size_t count ) ; When reading, read returns the number of bytes read. Amount may be less than the amount requested! Value -1 means error, and zero means end of file. Similarly, writing returns the number of bytes written, may be less than amount requested, even zero. Value -1 means error. Partial operations may happen for many reasons: Trying to read past the end of the file. O_NONBLOCK on some file types returns only the available data. Signal may interrupt a read. ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 7/43
8 Seeking o f f _ t lseek ( int fd, o f f _ t offset, int whence ) ; # define _FILE_OFFSET_BITS 64 or # define _LARGEFILE64_SOURCE off64_t lseek64 ( int fd, off64_t offset, int whence ) ; Every open file descriptor has an offset that stores where next operation will occur. whence: SEEK_SET, SEEK_CUR, SEEK_END Some file descriptors are non-seekable. F.ex. FIFOs. 32-bit to 64-bit transition issues. ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 8/43
9 Closing files int close ( int fd ) ; Closes the file descriptor. If file was unlink()ed, when last file descriptor referring to it is closed, then file is actually deleted. Return value also returns errors that happened after the last write. ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 9/43
10 File permissions File mode, 16-bit value, usually represented as six digit octal value. Three lowest digits read/write/execute permissions for owner/group/others. Fourth digit : setuid, setgid, sticky. Two highest digits: file type, FIFO / character device / directory / block device / regular file / symbolic link / socket. See man 2 stat. Process has umask value to set defaults to created files. mode_t umask( mode_t mask ) ; ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 10/43
11 Permissions API int access ( const char pathname, int mode ) ; int chmod( const char path, mode_t mode ) ; int fchmod ( int fd, mode_t mode ) ; int chown( const char path, uid_t owner, gid_t group ) ; int fchown ( int fd, uid_t owner, gid_t group ) ; int lchown ( const char path, uid_t owner, gid_t group ) ; ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 11/43
12 File info #include <sys / s t a t. h> int s t a t ( const char path, struct s t a t buf ) ; int f s t a t ( int fd, struct s t a t buf ) ; int l s t a t ( const char path, struct s t a t buf ) ; lstat() is like stat() but if file is a symbolic link, it stats the link and not the linked file. ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 12/43
13 File info structure struct s t a t { dev_t st_dev ; / ID of device containing f i l e / ino_t st_ino ; / inode number / mode_t st_mode ; / p r o t e c t i o n / nl i nk_ t st_nlink ; / number of hard lin ks / uid _ t st_uid ; / user ID of owner / gid _ t st_gid ; / group ID of owner / dev_t st_rdev ; / device ID ( i f special f i l e ) / o f f _ t st_size ; / t o t a l size, i n bytes / blksize_t st_blksize ; / blocksize for f i l e system I /O / blkcnt_t st_blocks ; / number of 512B blocks a l l o c a t e d / time_t st_atime ; / time of l ast access / time_t st_mtime ; / time of l ast modification / time_t st_ctime ; / time of l ast status change / } ; ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 13/43
14 Creating and deleting links #include <unistd. h> int unlink ( const char pathname ) ; int l i n k ( const char oldpath, const char newpath ) ; int symlink ( const char oldpath, const char newpath ) ; ssize_t r eadlink ( const char path, char buf, size_t bufsiz ) ; unlink() is used to delete files. ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 14/43
15 Directory operations 1/2 #include <unistd. h> i n t mkdir ( const char pathname, mode_t mode ) ; int rmdir ( const char pathname ) ; int chdir ( const char path ) ; int f c h d i r ( int fd ) ; char getcwd ( char buf, size_t size ) ; ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 15/43
16 Directory operations 2/2 #include < d i r e n t. h> DIR opendir ( const char name ) ; struct d i r e n t readdir ( DIR d i r p ) ; i nt readdir_r ( DIR dirp, struct d i r e n t entry, struct d i r e n t r e s u l t ) ) ; void seekdir ( DIR dirp, long o f f s e t ) ; void rewinddir ( DIR d i r p ) ; long t e l l d i r ( DIR d i r p ) ; i nt c l o s e d i r ( DIR d i r p ) ; DIR fdopendir ( i nt fd ) ; ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 16/43
17 Additional i n t rename ( const char ol dpath, const char newpath ) ; i nt truncate ( const char path, o f f _ t length ) ; i nt f t r u n c a t e ( i nt fd, o f f _ t length ) ; i nt mknod( const char path, mode_t mode, dev_t dev ) ; i nt utime ( const char path, const struct utimbuf times ) ; i nt utimes ( const char path, const struct timeval times [ 2 ] ) ; rename() is atomic on POSIX-compliant systems. ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 17/43
18 Duplicating file descriptors #include <unistd. h> int dup ( int oldfd ) ; int dup2 ( int oldfd, int newfd ) ; ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 18/43
19 Creating unnamed pipes #include <unistd. h> int pipe ( int pipefd [ 2 ] ) ; Both ends are in one process, unless passed via some mechanism (fork() or UNIX domain socket). ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 19/43
20 Buffered file I/O C library provides buffered I/O on top of system calls. Should be familiar from C programming, let s just run through. Three modes: Fully buffered (_IOFBF) Line buffered (_IOLBF) Unbuffered (_IONBF) ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 20/43
21 Setting buffering #include < s t d i o. h> void setbuf ( FILE stream, char buf ) ; int setvbuf ( FILE stream, char buf, int mode, size_t size ) ; buf is user allocated buffer, if none given, system allocates it. setbuf() must have BUFSIZ size buffer. Just use setvbuf(). ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 21/43
22 Opening and closing files #include < s t d i o. h> FILE fopen ( const char path, const char mode ) ; FILE fdopen ( int fd, const char mode ) ; FILE freopen ( const char path, const char mode, FILE stream ) ; int fclose ( FILE fp ) ; int f f l u s h ( FILE stream ) ; ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 22/43
23 Buffered input #include < s t d i o. h> int fgetc ( FILE stream ) ; char fgets ( char s, int size, FILE stream ) ; int getc ( FILE stream ) ; int getchar ( void ) ; char gets ( char s ) ; < DEPRECATED int ungetc ( int c, FILE stream ) ; size_t fread ( void ptr, size_t size, size_t nmemb, FILE stream ) ; ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 23/43
24 Buffered output #include < s t d i o. h> int fputc ( int c, FILE stream ) ; int fputs ( const char s, FILE stream ) ; int putc ( int c, FILE stream ) ; int putchar ( int c ) ; int puts ( const char s ) ; size_t f w r i t e ( const void ptr, size_t size, size_t nmemb, FILE stream ) ; ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 24/43
25 Error handling #include < s t d i o. h> void c l e a r e r r ( FILE stream ) ; int f e o f ( FILE stream ) ; int f e r r o r ( FILE stream ) ; int f i l e n o ( FILE stream ) ; ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 25/43
26 Seeking #include < s t d i o. h> int fseek ( FILE stream, long offset, int whence ) ; long f t e l l ( FILE stream ) ; void rewind ( FILE stream ) ; int fgetpos ( FILE stream, fpos_t pos ) ; int fsetpos ( FILE stream, fpos_t pos ) ; ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 26/43
27 Formatted output #include < s t d i o. h> i nt p r i n t f ( const char format,... ) ; i nt f p r i n t f ( FILE stream, const char format,... ) ; i nt s p r i n t f ( char str, const char format,... ) ; i nt s n p r i n t f ( char str, size_t size, const char format,... ) ; #include <stdarg. h> i nt v p r i n t f ( const char format, v a _ l i s t ap ) ; i nt v f p r i n t f ( FILE stream, const char format, v a _ l i s t ap ) ; i nt v s p r i n t f ( char str, const char format, v a _ l i s t ap ) ; i nt v s n p r i n t f ( char str, size_t size, const char format, v a _ l i s t ap ) ; ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 27/43
28 Formatted input #include < s t d i o. h> i nt scanf ( const char format,... ) ; i nt fscanf ( FILE stream, const char format,... ) ; i nt sscanf ( const char str, const char format,... ) ; #include <stdarg. h> i nt vscanf ( const char format, v a _ l i s t ap ) ; i nt vsscanf ( const char str, const char format, v a _ l i s t ap ) ; i nt vfscanf ( FILE stream, const char format, v a _ l i s t ap ) ; ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 28/43
29 Temporary files #include < s t d i o. h> FILE t m p f i l e ( void ) ; Obsolete functions tmpnam() and tempnam(), mktemp() i nt mkstemp ( char template ) ; i nt mkostemp ( char template, i nt f l a g s ) ; i nt mkstemps ( char template, i nt s u f f i x l e n ) ; i nt mkostemps ( char template, i nt s u f f i x l e n, i nt f l a g s ) ; ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 29/43
30 Synchronizing data to storage #include <unistd. h> int fsync ( int fd ) ; int fdatasync ( int fd ) ; fsync() flushes all changes related to the file to disk. (data+metadata) fdatasync() flushes all data changes related to the file to disk. (data only) ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 30/43
31 Filesystem tricks: How to keep a file consistent Avoid losing files, either keep new or old. Procedure: 1. Write new data into a temporary file 2. Fsync() the temporary file 3. Rename() it to the target name Use on important files, the ones that must not be corrupt. ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 31/43
32 Tale of fsync() and ext3 Example of how synchronizing data to disk may have really adverse effect on system performance. Hard disks are slow. 6-9ms seek times, transfer speed in tens of MB/s. (SSDs help some) Ext3 is a common journaling Linux filesystem, meaning it keeps a separate record of disk actions to maintain consistency even in case of sudden power losses. Does this by keeping a log in the order in which events occured and plays them out in that order. When you fsync() any file, all operations that preceded it must be also flushed. Firefox 3 introduced storage backend that fsync()ed data to disk.. ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 32/43
33 Filesystem tricks: Sparse files UNIX filesystems can allocate discontinuous blocks for a file. Only parts of a file actually written to are stored. Every unwritten part reads as zeroes. Procedure: 1. Create file. 2. Seek to points where you want data. 3. Write data. 4. Repeat 2-3. Use cases include databases and filesystem images. ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 33/43
34 For those occasions.. ioctls How to cover unanticipated operations in filesystem? #include <sys / i o c t l. h> int i o c t l ( int fd, int request,... ) ; Basically a open interface to OS kernel, tied to filesystem. Calls are varied and there are few standards. Example: Linux CDROM ioctl calls. ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 34/43
35 Memory mapping 1/2 #include <sys /mman. h> void mmap( void addr, size_t length, int prot, int flags, int fd, o f f _ t o f f s e t ) ; int munmap( void addr, size_t length ) ; int msync( void addr, size_t length, int f l a g s ) ; Uses virtual memory system to map a file into memory. On modern systems, demand-paged. ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 35/43
36 Memory mapping 2/2 Flags: MAP_SHARED, mapping is allowed to be shared. MAP_PRIVATE, copy-on-write mapping, based on file, but creates a private copy if data is modified. No changes to files. MAP_ANONYMOUS, mapping is not backed by a file, rather initialized to zero. Very useful, can simplify many problems, used for shared memory IPC (more later). Though, error handling is dangerous, and makes performance analysis complex. ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 36/43
37 Terminals Abstraction for a text-based display device Serial port, monitor+keyboard console, terminal programs, ssh terminal session, etc. Loads and loads of history, nowadays mostly worked out. Two-ended; software<->device or software<->software (pty) Two modes : raw and cooked, alias non-canonical and canonical. OS keeps terminal line discipline for handling cooked mode POSIX API is called termios A nice write-up on terminals: ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 37/43
38 Terminal attributes #include <termios. h> #include <unistd. h> int t c g e t a t t r ( int fd, struct termios termios_p ) ; int t c s e t a t t r ( int fd, int optional_actions, const struct termios termios_p ) ; Struct termios has members c_iflag, c_oflag, c_cflag, c_lflag and c_cc. Dozens of attributes controlled by the members. See man tcgetattr. ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 38/43
39 Buffer control int tcsendbreak ( int fd, int duration ) ; int t c d r a i n ( int fd ) ; int t c f l u s h ( int fd, int queue_selector ) ; int t c f l o w ( int fd, int action ) ; ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 39/43
40 Terminal line speed speed_t cfgetispeed ( const struct termios termios_p ) ; speed_t cfgetospeed ( const struct termios termios_p ) ; int cfsetispeed ( struct termios termios_p, speed_t speed ) ; int cfsetospeed ( struct termios termios_p, speed_t speed ) ; Note: speed_t is not a bps value, but a type tag. See man page. ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 40/43
41 Non-POSIX but useful void cfmakeraw ( struct termios termios_p ) ; int cfsetspeed ( struct termios termios_p, speed_t speed ) ; cfmakeraw() does most things you want to do to use a raw terminal. cfsetspeed() sets both input and output speed at once. ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 41/43
42 Why use such monstrosity? Legacy. Asking password on console. Serial port programming. Helper libraries for actual console use: ncurses, S-Lang. ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 42/43
43 Did you learn this? Filesystem is a straightforward tool. Filesystem semantics are important. Terminals are painful but necessary. Next time: Processes and signals. ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem 43/43
I/O OPERATIONS. UNIX Programming 2014 Fall by Euiseong Seo
I/O OPERATIONS UNIX Programming 2014 Fall by Euiseong Seo Files Files that contain a stream of bytes are called regular files Regular files can be any of followings ASCII text Data Executable code Shell
More informationI/O OPERATIONS. UNIX Programming 2014 Fall by Euiseong Seo
I/O OPERATIONS UNIX Programming 2014 Fall by Euiseong Seo Files Files that contain a stream of bytes are called regular files Regular files can be any of followings ASCII text Data Executable code Shell
More informationHyo-bong Son Computer Systems Laboratory Sungkyunkwan University
File I/O Hyo-bong Son (proshb@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Unix Files A Unix file is a sequence of m bytes: B 0, B 1,..., B k,..., B m-1 All I/O
More informationLecture 23: System-Level I/O
CSCI-UA.0201-001/2 Computer Systems Organization Lecture 23: System-Level I/O Mohamed Zahran (aka Z) mzahran@cs.nyu.edu http://www.mzahran.com Some slides adapted (and slightly modified) from: Clark Barrett
More informationThe course that gives CMU its Zip! I/O Nov 15, 2001
15-213 The course that gives CMU its Zip! I/O Nov 15, 2001 Topics Files Unix I/O Standard I/O A typical hardware system CPU chip register file ALU system bus memory bus bus interface I/O bridge main memory
More informationImportant Dates. October 27 th Homework 2 Due. October 29 th Midterm
CSE333 SECTION 5 Important Dates October 27 th Homework 2 Due October 29 th Midterm String API vs. Byte API Recall: Strings are character arrays terminated by \0 The String API (functions that start with
More informationOperating System Labs. Yuanbin Wu
Operating System Labs Yuanbin Wu CS@ECNU Operating System Labs Project 3 Oral test Handin your slides Time Project 4 Due: 6 Dec Code Experiment report Operating System Labs Overview of file system File
More informationMemory Mapped I/O. Michael Jantz. Prasad Kulkarni. EECS 678 Memory Mapped I/O Lab 1
Memory Mapped I/O Michael Jantz Prasad Kulkarni EECS 678 Memory Mapped I/O Lab 1 Introduction This lab discusses various techniques user level programmers can use to control how their process' logical
More informationCptS 360 (System Programming) Unit 6: Files and Directories
CptS 360 (System Programming) Bob Lewis School of Engineering and Applied Sciences Washington State University Spring, 2019 Motivation Need to know your way around a filesystem. A properly organized filesystem
More informationFile I/O. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University
File I/O Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Unix Files A Unix file is a sequence of m bytes: B 0, B 1,..., B k,..., B m-1 All I/O devices
More informationFile I/O. Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University Embedded Software Lab.
1 File I/O Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University http://nyx.skku.ac.kr Unix files 2 A Unix file is a sequence of m bytes: B 0, B 1,..., B k,..., B m-1 All I/O devices are represented
More informationLecture files in /home/hwang/cs375/lecture05 on csserver.
Lecture 5 Lecture files in /home/hwang/cs375/lecture05 on csserver. cp -r /home/hwang/cs375/lecture05. scp -r user@csserver.evansville.edu:/home/hwang/cs375/lecture05. Project 1 posted, due next Thursday
More informationFile System User API
File System User API Blunk Microsystems file system API includes the file-related routines from Standard C and POSIX, as well as a number of non-standard functions that either meet a need unique to embedded
More informationFiles and Directories
Files and Directories Stat functions Given pathname, stat function returns structure of information about file fstat function obtains information about the file that is already open lstat same as stat
More informationCS , Spring Sample Exam 3
Andrew login ID: Full Name: CS 15-123, Spring 2010 Sample Exam 3 Mon. April 6, 2009 Instructions: Make sure that your exam is not missing any sheets, then write your full name and Andrew login ID on the
More informationContents. Programming Assignment 0 review & NOTICE. File IO & File IO exercise. What will be next project?
File I/O Prof. Jin-Soo Kim(jinsookim@skku.edu) TA - Dong-Yun Lee(dylee@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Contents Programming Assignment 0 review & NOTICE
More informationAll the scoring jobs will be done by script
File I/O Prof. Jin-Soo Kim( jinsookim@skku.edu) TA Sanghoon Han(sanghoon.han@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Announcement (1) All the scoring jobs
More informationFile Systems. q Files and directories q Sharing and protection q File & directory implementation
File Systems q Files and directories q Sharing and protection q File & directory implementation Files and file systems Most computer applications need to Store large amounts of data; larger than their
More informationwhich maintain a name to inode mapping which is convenient for people to use. All le objects are
UNIX Directory Organization UNIX directories are simple (generally ASCII) les which maain a name to inode mapping which is convenient for people to use. All le objects are represented by one or more names
More informationFile Systems. Today. Next. Files and directories File & directory implementation Sharing and protection. File system management & examples
File Systems Today Files and directories File & directory implementation Sharing and protection Next File system management & examples Files and file systems Most computer applications need to: Store large
More informationAll the scoring jobs will be done by script
File I/O Prof. Jinkyu Jeong( jinkyu@skku.edu) TA-Seokha Shin(seokha.shin@csl.skku.edu) TA-Jinhong Kim( jinhong.kim@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu
More informationUNIX System Calls. Sys Calls versus Library Func
UNIX System Calls Entry points to the kernel Provide services to the processes One feature that cannot be changed Definitions are in C For most system calls a function with the same name exists in the
More informationContents. NOTICE & Programming Assignment #1. QnA about last exercise. File IO exercise
File I/O Examples Prof. Jin-Soo Kim(jinsookim@skku.edu) TA - Dong-Yun Lee(dylee@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Contents NOTICE & Programming Assignment
More informationContents. NOTICE & Programming Assignment 0 review. What will be next project? File IO & File IO exercise
File I/O Prof. Jin-Soo Kim( jinsookim@skku.edu) TA Dong-Yun Lee(dylee@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Contents NOTICE & Programming Assignment 0 review
More informationFiles and Directories Filesystems from a user s perspective
Files and Directories Filesystems from a user s perspective Unix Filesystems Seminar Alexander Holupirek Database and Information Systems Group Department of Computer & Information Science University of
More informationOperating System Labs. Yuanbin Wu
Operating System Labs Yuanbin Wu CS@ECNU Operating System Labs Project 4 (multi-thread & lock): Due: 10 Dec Code & experiment report 18 Dec. Oral test of project 4, 9:30am Lectures: Q&A Project 5: Due:
More informationSystems Programming. 08. Standard I/O Library. Alexander Holupirek
Systems Programming 08. Standard I/O Library Alexander Holupirek Database and Information Systems Group Department of Computer & Information Science University of Konstanz Summer Term 2008 Last lecture:
More informationSystem-Level I/O. Topics Unix I/O Robust reading and writing Reading file metadata Sharing files I/O redirection Standard I/O
System-Level I/O Topics Unix I/O Robust reading and writing Reading file metadata Sharing files I/O redirection Standard I/O A Typical Hardware System CPU chip register file ALU system bus memory bus bus
More informationSystem- Level I/O. Andrew Case. Slides adapted from Jinyang Li, Randy Bryant and Dave O Hallaron
System- Level I/O Andrew Case Slides adapted from Jinyang Li, Randy Bryant and Dave O Hallaron 1 Unix I/O and Files UNIX abstracts many things into files (just a series of bytes) All I/O devices are represented
More informationCS 201. Files and I/O. Gerson Robboy Portland State University
CS 201 Files and I/O Gerson Robboy Portland State University A Typical Hardware System CPU chip register file ALU system bus memory bus bus interface I/O bridge main memory USB controller graphics adapter
More informationChapter 4 - Files and Directories. Information about files and directories Management of files and directories
Chapter 4 - Files and Directories Information about files and directories Management of files and directories File Systems Unix File Systems UFS - original FS FFS - Berkeley ext/ext2/ext3/ext4 - Linux
More informationOPERATING SYSTEMS: Lesson 2: Operating System Services
OPERATING SYSTEMS: Lesson 2: Operating System Services Jesús Carretero Pérez David Expósito Singh José Daniel García Sánchez Francisco Javier García Blas Florin Isaila 1 Goals To understand what an operating
More informationstructs as arguments
Structs A collection of related data items struct record { char name[maxname]; int count; ; /* The semicolon is important! It terminates the declaration. */ struct record rec1; /*allocates space for the
More informationFiles and Directories
Contents 1. Preface/Introduction 2. Standardization and Implementation 3. File I/O 4. Standard I/O Library 5. Files and Directories 6. System Data Files and Information 7. Environment of a Unix Process
More informationRicardo Rocha. Department of Computer Science Faculty of Sciences University of Porto
Ricardo Rocha Department of Computer Science Faculty of Sciences University of Porto For more information please consult Advanced Programming in the UNIX Environment, 3rd Edition, W. Richard Stevens and
More informationFall 2017 :: CSE 306. File Systems Basics. Nima Honarmand
File Systems Basics Nima Honarmand File and inode File: user-level abstraction of storage (and other) devices Sequence of bytes inode: internal OS data structure representing a file inode stands for index
More informationCS631 - Advanced Programming in the UNIX Environment
CS631 - Advanced Programming in the UNIX Environment Slide 1 CS631 - Advanced Programming in the UNIX Environment Files and Directories Department of Computer Science Stevens Institute of Technology Jan
More information17: Filesystem Examples: CD-ROM, MS-DOS, Unix
17: Filesystem Examples: CD-ROM, MS-DOS, Unix Mark Handley CD Filesystems ISO 9660 Rock Ridge Extensions Joliet Extensions 1 ISO 9660: CD-ROM Filesystem CD is divided into logical blocks of 2352 bytes.
More informationNaked C Lecture 6. File Operations and System Calls
Naked C Lecture 6 File Operations and System Calls 20 August 2012 Libc and Linking Libc is the standard C library Provides most of the basic functionality that we've been using String functions, fork,
More informationStandard I/O in C, Computer System and programming in C
Standard I/O in C, Contents 1. Preface/Introduction 2. Standardization and Implementation 3. File I/O 4. Standard I/O Library 5. Files and Directories 6. System Data Files and Information 7. Environment
More informationCSC 271 Software I: Utilities and Internals
CSC 271 Software I: Utilities and Internals Lecture 13 : An Introduction to File I/O in Linux File Descriptors All system calls for I/O operations refer to open files using a file descriptor (a nonnegative
More informationFile System (FS) Highlights
CSCI 503: Operating Systems File System (Chapters 16 and 17) Fengguang Song Department of Computer & Information Science IUPUI File System (FS) Highlights File system is the most visible part of OS From
More informationCMPS 105 Systems Programming. Prof. Darrell Long E2.371
+ CMPS 105 Systems Programming Prof. Darrell Long E2.371 darrell@ucsc.edu + Chapter 3: File I/O 2 + File I/O 3 n What attributes do files need? n Data storage n Byte stream n Named n Non-volatile n Shared
More informationSystem-Level I/O Nov 14, 2002
15-213 The course that gives CMU its Zip! System-Level I/O Nov 14, 2002 Topics Unix I/O Robust reading and writing Reading file metadata Sharing files I/O redirection Standard I/O class24.ppt A Typical
More information39. File and Directories
39. File and Directories Oerating System: Three Easy Pieces AOS@UC 1 Persistent Storage Kee a data intact even if there is a ower loss. w Hard disk drive w Solid-state storage device Two key abstractions
More informationCSE 333 SECTION 3. POSIX I/O Functions
CSE 333 SECTION 3 POSIX I/O Functions Administrivia Questions (?) HW1 Due Tonight Exercise 7 due Monday (out later today) POSIX Portable Operating System Interface Family of standards specified by the
More informationAdvanced Systems Security: Ordinary Operating Systems
Systems and Internet Infrastructure Security Network and Security Research Center Department of Computer Science and Engineering Pennsylvania State University, University Park PA Advanced Systems Security:
More informationFile and Directories. Advanced Programming in the UNIX Environment
File and Directories Advanced Programming in the UNIX Environment stat Function #include int stat(const char *restrict pathname, struct stat *restrict buf ); int fstat(int fd, struct stat
More informationDesign Choices 2 / 29
File Systems One of the most visible pieces of the OS Contributes significantly to usability (or the lack thereof) 1 / 29 Design Choices 2 / 29 Files and File Systems What s a file? You all know what a
More informationUNIX System Programming
File I/O 경희대학교컴퓨터공학과 조진성 UNIX System Programming File in UNIX n Unified interface for all I/Os in UNIX ü Regular(normal) files in file system ü Special files for devices terminal, keyboard, mouse, tape,
More informationCSCI 4500/8506 Operating Systems Some UNIX System Calls, Library, and PThreads Functions
CSCI 4500/8506 Operating Systems Some UNIX System Calls, Library, and PThreads Functions Described below is a subset of UNIX system calls, library functions, and Pthreads (that is, POSIX Threads) functions.
More informationFile Systems. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University
File Systems Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu SSE3044: Operating Systems, Fall 2016, Jinkyu Jeong (jinkyu@skku.edu) File System Layers
More informationA Typical Hardware System The course that gives CMU its Zip! System-Level I/O Nov 14, 2002
class24.ppt 15-213 The course that gives CMU its Zip! System-Level I/O Nov 14, 2002 Topics Unix I/O Robust reading and writing Reading file metadata Sharing files I/O redirection Standard I/O A Typical
More informationOperating System Labs. Yuanbin Wu
Operating System Labs Yuanbin Wu cs@ecnu Annoucement Next Monday (28 Sept): We will have a lecture @ 4-302, 15:00-16:30 DON'T GO TO THE LABORATORY BUILDING! TA email update: ecnucchuang@163.com ecnucchuang@126.com
More informationCSI 402 Lecture 11 (Unix Discussion on Files continued) 11 1 / 19
CSI 402 Lecture 11 (Unix Discussion on Files continued) 11 1 / 19 User and Group IDs Ref: Chapter 3 of [HGS]. Each user is given an ID (integer) called uid. (Most system programs use uid instead of the
More informationThe link() System Call. Preview. The link() System Call. The link() System Call. The unlink() System Call 9/25/2017
Preview The link() System Call link(), unlink() System Call remove(), rename() System Call Symbolic link to directory Symbolic link to a executable file symlink() System Call File Times utime() System
More informationFile Input and Output (I/O)
File Input and Output (I/O) Brad Karp UCL Computer Science CS 3007 15 th March 2018 (lecture notes derived from material from Phil Gibbons, Dave O Hallaron, and Randy Bryant) 1 Today UNIX I/O Metadata,
More informationRicardo Rocha. Department of Computer Science Faculty of Sciences University of Porto
Ricardo Rocha Department of Computer Science Faculty of Sciences University of Porto For more information please consult Advanced Programming in the UNIX Environment, 3rd Edition, W. Richard Stevens and
More informationINTRODUCTION TO UNIX FILE SYSTEM:
INTRODUCTION TO UNIX FILE SYSTEM: The internal representation of a file is given by an inode, which contains a description of the disk layout of the file data and other information such as the file owner,
More informationSystems Programming. COSC Software Tools. Systems Programming. High-Level vs. Low-Level. High-Level vs. Low-Level.
Systems Programming COSC 2031 - Software Tools Systems Programming (K+R Ch. 7, G+A Ch. 12) The interfaces we use to work with the operating system In this case: Unix Programming at a lower-level Systems
More informationCS240: Programming in C
CS240: Programming in C Lecture 15: Unix interface: low-level interface Cristina Nita-Rotaru Lecture 15/Fall 2013 1 Streams Recap Higher-level interface, layered on top of the primitive file descriptor
More informationFiles and Directories Filesystems from a user s perspective
Files and Directories Filesystems from a user s perspective Unix Filesystems Seminar Alexander Holupirek Database and Information Systems Group Department of Computer & Information Science University of
More informationSystems Programming. 09. Filesystem in USErspace (FUSE) Alexander Holupirek
Systems Programming 09. Filesystem in USErspace (FUSE) Alexander Holupirek Database and Information Systems Group Department of Computer & Information Science University of Konstanz Summer Term 2008 Schedule
More informationCSci 4061 Introduction to Operating Systems. File Systems: Basics
CSci 4061 Introduction to Operating Systems File Systems: Basics File as Abstraction Naming a File creat/open ( path/name, ); Links: files with multiple names Each name is an alias #include
More informationFile (1A) Young Won Lim 11/25/16
File (1A) Copyright (c) 2010-2016 Young W. Lim. 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
More informationIntroduction to Computer Systems , fall th Lecture, Oct. 19 th
Introduction to Computer Systems 15-213, fall 2009 15 th Lecture, Oct. 19 th Instructors: Majd Sakr and Khaled Harras Today System level I/O Unix I/O Standard I/O RIO (robust I/O) package Conclusions and
More informationSystem Calls. Library Functions Vs. System Calls. Library Functions Vs. System Calls
System Calls Library Functions Vs. System Calls A library function: Ordinary function that resides in a library external to the calling program. A call to a library function is just like any other function
More informationSystem-Level I/O March 31, 2005
15-213 The course that gives CMU its Zip! System-Level I/O March 31, 2005 Topics Unix I/O Robust reading and writing Reading file metadata Sharing files I/O redirection Standard I/O 21-io.ppt Unix I/O
More informationOutline. OS Interface to Devices. System Input/Output. CSCI 4061 Introduction to Operating Systems. System I/O and Files. Instructor: Abhishek Chandra
Outline CSCI 6 Introduction to Operating Systems System I/O and Files File I/O operations File Descriptors and redirection Pipes and FIFOs Instructor: Abhishek Chandra 2 System Input/Output Hardware devices:
More informationCSE 333 SECTION 3. POSIX I/O Functions
CSE 333 SECTION 3 POSIX I/O Functions Administrivia Questions (?) HW1 Due Tonight HW2 Due Thursday, July 19 th Midterm on Monday, July 23 th 10:50-11:50 in TBD (And regular exercises in between) POSIX
More informationFiles. Eric McCreath
Files Eric McCreath 2 What is a file? Information used by a computer system may be stored on a variety of storage mediums (magnetic disks, magnetic tapes, optical disks, flash disks etc). However, as a
More informationLinux Forensics. Newbug Tseng Oct
Linux Forensics Newbug Tseng Oct. 2004. Contents Are u ready Go Real World Exploit Attack Detect Are u ready Linux File Permission OWNER 4 2 1 GROUP 4 2 1 OTHER 4 2 1 R R R W SUID on exection 4000 X W
More informationCSE 410: Systems Programming
CSE 410: Systems Programming Input and Output Ethan Blanton Department of Computer Science and Engineering University at Buffalo I/O Kernel Services We have seen some text I/O using the C Standard Library.
More informationThe bigger picture. File systems. User space operations. What s a file. A file system is the user space implementation of persistent storage.
The bigger picture File systems Johan Montelius KTH 2017 A file system is the user space implementation of persistent storage. a file is persistent i.e. it survives the termination of a process a file
More informationUnix File and I/O. Outline. Storing Information. File Systems. (USP Chapters 4 and 5) Instructor: Dr. Tongping Liu
Outline Unix File and I/O (USP Chapters 4 and 5) Instructor: Dr. Tongping Liu Basics of File Systems Directory and Unix File System: inode UNIX I/O System Calls: open, close, read, write, ioctl File Representations:
More informationPOSIX Shared Memory. Linux/UNIX IPC Programming. Outline. Michael Kerrisk, man7.org c 2017 November 2017
Linux/UNIX IPC Programming POSIX Shared Memory Michael Kerrisk, man7.org c 2017 mtk@man7.org November 2017 Outline 10 POSIX Shared Memory 10-1 10.1 Overview 10-3 10.2 Creating and opening shared memory
More informationSystem-Level I/O. William J. Taffe Plymouth State University. Using the Slides of Randall E. Bryant Carnegie Mellon University
System-Level I/O William J. Taffe Plymouth State University Using the Slides of Randall E. Bryant Carnegie Mellon University Topics Unix I/O Robust reading and writing Reading file metadata Sharing files
More informationCS240: Programming in C
CS240: Programming in C Lecture 13 si 14: Unix interface for working with files. Cristina Nita-Rotaru Lecture 13/Fall 2013 1 Working with Files (I/O) File system: specifies how the information is organized
More informationCS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017
CS 471 Operating Systems Yue Cheng George Mason University Fall 2017 Review: RAID 2 RAID o Idea: Build an awesome disk from small, cheap disks o Metrics: Capacity, performance, reliability 3 RAID o Idea:
More informationAutomated Test Generation in System-Level
Automated Test Generation in System-Level Pros + Can be easy to generate system TCs due to clear interface specification + No false alarm (i.e., no assert violation caused by infeasible execution scenario)
More informationOperating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst
Operating Systems CMPSCI 377 Spring 2017 Mark Corner University of Massachusetts Amherst Clicker Question #1 For a sequential workload, the limiting factor for a disk system is likely: (A) The speed of
More informationFile Descriptors and Piping
File Descriptors and Piping CSC209: Software Tools and Systems Programming Furkan Alaca & Paul Vrbik University of Toronto Mississauga https://mcs.utm.utoronto.ca/~209/ Week 8 Today s topics File Descriptors
More informationUNIT I INTRODUCTION TO UNIX & FILE SYSTEM
INTRODUCTION TO UNIX & FILE SYSTEM Part A 1. What is UNIX? UNIX(Uniplexed Information Computing System) it is an operating system was developed in Early 1970 at Bell Labs. It was initially a character
More informationread(2) There can be several cases where read returns less than the number of bytes requested:
read(2) There can be several cases where read returns less than the number of bytes requested: EOF reached before requested number of bytes have been read Reading from a terminal device, one line read
More informationSystem- Level I/O. CS 485 Systems Programming Fall Instructor: James Griffioen
System- Level I/O CS 485 Systems Programming Fall 2015 Instructor: James Griffioen Adapted from slides by R. Bryant and D. O Hallaron (hip://csapp.cs.cmu.edu/public/instructors.html) 1 Today Unix I/O Metadata,
More informationThesis, antithesis, synthesis
Identity Page 1 Thesis, antithesis, synthesis Thursday, December 01, 2011 4:00 PM Thesis, antithesis, synthesis We began the course by considering the system programmer's point of view. Mid-course, we
More informationUNIX FILESYSTEM STRUCTURE BASICS By Mark E. Donaldson
THE UNIX FILE SYSTEM Under UNIX we can think of the file system as everything being a file. Thus directories are really nothing more than files containing the names of other files and so on. In addition,
More informationChapter 3. File I/O. System Programming 熊博安國立中正大學資訊工程學系
Chapter 3. File I/O System Programming http://www.cs.ccu.edu.tw/~pahsiung/courses/sp 熊博安國立中正大學資訊工程學系 pahsiung@cs.ccu.edu.tw Class: EA-104 (05)2720411 ext. 33119 Office: EA-512 Textbook: Advanced Programming
More informationCSci 4061 Introduction to Operating Systems. Input/Output: High-level
CSci 4061 Introduction to Operating Systems Input/Output: High-level I/O Topics First, cover high-level I/O Next, talk about low-level device I/O I/O not part of the C language! High-level I/O Hide device
More informationLecture 21 Systems Programming in C
Lecture 21 Systems Programming in C A C program can invoke UNIX system calls directly. A system call can be defined as a request to the operating system to do something on behalf of the program. During
More informationWhat Is Operating System? Operating Systems, System Calls, and Buffered I/O. Academic Computers in 1983 and Operating System
What Is Operating System? Operating Systems, System Calls, and Buffered I/O emacs gcc Browser DVD Player Operating System CS 217 1 Abstraction of hardware Virtualization Protection and security 2 Academic
More informationOutline. Relationship between file descriptors and open files
Outline 3 File I/O 3-1 3.1 File I/O overview 3-3 3.2 open(), read(), write(), and close() 3-7 3.3 The file offset and lseek() 3-21 3.4 Atomicity 3-30 3.5 Relationship between file descriptors and open
More informationHEC POSIX I/O API Extensions Rob Ross Mathematics and Computer Science Division Argonne National Laboratory
HEC POSIX I/O API Extensions Rob Ross Mathematics and Computer Science Division Argonne National Laboratory rross@mcs.anl.gov (Thanks to Gary Grider for providing much of the material for this talk!) POSIX
More informationRTEMS Filesystem Design Guide
RTEMS Filesystem Design Guide Edition 1, for RTEMS 4.5.0-beta3 May 2000 On-Line Applications Research Corporation On-Line Applications Research Corporation TEXinfo 1999-09-25.10 COPYRIGHT c 1988-2000.
More informationRCU. ò Dozens of supported file systems. ò Independent layer from backing storage. ò And, of course, networked file system support
Logical Diagram Virtual File System Don Porter CSE 506 Binary Formats RCU Memory Management File System Memory Allocators System Calls Device Drivers Networking Threads User Today s Lecture Kernel Sync
More informationVirtual File System. Don Porter CSE 506
Virtual File System Don Porter CSE 506 History ò Early OSes provided a single file system ò In general, system was pretty tailored to target hardware ò In the early 80s, people became interested in supporting
More informationECE 650 Systems Programming & Engineering. Spring 2018
ECE 650 Systems Programming & Engineering Spring 2018 Inter-process Communication (IPC) Tyler Bletsch Duke University Slides are adapted from Brian Rogers (Duke) Recall Process vs. Thread A process is
More informationOperating System Labs. Yuanbin Wu
Operating System Labs Yuanbin Wu cs@ecnu Announcement Project 1 due 21:00, Oct. 8 Operating System Labs Introduction of I/O operations Project 1 Sorting Operating System Labs Manipulate I/O System call
More informationAdvanced Programming in the UNIX Environment W. Richard Stevens
Advanced Programming in the UNIX Environment W. Richard Stevens ADDISON-WESLEY PUBLISHING COMPANY Reading, Massachusetts Menlo Park, California New York Don Mills, Ontario Wokingham, England Amsterdam
More informationFILE SYSTEMS. Jo, Heeseung
FILE SYSTEMS Jo, Heeseung TODAY'S TOPICS File system basics Directory structure File system mounting File sharing Protection 2 BASIC CONCEPTS Requirements for long-term information storage Store a very
More information