繁体   English   中英

linux中的文件输入输出

[英]File input output in linux

我试图在当前安装的恢复模式下在 android 中打开块文件系统,在打开该文件系统后,我想将光标位置移动到该块文件的开头。

int movecursor(const char* blockPartition)
{
    int fd_read = open(blockPartition, O_RDONLY);
    printf("fd_read=%d \n",fd_read); 

    // go to beginning
    int returncode1 = lseek(fd_read, 0, SEEK_SET);// Here it is returning -1
    printf("returncode1=%d and \n",returncode1);
}

在这里,我能够以当前安装的读取模式打开文件系统,但是当我尝试将光标移动到该文件的开头时,它返回 -1(不允许操作)。

上面的代码片段作为 android 本机服务运行。

请帮我移动文件系统开头的光标位置。

在打开块分区之前,您可以使用访问系统调用来检查您是否具有访问权限。

 if (access(partition, F_OK | W_OK) != -1) { printf("%s partition is available.Continuing...\\n", partition); /* Open the mtd device for reading and writing */ int fd_path = open(partition, O_RDONLY); lseek(fd_path, 0, SEEK_SET);// or lseek64 based on your system architecture }

通常,当您传递给函数的文件描述符无效时遇到“Bad File Descriptor”时,可能有多种原因:

* fd 已在某处关闭。 * fd 有一个错误的值,与 open 系统调用得到的值不一致。

暂无
暂无

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

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