Operating Systems COMP 4850CISG 5550 - PowerPoint PPT Presentation

1 / 39
About This Presentation
Title:

Operating Systems COMP 4850CISG 5550

Description:

Directories are system files for maintaining the structure of the file system ... Set attributes- sets the attributes in a similar fashion to get attributes. ... – PowerPoint PPT presentation

Number of Views:53
Avg rating:3.0/5.0
Slides: 40
Provided by: nccu
Category:

less

Transcript and Presenter's Notes

Title: Operating Systems COMP 4850CISG 5550


1
Operating SystemsCOMP 4850/CISG 5550
  • File Systems
  • Files
  • Dr. James Money

2
File Systems
  • We have three requirements for long term storage
    of data
  • We must be able to store a large amount of
    information
  • The information must survive the terminate of the
    process
  • Multiple processes should be able to access the
    data concurrently

3
File Systems
  • The solution involves storing the data on disks
    in units called files
  • The information in files must be persistent
    that is not affected by creation/destruction of
    processes
  • These files must be managed by the OS
  • The part of the OS that handles this is called
    the file system

4
Files
  • There are several important aspects to the file
    system
  • File Naming
  • File Structure
  • File Types
  • File Access
  • File Attributes
  • File Operations

5
File Naming
  • The naming of files is an abstraction of the data
    on the disk
  • We must shield the user from the details of this
    process
  • In order to do this, we usually refer to files by
    name rather than location or a number

6
File Naming
  • The exact rules vary from each file system
  • All current OSes allow string of one to eight
    characters
  • Many times digits are permitted as well
  • Some times even special characters are allowed
  • Many support names as long as 255 characters

7
File Naming
  • Examples
  • cathy
  • bruce
  • 2
  • urgent!
  • Fig.2-14
  • supercalifragilicious

8
File Naming
  • Some systems distinguish between upper and
    lowercase letters
  • UNIX, Linux
  • John, john, and JOHN are all different files
  • Others do not
  • DOS, Windows 1,2,3,95,98,XP,Vista
  • John, john, and JOHN are all the same file

9
File Naming
  • Many operating systems have two part files names
    separated by a period
  • File Name
  • File extension indicated usually the program
    that created the file and data it contains
  • UNIX does not differentiate this, but names can
    include a period
  • This also allows files such as file.tar.gz
    instead of just file.tar or file.gz or file.tgz

10
File Naming
11
File Structure
  • File can be structured many ways
  • Simple byte pattern
  • Set of records
  • Tree of data
  • However, the file system usually only sees the
    files as a group of bytes with no structure to it

12
File Structure
13
File Structure
  • By assuming just a byte sequence for files, this
    give flexibility
  • Now user programs can interpret the data in the
    file anyway they want
  • In the user wants to do unusual things, this
    prevents the OS from getting in the way

14
File Structure
  • The second choice is a record based approach
  • The records are fixed length with an internal
    structure
  • Historically used with punch card systems b/c
    they had 132 character records
  • No current system works this way

15
File Structure
  • The third type of file structure is a tree system
  • This is a tree of records, not all being the same
    length usually
  • There is a fixed length key field at a fixed
    position
  • The tree is sorted on this key field for rapid
    searching
  • You refer to a record by this key field

16
File Types
  • Most OSes have several types of files
  • Most of them support regular files and
    directories
  • Regular files contain user information
  • Directories are system files for maintaining the
    structure of the file system
  • Character special files are special I/O files for
    serial devices
  • Block special files are special I/O files for
    block devices

17
File Types
  • Regular Files can contain either ASCII or binary
    data
  • ASCII data just contains line of text, readable
    by humans
  • Lines are terminated by carriage returns or line
    feeds
  • DOS uses both (CR-LF)

18
File Types
  • ASCII file can edited with any basic text editor
  • It is easy to connect input and output of two
    programs this way
  • Interpretation of the data is easy in this format

19
File Types
  • The other type of regular files are binary files
  • The data usually is not human readable
  • They have an internal structure
  • This structure usually varies from file to file

20
File Types
executable
Archive file
21
File Access
  • Early OSes had only one type of access
    sequential access
  • In sequential access, you could only read the
    bytes in a file in order
  • There was no skipping around
  • You could rewind to the beginning of the file
  • This worked well with tapes

22
File Access
  • When disks become more popular for storage, there
    was a need for out of order reading of data in
    files
  • This is called random access files
  • This is required by most applications

23
File Access
  • There are two methods to specify where to read
  • Every read() call can specify a starting position
  • A special function called seek() can set the
    current position
  • Older systems used to make you define the type of
    file at creation

24
File Attributes
  • In addition to the name and data, every file has
    associated information with it
  • For example, the create and modification dates
    and its size
  • These are called file attributes

25
File Attributes
26
File Attributes
  • The first four are related to the file protection
    and who may access it
  • The flags are bit the control a particular
    property

27
File Attributes
  • The record length, key position, and key length
    are only used by files who have records
    referenced by keys
  • The times key track of creation, modification and
    access times
  • The current size tells how big the file is

28
File Operations
  • Recall that files exist to store information and
    retrieve it later
  • The calls among the different OSes vary
  • However, every OS provides functionality for all
    the operations

29
File Operations
  • Create The file is created with no data. This
    tells the OS that there is a file coming and to
    set its attributes
  • Delete removes the file from the file system.
    The file has to be deleted to free up disk space
  • Open Before the file can be read from/written
    to, you must open it. The open call may retrieve
    its attributes and disk locations

30
File Operations
  • Close - when access is done, the file should be
    closed. Sometimes this is forced by allowing a
    limited number of open files per process. This
    also forces the writing of the data to the disk
    if it has not already happened.
  • Read retrieve the data from the file. The bytes
    usually come from the current position, and the
    number of bytes is specified.

31
File Operations
  • Write Data is written to the file, at the
    current position. If we are at the end of the
    file, the file size increases. If we are in the
    middle of the file, the data there is
    overwritten.
  • Append This is a special form of write(). It
    adds data to the end of the file. This is the
    same as seek-ing to the end of file and calling
    write()

32
File Operations
  • Seek For random access files, repositions the
    current read/write position.
  • Get attributes retrieves the file attributes,
    for example the modification time. This is
    typically a struct of values.

33
File Operations
  • Set attributes- sets the attributes in a similar
    fashion to get attributes. Note that not all
    attributes are settable.
  • Rename- allows you to rename a file after it has
    been created. Not always needed since we can copy
    the file and delete the old one.

34
Example
  • We consider an example program that copies one
    file to another.
  • The program name is copyfile
  • Its syntax is
  • copyfile file1 file2
  • which copies file1 to file2

35
Example
  • If file2 exists, it is overwritten
  • If file2 does not exist, it will be created
  • file1 must exist
  • There are exactly two arguments

36
Example
37
Example
38
Memory Mapped Files
  • Many programmers feel that the prior way of
    working with files is cumbersome
  • There would prefer to use it similar to memory
    access
  • One way to do this is to map/unmap a file to a
    virtual address range
  • map() provides a file and a starting address
  • unmap() provides just the address usually

39
Memory Mapped Files
  • If a file of length 32KB is mapped to virtual
    memory at address 512K, then any instruction to
    read and write between 512K and 542K refers to
    the file.
  • 512K is the OK block, 513K is the 1K block of the
    file, and so on
Write a Comment
User Comments (0)
About PowerShow.com