Lecture 10 Linux File System

 

LINUX FILE SYSTEM

Introduction

One essential part of the operating system is the Linux file system.

It offers a hierarchical data management and organization system.


Root Directory

The root directory ("/") as the initial directory.

a subdirectory and directory hierarchy.

Files and subdirectories are found in directories.


Data management

maintains metadata, sizes, creation dates, and file names.

in charge of ownership, security, and permits.


Representation and Organization of Storage Resources

Allocates disk space for files and directories.

Maintains directory structure.

Stores metadata for each file.


Pathnames

Textual file or directory locations.

Absolute (from the root) or relative (from the current directory).


Example of Absolute and Relative Path in Directory Navigation:

Current Directory: You are currently located in "/home/kt."


Objective: You want to change your directory to "/home/kt/abc."


Using the Relative Path Concept:

Check the current directory:

Command: $pwd

Output: /home/kt


Change directory using a relative path:

Command: $cd abc

Confirm the new directory:

Command: $pwd

Output: /home/kt/abc


Using the Absolute Path Approach:

Verify your current location:

Command: $pwd

Result: /home/kt


Change the directory using an absolute path:

Command: $cd /home/kt/abc

Confirm the new directory:

Command: $pwd

Result: /home/kt/abc


Unified Hierarchy

Single, root-to-subdirectory file structure.


Root Directory ("/")

The top-level directory, starting point.


File Organization

Files (data, programs) and directories (nesting).


Hierarchical Structure

Tree-like structure for organization.


Management

Pathnames for file/directory navigation.

Basic commands: "cd," "ls," "cp," "mv."


Access Control

Permissions for file and directory security.


File types in Linux

In the Linux system, the fundamental principle is that everything can be treated as a file or a process.

Most file system implementations categorize files into seven main types. Even if new elements are introduced into the file structure, such as process information located in "/", they must still conform to one of these seven types:

  1. Regular files
  2. Directories
  3. Character device files
  4. Block device files
  5. Local domain sockets
  6. Named pipes (FIFO)
  7. Link files

The structure and categorization of these file types remain consistent, even when new additions are made to the system.


1. Regular (Ordinary) Files in Linux

Definition: Regular or ordinary files are used to store various types of data, including text, audio, video, images, scripts, and programs.

Commonality: The majority of files on UNIX and Linux systems are regular files.

File Types: Regular files can store a wide range of content, making them one of the most versatile file types in Linux.

Extensions: In Linux, regular files can be created both with and without file extensions. The presence of extensions can provide information about the file type, but they are not mandatory.

Naming Convention: Regular files start with -


2. Directories in the Linux File System

Definition: A directory is a file that stores named references to other files. It's used to organize and locate files and directories.

Binary File: Directories are binary files containing information about the files and subdirectories they reference.

Creation and Deletion: Directories can be created using the "mkdir" command and deleted using "rmdir" if they are empty.

Hierarchy Organization: To structure files in a hierarchical manner, file systems rely on directories.

Root Directory: The Linux file system starts with a root directory ("/"), which serves as the top-level directory. All files and directories are created under this root directory.

Parent-Child Relationships: With the exception of the root directory, each directory has a parent directory, forming a parent-child relationship between directories.


3. Special Files: Character device & Block device file

Special File Concept: In Linux, all hardware devices, including hard drives, printers, monitors, terminal emulators, and CD/DVD drives, are treated as special files.

Exposing Hardware as Files: The purpose of a special file is to represent a hardware device as if it were a file in the file system. This abstraction simplifies device access.

Universal Interface: Special files create a universal interface for both hardware devices and virtual devices managed by the kernel. This allows tools for file input/output (I/O) to interact with the device.

Immediate Data Transfer: When data is read from or written to a special file, the operation occurs immediately and is not subject to the usual rules and restrictions of a conventional file system. This allows direct interaction with the underlying hardware.


4. Link Files: Hard Links and Soft (Symbolic) Links

Linking Purpose: Link files enable the use of a file under a different name or from an alternative location. They serve as a way to reference files.

Link File Definition: A link file is essentially a reference or pointer to another file. There are two primary types: hard links and symbolic (soft) links.

Hard Links: Hard links create a mirror copy of the original file. They point directly to the underlying data. Note that hard links cannot be created for directories, and they must reside on the same filesystem as the original file.

Symbolic or "Soft" Links: Symbolic links, also known as soft links, point to a file by its name. They act as pointers to the file's location. Unlike hard links, symbolic links can reference directories and files on different filesystems.


5. Socket Files

A socket is an endpoint for communication that enables applications to exchange data. It's a crucial element in networking.

Communication Example: For instance, if a local system's application intends to communicate with an application on a remote system, it connects to the socket of the remote application. This connection is established using the IP address and port number associated with that socket.

Service Provision: Applications providing services to other applications or remote clients utilize sockets to accept connections. Sockets facilitate communication between these services.

IP Address and Port: Each socket is identified by an associated IP address and port number. This combination allows the socket to accept connections from clients and facilitate data exchange.

6. Named Pipes

Named pipes, also known as "FIFO files," facilitate communication between two processes running on the same host. They are used for inter-process communication.

Creation and Deletion: Named pipes can be created using the "mknod" command and removed with "rm."

Purpose Comparison: Named pipes and local domain sockets serve similar purposes. The existence of both can be considered a historical artifact. If UNIX and Linux were designed today, network sockets might replace both, serving as a more versatile and unified solution for inter-process communication.

Comments

Popular posts from this blog

Lecture 2 - Fetch, Execution and IO

Lecture 11 Linux Network and Process Management

Lecture 12 Clint Server Architecture