Bài giảng Hệ điều hành - File system - Nguyễn Xuân Vinh
Bạn đang xem tài liệu "Bài giảng Hệ điều hành - File system - Nguyễn Xuân Vinh", để tải tài liệu gốc về máy bạn click vào nút DOWNLOAD ở trên
Tài liệu đính kèm:
- bai_giang_he_dieu_hanh_file_system_nguyen_xuan_vinh.pptx
Nội dung text: Bài giảng Hệ điều hành - File system - Nguyễn Xuân Vinh
- NHẬP MÔN HỆ ĐIỀU HÀNH INTRODUCTION TO OPERATING SYSTEMS [214242] GV: NGUYỄN XUÂN VINH FILE SYSTEM MÔN HỆ ĐIỀU HÀNH Hard Link - Soft Link NHẬP Nguyễn Xuân Vinh nguyenxuanvinh@hcmuaf.edu.vn 23/05/2021 /XX 1
- File Parts q Unix files consist of two parts: § Data part: associated with Inode which carries the map of where GV: NGUYỄN XUÂN VINH the data is, the file permissions, MÔN HỆ ĐIỀU HÀNH § Filename part : carries a name and an associated inode number. NHẬP 23/05/2021 /XX 2
- 3 /XX 23/05/2021 NHẬP MÔN HỆ ĐIỀU HÀNH GV: NGUYỄN XUÂN VINH Hardlinked q § More than one filename can reference the same inode number These files are said to be “hard linked” together The specificlocationofphysical data.
- Soft link (symbolic link, symlink) q Special file type whose data part carries a path to another file q OS recognizes the data as a path, and redirects opens, reads, and GV: NGUYỄN XUÂN VINH writes so that, instead of accessing the data within the special file MÔN HỆ ĐIỀU HÀNH NHẬP 23/05/2021 /XX A symbolic path indicating the 4 abstract location of another file.
- Directory q The directory, as a file, is just an array of filename parts of other files GV: NGUYỄN XUÂN VINH q When a directory is built, it is initially populated with the filename parts of two special files: the “.” and “ ” files. § The filename part for the “.” file is populated with the inode# of the directory file in which the entry has been made. Ø“.” is a hardlink to the file of the current directory. § The filename part for the “ ” file is populated with the inode# of MÔN HỆ ĐIỀU HÀNH the directory file that contains the filename part of the current NHẬP directory file. Ø“ ” is a hardlink to the file that implements the immediate parent of the current directory. 23/05/2021 /XX 5
- Restrictions q Hardlinked: § Both links must reside on the same filesystem. GV: NGUYỄN XUÂN VINH § The source file must exist. § Hard links shouldn’t link directories. q Softlinks: § Source and target can be on separate file systems. MÔN HỆ ĐIỀU HÀNH § Source does not have to exist. NHẬP § Additional I/O necessary to complete file access § Additional storage taken up by softlink file’s data 23/05/2021 /XX 6
- Example q Let's start off with an empty directory, and create a file in it GV: NGUYỄN XUÂN VINH q Now, let's make a hardlink to the file MÔN HỆ ĐIỀU HÀNH NHẬP 23/05/2021 /XX a.hardlink.file shares the same inode (73478) as basic.file 7 b.hardlink.file shares the same data as basic.file
- Example q If we change the permissions on basic.file: GV: NGUYỄN XUÂN VINH then the same permissions change on hardlink.file. q Let's now make a softlink to the original file: MÔN HỆ ĐIỀU HÀNH NHẬP Here, we see that although softlink.file accesses the same data as basic.file and hardlink.file, it does not share the same inode (73479 vs 23/05/2021 73478), nor does it exhibit the same file permissions. It does show a new permission bit: the 'l' (softlink) bit /XX 8
- File System q If we delete basic.file: GV: NGUYỄN XUÂN VINH then we lose the ability to access the linked data through the softlink: However, we still have access to the original data through the hardlink: MÔN HỆ ĐIỀU HÀNH NHẬP You will notice that when we deleted the original file, the hardlink didn't vanish. Similarly, if we had deleted the softlink, the original file wouldn't have vanished. 23/05/2021 /XX 9
- File System q When deleting files, the data part isn't disposed of until all the filename parts have been deleted GV: NGUYỄN XUÂN VINH q There's a count in the inode that indicates how many filenames point to this file § That count is decremented by 1 each time one of those filenames is deleted § When the count makes it to zero, the inode and its associated data are deleted MÔN HỆ ĐIỀU HÀNH § By the way, the count also reflects how many times the file has NHẬP been opened without being closed (in other words, how many references to the file are still active) Can delete a file so that no "filename" part points to the inode, 23/05/2021 without releasing the space for the data part of the file, because the /XX file is still open 10
- /var/log/messages q notice that /var/log/messages (or some other syslog-owned file) has grown too big, and you GV: NGUYỄN XUÂN VINH to reclaim the space, but the used space doesn't reappear? This is because, although you've deleted the filename part, there's a process that's got the data part open still (syslogd), and the OS won't release the space for the data until the process closes it. In order to complete your space reclamation, you have to MÔN HỆ ĐIỀU HÀNH NHẬP to get syslogd to close and reopen the file. 23/05/2021 /XX 11
- 12 /XX 23/05/2021 NHẬP MÔN HỆ ĐIỀU HÀNH GV: NGUYỄN XUÂN VINH Advantage inprograms q following: how you could hide a temporary file? Well, you could do the use this to your advantage in programs: have you ever wondered
- 13 /XX 23/05/2021 NHẬP MÔN HỆ ĐIỀU HÀNH GV: NGUYỄN XUÂN VINH HỎI ĐÁP