08 file mgmt - university of malayaweb.fsktm.um.edu.my/~mazliza/kuliah/os/08-file-mgmt.pdf · •if...

32
24/4/2019 1 FILE MANAGEMENT WIA2004 (8) 1 INTRODUCTION The File Mgr controls every file in the system. Its efficiency depends on: how the file system is organised, how they are stored, how each file’s records are structured, and how access to files is controlled. WIA2004 (8) 2

Upload: others

Post on 13-Jan-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

1

FILE MANAGEMENTWIA2004 (8)

1

INTRODUCTION

• The File Mgr controls every file in the system.

• Its efficiency depends on:• how the file system is organised,• how they are stored,• how each file’s records are structured,

and• how access to files is controlled.

WIA2004 (8) 2

Page 2: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

2

THE FILE MANAGER

• The File Mgr is responsible for creating, deleting, modifying and controlling access to files.

• Also manages resources used by files.• Provides support for libraries of programs

and data (collaborate with Device Mgr).

WIA2004 (8) 3

THE FILE MANAGER

• Performs 4 tasks:• Keep track of where each file is stored.• Use a policy that determines where and

how files are stored, makes efficient use of available storage space and provide efficient access to files.

• Allocate each file when a user has been granted access to it and record its use.

• Deallocate the file when the file is to be returned to storage and communicate its availability to others waiting.

WIA2004 (8) 4

Page 3: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

3

THE FILE MANAGER

• The File Mgr keeps track of its files with directories that contain the filename, its physical location in secondary storage and other related info about the files.

• Uses a policy to determine who has access to a material.

• The OS protects files against system malfunctions and provides security checks.

WIA2004 (8) 5

THE FILE MANAGER

• A file is allocated by activating the relevant secondary storage device, loading the file into memory and updating the record about who is using it.

• A file is deallocated by updating the file tables and rewriting the file (if updated) to the secondary storage.

WIA2004 (8) 6

Page 4: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

4

THE FILE MANAGER

• File management in the cloud.• Files stored on the cloud are managed

using concepts similar to managing files stored locally.

• The local device’s OS cooperates with the remote OS to perform the same services to retrieve/store files.

WIA2004 (8) 7

THE FILE MANAGER

• Field: a group of related bytes that can be identified by the user with a name, type and size.

• File: a group of related records that contains info to be used by specific application programs to generate reports.

• Database: a group of related files that are connected at various levels to offer flexible access to the data stored in it.

WIA2004 (8) 8

Page 5: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

5

THE FILE MANAGER

• Program files: contains instructions.• Data files: contains data.• Directory (folder): a special file that

contains listings of filenames and their attributes.

WIA2004 (8) 9

INTERACTING WITH THE FILE MGR

• File Mgr responds to specific commands to perform the required actions, e.g., OPEN, DELETE, RENAME, COPY.

• It also extrapolates other system-specific actions from the instructions it received.

• A user gives a command to save a new file – this isn’t an explicit command to create a new file. Therefore, it is interpreted as a CREATE command.

WIA2004 (8) 10

Page 6: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

6

INTERACTING WITH THE FILE MGR

• How is a new file created?• OS-dependent.• If the File Mgr is required to provide

detailed instruction (how to start it, how to move it to the correct place etc), the program is device dependent.

• If the info is readily available (usually in a device driver), the program is device independent.

WIA2004 (8) 11

INTERACTING WITH THE FILE MGR

• In order to access a file, a user needn’t know its physical location on the disk or the network specifics.

• Each logical command is broken down into a sequence of signals that trigger the step-by-step actions performed and the device.

WIA2004 (8) 12

Page 7: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

7

INTERACTING WITH THE FILE MGR

• E.g.,. a READ command consists of:• Move the read/write head to the

cylinder where the record is located.• Wait for the rotational delay until the

sector passes under the read/write head.

• Activate the appropriate read/write head and read the record.

• Transfer the record to main memory.• Send a flag to indicate the device is free

to satisfy another request.

WIA2004 (8) 13

INTERACTING WITH THE FILE MGR:VOLUME CONFIGURATION

• A secondary storage unit is considered a volume.

• Each volume can contain several files (multi-file volumes).

• Some files are extremely large and are contained in several volumes (multi-volume files).

• Each volume is given a name, which along with other descriptive info, is written on an easy-to-access place.

WIA2004 (8) 14

Page 8: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

8

INTERACTING WITH THE FILE MGR:VOLUME CONFIGURATION

WIA2004 (8) 15

INTERACTING WITH THE FILE MGR:VOLUME CONFIGURATION

• The master file directory (MFD) is stored immediately after the volume descriptor.

• Lists the names and characteristics of every file contained in the volume.

• File names may refer to program files, data files, system files.

• Also lists subdirectories.

WIA2004 (8) 16

Page 9: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

9

INTERACTING WITH THE FILE MGR:SUBDIRECTORIES

• File Mgr creates an MFD for each volume that contains entries for files and subdirectories.

• A subdirectory is created when a user open an account to access the computer system.

• Its MFD is flagged to indicate that it is a subdirectory.

• Its records are filenames pointing to files.

WIA2004 (8) 17

INTERACTING WITH THE FILE MGR:SUBDIRECTORIES

• File Mgr allows users to create their own subdirectories (folders).

• Implemented as an upside-down tree.• Allows the system to search individual

directories efficiently.• The path to the requested file may lead

through several directories.• MFD is the point of entry for each file

request.

WIA2004 (8) 18

Page 10: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

10

WIA2004 (8) 19

INTERACTING WITH THE FILE MGR:SUBDIRECTORIES

• Each file entry has a file descriptor:• Filename• File type• File size• File location• Date and time of creation• Owner• Protection info• Record size

WIA2004 (8) 20

Page 11: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

11

INTERACTING WITH THE FILE MGR:FILE NAMING CONVENTIONS

• 2 components of a filename: • A relative filename differentiates it from

other files in the same directory.• An extension is 2-4 characters long and is

separated from the relative name by a period, e.g. , dll, .doc, .xls, .htm.

WIA2004 (8) 21

FILE ORGANISATION

• File organisation is concerned with the arrangement of records within a file.

• When a user modifies the content of a file, he is actually accessing the records within a file.

WIA2004 (8) 22

Page 12: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

12

FILE ORGANISATION: RECORD FORMAT

• A file is composed of records.• Within a file, records have the same

format.• May be of fixed or variable length.• May be blocked or not blocked.

• Fixed-length records are the easiest to access directly.

• Critical factor is the record size.

WIA2004 (8) 23

FILE ORGANISATION: RECORD FORMAT

WIA2004 (8) 24

Page 13: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

13

FILE ORGANISATION: RECORD FORMAT

• Variable-length records don’t leave empty storage space and don’t truncate any characters.

• Disadvantage: difficult to access directly because it is hard to calculate exactly where the record is located.

• Mostly used in files that are likely to be accessed sequentially.

• The record format, how it’s blocked and other info are kept in the file descriptor.

WIA2004 (8) 25

FILE ORGANISATION: PHYSICAL FILE ORGANISATION

• Physical organisation is concerned with:• how records are arranged, and • characteristics of the medium used to

store it.• On magnetic disks, files are organised as

either sequential, direct, or indexed sequential.

WIA2004 (8) 26

Page 14: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

14

FILE ORGANISATION: PHYSICAL FILE ORGANISATION

• Factors to consider to choose the best file organisation:

• Volatility of data,• Activity of the file,• Size of file,• Response time.

WIA2004 (8) 27

FILE ORGANISATION: PHYSICAL FILE ORGANISATION

• Sequential record organisation is the easiest to implement.

• Optimisation feature: select a key field from the record and sort records by the key.

• Drawback: complicates the maintenance algorithm because the original order must be preserved each time a record is added or deleted.

WIA2004 (8) 28

Page 15: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

15

FILE ORGANISATION: PHYSICAL FILE ORGANISATION

• Direct record organisation uses direct access files and can only be implemented on DASDs.

• Flexibility of accessing a record in any order without having to search from the beginning of the file.

• Also known as random organisation; files are called random access files.

WIA2004 (8) 29

FILE ORGANISATION: PHYSICAL FILE ORGANISATION

• A record is identified by its relative address.• An address relative to the beginning of a

file.• Is a logical address that is calculated

when the record is stored/retrieved.• How is the logical address calculated?

• A record has a unique key field.• A hashing algorithm is used to transform

the key into a number that is used as the record’s logical address.

WIA2004 (8) 30

Page 16: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

16

FILE ORGANISATION: PHYSICAL FILE ORGANISATION

WIA2004 (8) 31

FILE ORGANISATION: PHYSICAL FILE ORGANISATION

• Indexed sequential record organisation combines sequential and direct access.

• Is maintained through an Indexed Sequential Method (ISAM) software.

• Does not use a hashing algorithm.• Generates an index file that is used to

retrieve records.• An ordered sequential file is divided into

blocks of equal size.WIA2004 (8) 32

Page 17: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

17

FILE ORGANISATION: PHYSICAL FILE ORGANISATION

• To access a record in a file:• System searches the index file (acts as a

pointer to the data file).• Go to the physical location indicated at

that entry.

WIA2004 (8) 33

PHYSICAL STORAGE ORGANISATION

• The File Mgr works with files as whole units. Also as logical units / records.

• Records within a file must have the same format but may vary in length.

• Records are sub-divided into fields –structure is managed by application programs.

• File Mgr cooperates with Device Mgr to store/retrieve records.

WIA2004 (8) 34

Page 18: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

18

PHYSICAL STORAGE ORGANISATION

WIA2004 (8) 35

PHYSICAL STORAGE ORGANISATION: CONTIGUOUS STORAGE

• Contiguous storage means records are stored one after another.

• Simple to implement and manage.• A record can be found and read once its

starting address and size are known. Ease of direct access.

• Disadvantages: • A file cannot be expanded unless there is

empty space available immediately following it.

• Fragmentation.

WIA2004 (8) 36

Page 19: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

19

PHYSICAL STORAGE ORGANISATION: CONTIGUOUS STORAGE

WIA2004 (8) 37

PHYSICAL STORAGE ORGANISATION: NON-CONTIGUOUS STORAGE

• Non-contiguous storage allows files to use any storage space available on the disk.

• Records are stored contiguously only if there is enough empty space.

• Remaining records are stored in other sections of the disk.

• An extent refers to any remaining records stored in other sections.

WIA2004 (8) 38

Page 20: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

20

PHYSICAL STORAGE ORGANISATION: NON-CONTIGUOUS STORAGE

WIA2004 (8) 39

WIA2004 (8) 40

Page 21: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

21

PHYSICAL STORAGE ORGANISATION: INDEXED STORAGE

• Indexed storage allows direct record access by combining an index block with pointers that link every extent of that file.

• Each file has its own index block consisting of the addresses of each disk sector that make up the file.

• The index lists each entry in the same order the sectors are linked.

WIA2004 (8) 41

WIA2004 (8) 42

Page 22: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

22

ACCESS METHODS

• Access methods are determined by file organisation.

• 2 types of access methods:• Sequential access,• Direct access.

• The current byte address (CBA) is the last byte read.

• Is used by the File Mgr to access records.• Must be updated each time a record is

accessed.

WIA2004 (8) 43

ACCESS METHODS

WIA2004 (8) 44

Page 23: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

23

ACCESS METHODS: SEQUENTIAL ACCESS

• For fixed-length records, the CBA is updated by incrementing it by the record length (RL).

CBA = CBA + RL• For variable-length records, CBA is

updated by adding RL and the number of bytes used to hold the record length (N).

CBA = CBA + N + RL

WIA2004 (8) 45

ACCESS METHODS: DIRECT ACCESS

• For fixed-length records, the CBA is computed directly from the record length and the desired record number (RN).

CBA = (RN - 1) * RL• For variable-length records, the File Mgr

has to do a sequential search through the records.

• Cannot access a record directly because the address is difficult to compute.

WIA2004 (8) 46

Page 24: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

24

ACCESS METHODS: DIRECT ACCESS

• To access a record, the File Mgrsearches sequentially through the records (half-sequential read through the file).

• The File Mgr could save the address of the last record accessed and when the next request arrives, it searches forward from the CBA if the address is between the CBA and the end of file.

• Otherwise, search starts from the beginning of the file.

WIA2004 (8) 47

ACCESS METHODS: DIRECT ACCESS

• Alternative: File Mgr keeps a table of record numbers and their CBAs. To fill a request, this table is searched for the exact location of record.

WIA2004 (8) 48

Page 25: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

25

ACCESS METHODS: DIRECT ACCESS

• Indexed sequential files can be accessed sequentially or directly.

• Either approach to calculate CBA can be used.

• Extra step: the index file must be searched for the pointer to the block where data is stored.

• Index file is small and is kept in main memory.

WIA2004 (8) 49

LEVELS IN A FILE MGMT SYSTEM

• The higher positioned module passes info to the lower modules so that they can perform the required service and continue the communication down the chain to the lowest module.

• The highest-level module is the Basic File System.

WIA2004 (8) 50

Page 26: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

26

LEVELS IN A FILE MGMT SYSTEM

WIA2004 (8) 51

LEVELS IN A FILE MGMT SYSTEM

• Each module is further divided into more specific tasks.

• Example:READ RECORD NUMBER 7 FROM FILE CLASSES INTO STUDENT

• CLASSES is the name of a direct access file opened for input.

• STUDENT is the record previously defined within the program.

WIA2004 (8) 52

Page 27: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

27

LEVELS IN A FILE MGMT SYSTEM

• The info is used by the basic file system to activate the access control verification module.

• If the user is allowed access, info and control are passed to the logical file system.

• Otherwise, an “access denied” message is sent to the user.

• The logical file system uses the record number to obtain CBA.

CBA = (RN - 1) * RLWIA2004 (8) 53

LEVELS IN A FILE MGMT SYSTEM

• The result of the computation plus other info is passed to the physical file system.

• It computes the physical location (block number) where the record is stored.

• The info is passed to the device interface module.

• The device interface module transforms the block number to the actual cylinder/ surface/record combination to retrieve info from the disk.

WIA2004 (8) 54

Page 28: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

28

LEVELS IN A FILE MGMT SYSTEM

• Once the info is retrieved, control returns to the physical file system, which copies the info into the desired memory location.

• When the operation is complete, an “all clear” message is passed to all other modules.

WIA2004 (8) 55

ACCESS VERIFICATION MODULE

• Modern OS supports file sharing.• One of the concerns that arises from file

sharing is safeguarding the integrity of each file.

• Need control over who is allowed to access a file.

• What type of access is permitted.• 5 actions on a file: READ, WRITE,

EXECUTE, DELETE, or any combination of the four.

WIA2004 (8) 56

Page 29: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

29

ACCESS VERIFICATION MODULE

WIA2004 (8) 57

Access Control Matrix

ACCESS VERIFICATION MODULE

Access R W E D Resulting Code

R-E- - - 1010RWED 1111

---- - - - - 0000

WIA2004 (8) 58

Access Codes

Page 30: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

30

ACCESS VERIFICATION MODULE

File Access File 1 User1 (RWED), User2 (R-E-), User4 (RWE-), User5 (-

-E-), World (----)File 2 User2 (R-E-), User3 (R-E-), User4 (--E-), World (----)File 3 User1 (R-E-), User4 (--E-), World (----)File 4 User1 (R-E-), User5 (RWED), World (R---)File 5 User1 (RWED), World (----)

WIA2004 (8) 59

Access Control Lists

ACCESS VERIFICATION MODULE

WIA2004 (8) 60

Capability Lists

Page 31: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

31

DATA COMPRESSION

• 2 types:• Lossless algorithm.• Lossy algorithm

• 3 methods.

WIA2004 (8) 61

DATA COMPRESSION

• Records with repeated characters can be abbreviated.

• Data in a fixed-length field may contain many blank character, e.g. ADAMbbbbbb is encoded as ADAMb6.

• Numbers with trailing zeros can be shortened, e.g. 3000000 is encoded as 3#6.

WIA2004 (8) 62

Page 32: 08 File Mgmt - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/08-file-mgmt.pdf · •If the info is readily available (usually in a device driver), the program is device

24/4/2019

32

DATA COMPRESSION

• Repeated terms can be compressed by using symbols to represent most commonly used words in the database.

• Common words in a university database, such as course, student, grade etc., can be represented using a single character.

• Front end compression is used in DB mgmt systems for index compression.

WIA2004 (8) 63

DATA COMPRESSION

WIA2004 (8) 64