{"id":254,"date":"2020-08-18T19:23:47","date_gmt":"2020-08-18T20:23:47","guid":{"rendered":"http:\/\/www.linux-tutorial.info\/?page_id=77"},"modified":"2020-08-22T19:26:01","modified_gmt":"2020-08-22T20:26:01","slug":"this-is-the-page-title-toplevel-89","status":"publish","type":"page","link":"http:\/\/www.linux-tutorial.info\/?page_id=254","title":{"rendered":"Files and File Systems"},"content":{"rendered":"\n<title>Files and Filesystems<\/title>\n<p>\nAny time you access a Linux system, whether locally, across a\n<glossary>network<\/glossary>, or through any other\nmeans, both files and file systems are involved. Every program that you run\nstarts out as a file. Most of the time you are also reading or writing a file.\nBecause files (whether programs or data files) reside on file systems, every\ntime you access the system, you also access a file system.\n<\/p>\n<p>\nKnowing what and how a file is represented on the disk and how the system\ninterprets the contents of the file is useful for you to understand what the system\nis doing. With this understanding, you can evaluate both the system and\n<glossary>application<\/glossary> behavior to determine whether it is proper.\n<\/p>\n<p>\nKeep in mind that it is a misnomer when someone says that a directory &#8220;contains&#8221; other files and directories. What really happens is the directory contains the information necessary to  locate the directories and files. Therefore, when you do a long listing, which shows file sizes, the sizes of the directories does <strong>not<\/strong> include all of the subdirectory&#8217;s and files. Instead,\nit simply shows how much space this directory takes up on the hard disk. Defined the total\namount of space taken up by a directory and all subdirectories you would use the command:<\/p>\n<p>\n<commandexample command=\"du\">du -s &lt;directory_name&gt;<\/commandexample>\n<\/p>\n<p>\nthis shows you the disk usage for the directory given (the dash and option says to show a sum and not list the individual files and directories). Note that on some systems that <command>du<\/command> command may display space in disk blocks of 512 bytes.  If you use the -k option to du, you force it displays size in kilobytes.\n<!-- START copyright David Rusling:1996-1999:GNU General Public License -->\n<p>\nIn Linux, as it is for Unix, the separate filesystems that the system may use are\nnot accessed by device identifiers (such as a drive number or a drive name) but instead\nthey are combined into a single hierarchical tree structure that represents the\nfilesystem as a single entity.\nLinux adds each new filesystem into this single filesystem tree as they are mounted\nonto a mount directory, for example <directory>\/mnt\/cdrom<\/directory>.\nOne of the most important features of Linux is its support for many different filesystems.\nThis makes it very flexible and well able to coexist with other operating systems.\nThe most popular filesystem for Linux is the EXT2 filesystem and this is the\nfilesystem supported by most of the Linux distributions.\n<p>\nA filesystem gives the user a sensible view of files and directories held on the\nhard disks of the system regardless of the filesystem type or the characteristics\nof the underlying physical device.\nLinux transparently supports many different filesystems\n(for example MS-DOS and EXT2)\nand presents all of the mounted files and filesystems as one integrated virtual\nfilesystem.\nSo, in general, users and processes do not need to know what sort of filesystem that any\nfile is part of, they just use them.\n<p>\nThe block device drivers hide the differences between the physical block device\ntypes (for example, <glossary>IDE<\/glossary> and <glossary>SCSI<\/glossary>) and, so far as each filesystem is\nconcerned, the physical devices are just linear collections of blocks of data.\nThe block sizes may vary between devices, for example 512 bytes is common for\nfloppy devices whereas 1024 bytes is common for <glossary>IDE<\/glossary> devices and, again, this\nis hidden from the users of the system.\nAn EXT2 filesystem looks the same no matter what device holds it.\n<p>\nOne of the most important features of Linux is its support for many different file systems.\nThis makes it very flexible and well able to coexist with many other operating systems.\nAt the time of writing, Linux supports 15 file systems; <tt>ext<\/tt>, <tt>ext2<\/tt>, <tt>xia<\/tt>,\n<tt>minix<\/tt>, <tt>umsdos<\/tt>, <tt>msdos<\/tt>, <tt>vfat<\/tt>, <tt>proc<\/tt>, <tt>smb<\/tt>, <tt>ncp<\/tt>, <tt>iso9660<\/tt>,\n<tt>sysv<\/tt>, <tt>hpfs<\/tt>, <tt>affs<\/tt> and <tt>ufs<\/tt>, and no doubt, over time more will be added.\n<p>\nAll file systems, of whatever type, are mounted onto a directory and\nthe files of the mounted file system cover up the existing contents of that directory.\nThis directory is known as the mount directory or mount point.\nWhen the file system is unmounted, the mount directory&#8217;s own files are once again revealed.\n<p>\nWhen disks are initialized (using <font face=\"helvetica\">fdisk<\/font>, say) they have a partition structure\nimposed on them that divides the physical disk into a number of logical partitions.\nEach partition may hold a single file system, for example an <tt>EXT2<\/tt> file system.\nFile systems organize files into logical hierarchical structures with directories, soft links and\nso on held in blocks on physical devices.\nDevices that can contain file systems are known as block devices.\nThe IDE disk partition <tt>\/dev\/hda1<\/tt>, the first partition of the first IDE disk drive in the\nsystem, is a block device.\nThe Linux file systems regard these block devices as simply linear collections of blocks,\nthey do not know or care about the underlying physical disk&#8217;s geometry.\nIt is the task of each block device driver to map a request to read a particular\nblock of its device into terms meaningful to its device; the particular track, sector\nand cylinder of its hard disk where the block is kept.\nA file system has to look, feel and operate in the same way no matter what device is holding it.\nMoreover, using Linux&#8217;s file systems, it does not matter (at least to the system user) that\nthese different file systems are on different physical media controlled by\ndifferent hardware controllers.\nThe file system might not even be on the local system, it could just as\nwell be a disk remotely mounted over a network link.\nConsider the following example where a Linux system has its root file system on a SCSI disk:\n<pre>\nA         E         boot      etc       lib       opt       tmp       usr\nC         F         cdrom     fd        proc      root      var       sbin\nD         bin       dev       home      mnt       lost+found\n<\/pre>\n<p>\nNeither the users nor the programs that operate on the files themselves need know that\n<tt>\/C<\/tt> is in fact a mounted VFAT file system that is on the first IDE disk in the system.\nIn the example (which is actually my home Linux system), <tt>\/E<\/tt> is the master IDE disk\non the second IDE controller.\nIt does not matter either that the first IDE controller is a PCI controller and that the second\nis an ISA controller which also controls the IDE CDROM.\nI can dial into the network where I work using a modem and the PPP network protocol\nusing a modem and in this case I can remotely mount my Alpha AXP&nbsp;Linux system&#8217;s\nfile systems on <tt>\/mnt\/remote<\/tt>.\n<p>\nThe files in a file system are collections of data;\nthe file holding the sources to this chapter is an ASCII file called <tt>filesystems.tex<\/tt>.\nA file system not only holds the data that is contained within the files of the\nfile system but also the structure of the file system.\nIt holds all of the information that Linux users and processes see as files, directories\nsoft links, file protection information and so on.\nMoreover it must hold that information safely and securely, the basic integrity of the\noperating system depends on its file systems.\nNobody would use an operating system that randomly lost data and\nfiles<a href=\"#tthFtNtAAB\" name=tthFrefAAB><sup>1<\/sup><\/a>.\n<p>\n<tt>Minix<\/tt>, the first file system that Linux had is rather restrictive and lacking\nin performance.\n<p>\nIts filenames cannot be longer than 14 characters (which is still better than 8.3 filenames)\nand the maximum file size is 64MBytes.\n64Mbytes might at first glance seem large enough but large file sizes are necessary\nto hold even modest databases.\nThe first file system designed specifically for Linux, the Extended File system, or <tt>EXT<\/tt>, was\nintroduced in April 1992 and cured a lot of the problems but it was still felt\nto lack performance.\n<p>\nSo, in 1993, the Second Extended File system, or <tt>EXT2<\/tt>, was added.\nIt is this file system that is described in detail later.\n<p>\nAn important development took place when the EXT file system was added into Linux.\nThe real file systems were separated from the operating system and system services\nby an interface layer known as the Virtual File system, or VFS.\n<p>\nVFS allows Linux to support many, often very different, file systems,\neach presenting a common software interface to the VFS.\nAll of the details of the Linux file systems are translated by\nsoftware so that all file systems appear identical to the rest of the Linux kernel\nand to programs running in the system.\nLinux&#8217;s Virtual File system layer allows you to transparently\nmount the many different file systems at the same time.\n<p>\nThe Linux Virtual File system is implemented so that access to its files is as fast and\nefficient as possible.\nIt must also make sure that the files and their data are kept correctly.\nThese two requirements can be at odds with each other.\nThe Linux VFS caches information in memory from each file system as it is mounted and\nused.\nA lot of care must be taken to update the file system correctly as data within these\ncaches is modified as files and directories are created, written to and deleted.\nIf you could see the file system&#8217;s data structures within the running kernel,\nyou would be able to see data blocks being read and written by the file system.\nData structures, describing the files and directories being accessed would be\ncreated and destroyed and all the time the device drivers would be working\naway, fetching and saving data.\nThe most important of these caches is the Buffer Cache, which is integrated into the\nway that the individual file systems access their underlying block devices.\nAs blocks are accessed they are put into the Buffer Cache and kept on various queues\ndepending on their states.\nThe Buffer Cache not only caches data buffers, it also helps manage the asynchronous\ninterface with the block device drivers.\n<p>\n<!-- END copyrightDavid Rusling:1996-1999:GNU General Public License -->\n","protected":false},"excerpt":{"rendered":"<p>Files and Filesystems Any time you access a Linux system, whether locally, across a network, or through any other means, both files and file systems are involved. Every program that you run starts out as a file. Most of the &hellip; <a href=\"http:\/\/www.linux-tutorial.info\/?page_id=254\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-254","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/254","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=254"}],"version-history":[{"count":1,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/254\/revisions"}],"predecessor-version":[{"id":559,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/254\/revisions\/559"}],"wp:attachment":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}