0729学习日志

操作系统-mkdir

  1. 文件的物理结构
    1. 连续分配
    2. 链接分配
      • 隐式链接
      • 显式链接(FAT,file allocation table)
    3. 索引分配
      1. 单级索引分配
      2. 多级索引分配
      3. 混合索引分配
  2. 磁盘的管理和组织
    1. 磁盘结构
      • surface
      • track
      • gap
    2. 磁盘访问时间
    3. 文件存储空间管理
      1. 空闲表法
      2. 空闲链表法
        1. 空闲盘块链
        2. 空闲盘区链
        3. 位示图
        4. 成组链表法
  3. 磁盘格式化
    1. 低级格式化
    2. 高级格式化

附:系统调用open(),read(),close()使用代码示例

#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <time.h>
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#define MAX_BUFFER_SIZE 128

int do_the_same_thing(char *filename, bool sleep_enabled);

int main(int argc, char *argv[])
{
    bool sleep_enabled = false;
    // Open a file in read-only mode
    if (argc < 2)
    {
        fprintf(stderr, "Usage: %s <filename> --sleep\n", argv[0]);
        return 1;
    }
    if (argc == 3 && strcmp(argv[2], "--sleep") == 0)
    {
        sleep_enabled = true;
    }
    char *filename = argv[1];
    pid_t pid = fork(); // Get the current process ID
    if (pid < 0)
    {
        perror("Failed to fork");
        return 1;
    }
    else if  (pid == 0)
    {
        // Child process
        do_the_same_thing(filename, sleep_enabled);
        exit(0);
    }
    else if (pid > 0)
    {
        do_the_same_thing(filename, sleep_enabled);
        
    }
    else
    {
        perror("Failed to fork");
        return 1;
    }

    return 0;
}
int do_the_same_thing(char *filename,bool sleep_enabled)


{
    int fd = open(filename, O_RDONLY); // O_RDONLY means read-only
        

    if (fd == -1)
    {
        perror("Failed to open file");
        return 1;
    }
    // ... use fd ...
    ssize_t bytes_read;
    while (1)
    {
        char buffer[MAX_BUFFER_SIZE];
        bytes_read = read(fd, buffer, MAX_BUFFER_SIZE - 1); // Read up to MAX_BUFFER_SIZE - 1 bytes
        if (bytes_read <= 0)
        {
            break; // Exit loop on error or EOF
        }
        buffer[bytes_read] = '\0'; // Null-terminate the string
        printf("%s", buffer);
        if (sleep_enabled)
            sleep(1); // Sleep for 1 second to simulate processing time
    }

    close(fd);
    // This function is intentionally left empty.
    // It serves as a placeholder to demonstrate that the code can be extended.
}

课程编号:25-28