代写 Java operating system security Operating Systems Lecture 8b

Operating Systems Lecture 8b
Dr Ronald Grau School of Engineering and Informatics Spring term 2018

Previously 1 Memory management
 Virtual memory
 Addressing and address spaces  Partitioning and segmentation  Paging & Page replacement

Recap: Questions 2 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?

Today 3 Files
 Persistent storage
 Formats, access, operations  Attributes & permissions
 Implementation

File abstraction 4 Files
 Persistent storage of data  Named
 Byte-wise access
 Accessprotection
 Consistency guarantees Operating system duties:
 Manage efficient access (e.g. caching)
 Protect storage device from being damaged/corrupted
 Provideuniforminterfaceforheterogeneousdevices

File abstraction 5 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:agroupofcharacters
 Record:agroupoffields
 File: a group of related records
 Volume:aunitofdatastorageholdingmultiplefiles
 File system: the way the OS organises files and manages access

File names 6
 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

File types 7
 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

File formats 8 Define how the data is organised within a file
 Fixed-length records
 Variable-length records  Indexed records
 Trees: XML, JSON

File formats 9 Example: ZIP format

File formats 10 Example: ZIP format

File formats 11 Example: GIF format

File formats 12 Example: GIF format

File access 13

File access 14 Sequential access:
Random access:

File operations 15 Typical operations:
 Create, Delete, Rename
 Open, Close
 Read, Write, Append, Truncate  Seek
 Get Attributes, Set Attributes
 Lock, Unlock

File operations 16 Example: POSIX System calls
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 17 Example: POSIX System calls 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 18 Example: POSIX System calls 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 19 Example: POSIX System calls ssize_t lseek(int fd, off t_offset, int whence); // example: off_t pos = lseek(fd, 0, SEEK_CUR); File operations 20 Example: POSIX System calls int close(int fd); int unlink(const char *pathname); int fcntl(int fd, int cmd, ... /* args */ ); File operations 21 Example: POSIX System calls int stat(const char *filename, struct stat *buf); File attributes 22 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 File attributes 23 Example: UNIX file attributes File attributes 24 Example: UNIX file permissions File attributes 25 Example: UNIX file permissions File implementation 26 Example: java.io.File File(String pathname) 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 implementation 27 Example: java.io.RandomAccessFile RandomAccessFile(String name, String mode) throws FileNotFoundException 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, .. . File implementation 28 Example: java.io Streams and Readers/Writers FileInputStream(File file) FileOutputStream(File file) FileReader(File file) FileWriter(File file) int read(byte[] buf) void close() int write(byte[] buf) void close() int read(char[] cbuf) void close() int write(char[] cbuf) void close() Other aspects 29  How files are stored  How storage space is managed  Performance  Reliability Summary 30 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 Read 31  Tanenbaum & Bos., Modern Operating Systems  Chapter 4  Silberschatz et al., Operating System Concepts  Chapters 10 & 11 Next Lecture 32  Introduction  Operating System Architectures  Processes  Threads - Programming  Process Scheduling - Evaluation  Process Synchronisation  Deadlocks  Memory Management  File Systems (continued)  Input / Output  Security and Virtualisation