c - 使用 C 中的 undelete() 恢复已删除的文件

标签 c macos undelete

我只是想在 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 variable errno 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/

相关文章:

c - 关于 while 循环的表达式

git - 在 GIT 中撤消删除

c - 如何在 Linux 中向 Bash 添加运算符?

c - 我的数组中的偶数位置自动变成 0。你能修复我的代码吗?

macos - 如何使用 SwiftUI 在 macOS 侧边栏中获得放置目标背景效果?

Python WSS : chrome not recognizing auto validated certificate

c - 为什么 struct tm 中的 tm_year 成员相对于 1900 而不是 macosx 上 C 中的 1970?

amazon-s3 - 如何使用 boto 获取所有版本的 S3 key 并取消删除?

c - 从给定 1->2->3->4 的链表中删除所有其他节点以获得 2->4?