File System – Unix baed. An entry of Active File table: 1. Access Right: r/w/x 2. Process Count:...

10
File System – Unix bae d

Transcript of File System – Unix baed. An entry of Active File table: 1. Access Right: r/w/x 2. Process Count:...

Page 1: File System – Unix baed. An entry of Active File table: 1. Access Right: r/w/x 2. Process Count: no. of processes which are now referring to the file.

File System – Unix baed

Page 2: File System – Unix baed. An entry of Active File table: 1. Access Right: r/w/x 2. Process Count: no. of processes which are now referring to the file.

...fd1= open (file path, 0);

……

K=read (fd1, buf, n);...

Operating System

memory

User program

01234

1819

01234

1819

01234

1819

01234

1819

Active File table Active i-node tablefd U-ofile-1

fd U-ofile-2fd U-ofile-4

fd U-ofile-3

To key board

To screen

A.c

i-node table in disk

Page 3: File System – Unix baed. An entry of Active File table: 1. Access Right: r/w/x 2. Process Count: no. of processes which are now referring to the file.

• An entry of Active File table:• 1. Access Right: r/w/x• 2. Process Count: no. of processes which

are now referring to the file• 3. Read Pointer/Write pointer: The starting

points of next reading and writing,

respectively.• 4. Active i-node table entry: pointer to an

active i-node• …

Page 4: File System – Unix baed. An entry of Active File table: 1. Access Right: r/w/x 2. Process Count: no. of processes which are now referring to the file.

• An entry of Active i-node table:

• 1. Reference Count: no. of active file table

entries that are pointing to this entry

• 2. Device address: address of an I/O

device

• 3. Owner ID

• 4. Group ID

• 5. Last user who reads/writes: User ID of

the user who perform the last read/write.

Page 5: File System – Unix baed. An entry of Active File table: 1. Access Right: r/w/x 2. Process Count: no. of processes which are now referring to the file.

System call open():• 1. if U-ofile is full then return (-1)• 2. if (“file name” is not in Active i-node table)

read the directory entry from the i-node in

disk according to “file name”;• 3. if (“file name” does not exist in the i-node

table in disk) return (-1);• 4. check access right – user ID and

–rwx rwx rwx;• 5. if (access deny) then return (-1);• 6. allocate a free Active i-node table entry (AITE);

Page 6: File System – Unix baed. An entry of Active File table: 1. Access Right: r/w/x 2. Process Count: no. of processes which are now referring to the file.

• 7. copy directory data of underlying file to

this entry;

• 8. allocate a free Active File table entry

(AFTE);

• 9. copy directory data of underlying file to

this entry;

• 10. allocate a free U-ofile entry (UOE) with

the lowest fd in underlying user’s PCB;

• 11. connect the path UOE – AFTE – AITE;

Page 7: File System – Unix baed. An entry of Active File table: 1. Access Right: r/w/x 2. Process Count: no. of processes which are now referring to the file.

system call write ():

• 1. access the AFTE according to fd

specified by the user. fd is one of the

arguments of the system call; • 2. check the access right;• 3. if (access deny) return (-1);• 4. write the data specified in the buffer

“buf” to the file according to write pointer

recorded in the user’s corresponding AFTE;

Page 8: File System – Unix baed. An entry of Active File table: 1. Access Right: r/w/x 2. Process Count: no. of processes which are now referring to the file.

system call read ():

• 1. access the AFTE according to fd specified by the user. fd is one of the arguments of the system call; • 2. check the access right;• 3. if (access deny) return (-1);• 4. read the data pointed to by the user’s read pointer to the buffer “buf” specified in the arguments of the system call;

Page 9: File System – Unix baed. An entry of Active File table: 1. Access Right: r/w/x 2. Process Count: no. of processes which are now referring to the file.

system call create ():

• 1. allocate a free current directory entry;

• 2. fill in some data, like file name, date,

time, …;

• 3. write the directory entry back to disk;

• 4. system call open ();

Page 10: File System – Unix baed. An entry of Active File table: 1. Access Right: r/w/x 2. Process Count: no. of processes which are now referring to the file.

system call close (fd):

• 1. follow the fd specified in the argument of this system call to access the corresponding AFTE from user’s U-ofile;• 2. if ((process count--) == 0) {disconnect the connection between the AFTE and its AITE; if ((reference count--) == 0) store AITE back to i-node table in disk;}