- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 NT native 函数 NtCreateFile
,可以使用 FILE_OPEN_BY_FILE_ID
创建选项按 id 打开文件。但是,这样做时,DELETE
访问标志似乎被忽略。如果我设置它,文件将正常打开,但任何删除或重命名文件的尝试都将失败(例如通过设置 FILE_DELETE_ON_CLOSE
或使用 FILE_RENAME_INFORMATION
类与 NtSetInformationFile
)。
用这种方式打开的文件不能删除吗?有没有其他方法可以通过 id 而不是名称来删除文件?
最佳答案
除了 RbMm 的回答之外,我还发现了 Alex Carp 的一篇博文,Some Limitations Using Files Opened By ID ,这解释了这样做的基本原理。
Unfortunately the semantics for files opened by ID are a bit different from the semantics of the same files if they would have been opened by name. The file name namespace for example allows multiple names for a file (hardlinks) while the ID namespace does not. The different semantics of the different namespaces can make it so that some operations don't make sense.
For example because NTFS allows multiple names for a file if the file is opened by ID and an operation that changes the namespace is attempted, which name should be affected? To make this very clear, if file \Foo\f.txt and file \Bar\b.txt are hardlinks to the same file and I open the file by ID and I try to rename it, which name should change? How about if I try a delete?
简而言之,在 NTFS 模型中删除文件实际上意味着删除对文件的引用(也称为名称)。只有删除对它的所有引用后,作为副作用,文件本身才能被删除。很像许多编程语言中的引用计数。
假设有一个操作会获取文件 ID 并删除所有引用以及文件,但这将是一个非常不同的操作并且可能很棘手(例如,它需要对所有受影响的文件名执行权限检查,等等关闭所有相关句柄,防止新文件名引用被删除的文件等)。因此,从这方面来说,它不存在也就不足为奇了。
关于filesystems - 如何通过 id 打开具有 DELETE 访问权限的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58364266/
有没有办法确定我是否可以使用标准 (在所有支持 C++17 的现代 C++ 编译器上可用)或 由较旧的编译器使用。 (例如 g++ 6.3,这是 Debian Stretch 上的当前标准版本) 知
因此,boost::filesystem 允许您在文件所有者拥有的权限、组拥有的权限以及所有用户拥有的权限的意义上访问文件的权限。这很好,但我不想开始检查我是谁,我的组是什么等等——我只想检查我是否可
我不小心使用 rm -rf 删除了错误的文件夹,我尝试过的每个工具都告诉我我没有硬盘或找不到文件系统。 当我输入 df 时,我得到: 已使用的文件系统大小 Avail Use% Mounted on
我是 Java 的新手,正在尝试学习 IO 的概念。我遇到过两个非常相似的 Java 类,FileSystem 和 FileSystems。它们之间有什么区别?什么时候使用一个而不是另一个? 最佳答案
我查了很多关于c++17下文件系统链接的问题,还是无法链接成功。我的main.cpp文件如下。 #include int main(int argc, char** argv) { std:
Boost 库有一个类来处理文件路径:boost::filesystem::path。Boos 也有这个类 boost::filesystem::wpath 每个类都有方法string(), wstr
我正在编写一个利用 std::filesystem 的库(仅供学习)。它在 MSVC 上运行良好,但是默认情况下,Linux 的 LTS 版本就像 Ubuntu 一样附带 GCC 6.x,官方存储库中
请查找随附的代码片段。我正在使用此代码将文件从 hdfs 下载到我的本地文件系统 - Configuration conf = new Configuration(); FileSys
这段代码中std::filesystem::copy()和std::filesystem::copy_file()有什么区别? #include void testing() { const
以下代码旨在去除路径的第一部分,以防它存在: #include std::filesystem::path strip_prefix(std::filesystem::path p) {
在以下两种情况下,是否有理由调用lexically_normal: std::filesystem::path filepath = someFuntionThatGetsAPath(); filep
函数 boost::filesystem::canonical() ( doc of 1.66 , doc of current release ) 提供两个参数(忽略错误代码重载)base。第一个是
boost::filesystem::path使用 &转义路径字符串中的引号,see demo : std::cout 标题。 最佳答案 Boost::Filesystem 相当古老,早于 C++14
考虑以下关于路径分解的断言,其中每个局部变量,例如stem 具有明显的初始化,例如auto stem = path.stem() — assert(root_path == root_name / r
给定以下代码: fs::path p{ "a/b/" }; fs::path q{ "a/b/." }; assert(p == q); [注意定义 q 的字符串末尾的额
由于 C++17 std::filesystem 与 boost::filesystem 非常相似,所以我尝试做与这个问题相同的事情: Escaping some Directories in ite
我找到了这个页面,描述了 c++14 和 c++17 之间的变化: https://isocpp.org/files/papers/p0636r0.html ... 它链接到此页面,该页面描述了建议的
我有一些代码,当我编译它时,出现以下错误,我不知道如何解决。我尝试添加 -L/usr/lib/x86_64-linux-gnu、-lboost_system 和 -lboost_filesystem,
尝试使用 Asset.loadAsync 将 .txt Assets 作为字符串加载到 Expo 中 Asset.loadAsync(module) 解析并提供一个 localUri 但是,FileS
我在 中编码C++ 在 Visual Studio (Windows 10)并收到此错误: #error The header providing std::experimental::filesy
我是一名优秀的程序员,十分优秀!