跳到主要内容

文件系统常见问题

文件名

  • Linux
    • 不可以包含 /, \x00
    • 可以包含 :
  • macOS
    • Finder 不可以包含 :, 可以包含 /
    • 命令行 不可以包含 /, 可以包含 :
    • HFS Plus 支持 Unicode - 支持 \x00 - API 层可能会限制
  • Windows
    • 不可以包含 / \ : * ? " < > |. \x00-\x1f
    • 保留名字
      • CON, PRN, AUX, NUL
      • COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9
      • LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, LPT9
    • 文件名字不能以空格和点(.)结尾
  • URL
    • 安全字符 - [0-9a-zA-Z-._~]
    • 不安全字符 - <>[]{}|\^%#

文件系统限制

atime, mtime, ctime

fieldmeanstand for
atimeaccess time访问时间
mtimemodify time修改时间
ctimecreate time创建时间
btimebirth timefs 创建时间
  • btime
    • crtime EXTFS
    • Linux 4.11+ 支持 statx 返回 crtime
  • stat.1
  • ext
    • strictatime - 更严格的 atime 维护,影响性能,特殊场景使用
    • noatime - 不维护 atime
    • nodiratime - 不维护目录 atime
    • relatime - relative atime - 超过 24h 才更新 atime
touch hello.txt
# 查看所有时间
stat hello.txt

touch hello.txt # 修改 atime, mtime
touch -m hello.txt # 修改 mtime
touch -d "2020-01-15 10:30:45" hello.txt # 指定 atime, mtime

touch neo.txt
touch hello.txt -r neo.txt # 参照修改

# inode
stat -c $i /etc/profile
df --output=source /etc/profile | tail -1
# debugfs 能看到 crtime
debugfs -R "stat <$(stat -c %i /etc/profile)>" /dev/sda2

MBR vs GPT

  • MBR - Master Boot Record
    • 也叫 DOS 分区 - 最早于 IBM PC DOS 2.0
  • GPT - GUID Partition Table
    • 因为 UEFI 而诞生
  • 4096 disk sector - AFD - Advanced Format - 4Kn
    • 自 2010 年开始,厂商大多采用 4k sector
    • 使用 512 实际是使用模拟后的地址 - 512e
-mbrgpt
since19832005 - UEFI
interfaceBIOSUEFI
512b sector2TiB = 2^32 × 5128 ZiB = 2^64 × 512
4096b sector-64 ZiB = 2^64 × 4096
addressCHS - Cylinder-head-sectorLBA - Logical Block Addressing
bits3264

The size of this disk is 2 TiB (2199023255552 bytes). DOS partition table format cannot be used on drives for volumes larger than 2199023255040 bytes for 512-byte sectors. Use GUID partition table format (GPT).

重新挂载为可读写

mount -o rw,remount /

Do you want to remove the signature?

如果不希望删除 fs 则选择 No

cluster size for NTFS, FAT, and exFAT

NTFS

volumnblock
7 MB–16 TB4 KB
16 TB–32 TB8 KB
32 TB–64 TB16 KB
64 TB–128 TB32 KB
128 TB–256 TB64 KB

exFAT

volumnblock
7 MB–256 MB4 KB
256 MB–32 GB32 KB
32 GB–256 TB128 KB

FAT32

volumnblock
32 MB–64 MB512 bytes
64 MB–128 MB1 KB
128 MB–256 MB2 KB
256 MB–8 GB4 KB
8 GB–16 GB8 KB
16 GB–32 GB16 KB

FAT16

volumnblock
8 MB–32 MB512 bytes
32 MB–64 MB1 KB
64 MB–128 MB2 KB
128 MB–256 MB4 KB
256 MB–512 MB8 KB
512 MB–1 GB16 KB
1 GB–2 GB32 KB
2 GB–4 GB64 KB

NAND flash 大多为 128 KB blocksize,所以 extFAT 很适合闪存

/run vs /var/run

  • /run - 新的标准 - tmpfs
  • /var/run - symlink 到 /run

特殊文件

  • Windows
    • $RECYCLE.BIN
  • macOS
    • .DS_Store
    • ._XXX
    • .AppleDouble
    • .Spotlight-V100
    • .apDisk
    • .VolumeIcon.icns
    • .fseventsd
      • buffer for the File System Events daemon
    • .Trash
    • .Trashes
    • .TemporaryItems

.DS_Store

._XXX

  • HFS+ 支持扩展属性,所以没有这个问题
  • 用于在不支持 macOS 扩展属性的文件系统存储文件元数据
    • 早期 resource fork
    • finder 存储 icon
    • Time Machine
  • .AppleDouble
  • macOS 内置 dot_clean 工具可以删除
  • turds
  • smb.conf.5
    • veto files = /._*/
    • delete veto files = yes
    • hide special files - 隐藏特殊文件 - 客户端也看不到,所以不适合
dot_clean -m /Volumes/MyVolume
find /Volumes/MyVolume -name '._*' -type f -delete