0% found this document useful (0 votes)
34 views8 pages

DoQuangHuy HE191197

Long-term information storage is essential because processes have limited memory capacity, information is lost upon termination, and multiple processes often need simultaneous access to data. Files are logical units of information stored on disks, which can be organized in various structures such as byte sequences, record sequences, and trees. File operations include creating, deleting, opening, closing, reading, writing, and linking files, with different types of links (hard and symbolic) allowing for flexible file management.

Uploaded by

dohuy2915
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views8 pages

DoQuangHuy HE191197

Long-term information storage is essential because processes have limited memory capacity, information is lost upon termination, and multiple processes often need simultaneous access to data. Files are logical units of information stored on disks, which can be organized in various structures such as byte sequences, record sequences, and trees. File operations include creating, deleting, opening, closing, reading, writing, and linking files, with different types of links (hard and symbolic) allowing for flexible file management.

Uploaded by

dohuy2915
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Q1:

Why do we need long-term information storage?

-First reason: While a process is running, it can store a limited amount of information
within its own address space. However, the storage capacity is restricted to the size of the
virtual address space.

-Second reason:When the process terminates, the information is lost.

-Third reason:It is frequently necessary for multiple processes to access (parts of) the
information at the same time. If we have an online telephone directory stored inside the
address space of a single process, only that process can access it.

Q2:

A disk as a linear sequence of fixed-size blocks and supporting two operations:

1. Read block k.

2. Write block k

Q3:

Files are logical units of information created by processes. A disk will usually contain
thousands or even millions of them, each one independent of the others.

Q4:

Many operating systems support two-part file names, with the two parts separated by a
period, as in prog.c. The part following the period is called the file extension and usually
indicates something about the file.

-Example:+ In UNIX, the size of the extension, if any, is up to the user, and a file may even
have two or more extensions, as in homepage.html.zip, where .html indicates a Web page
in HTML and .zip indicates that the file has been compressed using the zip program.

+In C program,if you want to save the file,you need have the extensions called .c,where .c
indicates the C source program.

Q5:

Three common structures of file:

1.Byte sequence: The file in byte sequence is an unstructured sequence of bytes. In effect,
the operating system does not know or care what is in the file. All it sees are bytes.
-Advantage :

+Provides the maximum amount of flexibility.

+ User programs can put anything they want in their files and name them any way that they
find convenient.

-Disadvantage:

+ The operating system does not help.

+ Byte sequences are not human-readable, making debugging and manual inspection
difficult.

2.Record sequence:A file is a sequence of fixed-length records, each with some internal
structure. Central to the idea of a file being a sequence of records is the idea that the read
operation re turns one record and the write operation overwrites or appends one record.

-Advantage:

+ The fixed length of 80-character and 132-character records created a consistent


structure, making it easy for programs to process input and output without the complexity
of variable-length records.

+ Batch processing of data was highly efficient because each file could be processed in
uniform blocks of 80 or 132 characters, making it ideal for tasks like sorting, compiling, and
report generation on mainframes.

-Disadvantage:+ The rigid structure of fixed-length records often led to wasted space. For
instance, if a record didn’t fully utilize the 80 or 132 characters, the remaining characters
would typically be padded with spaces, leading to inefficient use of storage.

+ The fixed-length format imposed constraints on how data could be structured. Any input
exceeding 80 or 132 characters had to be split across multiple records, which could
complicate data management and reduce overall flexibility in file design.

3.Tree:In this organization, a file consists of a tree of records, not necessarily all the same
length, each containing a key field in a fixed position in the record. The tree is sorted on the
key field, to allow rapid searching for a particular key.

-Advantage:

+ Key-based access allows users to retrieve a record based on its key without needing to
know the record’s exact position.
+New records can be added to the tree without requiring the user to manage their physical
placement.

-Disadvantage:

+ Implementing and maintaining tree structures is more complex than simpler file
structures, such as unstructured byte streams (e.g., used in UNIX and Windows).

+ It is used on some large mainframe computers for commercial data processing.

Q6:

-Header: Contains metadata or file attributes like sizes, entry point, and flags and magic
number.

-Text Segment: Contains the compiled code.

-Data Segment: Holds initialized variables.

-Relocation Bits: Helps in adjusting memory addresses if needed.

-Symbol Table: Contains information used during linking and debugging.

Q7:

The another name of file attributes is:Metadata

-Example:

+Password: Password needed to access the file

+Creator: ID of the person who created the file

+ Read-only flag: 0 for read/write; 1 for read only

+ Hidden flag: 0 for normal; 1 for do not display in listings

Q8:

1. Create. The file is created with no data. The purpose of the call is to announce that the
file is coming and to set some of the attributes.

2. Delete. When the file is no longer needed, it has to be deleted to free up disk space.
There is always a system call for this purpose.

3. Open. Before using a file, a process must open it. The purpose of the open call is to allow
the system to fetch the attributes and list of disk addresses into main memory for rapid
access on later calls.
4. Close. When all the accesses are finished, the attributes and disk ad dresses are no
longer needed, so the file should be closed to free up internal table space.

5. Read. Data are read from file. Usually, the bytes come from the current position. The
caller must specify how many data are needed and must also provide a buffer to put them
in.

6. Write. Data are written to the file again, usually at the current position. If the current
position is the end of the file, the file’s size increases. If the current position is in the middle
of the file, existing data are overwritten and lost forever

7. Append. This call is a restricted form of write. It can add data only to the end of the file.

8. Seek. For random-access files, a method is needed to specify from where to take the
data.

9.Get attributes: Processes often need to read file attributes to do their work.

10.Set attributes: Some of the attributes are user settable and can be changed after the file
has been created.

11.Rename: It frequently happens that a user needs to change the name of an existing file.

Q9:

Feature Ordinary files Directory


Purpose Store data (text, binary, Organize and store file
etc.) references
Content Actual data Metadata about files and
subdirectories
Structure Stream of data Hierarchical collection of
files
Access Read/write data List/navigate contents
Q10:

- An absolute path name consisting of the path from the root directory to the file. As an
example, the path /usr/ast/mailbox means that the root directory contains a subdirectory
usr, which in turn contains a subdirectory ast, which contains the file mailbox. Absolute
path names always start at the root directory and are unique.

-The other kind of name is the relative path name. This is used in conjunction with the
concept of the working directory(current directory). A user can designate one directory as
the current working directory, in which case all path names not beginning at the root
directory are taken relative to the working directory. For example, if the current working
directory is /usr/ast, then the file whose absolute path is /usr/ast/mailbox can be
referenced simply as mailbox.

Q11:

In figure 4.9:

-The first one is the superblock. It contains all the key parameters about the file system
and is read into memory when the computer is booted or the file system is first touched.
Typical information in the superblock includes a magic number to identify the file-system
type, the number of blocks in the file system, and other key administrative information.
Next might come information about free blocks in the file system, for example in the form
of a bitmap or a list of pointers. This might be followed by the i-nodes, an array of data
structures, one per file, telling all about the file. After that might come the root directory,
which contains the top of the file-system tree. Finally, the remainder of the disk contains
all the other directories and files.

Q12:

-Advantages:

+ First, it is simple to implement because keeping track of where a file’s blocks are is
reduced to remembering two numbers: the disk address of the first block and the number
of blocks in the file.

+ Second, the read performance is excellent because the entire file can be read from the
disk in a single operation.

-Disadvantages:

+ Over the course of time, the disk becomes fragmented.

+ Inflexibility in File Size: To allocate a file contiguously, the system needs to know the final
size of the file at creation time.

Q13:

-The simplest approach is to set a limit on file-name length, typically 255 characters. This
approach is simple, but wastes a great deal of directory space, since few files have such
long names.

- One alternative is to give up the idea that all directory entries are the same size. With this
method, each directory entry contains a fixed portion, typically starting with the length of
the entry, and then followed by data with a fixed format, usually including the owner,
creation time, protection information, and other attributes. This fixed-length header is
followed by the actual file name, however long it may be as shown in Fig. 4-15(a) .A
disadvantage of this method is that when a file is removed, a variable-sized gap is
introduced into the directory into which the next file to be entered may not fit

- Another way to handle variable-length names is to make the directory entries themselves
all fixed length and keep the file names together in a heap at the end of the directory. This
method has the advantage that when an entry is removed, the next file entered will always
fit there. Of course, the heap must be managed and page faults can still occur while
processing file names. One minor win here is that there is no longer any real need for file
names to begin at word boundaries, so no filler characters are needed after file names in
Fig. 4-15(b) as they are in Fig. 4-15(a).

Q14:

*Link a file(Hard link)

A hard link(Tradional link) creates a new directory entry for an existing file. This means both
the original file and the newly linked file share the same underlying data on disk (i.e., they
point to the same i-node). The steps for creating a hard link are:

-New Directory Entry: A new directory entry is created in another directory (or the same
directory), and this new entry points to the same i-node as the original file.

-Increase Link Count: The link count in the i-node is incremented to track how many
directory entries (links) currently point to that file

-File Attributes: The attributes such as permissions, timestamps, and ownership remain
shared between the linked files. Changes made to the file content through any of the links
are reflected in both files.

-Example:

In Figure 4-17 (b), after the link is created, both B’s and C’s directories point to the same
file with an i-node shared between them. The link count in the i-node is updated to 2.

*Unlink a file(Hard unlink)

The steps are:

+Remove Directory Entry: The file's entry is deleted from the directory (whether it’s the
original or a hard link).

+Decrease Link Count: The i-node’s link count is decremented. If the link count drops to
zero, the system knows there are no more directory entries pointing to the file, and it can
proceed to delete the i-node and reclaim the disk blocks used by the file’s data.
+Shared Ownership Problem: If a file is shared between users (like in the case of Figure 4-
17 (c)), unlinking from one directory (e.g., C's) will leave the file owned by C but only
referenced in B's directory. If B does not remove the file, C may continue being billed for
storage (if quotas are enabled), despite no longer having direct access.

-Example:

+In Figure 4-17 (c), after C removes their directory entry, the i-node remains intact with a
link count of 1 because B’s directory still contains the link to the file

*Link a file(Symbolic link)

A symbolic link (also called a soft link) is different from a hard link in that it creates a new
file that contains a path to the original file, not a reference to the same i-node. The steps
are:

-New Directory Entry: A new file (of type LINK) is created in the directory where the
symbolic link is being made.

-Store Path to Original File: Instead of pointing directly to the original file’s i-node, the
symbolic link contains a string that represents the path to the original file (e.g.,
/user/c/documents/report.txt).

-No Change in Link Count: The link count of the original file’s i-node is not incremented
since symbolic links don't reference the i-node directly.

-Accessing the Linked File: When a user accesses the symbolic link, the operating system
parses the stored path, follows it, and accesses the original file.

-Example:

In Figure 4-16, B’s directory could contain a symbolic link to C’s file. B’s directory entry will
not directly point to the file's i-node but rather hold the path to C’s file.

*Unlinking a File (Symbolic Link):

Unlinking a symbolic link is straightforward and does not affect the original file. The steps
are:

-Remove the Link: The symbolic link itself (the path entry) is deleted from the directory.

-No Impact on Original File: The original file remains unaffected. The i-node and its link
count are unchanged, as the symbolic link does not reference the i-node directly.
-Broken Link: If the original file is removed while the symbolic link still exists, the symbolic
link becomes a broken link. Any attempts to access it will fail because the path points to a
non-existent file.

Q15:

To deal with the issue that a shared file cannot be seen by other users who do not append
the file,we can use symbolic links but ensure that these links reference a central file or
data structure rather than directly duplicating file pointers in each user's directory.

You might also like