The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of...

23
The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of Computing and Engineering Galgotias University

Transcript of The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of...

Page 1: The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of Computing and Engineering Galgotias University.

The Unix File system (UFS)

Presented by:

Gurpreet SinghAssistant Professor

Department of School of Computing and EngineeringGalgotias University

Page 2: The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of Computing and Engineering Galgotias University.

Introduction

File: logically a container for data.

Filesystem: represent and organize the system’s storage

resources.

Page 3: The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of Computing and Engineering Galgotias University.

Introduction Cont’d

Some portions of a file tree are handled by traditional disk based implementation; others are fielded by separate drivers within the kernel.

A complicated factor in UNIX filesystems is that they tend to support more than one type of disk-based file systems.

Page 4: The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of Computing and Engineering Galgotias University.

Main Components

Namespace: a way of naming and arranging things in a hierarchy.

API (Application Programming Interface) : a set of system calls for navigating and manipulating nodes.

Security Model: protection mechanism to enable sharing.

Implementation: code that ties the logical model to the actual disk.

Page 5: The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of Computing and Engineering Galgotias University.

Pathnames Unix organizes files in a single hierarchy.

It starts at root directory /. It continues through an arbitrary number of subdirectories.

List of directory to be traversed to locate a file forms the pathname.

No restriction on depth of filesystem.

Page 6: The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of Computing and Engineering Galgotias University.

/

bin vmunix

hostspasswdpasswd

etc dev usr

local lib

A directory tree

Page 7: The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of Computing and Engineering Galgotias University.

Pathnames Cont’d Pathnames can be either absolute (starting at the root

directory) or relative (starting at the current directory). Each component of a pathname can not be more than

255 characters in length. To access a file with pathname longer than 1023

characters, “cd” to an intermediate directory and use a relative pathname.

No restrictions on naming of files except they are limited in length and must not contain the “/” character or nulls.

The space character is supported. Quote the file name containing spaces:

% more “My Excellent file.txt”

Page 8: The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of Computing and Engineering Galgotias University.

Mounting

One file system is configured to be the “root file system”

and its root directory becomes the “system root

directory”.

Other file systems are attached to the root file system by

mounting each new file system onto a directory in the

root file system. That “mounted on” directory is also

called the “mount point”.

The previous contents of the mount point become

inaccessible.

Page 9: The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of Computing and Engineering Galgotias University.

Mounting one filesystem to another

/

usr sys dev etc bin

/

local adm users bin

fs0

fs1

usr

/

Page 10: The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of Computing and Engineering Galgotias University.

Unmounting

File systems are detached with the unmount command.

In order to unmount a file system:

1) No files or process should be open or running.

2) If a file system contains executable programs, they must not be running.

Page 11: The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of Computing and Engineering Galgotias University.

Unmounting Cont’d

Do not use command unmount –f. It forces a busy filesystem to be unmounted and may cause crash.

Earlier versions :

a) lockfs –h dir to “hard lock” the file system.

b) unmount it normally.

To determine exactly what the offending processes are, run ps with a list of the PIDs returned by fuser.

Page 12: The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of Computing and Engineering Galgotias University.

To find out why a file system is busy, run the fuser -c dir

command.

Example:% fuser -c /usr/usr: 157tom 315ctom ……

c: a process that has a current directory on the filesystem.o: an open file.t: a running program.m: a mapped file (shared libraries usually).r: a process whose root directory is on the file system.

Unmounting Cont’d

Page 13: The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of Computing and Engineering Galgotias University.

Organization of the File Tree

Root file system contains the root directory and a minimal set of files and subdirectories.

File containing the kernel is called unix or vmunix, and it resides in either the root directory or in a subdirectory such as /kernel or /stand.

Part of the root filesystem are:/dev -- for device files. /etc -- for critical system files./sbin and /bin -- for important utilities./tmp -- for temporary files.

Page 14: The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of Computing and Engineering Galgotias University.

Organization of the File Tree Cont’d

Some systems keep shared libraries and the C preprocessor in the /lib directory. Others have moved this into /usr/lib.

/usr contains most of the user programs and online manuals etc.

/var provides a home for spool directories, log files, accounting information etc.

Home directories of users should be kept on different file systems and mounted beneath /usr.

Page 15: The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of Computing and Engineering Galgotias University.

File Types

Regular Files. Directories. Character Device Files. Block Device Files. UNIX domain sockets. Named pipes (FIFOs). Symbolic links.

A few systems do not support UNIX domain sockets and named

pipes.

Page 16: The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of Computing and Engineering Galgotias University.

File Types Cont’d

Directories

Current directory: .

Parent directory: ..

Create: mkdir

Delete: rmdir (empty directory)

Delete: rm -r (nonempty directory)

Page 17: The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of Computing and Engineering Galgotias University.

File Types Cont’d

Character and block device files

Create: mknod

Delete: rm

Unix domain sockets

Create: socket()

Delete: rm or unlink()

Page 18: The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of Computing and Engineering Galgotias University.

File Types Cont’d

Named pipes

Create: mknod

Delete: rm

Symbolic links

Create: ln -s

Delete: rm

Page 19: The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of Computing and Engineering Galgotias University.

File Attributes

Mode: 9 permission bits control who can read, write and

execute the contents of the file. 3 bits affect the operation of executable programs. the 12 bits can be changed by the owner of the file or

the superuser by using the chmod command.

16-bit word 12 bits together with 4 bits of file type information. The 4 file type bits are set when the file is first created

and can’t be changed

Page 20: The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of Computing and Engineering Galgotias University.

File Attributes Cont’d

The setuid and setgid bits: bits with octal values 4000 and 2000. They allow programs to access files and processes that would be otherwise off-limits to the user that runs them.

The sticky bit: octal value 1000. If this bit is set, most UNIX systems don’t allow you to delete them unless You are superuser, the owner of directory, or the owner of the file.

The permission bits: remaining 9 bits are permission bits. There are sets of permissions for the owner, group owner and everyone else.

Page 21: The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of Computing and Engineering Galgotias University.

File Attributes Cont’d use ls -l to view file attributes.

Example:% ls -l /bin/sh-rwxr-xr-x 1 root bin 85924 Sep 27 1997 /bin/sh

- regular filerwxr-xr-x three sets of permission bits1 link count for the fileroot owner of the filebin group owner of the file85924 size of the file in bytesSep 27 1997 the date of last modification/bin/sh name of the file

Page 22: The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of Computing and Engineering Galgotias University.

File Attributes Cont’d

chmod: changes the permissions on a file.

chown: changes a file's ownership.

chgrp: changes a file’s group ownership.

umask: asigns the default permissions.

Page 23: The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of Computing and Engineering Galgotias University.

Thanks