简体   繁体   English

我将如何检查我在C中工作的文件系统

[英]How would I go about checking the file system I'm working on in C

I'm making a program and one of the things it needs to do is transfer files. 我正在制作一个程序,它需要做的一件事就是传输文件。 I would like to be able to check before I start moving files if the File system supports files of size X. What is the best way of going about this? 如果文件系统支持大小为X的文件,我希望能够在开始移动文件之前进行检查。最好的方法是什么?

There's no C standard generic API for this. 这没有C标准通用API。 You could simply try creating a file and writing junk to it until it is the size you want, then deleting it, but even that isn't guaranteed to give you the info you need - for instance another process might have come and written a large file in between your test and your transfer, taking up space you were hoping to use. 您可以简单地尝试创建一个文件并将垃圾写入它,直到它达到您想要的大小,然后将其删除,但即使这样也无法保证为您提供所需的信息 - 例如,另一个进程可能已经编写了大量文件在您的测试和转移之间归档,占用您希望使用的空间。

继续使用像ftruncate类的函数在移动之前预先创建所需大小的文件,并在失败时进行适当的错误处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM