Operating Systems Moti Geva

Slides:



Advertisements
Similar presentations
File System – Unix baed. An entry of Active File table: 1. Access Right: r/w/x 2. Process Count: no. of processes which are now referring to the file.
Advertisements

Operating Systems, 112 Practical Session 1, System Calls.
Today’s topic: –File operations –I/O redirection –Inter-process communication through pipes.
1 System Calls & Stdio. 2 Two processes open the same file Both keep writing to it What happens?
CS 311 – Lecture 13 Outline File management system calls chown() chmod() dup() and dup2() link() Lecture 131CS Operating Systems 1.
1 Advanced programming in UNIX 1 File I/O Hua LiSystems ProgrammingCS2690File I/O.
1 System Calls and Standard I/O Professor Jennifer Rexford
CSE 451 Section 4 Project 2 Design Considerations.
1 Unix File System API Operating System Hebrew University Spring 2007.
Today’s topic: –File operations –I/O redirection –Inter-process communication through pipes.
POSIX: Files Introduction to Operating Systems: Discussion 1 Read Solaris System Interface Guide: Ch. 5.1 Basic File I/O.
Recitation 11: I/O Problems Andrew Faulring Section A 18 November 2002.
File Permissions. What are the three categories of users that apply to file permissions? Owner (or user) Group All others (public, world, others)
Recitation 9: Error Handling, I/O, Man Andrew Faulring Section A 4 November 2002.
Module 4 - File Security. Security Overview File Ownership Access to Files and Dircetories Changing File and Directory Ownership Changing File and Directory.
File System Review bottomupcs.com J. Kubiatowicz, UC Berkeley.
File Permission and Access. Module 6 File Permission and Access ♦ Introduction Linux is a multi-user system where users can assign different access permission.
Operating Systems Recitation 1, March th, 2002.
System Commands and Interprocess Communication. chroot int chroot(const char *path); chroot changes the root directory to that specified in path. This.
Pipes A pipe is a simple, synchronized way of passing information between processes A pipe is a special file/buffer that stores a limited amount of data.
CS252: Systems Programming Ninghui Li Based on Slides by Prof. Gustavo Rodriguez-Rivera Topic 8: Opening Files and Starting Processes.
UNIX Files File organization and a few primitives.
System Interface Interface that provides services from the OS (Higher than BIOS) Memory Scheduler File/Storage System Inter-process Communication and Network,
Lecture 3 Introduction to Unix Systems Programming: Unix File I/O System Calls.
Recitation 11 (Nov. 22) Outline Lab 6: interposition test Error handling I/O practice problem Reminders Lab 6: Due Tuesday Minglong Shao
CSCI 330 UNIX and Network Programming Unit VII: I/O Management I.
Recitation 9: Error Handling, I/O, Man Anubhav Gupta Section D.
CSCI 330 UNIX and Network Programming
January 7, 2003Serguei Mokhov, 1 File I/O System Calls Reference COMP 229, 444, 5201 Revision 1.2 Date: July 21, 2004.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Tarek Abdelzaher Vikram Adve CS241 Systems Programming System Calls and I/O.
File I/O open close lseek read and write – unbuffered I/O dup and dup2.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Virtual Filesystem.
Recitation 9: 11/04/02 Outline Error Handling I/O Linux man pages Annie Luo Office Hours: Thursday 6:00 – 7:00 Wean 8402.
CSCI 330 UNIX and Network Programming Unit VIII: I/O Management II.
OS interface: file and I/O system calls File operations in C/C++? –fopen(), fread(), fwrite(), fclose(), fseek() in C f.open(…), f.close(…) in C++ I/O.
Access Control. Many models Traditional Unix model Windows model Role-based access control (SE Linux)‏ Access control for confidentiality (Bell-La Padula.
1 COMP 3500 Introduction to Operating Systems Project 4 – Processes and System Calls Overview Dr. Xiao Qin Auburn University
Files in UNIX u UNIX deals with two different classes of files:  Special Files  Regular Files u Regular files are just ordinary data files on disk -
Error handling I/O Man pages
Andrew Hanushevsky: Basic I/O API’s
Lecture 5 Systems Programming: Unix Processes: Orphans and Zombies
Week 3 Redirection, Pipes, and Background
Robust I/O package Chapter 11 practice problems
Chapter 7 Text Input/Output Objectives
Chapter 7 Text Input/Output Objectives
Lecture 31: Introduction to File System
Week 12 - Wednesday CS222.
Chapter 7 Text Input/Output Objectives
Week 4 - Monday CS222.
CSE 333 – Section 3 POSIX I/O Functions.
Recitation 9: Tshlab + VM
Operating System Hebrew University Spring 2004
Unix Directories unix etc home pro dev motd snt unix ... slide1 slide2
LINUX System Programming with Processes (additional)
תרגול 8 – ק/פ ותקשורת תהליכים ב-Linux
Operating Systems Lecture 6.
CSE 333 – Section 3 POSIX I/O Functions.
Security and File Permission
Programming Assignment # 2 – Supplementary Discussion
I/O and Process Management
CSE 333 – Section 3 POSIX I/O Functions.
IPC Prof. Ikjun Yeom TA – Hoyoun
Advanced UNIX progamming
CSE 333 – Section 3 POSIX I/O Functions.
FILE I/O File Descriptors I/O Efficiency File Sharing
Section 3 Syscalls, I/O, Signals February 3rd, 2017 Taught by Josh Don.
Operating System Hebrew University Spring 2009
Standard I/O Library Implementation
Week 12 - Wednesday CS222.
Unix Directories unix etc home pro dev motd snt unix ... slide1 slide2
Presentation transcript:

Operating Systems Moti Geva geva.biu@gmail.com The basics of files Operating Systems Moti Geva geva.biu@gmail.com

Users UNIX manages users Users are declared in the /etc/passwd file – discussed later... Each user has a unique user id (UID) Each user may belong to a many groups Each group has a group ID (GID) Groups are declared in /etc/groups

Ownership Each file belongs to a single user Each file belongs to a single group A user may have permissions to a file even if he isn’t the owner or in the file’s group How is that?

Levels of permissions User The owner of the file Group Not the user but belongs to the file’s group Other Not the user and not in the group Also known as “the world”

Who are the “others”? An example... Users: Avi Ben Gil Dan Eitan Group: Students (Avi, Ben, Gil) Teachers (Gil, Dan) Files: Teachers Eitan File3 Gil File2 Students Avi File1 Group User/ Owner Name Who are the “others”?

Types of pemissions Three types of permissions Read (4) Write (2) Execute (1) Each one of ugo (user, group, other) has it’s own RWX permission allowed or revoked How many bits are needed for this?

An example...

The almighty root Permission apply to all users and groups With one exception...the “root” user root is the administrator of the OS All privileges are given to the root. If not he can take them Powerful yet dangerous...should be used only for special reasons

Changing permission attributes chown - change the ownership (user) chown [options]... user file chgrp - change the group chgrp [options]... group file chmod – change pemission chmod [[options]... mode file

Basic file operations We will consider open, read, write, close system calls Other file-system system-calls will be addressed at a later time But first a little about error-handling

errno Almost every system-call that fails does the following Error indication (func. return value) Specific error is kept in “errno” errno definition is in errno.h #include <errno.h> extern int errno;

errno usage The program should check what caused the error and manage the error if possible The program can print the error using perror() function call #include <stdio.h> void perror(const char *s); #include <string.h> char *strerror(int errnum); #include <stdio.h> // deprecated const char *sys_errlist[]; int sys_nerr;

File descriptors A file descriptor is used for mapping I/O between the process and the OS Each file descriptor represents an I/O resource It is used in various system calls such as read() and write()

Process descriptor table Each process has a single PDT Process descriptor table A file descriptor (fd) is an entry/offset in the PDT Special file descriptors: 0 – STDIN (standard input) 1 – STDOUT (standard output) 2 – STDERR (standard error)

STDIN, STDOUT, STDERR Where are they used? When using “scanf” the output is read from STDIN When using “printf” the output is printed into STDOUT When using perror the output is directed to STDERR

The open() system call open, creat - open and possibly create a file or device #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int open(const char *pathname, int flags); int open(const char *pathname, int flags, mode_t mode); int creat(const char *pathname, mode_t mode);

The close() system call close - close a file descriptor #include <unistd.h> int close(int fd);

The read() system call read - read from a file descriptor #include <sys/types.h> #include <unistd.h> ssize_t read(int fd, void *buf, size_t count);

The write() system call write - write to a file descriptor #include <sys/types.h> #include <unistd.h> ssize_t write(int fd, const void *buf, size_t count);

The ‘umask’ ‘umask’ is the file creation mask Whenever a file is created the mode (permissions) of the file is set to be mode & ~umask This means that the specified mode will be reduced according to permission not specified by umask Files permission can be changed manually at a later time

umask example umask is set to be umask = 042 (meaning do not give read permission to ‘group’ and write permission to ‘other’) If open() is called as fd = open(“hello”, O_CREAT | O_WRONLY, 0755); (meaning rwx to user rx to group and rx to other) The resulted file (if created) will be 0715

Changing the umask Synopsis #include <sys/stat.h> int umask(int mask); Description umask sets the umask to mask & 0777. Return value The previous value of the mask is returned

dup() and dup2() NAME dup, dup2 - duplicate a file descriptor SYNOPSIS #include <unistd.h> int dup(int oldfd); int dup2(int oldfd, int newfd); DESCRIPTION dup() and dup2() create a copy of the file descriptor oldfd. dup() uses the lowest-numbered unused descriptor for the new descrip‐ tor. dup2() makes newfd be the copy of oldfd, closing newfd first if neces‐ sary

IO Redirection Redirection is the changing the standard input/output/error to a file Examples: Get STDIN from a file (tee < file.txt) Send STDOUT to a file (ls > ls.txt) Send STDERR to a file (ls 2> ls.txt) How can we implement using dup()/dup2()? Example: dup.c