System Calls a Few Administrative Notes…

Total Page:16

File Type:pdf, Size:1020Kb

System Calls a Few Administrative Notes… Operating Systems Practical Session 1 System Calls A few administrative notes… • Course homepage: • http://www.cs.bgu.ac.il/~os182/Main • Assignments: ❑ Extending xv6 (a pedagogical OS) ❑ Submission in pairs. ❑ Frontal checking: 1. Assume the grader may ask anything. 2. Must register to exactly one checking session. Operating System An operating system (OS) is system software that manages computer hardware and software resources and provides common services for computer programs. Main Components for today • Process – Describes an execution of a program and all of its requirements • Kernel – The Heart of the OS, manages processes and other resources • System Calls – Means of communications between the process and the kernel Process Process Kernel Space User Space Run Kernel code Run user code Has: Has: - Stack - Stack - Heap - Heap - System wide view - Direct Hardware access System calls System Calls • A System Call is an interface between a user application and a service provided by the operating system (or kernel). • These can be roughly grouped into five major categories: 1. Process control (e.g. create/terminate process) 2. File Management (e.g. read, write) 3. Device Management (e.g. logically attach a device) 4. Information Maintenance (e.g. set time or date) 5. Communications (e.g. send messages) System Calls - motivation • A process is not supposed to have a direct access the hardware/kernel. It can’t access the kernel memory or functions. • This is strictly enforced (‘protected mode’) for good reasons: • Can jeopardize other processes running. • Cause physical damage to devices. • Alter system behavior. • The system call mechanism provides a safe mechanism to request specific kernel operations. Jumping from user space to kernel space • A process running in user space cannot run code/access data structures in the kernel space • In x86 arch, in order to jump to kernel space, it is common that the process will use interrupts • When jumping to kernel space, the process (kernel) must store a “backup” for its current execution state (so that the kernel will be able to resume the execution later), this backup is referred to as a trapframe. System Calls - interface • Calls are usually made with C/C++ library functions: User Application C - Library Kernel System Call getpid() Load arguments, eax ← _NR_getpid, kernel mode (int 80) Call Sys_Call_table[eax] sys_getpid() syscall_exit return resume_userspace return User-Space Kernel-Space Remark: Invoking int 0x80 is common although newer techniques for “faster” control transfer (SYSCALL/SYSRET) are provided by both AMD’s and Intel’s architecture. XV6 CODE 10 System Calls - interface syscall.h // System call numbers #define • Calls are usually made with C/C++ librarySYS_fork functions: 1 #define SYS_exit 2 #define User Application C - Library KernelSYS_wait 3System #define Call SYS_pipe 4 #define SYS_read 5 #define getpid() Load arguments, eax ← _NR_getpid, SYS_kill 6 #define kernel mode (int 80) SYS_exec 7 #define SYS_fstatCall 8 #define Sys_Call_table[eax]SYS_chdir 9 #definesys_getpid() SYS_dup 10 #define SYS_getpid 11 #define return syscall_exit SYS_sbrk 12 #define SYS_sleep 13 #define resume_userspace SYS_uptime 14 #define SYS_open 15 #define return SYS_write 16 #define SYS_mknod 17 #define SYS_unlink 18 #define SYS_link 19 #define User-Space Kernel-SpaceSYS_mkdir 20 #define SYS_close 21 Remark: Invoking int 0x80 is common although newer techniques for “faster” control transfer are provided by both AMD’s and Intel’s architecture. usys.S #include "syscall.h" #include "traps.h" .globl fork; \ #defineSystem SYSCALL(name) Calls \ - interface fork : \ .globl name; \ name: \ movl $SYS_fork, %eax; \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ int• $T_SYSCALL;Calls are \usually made with C/C++ret library functions: ret User Application C - Library Kernel System Call SYSCALL(fork) SYSCALL(exit) SYSCALL(wait) getpid() Load arguments, ← SYSCALL(pipe) eax _NR_getpid, kernel mode (int 80) SYSCALL(read) Call SYSCALL(write) Sys_Call_table[eax] sys_getpid() SYSCALL(close) SYSCALL(kill) .globl fork; \ return SYSCALL(exec) syscall_exitfork : \ SYSCALL(open) movl $1, %eax; \ SYSCALL(mknod) resume_userspace SYSCALL unlink int $64; \ ( ) SYSCALL(fstat) ret return SYSCALL(link) SYSCALL(mkdir) SYSCALL (chdir) SYSCALL(dup) User-Space Kernel-Space SYSCALL(getpid) SYSCALLRemark:( Invokingsbrk) int 0x80 is common although newer techniques for “faster” control transfer are provided SYSCALLby both( AMD’ssleep and) Intel’s architecture. SYSCALL(uptime) System Calls - interface trapasm.S .globl alltraps •alltrapsCalls :are usually made with C/C++ library functions: # Build trap frame. pushl User%ds Application C - Library Kernel System Call pushl %es pushl %fs getpid() Load arguments, pushl %gs eax ← _NR_getpid, pushal kernel mode (int 80) Call . Sys_Call_table[eax] sys_getpid() . return syscall_exit # Call trap(tf), where tf=%esp pushl %esp resume_userspace call trap . return . User-Space Kernel-Space Remark: Invoking int 0x80 is common although newer techniques for “faster” control transfer are provided by both AMD’s and Intel’s architecture. System Calls - interface syscall.c trap.c static int (*syscalls[])(void) = { [•SYS_forkCalls] sys_forkare usually, made with C/C++ libraryVoid trap(struct functions: trapframe* tf) [SYS_exit] sys_exit, { . User Application C - Library Kernel System Call . [SYS_close] sys_close, . }; getpid() Load arguments, eax ← _NR_getpid, if(tf->trapno == T_SYSCALL){ if(myproc()->killed) void syscall(void) { kernel mode (int 80) int num; Call exit (); struct proc *curproc = myproc(); Sys_Call_table[eax] myproc()->tf =sys_getpid() tf; syscall(); num = curproc->tf->eax; if(myproc()->killed) exit(); if(num > 0 && num < NELEM(syscalls) && syscall_exit return syscalls[num]) { return; curproc->tf->eax = syscalls[num](); } } else { resume_userspace . cprintf("%d %s: unknown sys call %d\n", . curproc->pid, curproc->name, num); return curproc->tf->eax = -1; . } } User-Space Kernel-Space Remark: Invoking int 0x80 is common although newer techniques for “faster” control transfer are provided by both AMD’s and Intel’s architecture. System Calls - interface • Calls are usually made with C/C++ library functions: trapasm.S User Application C - Library Kernel System Call . getpid() Load arguments, . eax ← _NR_getpid, addl $4, %esp kernel mode (int 80) Call sys_getpid() # Return falls through to trapret... Sys_Call_table[eax] .globl trapret trapret: return popal syscall_exit popl %gs popl %fs resume_userspace popl %es popl %ds return addl $0x8, %esp # trapno and errcode iret User-Space Kernel-Space Remark: Invoking int 0x80 is common although newer techniques for “faster” control transfer are provided by both AMD’s and Intel’s architecture. System Calls – tips • Kernel behavior can be enhanced by altering the system calls themselves: imagine we wish to write a message (or add a log entry) whenever a specific user is opening a file. We can re-write the system call open with our new open function and load it to the kernel (need administrative rights). Now all “open” requests are passed through our function. • We can examine which system calls are made by a program by invoking strace<arguments>. Process Control Kernel Space Proc 1 Proc 2 Proc 3 Proc 4 (running) (sleep) (ready) (ready) Process Control Block proc.h enum procstate { UNUSED, EMBRYO, SLEEPING, RUNNABLE, RUNNING, ZOMBIE }; // Per-process state struct proc { uint sz; // Size of process memory (bytes) pde_t* pgdir; // Page table char *kstack; // Bottom of kernel stack for this process enum procstate state; // Process state int pid; // Process ID struct proc *parent; // Parent process struct trapframe *tf; // Trap frame for current syscall struct context *context; // swtch() here to run process void *chan; // If non-zero, sleeping on chan int killed; // If non-zero, have been killed struct file *ofile[NOFILE]; // Open files struct inode *cwd; // Current directory char name[16]; // Process name (debugging) }; THE KILL SYSTEM CALL (XV6) /*** sysproc.c ***/ int sys_kill(void) { int pid; /*** syscall.c ***/ if(argint(0, &pid) < 0) return -1; static int (*syscalls[])(void) = { return kill(pid); [SYS_chdir] sys_chdir, } [SYS_close] sys_close, [SYS_dup] sys_dup, [SYS_exec] sys_exec, /*** proc.c ***/ [SYS_exit] sys_exit, [SYS_fork] sys_fork, // Kill the process with the given pid. [SYS_fstat] sys_fstat, // Process won't exit until it returns [SYS_getpid] sys_getpid, // to user space (see trap in trap.c). [SYS_kill] sys_kill, int [SYS_link] sys_link, kill(int pid) { [SYS_mkdir] sys_mkdir, struct proc *p; [SYS_mknod] sys_mknod, [SYS_open] sys_open, acquire(&ptable.lock); [SYS_pipe] sys_pipe, for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ [SYS_read] sys_read, if(p->pid == pid){ [SYS_sbrk] sys_sbrk, p->killed = 1; [SYS_sleep] sys_sleep, // Wake process from sleep if necessary. [SYS_unlink] sys_unlink, if(p->state == SLEEPING) [SYS_wait] sys_wait, p->state = RUNNABLE; [SYS_write] sys_write, release(&ptable.lock); [SYS_uptime] sys_uptime, return 0; }; } release(&ptable.lock); return -1; } 19 Fork • pid_t fork(void); • Fork is used to create a new process. It creates a duplicate of the original process (including all file descriptors, registers, instruction pointer, etc’). • Once the call is finished, the process and its copy go their separate ways. Subsequent changes to one should not effect the other. • The fork call returns a different value to the original process (parent) and its copy (child): in the child process this value is zero, and
Recommended publications
  • Copy on Write Based File Systems Performance Analysis and Implementation
    Copy On Write Based File Systems Performance Analysis And Implementation Sakis Kasampalis Kongens Lyngby 2010 IMM-MSC-2010-63 Technical University of Denmark Department Of Informatics Building 321, DK-2800 Kongens Lyngby, Denmark Phone +45 45253351, Fax +45 45882673 [email protected] www.imm.dtu.dk Abstract In this work I am focusing on Copy On Write based file systems. Copy On Write is used on modern file systems for providing (1) metadata and data consistency using transactional semantics, (2) cheap and instant backups using snapshots and clones. This thesis is divided into two main parts. The first part focuses on the design and performance of Copy On Write based file systems. Recent efforts aiming at creating a Copy On Write based file system are ZFS, Btrfs, ext3cow, Hammer, and LLFS. My work focuses only on ZFS and Btrfs, since they support the most advanced features. The main goals of ZFS and Btrfs are to offer a scalable, fault tolerant, and easy to administrate file system. I evaluate the performance and scalability of ZFS and Btrfs. The evaluation includes studying their design and testing their performance and scalability against a set of recommended file system benchmarks. Most computers are already based on multi-core and multiple processor architec- tures. Because of that, the need for using concurrent programming models has increased. Transactions can be very helpful for supporting concurrent program- ming models, which ensure that system updates are consistent. Unfortunately, the majority of operating systems and file systems either do not support trans- actions at all, or they simply do not expose them to the users.
    [Show full text]
  • Storage Administration Guide Storage Administration Guide SUSE Linux Enterprise Server 12 SP4
    SUSE Linux Enterprise Server 12 SP4 Storage Administration Guide Storage Administration Guide SUSE Linux Enterprise Server 12 SP4 Provides information about how to manage storage devices on a SUSE Linux Enterprise Server. Publication Date: September 24, 2021 SUSE LLC 1800 South Novell Place Provo, UT 84606 USA https://documentation.suse.com Copyright © 2006– 2021 SUSE LLC and contributors. All rights reserved. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or (at your option) version 1.3; with the Invariant Section being this copyright notice and license. A copy of the license version 1.2 is included in the section entitled “GNU Free Documentation License”. For SUSE trademarks, see https://www.suse.com/company/legal/ . All other third-party trademarks are the property of their respective owners. Trademark symbols (®, ™ etc.) denote trademarks of SUSE and its aliates. Asterisks (*) denote third-party trademarks. All information found in this book has been compiled with utmost attention to detail. However, this does not guarantee complete accuracy. Neither SUSE LLC, its aliates, the authors nor the translators shall be held liable for possible errors or the consequences thereof. Contents About This Guide xii 1 Available Documentation xii 2 Giving Feedback xiv 3 Documentation Conventions xiv 4 Product Life Cycle and Support xvi Support Statement for SUSE Linux Enterprise Server xvii • Technology Previews xviii I FILE SYSTEMS AND MOUNTING 1 1 Overview
    [Show full text]
  • Lecture 9: Data Storage and IO Models Lecture 9
    Lecture 9 Lecture 9: Data Storage and IO Models Lecture 9 Announcements • Submission Project Part 1 tonight • Instructions on Piazza! • PS2 due on Friday at 11:59 pm • Questions? Easier than PS1. • Badgers Rule! Lecture 9 Today’s Lecture 1. Data Storage 2. Disk and Files 3. Buffer Manager - Prelims 3 Lecture 9 > Section 1 1. Data Storage 4 Lecture 9 > Section 1 What you will learn about in this section 1. Life cycle of a query 2. Architecture of a DBMS 3. Memory Hierarchy 5 Lecture 9 > Section 1 Life cycle of a query Query Result Query Database Server Query Execute Parser Optimizer Select R.text from |…|……|………..|………..| Report R, Weather W |…|……|………..|………..| where W.image.rain() Scheduler Operators |…|……|………..|………..| and W.city = R.city |…|……|………..|………..| and W.date = R.date |…|……|………..|………..| and |…|……|………..|………..| R.text. |…|……|………..|………..| matches(“insurance claims”) |…|……|………..|………..| |…|……|………..|………..| |…|……|………..|………..| |…|……|………..|………..| Query Query Syntax Tree Query Plan Result Segments 6 Lecture 9 > Section 1 > Architecture of a DBMS Internal Architecture of a DBMS query Query Execution data access Storage Manager I/O access 7 Lecture 9 > Section 1 > Storage Manager Architecture of a Storage Manager Access Methods Sorted File Hash Index B+-tree Heap File Index Manager Buffer Manager Recovery Manager Concurrency Control I/O Manager IO Accesses In Systems, IO cost matters a ton! 8 Lecture 9 > Section 1 > Data Storage Data Storage • How does a DBMS store and access data? • main memory (fast, temporary) • disk (slow, permanent) • How
    [Show full text]
  • The Linux Kernel Module Programming Guide
    The Linux Kernel Module Programming Guide Peter Jay Salzman Michael Burian Ori Pomerantz Copyright © 2001 Peter Jay Salzman 2007−05−18 ver 2.6.4 The Linux Kernel Module Programming Guide is a free book; you may reproduce and/or modify it under the terms of the Open Software License, version 1.1. You can obtain a copy of this license at http://opensource.org/licenses/osl.php. This book is distributed in the hope it will be useful, but without any warranty, without even the implied warranty of merchantability or fitness for a particular purpose. The author encourages wide distribution of this book for personal or commercial use, provided the above copyright notice remains intact and the method adheres to the provisions of the Open Software License. In summary, you may copy and distribute this book free of charge or for a profit. No explicit permission is required from the author for reproduction of this book in any medium, physical or electronic. Derivative works and translations of this document must be placed under the Open Software License, and the original copyright notice must remain intact. If you have contributed new material to this book, you must make the material and source code available for your revisions. Please make revisions and updates available directly to the document maintainer, Peter Jay Salzman <[email protected]>. This will allow for the merging of updates and provide consistent revisions to the Linux community. If you publish or distribute this book commercially, donations, royalties, and/or printed copies are greatly appreciated by the author and the Linux Documentation Project (LDP).
    [Show full text]
  • Use of Seek When Writing Or Reading Binary Files
    Title stata.com file — Read and write text and binary files Description Syntax Options Remarks and examples Stored results Reference Also see Description file is a programmer’s command and should not be confused with import delimited (see [D] import delimited), infile (see[ D] infile (free format) or[ D] infile (fixed format)), and infix (see[ D] infix (fixed format)), which are the usual ways that data are brought into Stata. file allows programmers to read and write both text and binary files, so file could be used to write a program to input data in some complicated situation, but that would be an arduous undertaking. Files are referred to by a file handle. When you open a file, you specify the file handle that you want to use; for example, in . file open myfile using example.txt, write myfile is the file handle for the file named example.txt. From that point on, you refer to the file by its handle. Thus . file write myfile "this is a test" _n would write the line “this is a test” (without the quotes) followed by a new line into the file, and . file close myfile would then close the file. You may have multiple files open at the same time, and you may access them in any order. 1 2 file — Read and write text and binary files Syntax Open file file open handle using filename , read j write j read write text j binary replace j append all Read file file read handle specs Write to file file write handle specs Change current location in file file seek handle query j tof j eof j # Set byte order of binary file file set handle byteorder hilo j lohi j 1 j 2 Close
    [Show full text]
  • File Storage Techniques in Labview
    File Storage Techniques in LabVIEW Starting with a set of data as if it were generated by a daq card reading two channels and 10 samples per channel, we end up with the following array: Note that the first radix is the channel increment, and the second radix is the sample number. We will use this data set for all the following examples. The first option is to send it directly to a spreadsheet file. spreadsheet save of 2D data.png The data is wired to the 2D array input and all the defaults are taken. This will ask for a file name when the program block is run, and create a file with data values, separated by tab characters, as follows: 1.000 2.000 3.000 4.000 5.000 6.000 7.000 8.000 9.000 10.000 10.000 20.000 30.000 40.000 50.000 60.000 70.000 80.000 90.000 100.000 Note that each value is in the format x.yyy, with the y's being zeros. The default format for the write to spreadsheet VI is "%.3f" which will generate a floating point number with 3 decimal places. If a number with higher decimal places is entered in the array, it would be truncated to three. Since the data file is created in row format, and what you really need if you are going to import it into excel, is column format. There are two ways to resolve this, the first is to set the transpose bit on the write function, and the second, is to add an array transpose, located in the array pallet.
    [Show full text]
  • System Calls System Calls
    System calls We will investigate several issues related to system calls. Read chapter 12 of the book Linux system call categories file management process management error handling note that these categories are loosely defined and much is behind included, e.g. communication. Why? 1 System calls File management system call hierarchy you may not see some topics as part of “file management”, e.g., sockets 2 System calls Process management system call hierarchy 3 System calls Error handling hierarchy 4 Error Handling Anything can fail! System calls are no exception Try to read a file that does not exist! Error number: errno every process contains a global variable errno errno is set to 0 when process is created when error occurs errno is set to a specific code associated with the error cause trying to open file that does not exist sets errno to 2 5 Error Handling error constants are defined in errno.h here are the first few of errno.h on OS X 10.6.4 #define EPERM 1 /* Operation not permitted */ #define ENOENT 2 /* No such file or directory */ #define ESRCH 3 /* No such process */ #define EINTR 4 /* Interrupted system call */ #define EIO 5 /* Input/output error */ #define ENXIO 6 /* Device not configured */ #define E2BIG 7 /* Argument list too long */ #define ENOEXEC 8 /* Exec format error */ #define EBADF 9 /* Bad file descriptor */ #define ECHILD 10 /* No child processes */ #define EDEADLK 11 /* Resource deadlock avoided */ 6 Error Handling common mistake for displaying errno from Linux errno man page: 7 Error Handling Description of the perror () system call.
    [Show full text]
  • System Calls and I/O
    System Calls and I/O CS 241 January 27, 2012 Copyright ©: University of Illinois CS 241 Staff 1 This lecture Goals Get you familiar with necessary basic system & I/O calls to do programming Things covered in this lecture Basic file system calls I/O calls Signals Note: we will come back later to discuss the above things at the concept level Copyright ©: University of Illinois CS 241 Staff 2 System Calls versus Function Calls? Copyright ©: University of Illinois CS 241 Staff 3 System Calls versus Function Calls Function Call Process fnCall() Caller and callee are in the same Process - Same user - Same “domain of trust” Copyright ©: University of Illinois CS 241 Staff 4 System Calls versus Function Calls Function Call System Call Process Process fnCall() sysCall() OS Caller and callee are in the same Process - Same user - OS is trusted; user is not. - Same “domain of trust” - OS has super-privileges; user does not - Must take measures to prevent abuse Copyright ©: University of Illinois CS 241 Staff 5 System Calls System Calls A request to the operating system to perform some activity System calls are expensive The system needs to perform many things before executing a system call The computer (hardware) saves its state The OS code takes control of the CPU, privileges are updated. The OS examines the call parameters The OS performs the requested function The OS saves its state (and call results) The OS returns control of the CPU to the caller Copyright ©: University of Illinois CS 241 Staff 6 Steps for Making a System Call
    [Show full text]
  • The Power Supply Subsystem
    The Power Supply Subsystem Sebastian Reichel Collabora October 24, 2018 Open First Sebastian Reichel I Embedded Linux engineer at Collabora I Open Source Consultancy I Based in Oldenburg, Germany I Open Source contributor I Debian Developer I HSI and power-supply subsystem maintainer I Cofounder of Oldenburg's Hack(er)/Makerspace Open First The power-supply subsystem I batteries / fuel gauges I chargers I (board level poweroff/reset) I Originally written and maintained by Anton Vorontsov (2007-2014) Created by Blink@design from the Noun Project Created by Jenie Tomboc I Temporarily maintained by Dmitry from the Noun Project Eremin-Solenikov (2014) Open First Userspace Interface root@localhost# ls /sys/class/power_supply/ AC BAT0 BAT1 root@localhost# ls /sys/class/power_supply/BAT0 alarm energy_full_design status capacity energy_now subsystem capacity_level manufacturer technology charge_start_threshold model_name type charge_stop_threshold power uevent cycle_count power_now voltage_min_design ... root@localhost# cat /sys/class/power_supply/BAT0/capacity 65 Open First Userspace Interface root@localhost# udevadm info /sys/class/power_supply/BAT0 E: POWER_SUPPLY_CAPACITY=79 E: POWER_SUPPLY_ENERGY_FULL=15200000 E: POWER_SUPPLY_ENERGY_FULL_DESIGN=23200000 E: POWER_SUPPLY_ENERGY_NOW=12010000 E: POWER_SUPPLY_POWER_NOW=5890000 E: POWER_SUPPLY_STATUS=Discharging E: POWER_SUPPLY_VOLTAGE_MIN_DESIGN=11100000 E: POWER_SUPPLY_VOLTAGE_NOW=11688000 ... Open First Userspace Interface I one power-supply device = one physical device I All values are in uV,
    [Show full text]
  • Dell Update Packages for Linux Operating Systems User's Guide
    Dell™ Update Packages for Linux Operating Systems User’s Guide Notes and Cautions NOTE: A NOTE indicates important information that helps you make better use of your computer. CAUTION: A CAUTION indicates potential damage to hardware or loss of data if instructions are not followed. ____________________ Information in this document is subject to change without notice. © 2009 Dell Inc. All rights reserved. Reproduction of these materials in any manner whatsoever without the written permission of Dell Inc. is strictly forbidden. Trademarks used in this text: Dell, the DELL logo, and OpenManage are trademarks of Dell Inc.; Microsoft and Windows are either trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries; Intel is a registered trademark of Intel Corporation in the United States and other countries; Red Hat and Red Hat Enterprise Linux are registered trademarks of Red Hat, Inc. in the United States and other countries; SUSE is a registered trademark of Novell, Inc. in the United States and other countries; VMware and ESX Server are registered trademarks or trademarks of VMware, Inc. in the United States and/or other jurisdictions; Citrix and XenServer are either trademarks or registered trademarks of Citrix Systems, Inc. in the United States and/or other countries. Other trademarks and trade names may be used in this document to refer to either the entities claiming the marks and names or their products. Dell Inc. disclaims any proprietary interest in trademarks and trade names other than its own. April 2009 Contents 1 Getting Started With Dell Update Packages . 7 Overview .
    [Show full text]
  • Ext4 File System and Crash Consistency
    1 Ext4 file system and crash consistency Changwoo Min 2 Summary of last lectures • Tools: building, exploring, and debugging Linux kernel • Core kernel infrastructure • Process management & scheduling • Interrupt & interrupt handler • Kernel synchronization • Memory management • Virtual file system • Page cache and page fault 3 Today: ext4 file system and crash consistency • File system in Linux kernel • Design considerations of a file system • History of file system • On-disk structure of Ext4 • File operations • Crash consistency 4 File system in Linux kernel User space application (ex: cp) User-space Syscalls: open, read, write, etc. Kernel-space VFS: Virtual File System Filesystems ext4 FAT32 JFFS2 Block layer Hardware Embedded Hard disk USB drive flash 5 What is a file system fundamentally? int main(int argc, char *argv[]) { int fd; char buffer[4096]; struct stat_buf; DIR *dir; struct dirent *entry; /* 1. Path name -> inode mapping */ fd = open("/home/lkp/hello.c" , O_RDONLY); /* 2. File offset -> disk block address mapping */ pread(fd, buffer, sizeof(buffer), 0); /* 3. File meta data operation */ fstat(fd, &stat_buf); printf("file size = %d\n", stat_buf.st_size); /* 4. Directory operation */ dir = opendir("/home"); entry = readdir(dir); printf("dir = %s\n", entry->d_name); return 0; } 6 Why do we care EXT4 file system? • Most widely-deployed file system • Default file system of major Linux distributions • File system used in Google data center • Default file system of Android kernel • Follows the traditional file system design 7 History of file system design 8 UFS (Unix File System) • The original UNIX file system • Design by Dennis Ritche and Ken Thompson (1974) • The first Linux file system (ext) and Minix FS has a similar layout 9 UFS (Unix File System) • Performance problem of UFS (and the first Linux file system) • Especially, long seek time between an inode and data block 10 FFS (Fast File System) • The file system of BSD UNIX • Designed by Marshall Kirk McKusick, et al.
    [Show full text]
  • File Handling in Python
    hapter C File Handling in 2 Python There are many ways of trying to understand programs. People often rely too much on one way, which is called "debugging" and consists of running a partly- understood program to see if it does what you expected. Another way, which ML advocates, is to install some means of understanding in the very programs themselves. — Robin Milner In this Chapter » Introduction to Files » Types of Files » Opening and Closing a 2.1 INTRODUCTION TO FILES Text File We have so far created programs in Python that » Writing to a Text File accept the input, manipulate it and display the » Reading from a Text File output. But that output is available only during » Setting Offsets in a File execution of the program and input is to be entered through the keyboard. This is because the » Creating and Traversing a variables used in a program have a lifetime that Text File lasts till the time the program is under execution. » The Pickle Module What if we want to store the data that were input as well as the generated output permanently so that we can reuse it later? Usually, organisations would want to permanently store information about employees, inventory, sales, etc. to avoid repetitive tasks of entering the same data. Hence, data are stored permanently on secondary storage devices for reusability. We store Python programs written in script mode with a .py extension. Each program is stored on the secondary device as a file. Likewise, the data entered, and the output can be stored permanently into a file.
    [Show full text]