introduction to embedded systems

19
Fall 2013 SILICON VALLEY UNIVERSITY CONFIDENTIAL 1 Introduction to Embedded Systems Dr. Jerry Shiao, Silicon Valley University

Upload: axel

Post on 05-Jan-2016

31 views

Category:

Documents


0 download

DESCRIPTION

Introduction to Embedded Systems. Dr. Jerry Shiao, Silicon Valley University. File System. Review Inode. a) Logical structure of current directory. File, Chapter3, is created in current directory. b) Contents of current directory. Directory entry contains pair . - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Introduction to Embedded Systems

Fall 2013SILICON VALLEY UNIVERSITY

CONFIDENTIAL 1

Introduction to Embedded Systems

Dr. Jerry Shiao, Silicon Valley University

Page 2: Introduction to Embedded Systems

SILICON VALLEY UNIVERSITY CONFIDENTIAL 2

Copyright @2005 Pearson Addison-Wesley

File System

Review Inode

a) Logical structure of current directory. File, Chapter3, is created in current directory.

b) Contents of current directory. Directory entry contains pair <inode # / filename>.

c) Relationship among a directory entry, Inode Table, and physical file contents.-Inode # index into the Inode Table. -Inode Table entry contains the physical location of file on disk.

Page 3: Introduction to Embedded Systems

SILICON VALLEY UNIVERSITY CONFIDENTIAL 3Spring 2014

File System

Virtual File System (VFS)User space has the applications and glibc (provides API file system calls: open, read, write, close).

System call interface acts as a switch, funneling system calls from user space to the appropriate endpoints in kernel space.

VFS exports APIs and abstracts them to individual file systems.

Inode cache and Directory cache provides a pool of recently-used file system objects. Directory cache speeds up translation from file pathname to inode.

Individual file systems exports APIs that is used by the VFS.

Buffer cache buffers the requests between the file systems and the block devices that they manipulate (for faster access).

Page 4: Introduction to Embedded Systems

SILICON VALLEY UNIVERSITY CONFIDENTIAL 4Spring 2014

File System

Virtual File System (VFS)

File Object: Stores info about interaction between open file and process.

Dentry Object: Stores info about linking directory entry (file name) and file.

Inode Object: Stores info about specific file (inode number identifies file). The file control block.

Superblock Object: Stores info about mounted filesystem. The filesystem control block.

Process 1

Process 2

File Object

File Object

Dentry

Object

Dentry

Object

Dentry

Cache

Inode

Object

Superblock

Object

Inode

Cache

Process 1

Process 2

File Object

File Object

Dentry

Object

Dentry

Object

Dentry

Cache

Inode

Object

Superblock

Object

Inode

Cache

Disk File

Page 5: Introduction to Embedded Systems

SILICON VALLEY UNIVERSITY CONFIDENTIAL 5Spring 2014

Linux File SystemVirtual File System (VFS)

struct file_system_type links together currently-supported file systems (/proc/filesystems).

struct vfsmount links together file systems currently mounted. Link to struct superblock.

struct superblock represents a file system. Manage inodes: alloc_inode, destroy_inode, read_inode,

write_inode, sync_fs. struct inode represents an object (file or directory)

in the file system with unique identifier. Metadata to manage objects in the file system

struct inode_operations: Operations that operate on inode.

struct file_operations: Methods related to files and directories (the standard system calls).

Page 6: Introduction to Embedded Systems

SILICON VALLEY UNIVERSITY CONFIDENTIAL 6Spring 2014

Linux File System

Virtual File System (VFS)

To achieve the abstraction (i.e. “black box operation) to the user, common API to the user through glibc library and common callback function signature to the I/O functions.

Inode represents an object in the file system with a unique identifier (translating filename).

struct file_operations abstractions (i.e. read/write/open ) allow all I/O operations to have common interface. The indirect calls (i.e. callback functions) are APIs specific to the file system.

Page 7: Introduction to Embedded Systems

SILICON VALLEY UNIVERSITY CONFIDENTIAL 7

Copyright @2005 Pearson Addison-Wesley

File System

Hard Links Hard link creates a file entry (new file name) in

directory with the same inode index as the linked file. ln [ options ] existing-file new-file ln [ options ] existing-file-list directory - f : Force creation of link. - n : Do not create the link if “new-file” exists. - s : Create symbolic link to “existing-file”. NOTE:

< no “– s” > : Create a hard link to “existing-file”. < “directory” > : The user MUST have execute

permission for all the directories in the path leading to the file.

Page 8: Introduction to Embedded Systems

SILICON VALLEY UNIVERSITY CONFIDENTIAL 8

Copyright @2005 Pearson Addison-Wesley

File System

Hard Links Current Directory $ ls -iltotal 122630032 -rw-r--r-x 1 sau users 102 2012-10-26 00:47 Chapter12630033 -rw-r--r-- 1 sau users 102 2012-10-26 00:47 Chapter22630034 -rw-r--r-- 1 sau users 79 2012-10-29 14:23 Chapter3 $ ln Chapter3 Chapter3.hard $ ls -iltotal 162630032 -rw-r--r-x 1 sau users 102 2012-10-26 00:47 Chapter12630033 -rw-r--r-- 1 sau users 102 2012-10-26 00:47 Chapter22630034 -rw-r--r-- 2 sau users 79 2012-10-29 14:23 Chapter32630034 -rw-r--r-- 2 sau users 79 2012-10-29 14:23 Chapter3.hard $ rm Chapter3 $ ls -iltotal 122630032 -rw-r--r-x 1 sau users 102 2012-10-26 00:47 Chapter12630033 -rw-r--r-- 1 sau users 102 2012-10-26 00:47 Chapter22630034 -rw-r--r-- 1 sau users 79 2012-10-29 14:23 Chapter3.hard $

Create hard link. The inode index for linked file and file are the same. Link count is 2.

Remove only removes the entry in the directory. File is physically still on disk. Link count is 1.

Page 9: Introduction to Embedded Systems

SILICON VALLEY UNIVERSITY CONFIDENTIAL 9

Copyright @2005 Pearson Addison-Wesley

File System Link Count

Number of different directory entries pointing to inode of the object (i.e. directory or file).

File: Number of hard links to that file. $ ls -il memo6

2630044 -rw-r--r-x 1 sau users 253 2012-10-29 16:16 memo6 Directory: Number of directory entries connecting

local directory to Linux file system. $ ls -a

.  ..  students  students_2  students.gz    $ ls -lddrwxr-xr-x 2 student1 student1 4096 2013-10-19 02:06 .$ mkdir test_dir$ ls -a.  ..  students  students_2  students.gz  test_dir$ ls -lddrwxr-xr-x 3 student1 student1 4096 2013-10-19 02:06 .

Page 10: Introduction to Embedded Systems

SILICON VALLEY UNIVERSITY CONFIDENTIAL 10

Copyright @2005 Pearson Addison-Wesley

File System

Create Hard Link

a) Logical structure of current directory. Hard link, Chapter3.hard, is linked to file, Chapter3 in current directory.

b) Contents of current directory. Directory entry contains pair <inode # / filename> for Chapter3.hard. The inode# is same as file Chapter3.

c) Relationship among a directory entry, Inode Table, and physical file contents.-Inode # index into the Inode Table for both Chapter3 and Chapter3.hard.

Page 11: Introduction to Embedded Systems

SILICON VALLEY UNIVERSITY CONFIDENTIAL 11

Copyright @2005 Pearson Addison-Wesley

File System

Hard Link Different Directory

Page 12: Introduction to Embedded Systems

SILICON VALLEY UNIVERSITY CONFIDENTIAL 12

Copyright @2005 Pearson Addison-Wesley

File System

Hard Links Different Directory $ ls -il memos/memo62630044 -rw-r--r-x 1 sau users 253 2012-10-29 16:16 memos/memo6 $ ln memos/memo6 memo6.hard $ ls -il memos/memo62630044 -rw-r--r-x 2 sau users 253 2012-10-29 16:16 memos/memo6 $ ls -il memo6.hard2630044 -rw-r--r-x 2 sau users 253 2012-10-29 16:16 memo6.hard $ $ rm memos/memo6 $ ls -il memos/memo6ls: cannot access memos/memo6: No such file or directory $ ls -il memo6.hard2630044 -rw-r--r-x 1 sau users 253 2012-10-29 16:16 memo6.hard $

Create hard link. The inode index for linked file and file are the same. Link count is 2.

Remove only removes the entry in the directory. File is physically still on disk. Link count is 1.

Page 13: Introduction to Embedded Systems

SILICON VALLEY UNIVERSITY CONFIDENTIAL 13

Copyright @2005 Pearson Addison-Wesley

File System

Hard Links Limitations Cannot use Hard Links between files on different file systems.

# ln /usr/bin/zip my_zipln: creating hard link `my_zip' => `/usr/bin/zip': Invalid cross-device link

Moving a hard linked file to different file system causes physical copy of file to be made.

$ ls -il memo6.hard2630045 -rw-r--r-x 2 sau users 253 2012-10-29 16:25 memo6.hard $ ls -il memos/memo62630045 -rw-r--r-x 2 sau users 253 2012-10-29 16:25 memos/memo6 $ mv memo6.hard /tmp $ ls -il /tmp/memo6.hard 953686 -rw-r--r-x 1 sau users 253 2012-10-29 16:25 /tmp/memo6.hard

Page 14: Introduction to Embedded Systems

SILICON VALLEY UNIVERSITY CONFIDENTIAL 14

Copyright @2005 Pearson Addison-Wesley

File System

Soft Links Does not have any of the Hard Link issues. Soft link creates a new file entry (new file name and

new inode index) in directory. ln [ options ] existing-file new-file ln [ options ] existing-file-list directory - f : Force creation of link. - n : Do not create the link if “new-file” exists. - s : Required. Create symbolic link to “existing-file”.

Page 15: Introduction to Embedded Systems

SILICON VALLEY UNIVERSITY CONFIDENTIAL 15

Copyright @2005 Pearson Addison-Wesley

File System

Soft Links Current Directory

$ ls -il Chapter32630032 -rw-r--r-x 1 sau users 102 2012-10-26 00:47 Chapter3 $ ln -s Chapter3 Chapter3.soft $ ls -il Chapter3 Chapter3.soft2630032 -rw-r--r-x 1 sau users 102 2012-10-26 00:47 Chapter32630044 lrwxrwxrwx 1 sau users 8 2012-10-29 18:12 Chapter3.soft -> Chapter3 $

Create soft link. 1)The inode index for linked file and file are different. These are different files.2)Original file is file type “-”, an ordinary file. Link file is type “l”, a link file.3)Link count 1. 4)File sizes are different. Link file is 8 bytes, the length of “Chapter3”, the pathname is placed in the link file.

Page 16: Introduction to Embedded Systems

SILICON VALLEY UNIVERSITY CONFIDENTIAL 16

Copyright @2005 Pearson Addison-Wesley

File System

Soft Links

Create soft link. 1)The inode index for linked file and file are different. These are different files.2)Original file is file type “-”, an ordinary file. Link file is type “l”, a link file.3)Link count 1. 4)File sizes are different. Link file is 8 bytes, the length of “Chapter3”, the pathname is placed in the link file.

Page 17: Introduction to Embedded Systems

SILICON VALLEY UNIVERSITY CONFIDENTIAL 17

Copyright @2005 Pearson Addison-Wesley

File System

Soft Links Pros and Cons Pros

Establish symbolic link between files across file systems. Establish symbolic link between directories. Symbolic linked file edited by editor does not change

filename. Cons

If the file that the symbolic link points to is moved from one directory to another, it can no longer be accessed via the link.

UNIX has to support an additional file type (the link type) and a new file has to be created for every link.

Symbolic links also result in slow file operations because, for every reference to the file, the link file has to be opened and read in order to reach the actual file.

Page 18: Introduction to Embedded Systems

SILICON VALLEY UNIVERSITY CONFIDENTIAL 18

Copyright @2005 Pearson Addison-Wesley

Assignment 9

Page 19: Introduction to Embedded Systems

SILICON VALLEY UNIVERSITY CONFIDENTIAL 19

Copyright @2005 Pearson Addison-Wesley

Assignment 9