程序代写代做代考 Java Hive file system Object-Oriented Programming

Object-Oriented Programming

Operating Systems

Lecture 8b

Dr Ronald Grau School of Engineering and Informatics Spring term 2018

Previously

Memory management

 Virtual memory

 Addressing and address spaces

 Partitioning and segmentation

 Paging & Page replacement

1

Recap: Questions

Recap questions

1. How can we avoid page faults when a process starts?

2. How can thrashing be controlled?

3. What is a working set?

4. What is the significance of the reference bit in the page table?

5. What is the main problem of the FIFO page replacement policy?

6. What information is required to operate the LRU policy?

2

Today

Files

 Persistent storage

 Formats, access, operations

 Attributes & permissions

 Implementation

3

File abstraction

Files

 Persistent storage of data

 Named

 Byte-wise access

 Access protection

 Consistency guarantees

Operating system duties:

 Manage efficient access (e.g. caching)

 Protect storage device from being damaged/corrupted

 Provide uniform interface for heterogeneous devices

4

File abstraction

Basic terminology

 Bit: 0, 1

 Byte: typically 8 bits

 Word: the number of bits a processor can operate on at once

 Character: maps one or more bytes to letters, digits, etc

 Character set: defines the mapping system (e.g. ASCII, Unicode)

 Field: a group of characters

 Record: a group of fields

 File: a group of related records

 Volume: a unit of data storage holding multiple files

 File system: the way the OS organises files and manages access

5

File names

 Human-readable name to identify a file

 Maps to an internal identifier in the file system

 Length of the file name

 MS-DOS: 8 characters + extension

 Modern OS: 255 characters

 Relevance of upper/lower case, allowed characters

 Unix distinguishes between upper/lower case, unlike Windows

 File name extensions

 MS-DOS: separate from the le name

 Modern OS: convention, multiple extensions possible

6

File types

 Regular files

 Text files: interpretation as characters

 Binary files: interpretation application-specific

e.g. executables, pictures

 Directories: hierarchy of files

 Special files for I/O devices

7

File formats

Define how the data is organised within a file

 Fixed-length records

 Variable-length records

 Indexed records

 Trees: XML, JSON

8

File formats

Example: ZIP format

9

File formats

Example: ZIP format

10

File formats

Example: GIF format

11

File formats

Example: GIF format

12

File access 13

File access 14

Sequential access:

Random access:

File operations

Typical operations:

 Create, Delete, Rename

 Open, Close

 Read, Write, Append, Truncate

 Seek

 Get Attributes, Set Attributes

 Lock, Unlock

15

File operations

Example: POSIX System calls

16

int open(const char *filename, int flags, mode t mode);

// example:
int fd = open(“myfile.txt”, O WRONLY | O CREAT, 0644);
if (fd < 0) switch(errno) { ... } File operations Example: POSIX System calls 17 ssize_t read(int fd, void *buf, size_t count); // example: char buffer[BUF SIZE]; ssize_t bytes read = read(fd, buffer, BUF_SIZE); File operations Example: POSIX System calls 18 ssize_t write(int fd, void *buf, size_t count); // example: char buffer[BUF_SIZE]; ssize_t_bytes_written = write(fd, buffer, BUF_SIZE); File operations Example: POSIX System calls 19 ssize_t lseek(int fd, off t_offset, int whence); // example: off_t pos = lseek(fd, 0, SEEK_CUR); File operations Example: POSIX System calls 20 int close(int fd); int unlink(const char *pathname); int fcntl(int fd, int cmd, ... /* args */ ); File operations Example: POSIX System calls 21 int stat(const char *filename, struct stat *buf); File attributes Typical metadata:  Creator, Owner, Owner Group, Protection, Password  Read-only flag, Write flag, Executable flag, Hidden flag, System flag, Archive flag, ASCII/binary flag, Random access flag, Temporary flag, Lock flags  Creation time, Time of last access, Time of last change  Record length, Key position, Key length  Current size, Maximum size 22 File attributes Example: UNIX file attributes 23 File attributes Example: UNIX file permissions 24 File attributes Example: UNIX file permissions 25 File implementation Example: java.io.File 26 boolean exists() boolean createNewFile() boolean renameTo(File dest) boolean delete() long length() long lastModified() boolean canRead() ) boolean canWrite() boolean canExecute() boolean setReadable(boolean readable, boolean ownerOnly) boolean setWritable(boolean writable, boolean ownerOnly) boolean setExecutable(boolean executable, boolean ownerOnly) . . . File(String pathname) File implementation Example: java.io.RandomAccessFile 27 void close() int read(byte[] b) int write(byte[] b) void seek(long pos) long getFilePointer() void setLength(long newLength) String readLine() double readDouble() . . . throw IOException, EOFException, SecurityException, . . . RandomAccessFile(String name, String mode) throws FileNotFoundException File implementation Example: java.io Streams and Readers/Writers 28 int read(byte[] buf) void close() FileInputStream(File file) FileOutputStream(File file) int write(byte[] buf) void close() FileReader(File file) FileWriter(File file) int read(char[] cbuf) void close() int write(char[] cbuf) void close() Other aspects  How files are stored  How storage space is managed  Performance  Reliability 29 Summary Files  Naming: human-readable identification  Attributes: permissions, ownership, dates, . . .  Access: open - read / write - close  Unified interface for access to a variety of devices  Examples: POSIX, Java 30 Read  Tanenbaum & Bos., Modern Operating Systems  Chapter 4  Silberschatz et al., Operating System Concepts  Chapters 10 & 11 31 Next Lecture  Introduction  Operating System Architectures  Processes  Threads - Programming  Process Scheduling - Evaluation  Process Synchronisation 32  Deadlocks  Memory Management  File Systems (continued)  Input / Output  Security and Virtualisation