1 week 13 fat32 utility operations guide: rm and rmdir classes cop4610 / cgs5765 florida state...
TRANSCRIPT
![Page 1: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/1.jpg)
1
Week 13FAT32 Utility
OperationsGuide: rm and
rmdirClasses COP4610 / CGS5765
Florida State University
![Page 2: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/2.jpg)
Outline
Problem of orphaned data File removal walkthrough Directory removal walkthrough
2
![Page 3: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/3.jpg)
Orphans
3
![Page 4: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/4.jpg)
What is orphaned data?
Orphaned data – data marked as valid in the file system that cannot be reached through the file system mechanisms
How could this ever happen?
4
![Page 5: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/5.jpg)
Orphan Example
Suppose we want to delete a file It has
A directory entry with a first cluster number Data clusters Entries in the FAT
5
![Page 6: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/6.jpg)
DATA
DATA
Orphan Example
6
FAT
1 2 3 4 5 6 7
Dir Entry: First Cluster # 3
3
4
4 EoC
Index
Next Cluster
Cluster numbers
Our sample file starts at cluster 3 and continues to cluster 4.
![Page 7: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/7.jpg)
Orphan Example
Normally when we want to find a file’s contents, we start by reading its directory entry contents What if we start deleting there?
7
![Page 8: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/8.jpg)
DATA
DATA
Orphan Example
8
FAT
1 2 3 4 5 6 7
Dir Entry: First Cluster # 3
3
4
4 EoC
Index
Next Cluster
Cluster numbers
Step 1: Read the file’s first cluster number into memory.
![Page 9: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/9.jpg)
DATA
DATA
Orphan Example
9
FAT
1 2 3 4 5 6 7
3
4
4 EoC
Index
Next Cluster
Cluster numbers
Step 2: Delete the file’s directory entry.
![Page 10: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/10.jpg)
DATA
DATA
Orphan Example
10
FAT
1 2 3 4 5 6 7
3
4
4 EoC
Index
Next Cluster
Cluster numbers
Step 3: Look up cluster 3 in the FAT.
![Page 11: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/11.jpg)
DATA
DATA
Orphan Example
11
FAT
1 2 3 4 5 6 7
3
4
4 EoC
Index
Next Cluster
Cluster numbers
Step 4: Read the file’s next cluster number into memory (4).
![Page 12: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/12.jpg)
DATA
DATA
Orphan Example
12
FAT
1 2 3 4 5 6 7
3
4
4 EoC
Index
Next Cluster
Cluster numbers
Crash!
![Page 13: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/13.jpg)
Orphan Example
We just crashed and have to reboot the system
Can the file system get to the data we were deleting?
13
![Page 14: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/14.jpg)
DATA
DATA
Orphan Example
14
FAT
1 2 3 4 5 6 7
3
4
4 EoC
Index
Next Cluster
Cluster numbers
We are now in trouble. Since we deleted the file’s directory entry, we don’t know where the file started…
![Page 15: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/15.jpg)
DATA
DATA
Orphan Example
15
FAT
1 2 3 4 5 6 7
3
4
4 EoC
Index
Next Cluster
Cluster numbers
Leftover entries in the FAT that we can never reclaim…
Allocated disk space we can never clean up…
![Page 16: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/16.jpg)
Preventing Orphans
How can we avoid the chance of orphans while we delete?
Answer: delete backwards!
16
![Page 17: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/17.jpg)
DATA
DATA
Preventing Orphans
17
FAT
1 2 3 4 5 6 7
Dir Entry: First Cluster # 3
3
4
4 EoC
Index
Next Cluster
Cluster numbers
Step 1: Read through entire file until we find the last cluster entry for the file in the FAT
![Page 18: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/18.jpg)
DATA
DATA
Preventing Orphans
18
FAT
1 2 3 4 5 6 7
Dir Entry: First Cluster # 3
3
4
4
Index
Next Cluster
Cluster numbers
Step 2: Mark the last cluster as free. What happens if we crash here?
![Page 19: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/19.jpg)
DATA
DATA
Preventing Orphans
19
FAT
1 2 3 4 5 6 7
Dir Entry: First Cluster # 3
3
4
4
Index
Next Cluster
Cluster numbers
Step 3: Find the new last file cluster in the FAT.
![Page 20: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/20.jpg)
DATA
DATA
Preventing Orphans
20
FAT
1 2 3 4 5 6 7
Dir Entry: First Cluster # 3
3
4
Index
Next Cluster
Cluster numbers
Step 4: Mark the last cluster as free.
![Page 21: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/21.jpg)
DATA
DATA
Preventing Orphans
21
FAT
1 2 3 4 5 6 7
3
4
Index
Next Cluster
Cluster numbers
Step 5: Finally, if all the FAT entries for the file are marked free, delete the directory entry.
![Page 22: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/22.jpg)
DATA
DATA
Preventing Orphans
22
FAT
1 2 3 4 5 6 7
3
4
Index
Next Cluster
Cluster numbers
Why don’t we zero out the file’s data?
![Page 23: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/23.jpg)
File Data Leftovers
Most file systems only update metadata upon deletion and leave old data as it was. Why? Old data will just be overwritten later anyway by
new, valid data File system will never display old data to the user
because it is no longer part of a file It can take a significant amount of time to zero
over large amounts of file data Zeroing the data can cause extra wear on the
device
23
![Page 24: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/24.jpg)
File Data Leftovers
File recovery utilities leverage this situation Scans the file system for data clusters that are not
currently allocated
24
![Page 25: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/25.jpg)
File Deletion
rm operation
25
![Page 26: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/26.jpg)
File Deletion : rm
1. Check that the file to removed is a file and does exist
Cannot use this utility command to delete a directory
2. Seek to the last cluster entry in the FAT
3. Mark the last cluster entry in the FAT with the free mark of 0x00000000
4. Repeat 2 and 3 until there are no more cluster entries in the FAT
5. Delete the file’s directory entry
26
![Page 27: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/27.jpg)
Deleting a Directory Entry
Can just mark the first byte in the directory entry to symbolize deletion If DIR_Name[0] == 0xE5, then the directory entry
is free (no file or directory name in this entry) If DIR_Name[0] == 0x00, then the directory entry
is free (same as for 0xE5), and there are no allocated directory entries after this one
27
![Page 28: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/28.jpg)
Deleting a Directory Entry
28
Deleted directory entry staring with 0xE5
![Page 29: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/29.jpg)
Deleting a Directory Entry
29
Starts with 0x00, so no more directory entries in this cluster
![Page 30: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/30.jpg)
rm Use Cases
Successful rm/FILES/] ls. .. CONST.TXT EMPTY.TXT HELLO.TXT/FILES/] rm HELLO.TXT/FILES/]
Unsuccessful rm/FILES/] rm NOTHERE.TXTError: does not exist/FILES/]
30
![Page 31: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/31.jpg)
Directory Deletion
rmdir
31
![Page 32: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/32.jpg)
Directory Deletion: rmdir
1. Check that directory to be removed is empty and is actually a directory
2. Go to step #2 for rm Rest of directions just like deleting a file!
32
![Page 33: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/33.jpg)
rmdir Use Cases
Successful rmdir
/DIRS/] rmdir A
/DIRS/]
Unsuccessful rmdir
/DIRS/] rmdir B
Error: directory not empty
/DIRS/]
33
![Page 34: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/34.jpg)
rmdir Use Cases
Unsuccessful rmdir
/DIRS/] cd ..
/] rmdir FATINFO.TXT
Error: not a directory
/]
34
![Page 35: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/35.jpg)
Next Time
Today’s lecture is last recitation lecture Next recitation will be office hours
35
![Page 36: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/36.jpg)
Project 3 Submission Hints Make sure everything is included!
Points will be taken off if things are missing Make sure the project at least compiles
If it doesn’t, it will get a 0. Please remove all executables and *.o files
before emailing submissions Please email submission to TA address
36
![Page 37: 1 Week 13 FAT32 Utility Operations Guide: rm and rmdir Classes COP4610 / CGS5765 Florida State University](https://reader035.vdocuments.us/reader035/viewer/2022062804/5697bf731a28abf838c7f0ca/html5/thumbnails/37.jpg)
Questions?
Good luck with project 3 and finals!
37