• No results found

Unix Programming. Session 3 VI Editor & File commands

N/A
N/A
Protected

Academic year: 2021

Share "Unix Programming. Session 3 VI Editor & File commands"

Copied!
29
0
0

Loading.... (view fulltext now)

Full text

(1)

Session –3 VI Editor

&

File commands

(2)

Review

(3)

Inode structure

Mode Time Stamp Direct Blocks Indirect Blocks Double Indirect Blocks Triple Indirect Blocks Owner Info Size

(4)

Review

(5)

Directory

 Directory is a file

 Contains sequential list of inode number and file name mapping for all files and subdirectories

 Size of directory entry was 16 bits on Unix systems –

2 bytes for inode and 14 bits for file name

(6)

Reading Directory

System calls to read directory

• opendir --- to open directory file • readdir --- to read director entry

struct dirent {

long d_ino; /* inode number */

off_t d_off; /* offset to next dirent */

unsigned short d_reclen; /* length of this dirent */

char d_name [NAME_MAX+1]; /* filename (null-terminated) */ }

(7)

Directory hierarchy example

• Current Directory

[pilani@labserver sample]$ pwd /home/pilani/sample

• inode list of current directory

[pilani@labserver sample]$ ls -ai

2490381 . 2490384 direntry 2490383 file1hlink.txt 2490382 file2.txt

2490369 .. 2490387 direntry.c 2490383 file1.txt

[pilani@labserver sample]$ ls -ai /home/pilani

2490369 . 2490376 cs1 2 .. 2490381 sample

• inode list of pilani home directory

[pilani@labserver sample]$ ls -ai /home/ 2 . 2490369 pilani

2 .. 2621441 pilani1

(8)

Inode role in file operations

Example: Opening file /home/pilani/sample/file1.txt

• Kernel has inode number of root (/)

• Load data block of / and find inode number of home • Load data block of /home and find inode of sample

• Load data block of /home/sample and find inode of file1.txt • Load first data block of file1.txt

(9)

File permission

 What does executable permission of directory mean?

(10)

File permission

 What does executable permission of directory mean?

(11)

File listing details

[user1@labserver ~]$ ls -l

total 4

-rw-r--r-- 1 user1 user1 36 Aug 30 16:02 file1.txt

File Type – Directory/File/Link Permission to Owner - r/w/x Owner group name

File size Date of last change

(12)

File Modification time

 File has two data

 Content (data)

 Metadata

 Changing contents changes Metadata also

 Changing Metadata may not change content

$ls -lu  Display access time

$ls –lc  Display change time  You can also use stat command

(13)

File listing details

[user1@labserver ~]$ ls -l

total 4

-rw-r--r-- 1 user1 user1 36 Aug 30 16:02 file1.txt

File Type – Directory/File/Link Permission to Owner - r/w/x ? Owner group name

File size Date of last change

(14)

File listing details

[user1@labserver ~]$ ls -l

total 4

-rw-r--r-- 1 user1 user1 36 Aug 30 16:02 file1.txt

File Type –

Directory/File/Link

Permission to Owner - r/w/x

Number of files

linked to this inode

Owner group name

File size Date of last change

(15)

VI Editor

 Powerful Text Editor on Unix

 Enhanced versions on Linux -- vim, gvim

 Need some learning time but once learned editing text files (scripts, code, documents..) becomes

(16)

Modes

File Xxxxxxxxxxxxxxxxx Xxxxxxxxxxxxxxxxx Xxxxxxxxxxxxxxxxxx Xxxxxxxxxxxxxxxxxx Search, move, Replace, delete Command Mode File Xxxxxxxxxxxxxxxxx Xxxxxxxxxxxxxxxxx Xxxxxxxxxxxxxxxxxx Xxxxxxxxxxxxxxxxxx Xxxxxxxxxxxxxxxxxxx Edit Mode i,a,o Escape File Xxxxxxxxxxxxxxxxx Xxxxxxxxxxxxxxxxx Xxxxxxxxxxxxxxxxxx Xxxxxxxxxxxxxxxxxx :w,s,q,

Command Line Mode

Escape & :

(17)
(18)
(19)
(20)

File Management

 File Descriptor

 Handle or Index returned to process when file is opened e.g. using fopen call

 File Descriptor Table

 Maintained by Kernel for each process

 Contains entries for all files opened by the process

 File descriptor indexes into this table

 File Entry

 System wide tabled maintained by Kernel

 Contains entries for all files opened by all processes on this server

 Per process file descriptor table entries indexes into this table to access the file

(21)
(22)

Device Drivers

 Every physical device has its own hardware controller (apart from CPU)

 Device Drivers are low level hardware controller handling software routines

 Each device in the system is represented by special device file and listed in /dev directory

 Devices are identified by major and minor number

 Major number mapping can be viewed from file /proc/devices

(23)

Device Drivers

Block Devices

 Examples: Hard disk, RAM, CDROM …

 Usually I/O is performed using buffer cache

 Device file is identified by ‘b’

Character Devices

 Examples: keyboard, printer, …

 I/O is performed byte/stream without buffering

(24)

Device Drivers

Block Devices

 Examples: Hard disk, RAM, …  Device file is identified by ‘b’

Character Devices

 Examples: keyboard, printer, …  Device file is identified by ‘c’

$ls –l /dev

brw-rw---- 1 root disk 1, 0 Sep 22 13:21 ram0 brw-rw---- 1 root disk 8, 0 Sep 22 13:21 sda crw-rw-rw- 1 root tty 5, 0 Sep 22 13:21 tty crw-rw---- 1 root lp 6, 0 Sep 22 13:21 lp0

(25)

Device file

vs

regular file?

$ls –li /dev/ram0

8207 brw-rw---- 1 root disk 1, 0 Sep 22 13:21 /dev/ram0

$ls –li file2.txt

2490382 -rw--- 1 pilani pilani 42 Sep 17 10:46 file2.txt

$ls –ldi /home/pilani/sample

2490381 drwx--- 2 pilani pilani 4096 Sep 21 13:48 /home/pilani/sample/

(26)

Device file

vs

regular file?

$ls –li /dev/ram0

8207 brw-rw---- 1 root disk 1, 0 Sep 22 13:21 /dev/ram0

$ls –li file2.txt

2490382 -rw--- 1 pilani pilani 42 Sep 17 10:46 file2.txt

$ls –ldi /home/pilani/sample

2490381 drwx--- 2 pilani pilani 4096 Sep 21 13:48 /home/pilani/sample/

Type: b/c/-/d

Size: File content size/

(27)

Device file

vs

regular file?

$ls –li /dev/ram0

8207 brw-rw---- 1 root disk 1, 0 Sep 22 13:21 /dev/ram0

$ls –li file2.txt

2490382 -rw--- 1 pilani pilani 42 Sep 17 10:46 file2.txt

$ls –ldi /home/pilani/sample

2490381 drwx--- 2 pilani pilani 4096 Sep 21 13:48 /home/pilani/sample/

(28)

Device Driver Sections

Auto Configuration Routines I/O Servicing Routines Interrupt Service Routines

Triggered due to system calls

Triggered due to hardware interrupts Triggered during driver

(29)

Device Driver

 Interrupt driven device driver

 Controller raises interrupt when it is ready to be

serviced e.g. network driver is ready when packet is received from network

 Kernel passes on interrupt to correct device driver to process the interrupt

References

Related documents

If a file is checked out, this command is available to bring revisions from the local working copy to the server while leaving the file checked out.. Refresh

Using the map, the current position by a precise localization, the path from its current position to the desired destination and a goal in the path, IARA’s MPMP is able

CLASS: The class of a world describes what type of planet it is, what kind of civilisation and society can be found on the planet, what level of technology is commonly used on

For WriteMemory commands and video-mode commands, filename can be test pattern, frame buffer, video file, image file or binary file. Note 5 CSI Compression commands require

Parasitology Information SPECIMEN DATA Specimens Collected: 3 Date Collected: 05/10/2021 Date Received: 05/11/2021 Date Reported: 05/12/2021 Methodology: Microscopy

If you must start from other users must quote characters as filenames, it names on output not find command in unix with examples pdf files or more commands pdf file.. The

• Parse the file to the final command and print the output in the console or a different file using the below commands:. - print the output

accelerations. But on the whole those determinants do a very poor job of predicting the turning points. It would appear that growth accelerations are caused predominantly by