0% found this document useful (0 votes)
19 views

OS Lab 7 - User Guide

Operating Systems Lab 7

Uploaded by

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

OS Lab 7 - User Guide

Operating Systems Lab 7

Uploaded by

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

Department of Computing

CS 330: Operating Systems


BESE: 13 AB

Lab 7: File Management (Open Ended


Lab) Date: 5th April 2024

Instructor: Engr. Taufiq ur Rehman

User Guide
Directory Structure:
In the file system implementation, we use a tree-like data structure to represent the hierarchical
directory structure.
Data Structure for File System:
1. Tree Structure:
a. The file system is represented using a tree data structure.
b. Each node in the tree represents either a directory or a file.
c. The root node represents the root directory, denoted by /.
2. Directory Node:
a. Each directory is represented by a node in the tree.
b. Directory nodes contain:
i. Name: The name of the directory.
ii. Children: A dictionary or mapping containing child nodes (directories and
files) of the directory.
c. Example:

{
"name": "documents",
"children": {
"file1.txt": { File Node },
"subdirectory": { Directory Node },
...
}
}

3. File Node:
a. Each file is represented by a node in the tree.
b. File nodes contain:
i. Name: The name of the file.
ii. Content: The content of the file.
c. Example:
{
"name": "file1.txt",
"content": "Hello, World!"
}

4. Data Persistence:
a. The file system data is typically persisted to a data file (e.g., JSON, XML) to maintain
state across sessions.
b. Serialization and deserialization techniques are used to convert the tree structure
into a format suitable for storage and vice versa.

Example of Data Structure Usage:


Suppose we have a file system with the following structure:
/
└── root
├── documents
│ └── file1.txt
├── images
│ └── pic1.jpg
└── videos
└── video1.mp4

The corresponding tree structure representation might look like this in the JSON file:
{
"name": "/",
"children": {
"root": {
"name": "root",
"children": {
"documents": {
"name": "documents",
"children": {
"file1.txt": {
"name": "file1.txt",
"content": "Hello, World!"
}
}
},
"images": {
"name": "images",
"children": {
"pic1.jpg": {
"name": "pic1.jpg",
"content": "<binary_data>"
}
}
},
"videos": {
"name": "videos",
"children": {
"video1.mp4": {
"name": "video1.mp4",
"content": "<binary_data>"
}
}
}
}
}
}
File System Operations:
1. Create Directory:
○ This operation allows you to create a new directory at a specified path within the
file system.
○ Input: Path of the directory to be created.
○ Example: 1. Create Directory
○ Example Input: /root/documents
○ Example Output: If the directory does not already exist, it will be created at the
specified path.
2. Create File:
○ This operation allows you to create a new file at a specified path within the file
system.
○ Input: path where the file will be created and the name of the file.
○ Example: 2. Create File
○ Example Input: /root/documents, file1.txt
○ Example Output: If the file does not already exist, it will be created at the specified
path.
3. Delete File:
○ This operation allows you to delete a file from a specified path within the file
system.
○ Input: Path of the file to be deleted and the name of the file.
○ Example: 3. Delete File
○ Example Input: /root/documents, file1.txt
○ Example Output: If the file exists at the specified path, it will be deleted from the
file system.
4. Move File:
○ This operation allows you to move a file from one location to another within the file
system.
○ Input: Current path and name of the file, and the new path and name for the file.
○ Example: 4. Move File
○ Example Input: /root/documents, file1.txt, /root/images, new_file.txt
○ Example Output: If the file exists at the current path, it will be moved to the new
path with the specified name.
5. Open File:
○ This operation allows you to open a file and read its content.
○ Input: Path of the file to be opened and the name of the file.
○ Example: 5. Open File
○ Example Input: /root/documents, file1.txt
○ Example Output: If the file exists at the specified path, its content will be displayed.
6. Write to File:
○ This operation allows you to write data to a file within the file system.
○ Input: Path of the file to write to, name of the file, data to write, and mode (append
or write_at).
○ Example: 6. Write to File
○ Example Input: /root/documents, file1.txt, Hello, World!, append
○ Example Output: If the file exists at the specified path, the provided data will be
appended to its content.
7. Read from File:
○ This operation allows you to read data from a file within the file system.
○ Input: Path of the file to read from, name of the file, mode (sequential or
readFrom), start position, and size of data to read (if using readFrom mode).
○ Example: 7. Read from File
○ Example Input: /root/documents, file1.txt, sequential
○ Example Output: If the file exists at the specified path, its content will be displayed.
8. Logout:
○ This operation allows you to log out from the file system, terminating the current
session.
○ Example: 8. Logout
○ Example Output: The current session is ended, and you are returned to the login
screen.
9. Exit:
○ This operation allows you to exit the file system application, ending the program.
○ Example: 9. Exit
○ Example Output: The file system application is terminated.
Notes:
● Each operation requires appropriate input according to the specified instructions. Incorrect
input may result in error messages.
● The file system maintains persistent data, meaning that changes made during a session are
saved and can be accessed in subsequent sessions.
● The file system provides basic functionalities similar to those found in real-world operating
systems, allowing users to manage directories and files effectively.
● Ensure to save the data using the Logout option before exiting the file system to maintain
data integrity.
Example Usage:
Enter your choice: 1
Enter the path of the directory to be created: /root/documents
Directory '/root/documents' created successfully.

Enter your choice: 2


Enter the path where the file will be created: /root/documents
Enter the name of the file: file1.txt
File '/root/documents/file1.txt' created successfully.

Enter your choice: 6


Enter the path of the file to write to: /root/documents
Enter the name of the file: file1.txt
Enter the data to write: Hello, World!
Enter the mode (append or write_at): append
Data appended to file '/root/documents/file1.txt' successfully.

Enter your choice: 5


Enter the path of the file to be opened: /root/documents
Enter the name of the file: file1.txt
Content of file '/root/documents/file1.txt':
Hello, World!

Enter your choice: 3


Enter the path of the file to be deleted: /root/documents
Enter the name of the file: file1.txt
File '/root/documents/file1.txt' deleted successfully.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy