1 / 42

Chapter 7

Chapter 7. The File System. What Is the File System?. Besides organizing our data files and useful programs, it also manages configuration information required for the operating system to provide us a consistent environment every time we restart the computer.

chasityr
Télécharger la présentation

Chapter 7

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 7 The File System

  2. What Is the File System? • Besides organizing our data files and useful programs, it alsomanages configuration information required for the operating system to provide us a consistent environmentevery time we restart the computer. • It also enforces security and allows us to control access to our files. • Processes may read, write, append, delete, move, or rename files and directories. • The file system defines therules of the game when such operations are performed.

  3. What Is the File System? • The shell, combined with a host of other programs, allows us to navigate the file system and get our tasksdone. • Depending on the distribution and installed software, we may also use file managers to navigate the filesystem. • In the case of Red Hat Linux 9, we may use the Nautilus file manager.

  4. What Is the File System? • Linux treats almost all devices as files. • Hard disks, terminals, printers, and floppy disk drives are all devices − devices that can be read from and written to (mostly). • In fact, with the proc file system, Linuxgoes so far as to provide a file system abstraction to running processes.

  5. What Is the File System? • Linux supports a wide variety of file system types including Microsoft Windows file system types. • In fact, Linux even allowsremote Windows−shared file systems to be accessed locally using Samba.

  6. The Anatomy of a File • creating a file with a line of data in it: • $ cat >dissectme.txt • ^D • $ ls −1 dissectme.txt • Now that we have created our file, let's list it with the ls command: • −rw−r−−r−− 1 deepakt users 21 Jan 19 18:40 dissectme.txt

  7. The Anatomy of a File • We examining the various attributes of a file. • By attributes, we mean the various characteristicsof the file including its name, date of creation, permissions to access it, and so on. • file and directory names in Linux are case−sensitive − that is, bluecurve.txt, Bluecurve.txt andBLUECURVE.txt are all different file names.

  8. File Types • The first column (that is, the −rw−r−−r−− segment)has information about the type of the file and the permissions to access it. • The first '−' symbol indicates thatthe file is a regular file and not a directory or other type of file. • The first character of the ls − l listing alwaysindicates the type of the file, to tell us whether it is a regular file, a directory • In the listing for the/etc directory, the first letter indicating the type of the file is the letter 'd', confirming that /etc is indeed a directory:

  9. File Types • $ ls −ld /etc • drwxr−xr−x 59 root root 8192 Jan 19 18:32 /etc • In the next two listings, we initially list one of the first hard disks on the system, /dev/hda in this case. • We seethe letter b, which indicates that this is a block device.

  10. While listing the terminal device /dev/tty, we see thatthe letter c indicates a character device: •  $ ls −l /dev/hda • brw−rw−−−− 1 root disk 3, 0 Aug 30 16:31 /dev/hda • $ ls −1 /dev/tty • crw−rw−rw− 1 root root 5, 0 Aug 30 16:31 /dev/tty

  11. A block device performs input and output in blocks of data. • for example, when we read a file from the harddisk, data is read in multiples of a block of (say) 4096 bytes. • By contrast, a character device (such as aterminal) reads and writes data one character at a time.

  12. A link is not really a file by itself; rather, it is a pointer to another file. • Theletter 'p' indicates that this is a FIFO: •  $ mknod myfifo p • $ ls −1 myfifo • The Anatomy of a File • prw−r−−r−− 1 deepakt users 0 Jan 19 19:09 myfifo

  13. A FIFO is a mechanism used by processes to talk to each other, therefore known as aninter−process communication mechanism or IPC. • FIFO is an acronym for "First In, FirstOut", Programmers, rather than end−users, deal with FIFOs.

  14. Another command that is useful in checking the type of files is the file command. • It does more than just listthe type of the file; it is often able to distinguish between files of the same type. • That is, it can differentiatebetween a regular text file and a program file:

  15. $ file /etc /dev/hda /dev/tty /bin/sh /bin/bash dissectme.txt myfifo • /tmp/ssh−*/* • /etc: directory • /dev/hda: block special (3/0) • /dev/tty: character special (5/0) • /bin/sh: symbolic link to bash • /bin/bash: ELF 32−bit LSB executable, Intel 80386,

  16. Linux treats files as a 'stream of bytes', without record boundaries; that is, there are no special characters used by the system to distinguish, say, one line from the next. • On the other hand, even though files on MicrosoftWindows operating systems also do not have explicit record boundaries, the operating system uses theconvention that text files have a carriage return−line feed pair at the end of lines. • The operating system alsouses different modes for opening files as text or binary files. •  unix executable files don't have extensions like .comor .exe.

  17. Links • When we listed the /bin/sh file, we noted that it is in fact a link to the file /bin/bash. • In other words, /bin/sh isnot really a file in itself, but anyone executing /bin/sh is actually executing /bin/bash. • since Bash is a replacement for the sh shell. • let us consider a program which has two different modes ofoperation; • in mode one, it copies files, • in mode two, it renames files.

  18. One way to switch between themodes of the program is to pass it an option, • say foo −c file1 file2 would create a copy of file1 named file2. • Ifwe pass it the −m option (that is, foo −m file1 file2), it would create a copy of file1 named file2 but wouldalso remove file1 (therefore effectively renaming it). • Another way to switch modes would be to create two links to the file foo, one named copy and the othernamed rename.

  19. Now the program foo needs to figure out only the name it was invoked with to switch to theappropriate mode. • In other words, if it was invoked with the name copy, foo would copy the file, • and if it wasinvoked with the name rename, it would copy the file and remove the original.

  20. The concept of a link is analogous to that of a shortcut in Microsoft Windows. • A link allows us to refer to afile (or directory) by a different name, even from a different directory altogether. • This leads us to another useof links − version management of software.

  21. Here, we can see that libc.so.6 is actually a symbolic link to the actual library libc−2.2.93.so. • This means thatif the library is upgraded from version 2.2.93 to (say) 2.2.94, the upgrade process removes the link betweenlibc.so.6 and libc−2.2.93.so and creates a new link between libc.so.6 and libc−2.2.94.so. • This ensures that theprograms referring to libc.so.6 need not be modified every time a library they refer to is changed.

  22. This applies not just to libraries, but also to executable programs. • Users typically refer to the program by alink, while system administrators can replace the actual executable with a newer version unknown to the user

  23. Hard Links and Symbolic Links • Links come in two flavors: hard links and symbolic links (also known as soft links). • operating system mostly refers to a file by its inode number. • The inode number is unique only within a disk partition. • In other words, it is possible for two files on differentpartitions (say, one on the /boot partition and another on the / partition) to have the same inode number.

  24. Thedf command can be used to list the partitions on our system. • To see the inode number of a file, we could usethe ls command again, this time with the −i option: • $ ls −li /etc • total 2012 • 226972 −rw−r−−r−− 1 root root 15228 Aug 5 03:14 a2ps.cfg

  25. The inode number is listed in the first column. Each file has a unique inode number. • While both hard linksand symbolic links are used to refer to another file, the real difference is in the inode number: • Hard links have the same inode number as the original file. • Symbolic links have their own unique inode number. • create both hard links and symbolic links • $ ln dissectme.txt hard.txt • $ ln −s dissectme.txt soft.txt

  26. Both hard links and symbolic links can be created using the ln command. • While the −s option of the lncommand creates a symbolic link, with no options it creates a hard link.

  27. When we list all three files with the −i option of ls, we see that inode numbers of the hard link and the inode number of the actual file are the same: •  $ cat dissectme.txt hard.txt soft.txt • Innards of this file • Innards of this file • Innards of this file •  When we list the contents of the file and the links, we see that output is just the same, indicating that all threeare actually referring to the same file. 

  28. Now let's try something else: • $ pwd • /home/deepakt • $ ln /boot/boot.b boot.b_hard ln: creating hard link 'boot.b_hard' to '/boot/boot.b': Invalid cross−devicelink • $ ln −s /boot/boot.b boot.b_soft • $ ls −al boot.b_soft lrwxrwxrwx 1 deepakt users 12 Jan 19 20:21 boot.b_soft −> /boot/boot.b

  29. When we attempt to create a hard link to a file on a different partition, the operating system does not allow usto do so. • This is because inode numbers are unique only within a partition and a hard link requires the sameinode number as the link target, which may not be possible on a different partition. • However, we are able tosuccessfully create a symbolic link to a file on a different partition

  30. Links are commonly used for organizing shared directories. • For instance, a project group may choose to sharefiles in a directory called /var/documents. • Users who wish to share documents may choose to leave thedocuments in any subdirectory under their own home for ease of maintenance. • This is how a typical directorystructure would look like in this case:

  31. $ ls −l /var/documents • total 0 • lrwxrwxrwx 1 deepakt users 22 Feb 23 23:54 deepakt −> /home/deepakt/joe_docs • lrwxrwxrwx 1 zora users 18 Feb 23 23:55 zora −> /home/zora/work/blueprints • lrwxrwxrwx 1 sarah users 18 Feb 23 23:55 sarah

  32. Ownership of Files • Every file stored on a Linux system has an owner − this indicates the creator of the file. • Each file also has thenotion of a group associated with it. • A group is essentially a group of users (a number of groups exist on thesystem by default − including the groups users, administrators, and daemon).

  33. The file /etc/group has acomplete list of available groups on the system: • $ cat /etc/group • root:x:0:root • bin:x:1:root,bin,daemon • daemon:x:2:root,bin,daemon • sys:x:3:root,bin,adm • ... • users:x:100:deepakt • ntp:x:38: • ...

  34. The first column indicates the name of the group; • the second column indicated by an x character is thepassword column; • the third column is the group ID of the group which is a unique number for the group. • Thelast column is a list of users who belong to the group. • In this case, the group users has a group id of 100 andthe user deepakt belongs to it.

  35. It is possible to assign access control based on group membership. • For instance, we can arrange for all themembers of a certain project to belong to the same group, and set up group access permissions for that groupto all the project−related documents on our Linux system. • we could allow access to thesedocuments for all users belonging to that group and to no other users.

  36. By default, the group of the file is the same as the group that the creator of the file belongs to. • However, it ispossible to change a file's group so that it is different from that of its owner. • To change the ownership of afile, we use the chown command; • to change its group, we use the chgrp command.

  37. File Permissions •  In the ls listing above, the −rw−r−−r−− part of the output indicates the permissions associated with a file. • Thepermissions block is split into three parts: • The first part indicates the read, write, and execute permissions for the owner. • The second indicates the read, write, and execute permissions for the group. • The last part indicates the read, write, and execute permissions for the rest of the world (that is, userswho do not belong to the group of this file).

  38. There are a number of different characters we use here to reflect permissions: • · An r indicates read permission • · A w indicates write permission • · An x indicates execute permission • · A hyphen (−) indicates that a particular permission is denied

  39. Directory Permissions • For a directory, "read", "write", and "execute" have slightly different meanings: • The "read" permission refers to the ability to list the files and subdirectories contained in thatdirectory. • The "write" permission refers to the ability to create and remove files and subdirectories within it. • The "execute" permission refers to the ability to enter the directory using the cd command (in otherwords, change the current working directory to be this directory).

  40. We can use the chmod command to change permissions for a file − by specifying the permissions for the owner, group, and others. • So what are the default permissions when we create a file? • This is controlled by the default file creation mask,which can be set using the umask command.

  41. A File and Directory Permissions • Let's create a file and a directory and experiment with changing permissions and ownership. First, we'll list thecurrent file mask: • $ umask −S • u=rwx, g=rw, o=rw • Here the −S option prints out the default file mask in rwx form. • This mask allows owners to read, write, andexecute files; it allows the group and others read and write permissions, but no execute permissions.

  42.  Now, let's modify the file mask: $ umask u=rwx,g=r,o=r $ umask −S u=rwx,g=r,o=r

More Related