OPERATING SYSTEMS COURSE THE HEBREW UNIVERSITY SPRING 2014 1 FUSE File System.

Slides:



Advertisements
Similar presentations
R4 Dynamically loading processes. Overview R4 is closely related to R3, much of what you have written for R3 applies to R4 In R3, we executed procedures.
Advertisements

Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
Chapter 7 Process Environment Chien-Chung Shen CIS, UD
Operating system services Program execution I/O operations File-system manipulation Communications Error detection Resource allocation Accounting Protection.
File System Interface CSCI 444/544 Operating Systems Fall 2008.
GNU/Linux Filesystem 1 st AUT GNU/Linux Festival Computer Engineering & IT Department Bahador Bakhshi.
CS 110 Intro to Computer Science I Sami Rollins Fall 2006.
Introduction to a Programming Environment
70-270, MCSE/MCSA Guide to Installing and Managing Microsoft Windows XP Professional and Windows Server 2003 Chapter Nine Managing File System Access.
CSE 451 Section 4 Project 2 Design Considerations.
NFS. The Sun Network File System (NFS) An implementation and a specification of a software system for accessing remote files across LANs. The implementation.
Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random access memory.
Systems Software Operating Systems.
File Systems (2). Readings r Silbershatz et al: 11.8.
Programming a computer. What does programming a computer mean ? Programming a computer: Since a computer can only execute machine instructions (encoded.
DELTA TAU Data Systems, Inc. 1 UMAC TurboTurbo PMAC PCIGeo Drive Single Source Machine Control motion logic data Power PMAC as a Linux Computer January.
1 SEEM3460 Tutorial Unix Introduction. 2 Introduction What is Unix? An operation system (OS), similar to Windows, MacOS X Why learn Unix? Greatest Software.
A crash course in njit’s Afs
POSIX: Files Introduction to Operating Systems: Discussion 1 Read Solaris System Interface Guide: Ch. 5.1 Basic File I/O.
The Programming Interface. Main Points Creating and managing processes – fork, exec, wait Performing I/O – open, read, write, close Communicating between.
Chapter 3.1:Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random access.
UNIX command line. In this module you will learn: What is the computer shell What is the command line interface (or Terminal) What is the filesystem tree.
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
Networked File System CS Introduction to Operating Systems.
CSCC69: Operating Systems Assignment 3 Review. Assignment Review Implement the file-related system calls – open, close, dup2 – read, write, lseek – chdir,
Lecturer: Ghadah Aldehim
Data Objects (revisited) Recall that values are stored in data objects, and that each data object holds one value of a particular type. Data objects may.
Pooja Shetty Usha B Gowda.  Network File Systems (NFS)  Drawbacks of NFS  Parallel Virtual File Systems (PVFS)  PVFS components  PVFS application.
CSC 322 Operating Systems Concepts Lecture - 4: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Intro to Computer Systems Summer 2014 COMP 2130 Introduction to Computer Systems Computing Science Thompson Rivers University.
1 SEEM3460 Tutorial Unix Introduction. 2 Introduction Unix-like system is everywhere Linux Android for smartphones Google Chrome OS for Chromebook Web.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Scons Writing Solid Code Overview What is scons? scons Basics Other cools scons stuff Resources.
Shell (Part 2). Example r What if we want to support something like this: m ps –le | sort r One process should execute ps –le and another should execute.
CS 590 Programming Environments with UNIX. Computer Lab Account Course Homepage
IBM TSpaces Lab 1 Introduction. Summary TSpaces Overview Basic Definitions Basic primitive operations Reading/writing tuples in tuplespace HelloWorld.
CE Operating Systems Lecture 3 Overview of OS functions and structure.
UNIX Files File organization and a few primitives.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Introduction to UNIX Road Map: 1. UNIX Structure 2. Components of UNIX 3. Process Structure 4. Shell & Utility Programs 5. Using Files & Directories 6.
Hands On UNIX II Dorcas Muthoni. Processes A running instance of a program is called a "process" Identified by a numeric process id (pid)‏  unique while.
Chapter Two Exploring the UNIX File System and File Security.
1 UNIT 13 The World Wide Web Lecturer: Kholood Baselm.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
Operating Systems Process Creation
Fall 2002 CS 325 Class Notes Page 1 Lecture 25 Today –exec() in Unix –CreateProcess in Windows Announcements.
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
Lecture 18 Windows – NT File System (NTFS)
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
UNIX File System By Vishal Desai. Introduction Basic purpose of file system: Represent and organize the system resources. But UNIX File System also maps.
CSCC69: Operating Systems Tutorial 10. Hints on testing Assignment 3 How to test tlb replacement algorithms? – Write a program that creates an array larger.
Lecture 02 File and File system. Topics Describe the layout of a Linux file system Display and set paths Describe the most important files, including.
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
Introduction to FUSE (File system in USEr space) Speaker:Zong-shuo Jheng Date:March 14, 2008.
C Programming Day 2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/LA07/003 Version No. 1.0 Union –mechanism to create user defined data types.
1 Chapter 2: Operating-System Structures Services Interface provided to users & programmers –System calls (programmer access) –User level access to system.
Chapter 7 Process Environment Chien-Chung Shen CIS/UD
Protecting Memory What is there to protect in memory?
File System Implementation
...looking a bit closer under the hood
Protecting Memory What is there to protect in memory?
Protecting Memory What is there to protect in memory?
Chapter 12: File System Implementation
Hands On UNIX AfNOG 2010 Kigali, Rwanda
Hands On UNIX AfNOG X Cairo, Egypt
Operation System Program 4
Chapter 15: File System Internals
Introduction to Computer Systems
System calls….. C-program->POSIX call
Introduction to Operating Systems
Presentation transcript:

OPERATING SYSTEMS COURSE THE HEBREW UNIVERSITY SPRING FUSE File System

File system 2 Used to control how data is stored and retrieved What would happen without file system? The file system manages access to the content of the files and the metadata There are files systems for many different kings of storage devices: Hard Disk Flash memory Not locally via a network protocol. For example, the Network File System (NFS) uses Remote Procedure Call (RPC).

Virtual File System (VFS) - motivation 3 Standard use of a user requires several files systems  Linux standard file system for the local files  NFS file system for the files in your directory  FAT32 file system in the memory device However, we would like to use the same set of file system commands, e.g. “ls”, “cd”, “open”, “read”, etc.

VFS 4 The Virtual File System is an abstraction layer on top of a more concrete file system. A VFS specifies an interface between the kernel and a concrete file system. It allows the client application to access different types of concrete file system in a uniform way.

VFS Figure 5

Mount 6 Before a user can access a file on a Unix- like machine, the file system that contains it needs to be mounted with the mount command. Mount is used for SD card, USB storage, DVD and other removable storage devices The mount command instructs the operating system that a file system is ready to use, and associates it with a particular point in the overall file system hierarchy (its mount point)

Unmount 7 Its counterpart umount instructs the operating system that the file system should be disassociated from its mount point, making it no longer accessible and may be removed from the computer. It is important to umount a device before removing it since changes to files may have only partially written and are completed as part of the umount

Filesystem in USErspace (FUSE) 8 FUSE is a loadable kernel module for Unix-like computer operating systems that lets non-privileged users create their own file systems without editing kernel code This is achieved by running file system code in user space while the FUSE module provides only a "bridge" to the actual kernel interfaces FUSE is often used for writing virtual file system, which don’t actually store data, but only translate existing file system. Extremely efficient and therefore usefull.

How FUSE Works 9 The FUSE kernel module and the FUSE library communicate via a special file descriptor which is obtained by opening /dev/fuse This file can be opened multiple times, and the obtained file descriptor is passed to the mount system call, to match up the descriptor with the mounted file system

What Do People use FUSE for? 10 Archive file systems Accessing the content of archive (i.e. tar or zip) without decompressing them. Encrypted file systems Storing files in a more secure way Database file systems Storing files in a relational database (MySQL, BerkeleyDB etc.) Monitoring file systems Providing notification when a file changes

HELLO WORLD FILE SYSTEM 11 FUSE Example #1

Hello World File System 12 In the next slides, we’ll be reviewing the Hello_World example This file system consists of a single file, with a predefined message, which can only be read: static const char *hello_str = "Hello World!\n"; // the string static const char *hello_path = "/hello"; To be honest, the file is not really read, but that’s what the user is lead to believe You can find the original documentation of this example herehere

Programming 13 Include the following: #include

struct fuse_operations 14 Instead of using the system’s implementation of the Unix File System API (which we reviewed in a previous TA), FUSE replaces it with the user’ implementation This struct defines which of the functions you provide should be used to implement the file system API instead of the default system’s implementation In this example, we’ll be overriding only 4 functions The fuse.h file contains the struct, and so a list of all the functions that can be overridden

struct fuse_operations (2) 15 How we use struct fuse_operations ? 1. Create a struct. 2. Init it with pointers to our functions 3. Send it to the fuse in the fuse_main function. Two different designs are possible 1. “static design”, the struct and all the functions are static. We will see example in the following slides. 2. “non-static design”, both are not static. We used this design in your exercise.

struct fuse_operations Hello World example 16 static struct fuse_operations hello_oper = {.getattr = hello_getattr,.readdir = hello_readdir,.open = hello_open,.read = hello_read, }; /* In our case, you must init the rest of the functions to NULL. We have done that for you… /*

fuse_file_info struct 17 This struct is given as input in may fuse functions. In the EX, you will use only the flags & fh fields.

hello_getattr 18 This function returns metadata concerning a file specified by path in a special stat structure

hello_getattr 19 static int hello_getattr(const char *path, struct stat *stbuf){ int res = 0; memset(stbuf, 0, sizeof(struct stat)); //Reset vals to 0 if (strcmp(path, "/") == 0) { // Root directory stbuf->st_mode = S_IFDIR | 0755; //irrelevant for you stbuf->st_nlink = 2; // # of hard links } else if (strcmp(path, hello_path) == 0) { stbuf->st_mode = S_IFREG | 0444; //irrelevant for you stbuf->st_nlink = 1; stbuf->st_size = strlen(hello_str); //size } else res = -ENOENT; return res; }

hello_readdir 20 Used to read directory contents Because this implementation is very simple, we will be interested only in path, buf and filler arguments passed to it Path is the path to the directory from which we will have to read our content buf will hold them, filler is a fuse_fill_dir_t function which we will use to add contents to directory Offset and fi are not important now

hello_readdir - cont. 21 static int hello_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi){ (void) offset; (void) fi; if (strcmp(path, "/") != 0) return -ENOENT; filler(buf, ".", NULL, 0); //Add "." directory entry filler(buf, "..", NULL, 0); //Add “.." filler(buf, hello_path + 1, NULL, 0); // w.o. “/” return 0; }

hello_open 22 This function is used to open a file. Before opening, it must check whatever the user is permitted to open it (using the flags given in the fuse_file_info structure) In our case, there is no need to open the file, because the content is saved in the memory (it’s a string). static int hello_open(const char *path, struct fuse_file_info *fi){ if (strcmp(path, hello_path) != 0) return -ENOENT; if ((fi->flags & 3) != O_RDONLY) return -EACCES; return 0; // Can open the file }

hello_read 23 Used to feed the user with data from the file Path is the path to the file to read buf is a buffer to which we will copy information from the file, size is at the same time the size of the buffer and tells how much of the data we have to read offset is the place from which we have to start reading fi contains additional information about the type of access

hello_read - cont. 24 static int hello_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi){ size_t len; (void) fi; if(strcmp(path, hello_path) != 0) return -ENOENT; // Can’t open a different file len = strlen(hello_str); if (offset < len) { if (offset + size > len) size = len - offset; memcpy(buf, hello_str + offset, size); } else size = 0; return size; }

The main function 25 Should always return the value received from calling fuse_main In the Hello World example: int main(int argc, char *argv[[]]) { return fuse_main(argc, argv, &hello_oper, NULL); }

Compiling and Running 26 gcc -Wall `pkg-config fuse --cflags -- libs` hello.c -o hello Run it with a single parameter - a mount point: $mkdir tmp $./hello tmp/ $

Compiling and Running – cont. 27 After running the program you should have a single file in the tmp/ directory named hello, its content should be Hello World!: $ ls tmp/ hello $ cat tmp/hello Hello World!

Unmount 28 To unmount, use: fusermount -u /tmp/fuse

BIG BROTHER FILE SYSTEM 29 FUSE Example #2

Big Brother File System 30 This FUSE program receives 2 arguments The root directory, which contains the actual directory data The mount directory All of the files that are really in rootdir appear to also be in mountdir. But, every time you perform any file operation in mountdir, the operation (and a whole bunch of both relevant and irrelevant stuff) gets logged to a new file in the current working directory called bbfs.log

Big Brother File System - How To Run 31 Download the tar file from the tutorial websitethe tutorial website Use the make file to compile the code in the /src folder Go to the /example directory, and execute:../src/bbfs rootdir mountdir Execute tail -F bbfslog in another terminal window to watch the operations get logged

32 Ex4 – Caching File System Using FUSE

Ex4 - Assignment 33 In this exercise you will implement a simple single threaded caching file system and a simple algorithm to manage the file system's cache memory Caching file systems saves files or parts of them to a memory segment called cached memory, which is stored in the main memory That way, if the user wishes to access information that is saved in the cache, it can be retrieved from the cache instead of the disk, thus reducing the number of disk access required

Guidelines 34 Start with a clean slate – don’t start with a working system as a base We’ll be providing a clean slate file for you – use it! Going through the Big Brother FUSE file system comes in handy when trying to understand the different structs and how they work We strongly suggest you not to do to copy lines from there. Don’t use any line (e.g.) a function that you don’t fully understand!

Our Caching File System 35 The caching in this exercise (not in real life though) is for read only, so you don’t have to implement the write system call It does not mean you won’t have to implement other system calls relating to read You are expected to separate the logic of the cache from the FUSE functions

FUSE Tips (1) 36 Mount folder must be empty! You should use only directories within “\tmp”. Don’t try to use files within your user, because they are accessed via NFS. FUSE doesn’t support non-static global variables. If you want to have a global variable – make it static. FUSE can’t be runing on the System’s servers. We suggest you to work from HUJI, but you may also work from home using virtual machine

FUSE Tips (2) 37 Be sure to unmount, even if your program cashes or you abort it You won’t be able to mount again until you do FUSE disables the cout prints, so print out a file in order to debug You may also use the FUSE –f flag, which will make the program run in the foreground (and therefore the prints will be visible).

Running and debugging 38 A bug may lead your OS to collapse. Make sure that you follow all the Guidelines and Tips mentioned in the exercise. Try to implement and check each function separately. We suggest you to have two phases of testing  Basic tests using shell commands.  More sophisticated tests via scripts.