Upload
vuongcong
View
239
Download
1
Embed Size (px)
Citation preview
The Linux Filesystem
History
Filenames
Filesystem
Inodes
File Attributes and Types
CST8207 - Algonquin College 2
Chapter 6 (Pages 188 to 222) and
Chapter 12 (Pages 480 – 486)
CST8207 - Algonquin College 3
CST8207 - Algonquin College 4
First there was a punch card (used in various forms since 1726 – a punched paper loop) (http://www.fourmilab.ch/documents/univac/cards.html)
Then there was punch tape
Then, in 1946, came Selectron tubes ◦ A 10 in long tube that could store about 4096 bits
◦ They were VERY expensive ($500 for a 256 bit version)
In the 1950s magnetic tape came along
Believe it or not cassette tapes were popularized in the 1970s
CST8207 - Algonquin College 5
Selectron tubes were replaced with “core memory” – early computer memory ◦ Made up of small magnetic ceramic rings ◦ Stored information based on the polarity of the
magnetic fields
The world’s first Hard Drive was created in 1956 and was able to store a massive 4.4MB of data ◦ The data was stored on fifty 24-inch magnetic
platters ◦ IBM leased the 305 RAMAC for $3200 a month!
The floppy disk wandered onto the scene in 1969 (it was 8 inches and stored 80kB of data) ◦ In 1973 the data capacity was increased to 256kB
CST8207 - Algonquin College 6
In 1958 the Laserdisc was invented ◦ In 1978, the first laserdisc player was introduced
to the market
In 1979 the CD was developed and reached the market in 1982
Then the DVD, USB, Blu-ray, HD DVD, Next: Holographic Versatile Disk (3.9TB)?
◦ 160 times what a Blu-ray can ◦ 4 600 to 11 900 hours of video using MPEG4
encoding ◦ Transfer rate of 1GB/sec
Or Protein-Coated Disc (50 TB)?
CST8207 - Algonquin College 7
From http://gadgets.fosfor.se/history-of-data-storage/
1 8.4GB DVD can be stored on: ◦ 90 000 000 Punch cards
◦ 6 000 Floppies
◦ 4 500 cassette tapes (281 days to “restore”)
◦ 0.2% of a Holographic Versatile Disk (3.9TB!)
CST8207 - Algonquin College 8
A filesystem is a collection of directories and files. A Unix/Linux system usually contains more than one filesystem.
Each filesystem does not have to exist on a single hard disk.
One hard disk may contain several filesystems or a single filesystem may be spread across multiple hard disks
9 CST8207 - Algonquin College
Most of today’s filesystems used in Linux allow you create files with names up 255 characters long
You can use almost any character in a filename
It’s a poor idea to use spaces within filenames ◦ If a filename that includes a space, you must quote the
space on the command line by preceding it with a backslash or by placing quotation marks around the filename
◦ Rule of thumb: If you want a space in the filename, use an underscore (_) instead.
◦ Example, instead of a file name use a_file_name
10 CST8207 - Algonquin College
A filename extension is part of the filename following a period. It helps describe the contents of the file
Extensions in the context of Linux do not exist.
A filename begins with a period is called a hidden filename
While you are in text mode (command prompt) of a Linux system, you are always associated with a directory that is called the working directory or current directory.
The pwd command displays the pathname of the working directory
11 CST8207 - Algonquin College
There is common ground between Linux and other O/S filesystems
Linux maintains a hierarchical filesystem structure
◦ all visible filesystems, directories and files as part of one main directory, the root (/) filesystem, and exist in directories under it
◦ the root (/) filesystem typically has it’s own partition, and contains critical information necessary for the system to run
◦ all other filesystems, local or remote, are mounted as subdirectories of the root (/) filesystem
◦ every path used is relative to root (/) or to the current directory the user is in
12 CST8207 - Algonquin College
Linux allow for maintaining any number of files and directories under the root (/) filesystem, organized in any way desired
◦ leads to a parent-child relationship between a directory and it’s subdirectories/files
CST8207 - Algonquin College 13
/ (root)
dev bin usr
bin elvis hda1 null
file1 file2 ls cat
Some pre-defined Directories by Fedora ◦ / - root directory (NOT the root user) ◦ /bin - most essential UNIX/Linux commands, such
as ls ◦ /boot - kernel and other files used during booting
are stored
◦ /dev - file interface for devices for hardware ◦ /etc - System configuration files ◦ /home - user personal directory and files ◦ /lib - libraries necessary to run executables in
/bin and /sbin ◦ /mnt - default directory for mounting non-
permanent devices
CST8207 - Algonquin College 14
A filesystem is the logical means for the O/S to store and retrieve data on available storage mediums ◦ create, move & delete files and directories (touch mkdir cp mv rmdir rm)
◦ modify filename (mv) ◦ open files for reading and writing (vi) ◦ Search for files (find) ◦ seek within a file (grep) ◦ list content of a directory (ls) ◦ etc...
CST8207 - Algonquin College 15
The aforementioned basic functions are common to most operating systems
However, how they are implemented and managed can differ drastically from one O/S to another
Can also impact on the effectiveness of the filesystem
In Linux, the file concept is simple:
◦ A file is a sequence of bytes. ◦ Therefore, everything, including network card, hard
drive, keyboard, printer, a simple file/directory is treated as a file.
◦ As a result, all input and output devices and directories are also treated as files in Linux.
CST8207 - Algonquin College 16
Linux stores information about each file in a data structure called an inode.
Each inode is identified by a unique number called the inode number.
Every Linux filesystem begins with a large set of inode numbers. ◦ When files are created the system creates an
inode to describe the file and assigns the inode an empty inode number
◦ When files are deleted the system removes its inode and marks the inode number as empty
◦ A filesystem cannot create a new file unless it has an empty inode number.
CST8207 - Algonquin College 17
filesystems store inode numbers in a file called the inode list.
Inode numbers are specific to a single filesystem. Every file on a filesystem has a unique inode number
Use the -i option with the ls command, to list the inode number of files.
◦ ls -i
CST8207 - Algonquin College 18
CST8207 - Algonquin College 19
…… ……
…… ……
File description 12005
12004
File description 12003
File description 12002
12001
File description 12000
The name and owner of the file The length of the file in bytes Device ID The User ID of the file's owner The Group ID of the file An inode number The file mode, which determines what users can
read, write, and execute the file. Timestamps telling when the inode itself was last
changed (ctime), the file content last modified (mtime), and last accessed (atime).
A reference count telling how many hard links point to the inode.
CST8207 - Algonquin College 20
simple file
directory
symbolic link
special file (device)
named pipe (FIFO)
CST8207 - Algonquin College 21
Used to store information and data on a secondary storage device, typically a disk
Can contain source code, executable program,
postscript code, pictures, audio, graphics, text, etc.
Linux doesn’t impose any naming conventions on files of any types. File name can be up to 255 characters
You can give file name any extensions, but the extensions mean nothing to Linux system
Some applications require extensions, some not
CST8207 - Algonquin College 22
named file container within the / (root) hierarchy
contains names of other files and/or directories
files sometimes referred to as nondirectory files
CST8207 - Algonquin College 23
symbolic link to an existing file and/or directory on the system
points to existing file/directory, allowing for sharing it without actually duplicating it’s contents
To create a symbolic link from slinkname to oldfilename:
ln -s oldfilename slinkname
A text editor that accesses slinkname will be redirected so that it acts on oldfilename. The ls command will list slinkname as a file rather than being redirected to oldfilename.
Removing oldfilename deletes the physical file Removing slinkname has no effect on oldfilename
CST8207 - Algonquin College 24
CST8207 - Algonquin College 25
Is a connection between a filename and inode number
A user identifies files by filename while the kernel identifies files by the inode number
One file can have any number of hard links. The hard links provide different filenames for the same physical file
The kernel assigns the file an unused inode number and creates the physical file
To create a hard link between newfilename and oldfilename:
ln oldfilename newfilename
CST8207 - Algonquin College 26
CST8207 - Algonquin College 27
Inode: 12345
Reference Count: 4
/home/user/aFile
/home/someone/aLink
/tmp/anotherLink
/home/user/lastLink
Changes made to either oldfilename or newfilename affect both of them because the changes are made to the same physical file.
Renaming either file will not affect the other.
Removing either file will not affect the other
The physical file will not be removed from the disk until all hard links are deleted.
CST8207 - Algonquin College 28
Means of accessing hardware devices and processes
Each hardware device is associated with at least one special file
A command or application accesses a special file in order to access the corresponding device
Special files are typically stored in /dev directory
Some special files stored under /dev ◦ cdrom - CD-ROM drive ◦ fdn - floppy drive (n = drive #) ◦ hdxn - non-SCSI hard drive (x = drive #, n = partition on
drive)
CST8207 - Algonquin College 29
CST8207 - Algonquin College 30
… brw-r----- 1 root disk 253, 1 Aug 28 10:54 dm-1 brw-r----- 1 root disk 253, 2 Aug 28 10:54 dm-2 crw------- 1 root root 14, 3 Aug 28 14:54 dsp lrwxrwxrwx 1 root root 3 Aug 28 14:54 dvd -> hdc lrwxrwxrwx 1 root root 3 Aug 28 14:54 dvd-hdc -> hdc lrwxrwxrwx 1 root root 13 Aug 28 14:54 fd -> /proc/self/fd/ …
The first character of each line is always – (ordinary), b (block), c (character), d (directory), l (symbolic link), or p (named pipe)
Character devices
◦ Transferring information character by character
Block devices
◦ Transferring blocks of information using memory buffers, which is much faster than character device
◦ Example:
ls –l /dev/fd0
ls –l /dev/input/mouse0
CST8207 - Algonquin College 31
CST8207 - Algonquin College 32
/dev/sda1 /dev/lp0
/dev/hda1 /dev/tty1
/dev/fd0 /dev/input/mouse0
Block device Character devices
mechanism that enables processes to communicate with each other (InterProcess Communication mechanism or IPC primitives)
Three commonly used IPC primitives: ◦ pipes: area in kernel memory shared by processes for
communication purposes
◦ names pipes/FIFO: file allowing two processes to communicate with each other on the same computer
◦ sockets: data structure in kernel memory that can be used by processes on different computers to communicate with each other
CST8207 - Algonquin College 33
Since we won’t be doing any coding, let’s not talk about them. Shhhh!
CST8207 - Algonquin College 34