19
Hard Disk Drives and UNIX File System EEN 322 Systems Programming November 18th, 2014

Hard Disk Drives and UNIX File System EEN 322 Systems Programming November 18th, 2014

Embed Size (px)

Citation preview

Hard Disk Drives and UNIX File System

EEN 322 Systems ProgrammingNovember 18th, 2014

Hard Disk Drive (HDD)

1. Attached to a computer by I/O bus (SATA/SCSI)2. Host controller3. Disk controller4. Memory-mapped I/O

ports5. Built-in cache on disk

controller

Hard Disk Drive (HDD)

1. Attached to a computer by I/O bus (SATA/SCSI)2. Host controller3. Disk controller4. Memory-mapped I/O

ports5. Built-in cache on disk

controller

IBM 305 RAMAC Disk System (1956- 1969)

Hard Disk Drive (HDD)

1. Attached to a computer by I/O bus (SATA/SCSI)2. Host controller3. Disk controller4. Memory-mapped I/O

ports5. Built-in cache on disk

controller

Structure of HDD

TI/O= Tseek + Trotation + Ttransfer

File System

1. Tasks: a. Provide user interfaceb. Mapping between user interface and device

2. FAT32, NTFS, ext family (ext2, ext3, and ext4)

3. UFS4. Format, Partition

Big Picture

1. Application programs: Client of file system2. Logical file system: metadata information

a. file system structure data except real datab. file control block (inode)

3. File organization module: logical/physical blocksa. logical block to physical block translationb. Free block management

4. Basic file system: command to device drivera. Block 88 -> (drive 1, cylinder 73, track 2,

sector 10)b. Manage buffers and caches.

5. I/O control: device driver and interrupt handlera. Read block 88 -> Disk controller instruction

6. Devices: HDD, CD/DVD, SSD

File Types

1. Regular file2. Directory file3. Symbolic link 4. Character file5. Block file6. Named pipe or FIFO7. Socket

Disk Organization

1. /etc/fstab and /etc/mtab2. mount -t iso9660 -o ro /dev/cdrom /mnt

Disk Drive and UFS Illustration

UNIX inode

1. struct describe a file2. flags3. generation numbers4. inode definition in

sys/ufs/ufs/dinod.h

Link

1. A directory entry point to the inode2. Created by: $ln /dirA/name1 /dirB/name2

open("/dirA/name1");readclosemodify memory image of the fileunlink("/dirA/name1");open("/dirA/name1");writeclose

Link

After unlink /dirA/name1

Symbolic Link

1. File contain the name of another file/directory2. Created by: $ln -s /dirA/name1 /dirB/name2

Access Privilege

1. Least-privilege: given only those privileges that it needs in order to complete its task.

2. What about change your password?3. UNIX process IDs

4. setuid(), seteuid(), setreuid() syscalls

setuid(), seteuid(), setreuid()

1. int setuid(uid_t uid); 2. int seteuid(uid_t uid); 3. int setreuid(uid_t ruid, uid_t euid);

Setuid Programs

1. passwd, su, chsh2. setuid bit for a program file.

#ls -l /usr/bin/passwd -r-sr-xr-x 2 root wheel 6444 Nov 17 2014

/usr/bin/passwd

3. How passwd use seteuid to access the password file /etc/pwd.db?

Exercise

Your classmate allow you to use his/her account in a system you also has an account. How can you take over his/her account in 10 seconds?

Exercise

Your classmate allow you to use his/her account in a system you also has an account. How can you take over his/her account in 10 seconds?victim$cp /bin/sh /tmpvictim$chmod 4777 /tmp/sh

attacker$cd /tmpattacker$./sh victim$