我只是想在 HFS+ 格式的卷上恢复 C 语言的文件。根据
man undelete
NAME undelete -- attempt to recover a deleted file
LIBRARY Standard C Library (libc, -lc)
SYNOPSIS #include
int undelete(const char *path);
DESCRIPTION
The
undelete()
system call attempts to recover the deleted file named by path. Currently, this works only when the named object is a whiteout in a union file system. The system call removes the whiteout causing any objects in a lower layer of the union stack to become visible once more.Eventually, the
undelete()
functionality may be expanded to other file systems able to recover deleted files such as the log-structured file system.RETURN VALUES
The
undelete()
function returns the value 0 if successful; otherwise the value -1 is returned and the global variableerrno
is set to indicate the error.
所以程序很简单:
当前目录 (pwd) 是/Users/Leo/Desktop/,我使用的是带有 HFS+ 文件系统的 Mac 10.7.2。
#include <unistd.h>
int main()
{
char a="/Users/Leo/Desktop/test/a.out";//I delete a.out using rm for testing
const char* pa=&a;
return undelete(pa);
}
但是当我运行该程序时,shell 返回了 255。
有什么想法吗?谢谢
最佳答案
取消删除失败。要找出原因,请检查 errno。例如:
#include <unistd.h> int main( int argc, char **argv ) { char *path = argc > 1 ? argv[ 1 ] : "a.out"; if( undelete(path)) perror( path ); return 0; }
虽然看起来你的问题是你有一个 char 而不是 char 指针。 您应该收到编译器警告。
关于c - 使用 C 中的 undelete() 恢复已删除的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8013895/