operating-system-file-system-experiment

Experiment Purpose

Through this experiment, students will deeply understand the principles and operational methods of the file system in operating systems, master the implementation ways of core functions such as file management, directory operations, and permission control, and verify theoretical knowledge through practical operations.

Experiment Environment

  • Operating System: Linux (e.g., Ubuntu 20.04)
  • Tools: Terminal commands (ls, cd, touch, mkdir, chmod, cp, rm etc.)
  • File System Type: ext4 (default Linux file system)

Experiment Content

1. File System Basic Concepts

  • Function of File System: Manage disk space, organize file structures, and provide a unified access interface.
  • Key Concepts:
    • Inode: Stores file metadata (permissions, size, timestamp etc.).
    • Directory Structure: Root directory (/), user home directory (~), system directories (e.g., /bin, /etc).
    • Superblock: Records global system information (total block count, available space etc.).

2. File and Directory Operations

  • Create File: Use touch filename command.
  • Create Directory: Use mkdir directory_name command.
  • Switch Directory: Use cd command (e.g., cd /home/user).
  • View Directory Contents: Use ls command (e.g., ls -l for detailed information).

3. File Permission Management

  • Permission Types:
    • Read (r): Allow viewing file contents.
    • Write (w): Allow modifying file contents.
    • Execute (x): Allow running executable files.
  • Permission Settings:
    • Use chmod command (e.g., chmod 755 filename to set permissions).
    • Use chown command (e.g., chown user:group filename to change owner).

Experiment Steps

  1. Initialize File System
    • Use df -h to check disk space usage.
    • Use df -i to verify inode resource availability.
  2. Create Test Files and Directories
    • Create file: touch testfile.txt
    • Create directory: mkdir testdir
    • Switch directory: cd testdir
  3. File Operations Practice
    • Copy file: cp testfile.txt .
    • Delete file: rm testfile.txt
    • Delete directory: rm -r testdir
  4. Permission Settings Test
    • Set file permissions: chmod 644 testfile.txt
    • Verify permissions: ls -l testfile.txt
    • Modify file owner: chown user:group testfile.txt

Experiment Results Analysis

  • File System Status: Confirmed via df command that disk space is within limits.
  • Permission Validation:
    • Only owner can read/write file (644 permissions).
    • Other users can only read file (444 permissions).
  • Directory Structure: Verified that created files and directories exist in expected paths.

Common Issues and Solutions

  • Issue 1: File cannot be read
    • Cause: Permission settings are incorrect.
    • Solution: Use chmod to fix permissions (e.g., chmod 644 filename).
  • Issue 2: Directory cannot be deleted
    • Cause: Directory contains files or is occupied by other processes.
    • Solution: Delete files inside the directory first, or use rm -r to force delete.
  • Issue 3: Inode exhaustion
    • Cause: Too many files.
    • Solution: Delete redundant files or expand the file system.

Experiment Summary

Through this experiment, students will master the operational methods of the Linux file system, understand the importance of file permission management, and independently complete the creation, modification, and deletion of files and directories. Attention should be paid to proper permission settings and reasonable use of disk resources to lay a foundation for subsequent studies in process management and storage management.