• 文件(file)1————An introduction to Linux filesystems


    这里讲的主要是关于文件,目录以及一部分磁盘的相关知识。主要依据是操作系统第4章 文件管理(参考书:王道的书)和鸟哥的私房菜的第567章。

     在系统运行时,计算机以进程为基本单位进行资源的调度和分配;而在用户进行的输入、输出中,则以文件为基本单位。


    1、什么是文件?

      从比喻的角度来讲,操作系统是图书管理员对于书的管理,则文件就是图书馆的书。

      从底层向上的角度来讲,数据项:用于描述一个对象的某种属性值,如姓名,日期或证件号(注意这三个例子中的一个就是数据项)

                 --->记录:一组相关数据项的集合,如一个考生报名记录包括:姓名,出生日期,学号,身份证号等等。

                 --->文件:由创建者所定义的一组相关数据集合,逻辑上可分为结构文件(类似于记录组成)和无结构文件(字符流,又称流式文件,在Linux下使用od反汇编的二进制文件?)两种。

                    对于结构文件分为顺序文件和索引文件。其中的顺序文件分为串结构和顺序结构。

     另外,我拜读了 

    我们对文件以及文件系统做出了一个在high-level的概述。先讲了为什么需要一个Non-volatile disk drive?便宜。然后分别从不同角度对文件系统进行了定义。Linux目录结构开始于"/",root dirctory;Linux支持几乎所有的(100多种)数据存储格式(type of data storage format);一个特定类型的文件系统分区(partition)或逻辑卷(logical volume)可以挂载(mount)在Linux文件系统的特定节点(mount point)上。

    接着讲述了文件系统的基本功能(basic function):磁盘存储(disk storage),并由此引申出

    1、命名空间,即命名和组织方法(组织方法就是目录结构,而非把文件堆在一起),

    2、然后又由命名空间引申出元数据(metadata)结构,元数据结构支持有层次的目录结构,这样可以知道哪一块是空的,哪一块的已经使用的。元数据结构同样可以维护文件和目录,元数据包括文件和目录的信息,包括他们的创建,修改和最后一次进入,存储地点和所属硬盘。另外元数据常常用来存储high-level 信息,关于磁盘的子目录如逻辑卷和分区。

    3、API,文件系统还需要提供可以接触系统调用的API。API可以创建,移动,删除文件以及算法。这些算法可以解决速度或者最小化磁盘的目标。

    4、当代文件系统还需要一个安全的模型。即文件的权限rxw这些东西。

    5、最后是实现这些功能所需要的软件。Linux使用两个部分来提高系统和程序员的效率。第一部分是VFS(虚拟文件系统)第二部分是特定文件系统的设备驱动。

    然后文章讲述了linux的树形结构以及FHS,统一的文件结构以及挂载。

    下面是稍微详细的英文讲解:

    Directory Structure--------Tree-like hierarchy and FHS

    The Linux directory structure is well defined and documented in the Linux Filesystem Hierarchy Standard (FHS).

    /    :The root filesystem is the top-level directory of the filesystem.All the things(such as files executables and libraries)required to boot are in it.After the system is booted,all other filesystems are mounted on standard .well-defined mount points as subdirectories of the root filesystem.

    /bin    :This directory contains user executable files.

    /boot  :Contains the static bootloader and kernel executable and configuration files required to boot the Linux computer.

    /dev   :This deirectory contains the device files for every hardware device attached to the system.These are not device drivers,rather they are files that represent each divice on the computer and facilitate(帮助) access to those devices.

    /etc    :Contains the local system configuration files for the host computer.    

    /home  :Home directory storage for user files. Each user has a subdirectory in /home.

    /lib     :Contains shared library files that are required to boot the system.

    /media :A place to mount external removable media devices such as USB thumb drives that may be connected to the host.

    /mnt     :A temporary mountpoint for regular filesystems (as in not removable media) that can be used while the administrator is repairing or working on a filesystem.

    /opt   :Optional files(鸟叔书中称为第三方协力文件) such as vendor supplied application programs should be located here.

    /root  :This is not the root (/) filesystem. It is the home directory for the root user.

    /sbin :System binary files. These are executables used for system administration.

    /tmp :Temporary directory. Used by the operating system and many programs to store temporary files. Users may also store files here temporarily. Note that files stored here may be deleted at any time without prior notice.

    /usr  :(Unix software resource,like ProgramFiles in windows)These are shareable, read-only files, including executable binaries and libraries, man files, and other types of documentation.

    /var  :Variable data files are stored here. This can include things like log files, MySQL, and other database files, web server data files, email inboxes, and much more.

      1、All the red directories and their subdirectories cannot be created as a separate filesystem and mounted at startup time. This is because they (specifically, their contents) must be present at boot time in order for the system to boot properly. 

      2、The /media and /mnt directories are part of the root filesystem, but they should never contain any data. Rather, they are simply temporary mount points.

      3、All the black directories do not need to be present during the boot sequence, but will be mounted later, during the startup sequence that prepares the host to perform useful work.

    Linux unified directory structure

      In windows you need to know a file or program is located on which hard drives,such as C: D: E:.Then you can use cd command to change to the correct directory to locate the desired file. Each hard drive has its own separate and complete directory tree.But linux filesystem unifies all physical hard drives and partitions into a single directory structure.

      This can work only because a filesystem, such as /home, /tmp, /var, /opt, or /usr can be created on separate physical hard drives, a different partition, or a different logical volume from the / (root) filesystem and then be mounted on a mountpoint (directory) as part of the root filesystem tree. Even removable drives such as a USB thumb drive or an external USB or ESATA hard drive will be mounted onto the root filesystem and become an integral part of that directory tree.

      One good reason to do this is apparent during an upgrade from one version of a Linux distribution to another, or changing from one distribution to another. There are other reasons for maintaining certain parts of the Linux directory tree as separate filesystems. 

    Mounting 

     A mount point is simply a directory, like any other, that is created as part of the root filesystem. So, for example, the home filesystem is mounted on the directory /home. Filesystems can be mounted at mount points on other non-root filesystems but this is less common.

    The Linux root filesystem is mounted on the root directory (/) very early in the boot sequence. Other filesystems are mounted later, by the Linux startup programs, either rc under SystemV or by systemd in newer Linux releases. Mounting of filesystems during the startup process is managed by the /etc/fstab configuration file.  An easy way to remember that is that fstab stands for "file system table," and it is a list of filesystems that are to be mounted, their designated mount points, and any options that might be needed for specific filesystems.

    Filesystems are mounted on an existing directory/mount point using the mountcommand. 

  • 相关阅读:
    Oil Deposits UVA
    工作区的颜值选择(中等)
    计算机网络 自定向下方法1.1-1.2
    工作区的颜值选择(简单)
    排序算法之简单选择排序
    排序算法之直接插入排序
    查找算法之查找一个数组中只出现过一次的数
    查找算法之查找一个数组中两两数字相同,只有其中两个数字是不一样的,将其找出
    Linux
    ASP.NET Web – 状态管理
  • 原文地址:https://www.cnblogs.com/SsoZhNO-1/p/9196739.html
Copyright © 2020-2023  润新知