zoukankan      html  css  js  c++  java
  • 操作系统第4次实验报告:文件系统

    • 姓名:李宗政
    • 学号:201821121029
    • 班级:计算1811

    1. 编写程序

    在服务器上用Vim编写一个程序:实现Linux系统命令ls -lai的功能,

    myls.h

     myls.c

     

     

    main_myls.c

     

    2. 分析运行结果

    运行结果:

     结果分析:

    以第一行为例

    第一列:索引号

      索引号为266867(printf("%d ",(int)file_message->st_ino);)

    第二列:文件的类型及权限

      drwxr--r-x:

      r:可读取文件的实际内容 w:可编辑、新增、修改该文件的实际内容 x:可被执行

      -:普通文件,d:目录文件,l:链接文件,b:设备文件,c:字符设备文件,p:管道文件

    void file_type(const struct stat* file_message)
    {
    //mode_t mode = (*get_message).st_mode;
      mode_t mode = file_message->st_mode;

      if (S_ISREG(mode)) printf("-"); // 普通文件
      else if(S_ISDIR(mode)) printf("d"); // 目录文件
      else if(S_ISCHR(mode)) printf("c"); // 字符设备文件
      else if(S_ISBLK(mode)) printf("b"); // 块设备文件
      else if(S_ISFIFO(mode)) printf("p"); // 管道文件
      else if(S_ISLNK(mode)) printf("l"); // 链接文件
      else printf("s"); // socket文件
    }

    void file_power(const struct stat* file_message)
    {
      mode_t mode = file_message->st_mode;

    // 判断USR权限
      printf("%c", mode&S_IRUSR?'r':'-');
      printf("%c", mode&S_IWUSR?'w':'-');
      printf("%c", mode&S_IXUSR?'x':'-');

    // 判断GRP权限
      printf("%c", mode&S_IRGRP?'r':'-');
      printf("%c", mode&S_IWGRP?'w':'-');
      printf("%c", mode&S_IXGRP?'x':'-');

    // 判断OTH权限
      printf("%c", mode&S_IROTH?'r':'-');
      printf("%c", mode&S_IWOTH?'w':'-');
      printf("%c ", mode&S_IXOTH?'x':'-');
    }

    第三列:文件的链接数.

      5(printf("%d ", file_message->st_nlink); // 打印硬链接数)

    第四列:拥有文件的用户

      lizongzheng

    第五列:拥有文件的组

      jmu-cs-18(file_id(file_message); // 转换并打印用户id与组id)

    第六列:文件的大小。

      4096(printf("%5ld ", file_message->st_size); // 打印文件大小)

    第七列:文件最后的修改时间。

      Apr 30 11.00(file_mtime(file_message); // 打印文件最后修改时间)

    第八列:文件名(printf("%s ", filename); // 打印文件名)

      

     

  • 相关阅读:
    JavaScript操作符instanceof揭秘
    Linux打开txt文件乱码的解决方法
    Working copy locked run svn cleanup not work
    poj 2299 UltraQuickSort 归并排序求解逆序对
    poj 2312 Battle City 优先队列+bfs 或 记忆化广搜
    poj2352 stars 树状数组
    poj 2286 The Rotation Game 迭代加深
    hdu 1800 Flying to the Mars
    poj 3038 Children of the Candy Corn bfs dfs
    hdu 1983 Kaitou Kid The Phantom Thief (2) DFS + BFS
  • 原文地址:https://www.cnblogs.com/Lucienight/p/12809444.html
Copyright © 2011-2022 走看看