Answers:
umount
是UNIX命令,它遵循传统的UNIX观点,即卸载文件系统是系统管理任务。
背后的理由是,如果计划或执行不当,卸载文件系统可能会造成破坏甚至破坏,特别是在多用户系统上。因此,普通用户可以免受此潜在危险命令的影响,并且只允许root用户或特权用户执行该命令。
当将UNIX用作服务器操作系统时,这很有意义,但是基于UNIX的桌面操作系统(例如OS X或Ubuntu)还有其他需求:任何用户都应该能够卸载闪存驱动器,可移动硬盘驱动器等。
Finder和diskutil
(有关更多信息,请参见man diskutil)以这种方式工作。例如,我可以打开终端并成功运行:
$ diskutil unmount /Volumes/Untitled
Volume Untitled on disk2s2 unmounted
而umount
失败:
$ umount /Volumes/Untitled
umount: unmount(/Volumes/Untitled): Operation not permitted
Finder的功能是diskutil
什么?在幕后,它们将请求发送到名为com.apple.SecurityServer的守护程序(有关更多信息,请参见手册页),该守护程序有权卸载文件系统:
$ tail -f /var/log/system.log
Feb 6 16:57:37 avallone.local com.apple.SecurityServer[17]: Succeeded authorizing right 'system.volume.removable.unmount' by client '/System/Library/CoreServices/Finder.app' [171] for authorization created by '/System/Library/CoreServices/Finder.app' [171] (100013,0)
Feb 6 16:57:37 avallone.local com.apple.SecurityServer[17]: Succeeded authorizing right 'system.volume.removable.unmount' by client '/usr/sbin/diskarbitrationd' [18] for authorization created by '/System/Library/CoreServices/Finder.app' [171] (100002,0)
Feb 6 17:01:46 avallone.local com.apple.SecurityServer[17]: Succeeded authorizing right 'system.volume.removable.unmount' by client '/usr/sbin/diskutil' [646] for authorization created by '/usr/sbin/diskutil' [646] (100013,0)
Feb 6 17:01:46 avallone.local com.apple.SecurityServer[17]: Succeeded authorizing right 'system.volume.removable.unmount' by client '/usr/sbin/diskarbitrationd' [18] for authorization created by '/usr/sbin/diskutil' [646] (100002,0)
这样,任何用户都可以卸载驱动器而无需其他身份验证。(Ubuntu也有类似的理念。如果您有兴趣,请在AskUbuntu上查看此答案。)
为了支持Finder上面解释的行为,并diskutil
使用几个Apple框架:
$ otool -L $(which diskutil) | grep Disk
/System/Library/PrivateFrameworks/DiskManagement.framework/Versions/A/DiskManagement (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration (compatibility version 1.0.0, current version 1.0.0)
$ otool -L /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder | grep Disk
/System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration (compatibility version 1.0.0, current version 1.0.0)
/System/Library/PrivateFrameworks/DiskImages.framework/Versions/A/DiskImages (compatibility version 1.0.8, current version 344.0.0)
/System/Library/PrivateFrameworks/DiskManagement.framework/Versions/A/DiskManagement (compatibility version 1.0.0, current version 1.0.0)
umount
另一方面,仅链接到此动态库:
$ otool -L $(which umount)
/sbin/umount:
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
(/usr/lib/libSystem.B.dylib
使用其他几个库,但未链接到任何框架。)
umount
和diskutil
/ Finder 之间的区别。
diskutil
。那是很好的知识。