strangerRidingCaml

File Systems 본문

Advanced operating system

File Systems

woddlwoddl 2024. 5. 15. 11:46
728x90
File Systems

File Systems

File system structures (inode-based, log-structured)

A file system organizes and manages data stored on a storage medium such as a hard disk or SSD. Two common structures are inode-based and log-structured file systems.

Inode-based file systems use inodes to represent files and directories, storing metadata such as permissions, ownership, and pointers to data blocks.

Log-structured file systems organize data as a log, where all modifications are written sequentially to a log segment, improving performance and reliability.

Disk scheduling algorithms

Disk scheduling algorithms optimize the order in which disk requests are serviced to minimize seek time and maximize throughput. Examples include FCFS (First-Come, First-Served), SSTF (Shortest Seek Time First), SCAN, and C-SCAN.

File system reliability and recovery

File system reliability ensures data integrity and availability, even in the event of hardware failures or system crashes. Techniques such as journaling, checksums, and redundancy (e.g., RAID) enhance reliability.

Recovery mechanisms restore file system consistency and recover lost data after a crash or failure. This may involve replaying journal entries, performing file system checks (e.g., fsck), and rebuilding data structures.

Lab Activities

Inode-based File System Lab Activity


        // Sample code for reading and modifying files using inode-based file system APIs in C
        #include <stdio.h>
        #include <fcntl.h>
        #include <unistd.h>

        int main() {
            int fd = open("myfile.txt", O_RDWR);
            if (fd == -1) {
                perror("open");
                return 1;
            }

            char buf[100];
            ssize_t bytes_read = read(fd, buf, sizeof(buf));
            if (bytes_read == -1) {
                perror("read");
                return 1;
            }

            printf("Read %zd bytes: %s\n", bytes_read, buf);

            close(fd);
            return 0;
        }
    

Log-Structured File System Lab Activity


        // Sample code for writing data to a log-structured file system in Python
        import os

        with open("logfile.txt", "a") as file:
            file.write("New log entry\n")
    

Disk Scheduling Algorithm Lab Activity


        // Sample code for implementing the SCAN disk scheduling algorithm in C
        #include <stdio.h>

        int main() {
            int queue[] = {98, 183, 37, 122, 14, 124, 65, 67};
            int head = 53;
            int total_seek_time = 0;

            int n = sizeof(queue) / sizeof(queue[0]);

            int direction = 1; // 1 for moving towards higher cylinder numbers, -1 for lower
            int i, j;
            int index = -1;

            // Sort the queue
            for (i = 0; i < n - 1; i++) {
                for (j = i + 1; j < n; j++) {
                    if (queue[i] > queue[j]) {
                        int temp = queue[i];
                        queue[i] = queue[j];
                        queue[j] = temp;
                    }
                }
            }

            // Find the position of the head in the queue
            for (i = 0; i < n; i++) {
                if (queue[i] >= head) {
                    index = i;
                    break;
                }
            }

            if (index == -1) {
                direction = -1;
                index = n - 1;
            }

            // SCAN algorithm
            printf("Sequence of disk accesses: %d", head);
            for (i = index; i >= 0 && i < n; i += direction) {
                printf(" -> %d", queue[i]);
                total_seek_time += abs(head - queue[i]);
                head = queue[i];
            }
            printf("\nTotal seek time: %d\n", total_seek_time);

            return 0;
        }
    

File System Recovery Lab Activity


        // Sample code for performing file system recovery using fsck in Linux
        $ fsck /dev/sda1
    

'Advanced operating system' 카테고리의 다른 글

Virtualization using QEMU or Docker  (0) 2024.05.15
Kernel Module Development for Linux  (0) 2024.05.15
Distributed Systems  (0) 2024.05.15
Virtualization  (0) 2024.05.15
Kernel Architecture  (0) 2024.05.15