File Organization Sheet - WordPress.com · File Organization Sheet 1. What is a File? ... Briefly...

13
1 | Page with our best wishes Dr. Ayman Elshenawy File Organization Sheet 1. What is a File? A collection of data is placed under permanent or non-volatile storage Examples: anything that you can store in a disk, hard drive, tape, optical media, and any other medium which doesn’t lose the information when the power is turned off. 2. Compare between Logical and physical files? Physical file: physically exists on secondary storage; known by the operating system; appears in its file directory Logical file, what your program actually uses, a ‘pipe’ though which information can be extracted, or sent. Type Physical File Logical File collection of bytes stored on a disk or tape A “Channel” (like a telephone line) that hides the details of the file’s location and physical format to the program 3. What is a Basic File System? A Basic File System (BFS) is the only software that interfaces directly with the peripheral devices attached to the system. The function of a basic file system is sometimes referred to as physical I/O. This is because it deals with the physical reading and writing of blocks of data on the peripheral devices. However, the BFS does not understand the content and meaning of the data being transferred. 4. Why Users and Computers Have a need for Basic File System? Users and computer systems need a BFS for the following reasons: To provide a common interface to perform block I/O.

Transcript of File Organization Sheet - WordPress.com · File Organization Sheet 1. What is a File? ... Briefly...

1 | P a g e w i t h o u r b e s t w i s h e s D r . A y m a n E l s h e n a w y

File Organization Sheet

1. What is a File?

A collection of data is placed under permanent or non-volatile storage

Examples: anything that you can store in a disk, hard drive, tape, optical

media, and any other medium which doesn’t lose the information when the

power is turned off.

2. Compare between Logical and physical files?

Physical file: physically exists on secondary storage; known by the

operating system; appears in its file directory

Logical file, what your program actually uses, a ‘pipe’ though which

information can be extracted, or sent.

Type Physical File Logical File

collection of

bytes stored on a disk or tape

A “Channel” (like a telephone line) that hides the details of the file’s

location and physical format to the program

3. What is a Basic File System?

A Basic File System (BFS) is the only software that interfaces directly with the

peripheral devices attached to the system. The function of a basic file system

is sometimes referred to as physical I/O. This is because it deals with the

physical reading and writing of blocks of data on the peripheral devices.

However, the BFS does not understand the content and meaning of the data

being transferred.

4. Why Users and Computers Have a need for Basic File System?

Users and computer systems need a BFS for the following reasons:

To provide a common interface to perform block I/O.

2 | P a g e w i t h o u r b e s t w i s h e s D r . A y m a n E l s h e n a w y

To provide a centralized control program to ensure that the devices

connected to the system are being allocated and scheduled properly.

To provide a central resource to ensure data integrity by providing error

recovery and exception handling for all users.

5. What are the Sources of File System inputs?

The data the BFS needs to perform its work must come from one of the

following sources:

• User Programs

• Command Language Files

• Job Control Languages (JCL), utilized at the user’s site a stand-alone utility

program that interactively request the data from the user. Such a program

can prompt the user for each of the required parameters, check inputs for

validity, and then store the information within the file itself.

3 | P a g e w i t h o u r b e s t w i s h e s D r . A y m a n E l s h e n a w y

6. What are the basic Functions of the Basic File System?

• The allocation of all space on the devices

• The centralization of all I/O through the BFS

• The control of the devices themselves, which usually requires a rather

detailed knowledge of device-specific details.

• The processing of all the I/O terminations to ensure that the correct

processing is performed. Also, it must then initiate the next I/O request

targeted for that device.

4 | P a g e w i t h o u r b e s t w i s h e s D r . A y m a n E l s h e n a w y

• Finally, upon completion of the user’s I/O request, the BFS must notify the

user as to whether the I/O request completed correctly. This is done by

returning a status field, which indicates how the I/O request terminated.

7. Briefly describe the fundamental file processing operations (write code

examples)?

Opening Files

code in C and C++ -> fd = open(filename, flags [, pmode]);

That makes the file ready to use by the program.

Closing Files

Files are usually closed automatically by the operating system (unless the

program is abnormally interrupted).

it Makes the logical file name available for another physical file.

Reading

Code -> Read(Source_file, Destination_addr, Size);

it reads data from the file which we define in “source_file” parameter which

located in the “Destination_addr” and we also specify the “Size”.

Write

Code-> Write(Destination_file, Source_addr, Size);

this function writes into the file which we specify it at the parameters.

Seeking

Code-> Seek(Source_file, Offset);

it’s The action of moving directly to a certain position in a file.

5 | P a g e w i t h o u r b e s t w i s h e s D r . A y m a n E l s h e n a w y

Create file operation

Required Data

The following data are needed to create a file:

Device/user name: tells where to place the file when it is

created.

Filename identifies the file among all the other files in the

computer system.

File size tell how much room to allocate when it is creating the

file

File organization needed so that the file system, or more

specifically the access methods, can know how to insert and

later retrieve the blocks within the file

Block size amount of data that will be read or written in every

I/O operation.

Tasks performed by the file system to create a file?

Validate the User’s Input Data

Check to see if the file already exists

Allocate space on the medium for the file:

The BFS can tell if enough space exists by comparing the

projected file size, from the vantage point of the user, against

the device allocation table on the target device. If there is not

enough space on the medium, the BFS has no choice but to

abort its processing.

Insert a pointer to the first block allocated to the file

Allocate and initialize I/O buffers and control blocks

First, it must allocate space in memory large enough of READ

in the largest block in the file. The blocks of memory, which

are dedicated to the transferring of the data from memory to

and from the peripheral devices, are called I/O buffers.

6 | P a g e w i t h o u r b e s t w i s h e s D r . A y m a n E l s h e n a w y

Next, the BFS must allocate and build a table, also known as

a file control block, in which the critical information about

the file will be saved.

Return success or fail status back to the user.

Errors:

Another file with the same name already exists.

The device has no available space to create another new file.

The device is, or has become, nonoperational.

There was a hardware problem which aborted the processing

One or more of the input parameters given to the BFS were

wrong.

Open File Operation

Required Data

Device name

User name, or account identification

Filename

The tasks for processing an OPEN file command are:

Allocate space for Internal Control Blocks (ICB)

Get the correct volumes mounted on the devices

Locate the file on the devices

Allocate internal memory space for I/O buffers

Protect against unauthorized users

Maintain a list of the entire open file in the system.

Errors:

File not found on the specified device and in the specified user

account or directory. This could be because of an incorrectly

specified filename or device identifier.

File already in use by some other user application.

Hardware error has occurred from which the BFS could not

recover.

7 | P a g e w i t h o u r b e s t w i s h e s D r . A y m a n E l s h e n a w y

Extend File Operation

The purpose of the EXTEND file function is to allow the user(s) to explicitly

increase the size of a file.

Required Data

Device and directory name where the file is located

Name of the file

Amount by which the file should be increased in size.

The Tasks must be done as follows:

Validate the parameters in this request

Check to see if there is enough room on this device to increase

the size of the file by the requested amount.

If space exists, take the space from the medium’s general space

pool, and mark it in such a way that no other user can take this

space.

Add the space to the file in question, and to the internal

information kept on the file, so that can be correctly processed

at a later date.

Return a success or failure status code to the user.

Errors:

Device has no space available in which to extend the file

File was not previously Opened, indicating that the user has

inadvertently gotten the sequence of I/O processing out of

order.

Close File Operation

The purpose of a CLOSE file function is to allow the user to decrease, stop using

the file,

Required Data

The name of the file to be closed.

An indication of which currently open file is to be closed.

The Tasks must be done as follows:

8 | P a g e w i t h o u r b e s t w i s h e s D r . A y m a n E l s h e n a w y

Write out any I/O buffers that have been modified and are still

in main memory but which have not yet been written out to the

specified device

Write out any updated information about the file that would be

useful or required to know in the future in order to process the

file correctly.

Release any internal memory space dedicated to the processing

of that particular file.

Return status to the user, indicating success or failure.

Errors:

The file to be closed was not currently open

Any of the errors that can occur on a WRITE operation could

occur, since we are writing blocks back into the file

A hardware problem could occur that could abort the CLOSE

processing.

Delete File Operation

The function of the DELETE file request is to erase or get rid of a specific file from

the system. This occurs when the user no longer needs a particular file and wishes

to reuse the file space from some other purpose.

Required Data

Device and user account name

File name

The Tasks must be done as follows:

Validate the user’s input parameters

Return all the space on the media taken up by the file to the

space pool on the media

Remove the file name from the directory where it resides.

Return status to the user.

Errors:

File could not be found, either because of an invalid file or user

account name.

9 | P a g e w i t h o u r b e s t w i s h e s D r . A y m a n E l s h e n a w y

Other users were currently active on the file

A hardware problem was detected.

Block Operation

A block of data is the unit of data that is transferred to, or from, a device.

The amount of data (i.e., size of the block) is definable by the user. The larger the

block, the more data that will be transferred in that I/O operation and the greater

the performance of the program.

This is true but must be taken from the perspective that the memory resources

required to hold these blocks of data is not unlimited and should be considered

to be a scarce commodity.

Write Operation

Provide users with the capability of transferring data out of the computer’s main

memory and onto one of the devices connected to the system.

Required Data

Number of the block to be written

Address of the I/O buffer in many memory that contains the

block to be written

Size or amount of the block to be written

Name of the status field into which the file system will insert

the termination status of the I/O request.

The Tasks must be done as follows:

The WRITE routine must perform the following tasks as part of

the job of processing the request:

Validate the input parameters

Convert the logical block number to a physical device address

Check if space exists in the file for this block

If space exists, execute the WRITE I/O operation to the device.

Reset the buffer-modified flag for that specific I/O buffer, since

that block has now been written out to the device.

10 | P a g e w i t h o u r b e s t w i s h e s D r . A y m a n E l s h e n a w y

If space does not exist in the file, extend the file. This is called

an implicit extend to the

Errors:

No space available for the operation to complete

Hardware unrecoverable error has occurred

Mismatch from READ after WRITE validation sequence.

Read Operation

The function of the READ routine is to transfer a specific block of data from the

medium into main memory. The unit of data transfer is the block.

Required Data

Number of the block to be read into memory

Address of the I/O block buffer in main memory into which the

block will be read

Size or amount of data to be read into main memory

The address of a field into which the file system can store the

status of the I/O request

The Tasks must be done as follows:

Validate input parameters

Convert the logical block number to a physical block

Read the block into an I/O buffer in main memory

Return status to the user program

Errors:

Read error detected by the device

Invalid device block number requested

Hardware failure detected

11 | P a g e w i t h o u r b e s t w i s h e s D r . A y m a n E l s h e n a w y

8. Write a code for opening a file and reading form all data from the file

and then print all file content on the screen, then close the file?

9. Write a code for calculating the size of a specific file?

10. How can the files are treated?

A file can be treated as

o a stream of bytes (as we have seen before)

o a collection of records with fields

12 | P a g e w i t h o u r b e s t w i s h e s D r . A y m a n E l s h e n a w y

11. What is meant by field, record, key, give an example?

Field: a data value, smallest unit of data with logical meaning

Record: A group of fields that forms a logical unit

Key: a subset of the fields in a record used to uniquely identify the record

Primary Key: A key that uniquely identifies a record.

Secondary Key: Other keys that may be used for search

12. What are the common methods for organizing fields in files?

13 | P a g e w i t h o u r b e s t w i s h e s D r . A y m a n E l s h e n a w y

13. What are the advantage and disadvantages of the different methods

that used in field structure?