Operating System & Administration UNIT-III Introduction to File System.

65
Operating System & Administration UNIT-III Introduction to File System

description

What is a file File is a collection of data items stored on disk. Or, it's device which can store the information like data, music (mp3 files), picture, movie, sound, book etc. In fact whatever you store in computer it must be in the form of file. File is the last object in your file system tree.

Transcript of Operating System & Administration UNIT-III Introduction to File System.

Page 1: Operating System & Administration UNIT-III Introduction to File System.

Operating System &

Administration

UNIT-IIIIntroduction to File System

Page 2: Operating System & Administration UNIT-III Introduction to File System.

OUTLINE

1.PathName

2.File System Mounting and Unmounting

3.Organization of File Tree

4.File Type

5.File Attribute

6.Access Control List

Page 3: Operating System & Administration UNIT-III Introduction to File System.

What is a file • File is a collection of data items stored on disk. Or, it's

device which can store the information like data, music (mp3 files), picture, movie, sound, book etc.

• In fact whatever you store in computer it must be in the form of file.

• File is the last object in your file system tree.

Page 4: Operating System & Administration UNIT-III Introduction to File System.

Component of File System

• A namespace – a way to name things and organize them in a hierarchy

• An API – a set of system calls for navigating and manipulating objects

• A security model – a scheme for protecting, hiding, and sharing things

• An implementation – software to tie the logical model to the hardware.

• Note:- file should not contain / in between file name characters.

Page 5: Operating System & Administration UNIT-III Introduction to File System.

• Modern kernels define an abstract interface that contains many different back-end filesystems.

• Windows - NTFS, FAT• Linux - Ext

– Ext2– Ext3– Ext4

Page 6: Operating System & Administration UNIT-III Introduction to File System.

Linux file system(History)• It has maximum size limit of 64 megabytes• There was also a filename length limit of 14 characters.• In 1991 a new file system came with addition of new

file system as a layer on top of linux kerenl that provide generic file API. Termed as VFS termed as ext.

• But has problems like allowed 2 gigabytes of data and filenames of up to 255 characters. with problems like there was no support for separate access, inode modification and data modification with timestamps.

Page 7: Operating System & Administration UNIT-III Introduction to File System.

• Ext2:-– Introduced in 1993 by Rémy Card.– maximum filename length of 255 characters– has variable length block size(maximum data size of

2047 gigabytes). – Maximum individual file size can be from 16 GB to 2TB– Overall ext2 file system size can be from 2 TB to 32 TB

Page 8: Operating System & Administration UNIT-III Introduction to File System.

• Ext3:-– Introduced in 2001 by Stephen Tweedie – The main benefit of ext3 is that it allows journaling.– Journaling has a dedicated area in the file system, where all

the changes are tracked. When the system crashes, the possibility of file system corruption is less because of journaling.

– maximum filename length of 255 characters– Maximum individual file size can be from 16 GB to 2 TB– Overall ext3 file system size can be from 2 TB to 32 TB

Page 9: Operating System & Administration UNIT-III Introduction to File System.

Ext4• It was introduced in 2008.• Starting from Linux Kernel 2.6.19 ext4 was available.• Supports huge individual file size and overall file system

size.• Maximum individual file size can be from 16 GB to 16

TB• Overall maximum ext4 file system size is 1 EB (exabyte).

1 EB = 1024 PB (petabyte).• 1 PB = 1024 TB (terabyte).

Page 10: Operating System & Administration UNIT-III Introduction to File System.

• Directory can contain a maximum of 64,000 subdirectories (as opposed to 32,000 in ext3)

• You can also mount an existing ext3 filesystem as ext4 filesystem (without having to upgrade it).

• Several other new features are introduced in ext4:– multiblock allocation,– delayed allocation,– journal checksum. fast fsck, etc. – All you need to know is that these new features have improved

the performance and reliability of the filesystem when compared to ext3

Page 11: Operating System & Administration UNIT-III Introduction to File System.

11

Filesystem Hierarchy Standard

• Started by Dennis Ritchie, 1993• Defines the main directories and their contents in most

Linux-based systems

Page 12: Operating System & Administration UNIT-III Introduction to File System.

12

FHS• There is no any drive C:, D:, …• All directories are under “/”

– “/” is the root directory• It is possible

– to have multiple partitions– to multiple filesystems

Page 13: Operating System & Administration UNIT-III Introduction to File System.

13

The “/”

• The primary hierarchy in FSH– The root of tree of filesystem

• All paths start form here• There is only one “/” in filesystem

Page 14: Operating System & Administration UNIT-III Introduction to File System.

Pathname

• What is Path• Path Types• Setting Path

Page 15: Operating System & Administration UNIT-III Introduction to File System.

What is path• A path is a unique location to a file or a directory in a

file system of an OS. • A path to a file is a combination of / and alpha-numeric

characters• Ex.

– /home/fedora/abc.txt– /etc/passwd– /proc/partitions– /etc/yum.d/yum.conf

Page 16: Operating System & Administration UNIT-III Introduction to File System.

Path Types in Linux• Absolute path -An absolute path is defined as the specifying the

location of a file or directory from the root directory(/). -In other words we can say absolute path is a complete

path from start of actual filesystem from “ / “directory• Relative path

-Relative path is defined as path related to the present working directory(pwd).

Page 17: Operating System & Administration UNIT-III Introduction to File System.

Examples of relative path and absolute path

• Example1: Present location is /abc/xyz,

remove /abc/xyz/read/hello.txt file.

Using relative path:rm read/hello.txt

Using absolute path:rm /abc/xyz/read/hello.txt

Page 18: Operating System & Administration UNIT-III Introduction to File System.

• Example2: My present location is /etc/samba and now I want to change directory to /etc.Using relative path:cd ..Using absolute path:cd /etc

Note:- there should be no ‘/’ in file Name Ex:- “abc/pqr” it will be assumed that pqr is in

abc directory

Page 19: Operating System & Administration UNIT-III Introduction to File System.

19

The Organization Of The File Tree

/

boot bin dev etc lib proc root sbin tmp usr var

Page 20: Operating System & Administration UNIT-III Introduction to File System.

boot

• Linux kernel• Boot loader configuration • vmlinuz-2.6.3.1 is a executable that loads

operating system in memory.(vmlinuz is a kernel).• If you lost boot

– You cannot boot your OS

Page 21: Operating System & Administration UNIT-III Introduction to File System.

21

boot

boot

vmlinuz-2.6.12 config-2.6.12 grub

grub.conf

Grand Unified boot LoaderDev by Erich Stefan Boleyn

Page 22: Operating System & Administration UNIT-III Introduction to File System.

22

bin

• Essential programs • Need for system startup• Common programs, shared by the system, the system

administrator and the users.• Basic commands for

– Navigating in filesystem– File management

Page 23: Operating System & Administration UNIT-III Introduction to File System.

23

bin

bin

bash bzip2 cat gzip ls mv rm...

Page 24: Operating System & Administration UNIT-III Introduction to File System.

24

dev

• Everything is file – Hardware components (devices) are file

• Hard disk• Key board

• All device files are here• Direct interaction with device driver

– Open the device file– Read & Write

Page 25: Operating System & Administration UNIT-III Introduction to File System.

25

dev

dev

hda fda sda tty random null...

Page 26: Operating System & Administration UNIT-III Introduction to File System.

etc

• System configuration directory • Critical startup and configuration files• All configuration file are text files

– You can view and edit it manually

Page 27: Operating System & Administration UNIT-III Introduction to File System.

27

etc

etc

bashrc fstab inittab passwd shadow X11

X11.conf

init.d

network named httpd

Page 28: Operating System & Administration UNIT-III Introduction to File System.

28

home

• Home directory of user• Each user has a directory

– /home/xyz– /home/abc

• All files of user are stored here

Page 29: Operating System & Administration UNIT-III Introduction to File System.

29

lib

• Libraries, shared libraries and parts of the C compiler

• Programs need libraries– Dynamically linked libraries

• All essential libraries are here– Needed for system startup

Page 30: Operating System & Administration UNIT-III Introduction to File System.

30

lib

lib

libc libm libcrypt libpthread modules

Page 31: Operating System & Administration UNIT-III Introduction to File System.

31

proc

• Information about all running processes• It represent current state of kernel

Page 32: Operating System & Administration UNIT-III Introduction to File System.

Directories with names as numbers

Do a ls -l /proc, and you’ll see lot of directories with just numbers. These numbers represents the process ids, the files inside this numbered directory correspond to the process with that particular PIDFollowing are some file located in proc directory as• cmdline – command line of the command.• environ – environment variables.• fd – Contains the file descriptors which is linked to the

appropriate files.• limits – Contains the information about the specific limits to the process.

Page 33: Operating System & Administration UNIT-III Introduction to File System.

Files about the system information

It contains system information such as cpuinfo, meminfo,

• /proc/cpuinfo – information about CPU,• /proc/meminfo – information about memory,• /proc/partitions – partition related information,• /proc/version – linux version

Page 34: Operating System & Administration UNIT-III Introduction to File System.

• mounts – mount related information

Page 35: Operating System & Administration UNIT-III Introduction to File System.

35

proc

proc

cpuinfo meminfo devices interrupts net sys

tcp udp kernelnet

1 129

Page 36: Operating System & Administration UNIT-III Introduction to File System.

36

root

• Home directory of root user or super user• Don’t confuse

– / is the “root of Filesystem”– root is the name of system admin– /root is the admin

Page 37: Operating System & Administration UNIT-III Introduction to File System.

37

sbin

• It contains executable programs (ready to run).• They are mostly admin tool and made available to

root user.• System configuration programs

– Format hard disk (fdisk,fsck, ifconfig,modinfo(info for kernel module)

– Halt, reboot,fasthalt(stop system without disk checking).

Page 38: Operating System & Administration UNIT-III Introduction to File System.

• /sbin should contain only binaries essential for booting, restoring, recovering, and/or repairing the system in addition to the binaries in /bin.

Page 39: Operating System & Administration UNIT-III Introduction to File System.

39

sbin

sbin

fsck mkfs mount adduser poweroff...

Page 40: Operating System & Administration UNIT-III Introduction to File System.

40

tmp

• Temporary directory• All temp files are created by programs• Your temp files• It is emptied regularly

Page 41: Operating System & Administration UNIT-III Introduction to File System.

41

usr

• It contains all the user binaries, their documentation, libraries, header files, etc and its supporting libraries can be found here.

• Also termed as Secondary hierarchy • Very useful programs

– We usually use them for • compiler, tools

• Are not essential for system startup

Page 42: Operating System & Administration UNIT-III Introduction to File System.

• /usr/bin:-– This directory contains the vast majority of binaries on

your system.– Executables in this directory vary widely. – For instance vi, gcc, gnome-session and mozilla and are all

found here.• /usr/doc:-

– The central documentation directory. – Documentation is actually located in /usr/share/doc and

linked from here.

Page 43: Operating System & Administration UNIT-III Introduction to File System.

43

usr

usr

bin doc include lib local sbin src

Linux-2.6.14

Page 44: Operating System & Administration UNIT-III Introduction to File System.

44

var• Contains variable data like system logging files, mail and

printer spool directories, and transient and temporary files.• Some portions of /var are not shareable between different

systems.like– /var/log, /var/lock, and /var/run.

• The shared – /var/mail, /var/cache/man, /var/cache/fonts, and

/var/spool/new• The variable directory • All dynamic files, User cannot change the files

Page 45: Operating System & Administration UNIT-III Introduction to File System.

45

var

var

cache lib lock log www named

message boot.log

Page 46: Operating System & Administration UNIT-III Introduction to File System.
Page 47: Operating System & Administration UNIT-III Introduction to File System.

47

File Types

• Filesystem implementation define seven types of files

1. Regular files2. Directories3. Character device files4. Block domain sockets5. Local domain sockets6. Named pipes (FIFO)7. Symbolic links

Page 48: Operating System & Administration UNIT-III Introduction to File System.

48

• How to create and remove files

Page 49: Operating System & Administration UNIT-III Introduction to File System.

49

Regular File :• It is consist of a series of bytes, filesystems

impose no structure on their contents.• Example: text files, data files, executable

programs.

Directories :• It contains named references to other files.

Page 50: Operating System & Administration UNIT-III Introduction to File System.

50

Character and Block device files :• Device files let programs communicate with the system’s

hardware and peripherals.• The kernel loads driver software for each of the system’s

devices.

• Character device files allow their associated drivers to do their own i/p and o/p buffering.

Device DriverFiles

HardwareProgram request

Page 51: Operating System & Administration UNIT-III Introduction to File System.

51

• Block device files are used by drivers that handle i/o in large chunks and want the kernel to perform buffering for them.

• Device files are characterized by two numbers, called the major and minor device numbers.

• The major device number tells the kernel which driver the file refers to, and the minor device number typically tells the driver which physical unit to address.

Page 52: Operating System & Administration UNIT-III Introduction to File System.

52

Local domain sockets :• Sockets are connections between processes that

allow processes to communicate.• Local domain sockets are accessible only from the

local host and are referred to through a filesystem object rather than a network port.

Page 53: Operating System & Administration UNIT-III Introduction to File System.

53

Named pipes :• It also allow communication between two

processes running on the same host. It is also known as “FIFO files”

Page 54: Operating System & Administration UNIT-III Introduction to File System.

54

Symbolic links :• Symbolic or “soft” link points to a file by name.• Pathname stored as the contents of the link.• Links : hard link and soft link• Hard link is a direct reference• Soft link is a reference by name

Page 55: Operating System & Administration UNIT-III Introduction to File System.

55

File Attributes

1. Permission bits :• Every file has a set of nine permission bits that

control who can read , write, and execute the contents of the file.

• There are 3 basic permissions– Read (r)– Write (w)– Execute (x)

• How to change them– chmod +/- r/w/x <filename>

Page 56: Operating System & Administration UNIT-III Introduction to File System.

56

• File permissions in terms of octal numbers because each digit of an octal no. represents three bits and each group of permission bits consists of three bits.

• In each triplet bits, the high bit is the read bit, middle bit is the write bit, and low bit is the execute bit.

• Two types of executable files exist: binaries, which the CPU runs directly , and script, which must be interpreted by a shell (bash or sh scripts).

Page 57: Operating System & Administration UNIT-III Introduction to File System.

57

2. Chmod : change permissions• Chmod cmd changes the permissions of a file.• Only the owner of the file and the superuser can

change its permissions.• Permission encoding for chmod:

Page 58: Operating System & Administration UNIT-III Introduction to File System.

58

3. chown and chgrp : change ownership and group:

• Using –R flag to change the setting of a directory and all the files underneath.

• Example : chown –R user:group dir/.*

4. umask : assign default permissions

Page 59: Operating System & Administration UNIT-III Introduction to File System.
Page 60: Operating System & Administration UNIT-III Introduction to File System.

60

Mounting and Unmounting

• Mount :– To add a filesystem to other filesystem

• Filesystems are attached to the tree with the mount cmd.

• Mount maps a directory within the existing file tree, called the mount point, to the root of the newly attached filesystem.

• The previous contents of the mount point become inaccessible as long as another filesystem is mounted there.

• Mount points are usually empty directories.

Page 61: Operating System & Administration UNIT-III Introduction to File System.

61

• How?– mount <options> <device> <mount point>– mount -t vfat /dev/sdb1 /mnt/flash

• To detach filesystems with the umount cmd.• Don’t forget the umount

– umount <mount point>– umount /mnt/flash

Page 62: Operating System & Administration UNIT-III Introduction to File System.

Access Control List

• What is an ACL?– Access Control List: collection of Access

Control Entries (ACEs) associated with a file.• What is an ACE?

– A structure specifying permission for a user, group, or other entity.

Page 63: Operating System & Administration UNIT-III Introduction to File System.
Page 64: Operating System & Administration UNIT-III Introduction to File System.

setfacl

• User command utility to set, modify, or delete ACLs on a file

• Can be ran by file owner or anyone given permission to modify permissions

• Sample commands:– setfacl –s u:alice:+rx:i myFile– setfacl –m o::drwx myFile– setfacl –u myFile– setfacl –d u:alice myFile

Page 65: Operating System & Administration UNIT-III Introduction to File System.

getfacl

• User utility to examine the ACL on a particular file

• Examines a file’s inode to detemine what permissions are set

• Sample:– getfacl myFile