DRAT 字似乎是零
我通过以下实验得出结论,所讨论的 SSD 的 DRAT 字为零:
- 创建一个小文件并获取其文件内容的块号。
- 删除文件。
- 运行
fstrim
以将 TRIM 命令发送到 SSD 的控制器。我的操作系统(Arch Linux 5.12.9)不会自动修剪 SSD,请在此处讨论。
- 使用以下命令读取已删除文件块的内容
debugfs
:全为零。
这是执行这些步骤的脚本:
#!/bin/sh
file=test_file
echo "Current date: $(date)" > "$file"; sync
# Get the device of our test file, for example "/dev/sda1"
device=$(df -P "$file" | awk 'END{print $1}')
# The block of the file's contents, stat gets the inode number
block=$(sudo debugfs -R "blocks <$(stat -c %i "$file")>" "$device")
# fstrim needs the mountpoint of the file system, e.g. "/"
mountpoint=$(stat -c %m "$file")
rm $file; sync
# Send TRIM to make the SSD delete unused blocks. Might take a while
sudo fstrim "$mountpoint"
# Read the contents of the deleted file, -D bypasses the buffer cache
sudo debugfs -D -R "block_dump $block" "$device"