簡體   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