ifuse icon indicating copy to clipboard operation
ifuse copied to clipboard

Input/output error when copying files

Open MrHm opened this issue 4 years ago • 27 comments

When copying files from an iPhone 6s, I get the following error:

cp: cannot open 'IMG_0001.PNG' for reading: Input/output error

In the log it says:

Jul 5 21:33:35 iPhone afcd(libafc.dylib)[302] <Notice>: AFCFileLine="2071" AFCFileName="server.c" AFCCode="1" NSDescription="Failed open operation as there are additional hard links (2) to the file being opened." AFCVersion="261.25999999999999"

iOS is 12.3.1. Before upgrade when it was running 11.x it was working.

What could be wrong?

libimobiledevice 1.2.1 git libusbmuxd 1.1.0 git ifuse 1.1.3 git OS: Debian 9

MrHm avatar Jul 05 '19 19:07 MrHm

This error is coming from the device, and nothing that is fixable from libimobiledevice or ifuse point of view. Does it work with other files? Like can you open files e.g. in the Downloads folder of the device via ifuse?

nikias avatar Jul 06 '19 20:07 nikias

I have done further testing and this is what I concluded:

  1. Non image/video files are readable via ifuse mount (for example in Downloads)

  2. If the image files are seen in Gnome filesystem (i.e. not ifuse), then the file is readable there. But the same image returns io error when read via ifuse mount.

  3. A very small portion of the image files are readable via ifuse. For example: IMG_0001.jpg - IMG_0007.jpg returns input/output error, but IMG_0008.jpg works. I have not found out why.

  4. The problem exists on two different iPhones (both 12.3.1)

The above tested on Linux Mint 19.

MrHm avatar Jul 07 '19 09:07 MrHm

Just to say I'm experiencing the same kind of behaviour trying to copy photos and movies on Debian Buster.

nick@polonius:~/mnt/DCIM/108APPLE$ ls -l *.MOV
-rw-r--r-- 2 nick nick 29467897 Jul 23 15:14 IMG_8252.MOV
-rw-r--r-- 2 nick nick 12190305 Jul 23 15:18 IMG_8347.MOV
-rw-r--r-- 2 nick nick  4770330 Jul 23 17:32 IMG_8644.MOV
nick@polonius:~/mnt/DCIM/108APPLE$ cp *.MOV /tmp
cp: cannot open 'IMG_8252.MOV' for reading: Input/output error
cp: cannot open 'IMG_8347.MOV' for reading: Input/output error
cp: cannot open 'IMG_8644.MOV' for reading: Input/output error

Most but not all JPEG files seem to copy OK. Using deb 1.1.4~git20181007.3b00243-1

nickbailey avatar Jul 27 '19 11:07 nickbailey

Just to confirm that I'm also experiencing this behaviour on latest Arch. Some (older?) files seem to copy, the new ones give input/output errors. IOS 12.4. Rebooting phone, computer, and re-pairing with idevicepair doesn't seem to help unfortunately. Any thoughts?

yellius avatar Aug 17 '19 08:08 yellius

I am also experiencing this problem. Someone recommended on a forum to put the rsync command in loop until it returns a successful exit code, but I haven't tried it yet. This assumes that eventually the files will transfer. According to the user who gave the recommendation, they do.

Not a very trustworthy or complete way to transfer files!


See: https://superuser.com/questions/676649/how-to-interpret-and-fix-a-input-output-error-in-linux

"I had a similar issue, I had a with fuse-mounted device via USB, which would frequently disconnect, causing IO errors. My backup could never finish because the IO errors would start mid-way into the rsync, and despite running rsync repeatedly, at some point the sync would not progress beyond updating existing files.

My solution was to use

--ignore-existing

option. This way I could run the sync in a loop until seeing a 0 exit status.

Of course, in this case I didn't care about updates to existing files."

greywood avatar Oct 22 '19 21:10 greywood

I believe I am seeing something similar with Ubuntu 18.04 and iOS 13.2.1, but I am trying to transfer files though the file browser, not via command line. When i plug the phone in and Trust the computer, I see a "Document on iPhone" mount that shows all of my apps that have file management enabled (FireFox, VOX, Maps.me, etc). I can drag/drop non-media files like .txt, .pdf, .odt, etc, but I cannot transfer media files like .png, .mp3, etc

I was able to transfer media files in this fashion earlier this summer, but now I can't. I'm not sure when the functionality broke or whether it was due to and iOS or limobiledevice update. I;m guessing the former since the later is ancient and seemingly dead.

This appears to be related: https://askubuntu.com/questions/1177391/cannot-transfer-files-to-iphone-with-libimobiledevice/1188872#1188872

arderyp avatar Nov 14 '19 23:11 arderyp

I am also experiencing this problem. Laptop with Debian 10.2 with 5.2.0 backported kernel, rsync 3.1.3, ifuse 1.1.4, libimobiledevice 1.2.1~git20181030.92c5462 Iphone 7 with IOS 13.2.3 but the problem has been observed several times the past 6 months.

Most files are transferred ok by rsync to the laptop, but some are not. Typical error for rsync is Input/output error (5). And cp also fails.

A not confirmed suspicion some months ago was that the files that fail to be read are received by sms messages or some other messaging tool, then saved to the file system on the iphone. The iphone can read and show them, but it seemed that they could not be transferred. Now I have seen an example of a file that fail to copy that I am confident was taken with the iphone camera.

andersbel avatar Nov 24 '19 20:11 andersbel

Did some further testing. All the files that failed to transfer by rsync when iphone was mounted with libimobiledevice/ifuse, did transfer when I just selected "Camera/Open with Dolphin file manager". This uses PTP mode.

But, some files that were present in the resulting pile from copying DCIM/100APPLE with libimobile/ifuse/rsync, were not present when copying 100APPLE when using Dolphin/PTP-mode.

And vice versa. Some other files that were transferred from 100APPLE with Dolphin/PTP were not seen nor transferred from 100APPLE when using libimobiledevice/ifuse/rsync.

Peculiar. Why would the file list be different in this directory depending on how it is accessed? I have not changed anything in between.

andersbel avatar Nov 24 '19 20:11 andersbel

Maybe some creative symlinking under the hood on Apples part? Or file permissions set on the phone that we can't detect? A very wild guess.

Sent from ProtonMail Mobile

On Sun, Nov 24, 2019 at 1:36 PM, andersbel [email protected] wrote:

Did some further testing. All the files that failed to transfer by rsync when iphone was mounted with libimobiledevice/ifuse, did transfer when I just selected "Camera/Open with Dolphin file manager". This uses PTP mode.

But, some files that were present in the resulting pile from copying DCIM/100APPLE with libimobile/ifuse/rsync, were not present when copying 100APPLE when using Dolphin/PTP-mode.

And vice versa. Some other files that were transferred from 100APPLE with Dolphin/PTP were not seen nor transferred from 100APPLE when using libimobiledevice/ifuse/rsync.

Peculiar. Why would the file list be different in this directory depending on how it is accessed? I have not changed anything in between.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

greywood avatar Nov 24 '19 20:11 greywood

I had this issue with about half of my photos. I have found that if I leave the camera app open while my ipad is plugged in and mounted all of my files with 2 hard links will slowly whittle down to 1.

I only encountered this because I was taking pictures while it was mounted and checking the number of hard links on the new photos and just happened to see my number of double linked files going down.

Edit: After some more investigating I was able to find out that if I load the 2 hard link files in the gallery app they will go down to 1 (for the most part). It is not consistent and does not always happen right away. But I have not found anything else that helps

JacobusH avatar Dec 30 '19 04:12 JacobusH

I ran into this issue and was able to fix it by setting the following in iOS: Settings -> Photos -> Download and Keep Originals I believe there's something weird going on inside iOS where it's displaying photos that are cloud backed as "real files" when mounted and not showing them at all via PTP. I noticed that all the missing files had an exclamation point on them when I had the Optimize iPhone Storage setting enabled. When I changed it to Download and Keep Originals, it started downloading the files and they showed up in the ifuse mounted folder.

brandonrobertz avatar May 22 '20 10:05 brandonrobertz

@brandonrobertz, thanks for the insight. It wouldn't surprise me at all is iOS was making cloud files appear as native on the device, leading to this error. That said, it certainly not whats happening in my case

arderyp avatar May 22 '20 14:05 arderyp

After running into this issue, I checked in the file manager and for the pictures that got this error there was no preview: Screenshot from 2020-05-25 20-13-50 And when I tried to open them I would get this error: Could not load image "IMG_0501.JPG". Failed to open input stream for file However, on my phone I can see these pictures and they are no different than other ones. Though unlike other people, most of my pictures were able to be copied over. And I think all of these pictures were in 101APPLE (out of 101APPLE to 111APPLE) I am not sure if this will help or not.

NewoIsTaken avatar May 26 '20 00:05 NewoIsTaken

This worked for me, after trying for hours on 20.04. rsync didn't help, mv at the command-line didn't help either.

Linked from above, read the first answer:

https://askubuntu.com/questions/928750/how-do-i-access-ios-camera-pictures-on-ubuntu

Avoiding the iphone camera "drive" in the file manager, and using the iphone documents drive instead. Removed the :3 at the end of the afc://deadbeef:3 path. Hit enter, which showed me a number of folders. Went into DCIM folder. Tried copying from there by dragging and dropping.

Bam, worked perfectly from this view!

Addendum: in newer versions the hexadecimal device id wasn't visible in the file manager. I found this command-line program printed it out: idevice_id -l

mixmastamyk avatar Jul 08 '20 07:07 mixmastamyk

Ok, thanks! My phone is on a later update, but will try.

NewoIsTaken avatar Jul 08 '20 13:07 NewoIsTaken

This worked for me, after trying for hours on 20.04. rsync didn't help, mv at the command-line didn't help either.

Linked from above, read the first answer:

https://askubuntu.com/questions/928750/how-do-i-access-ios-camera-pictures-on-ubuntu

Avoiding the iphone camera "drive" in the file manager, and using the iphone documents drive instead. Removed the :3 at the end of the afc://deadbeef:3 path. Hit enter, which showed me a number of folders. Went into DCIM folder. Tried copying from there by dragging and dropping.

Bam, worked perfectly from this view!

Works! Ubuntu 20.04 Saved hours of my life

tehcmanmax avatar Aug 07 '20 23:08 tehcmanmax

Just to confirm, this consistently happens with files that have a number of hardlinks above 1.

$ ls -l

-rw-r--r--  1 my-user  staff    1672225 Feb 11 11:26:56 2015 IMG_4992.JPG
-rw-r--r--  2 my-user  staff    1539231 Feb 11 11:26:58 2015 IMG_4993.JPG  ← fail
-rw-r--r--  2 my-user  staff    1692296 Feb 11 11:27:03 2015 IMG_4994.JPG  ← fail
-rw-r--r--  1 my-user  staff    1557357 Feb 11 12:51:52 2015 IMG_4995.JPG

The two files in the middle are unreadable, the other two are fine.

vszakats avatar Jan 09 '21 20:01 vszakats

I am having a similar issue copying files from an application directory for an application called "FiLMiC Pro" (an advanced video recording app). Strangely, I was able to copy video files produced by this app without issue before upgrading to Ubuntu 20.04. I can confirm that the files in question are in fact on the device, rather than up in the cloud.

skipcress avatar Jan 13 '21 01:01 skipcress

Indeed, the files were on the device and I could manually share them from the Photos app (or extract from a local backup using a different 3rd party tool). It seemed that these files were all created by specific iOS versions (possibly 8.2 and earlier) and shared in some ways. Hence the hardlinks.

[ My unrelated observation is that it took 1 week to copy off the DCIM folder, due to the 150-300KB/sec max transfer speed and the connection breaking up quite often. It certainly doesn't appear as if Apple wanted to make users accessing their own data simple or even possible. ] And big thanks to ifuse devs.

vszakats avatar Jan 13 '21 11:01 vszakats

I think the connection aborts have to do with a GnuTLS issue (which is used by default on ubuntu).

Ans yes, the speed is really slow but this is mostly due to the fuse layer (I tried to optimize this but couldn't figure out why). Direct AFC I/O is way faster than that. There's a tool called afcclient somewhere, I should add this to the official set of tools in libimobiledevice.

nikias avatar Jan 13 '21 15:01 nikias

@nikias Thanks for your tip with afcclient. I built it (with some minor patches) and it seems noticeably faster indeed (though tbf this was via USB, and the above was via WiFi). Anyhow, with some light scripting, afclient is a nice alternative. Hardlinked photos result in AFC_E_UNKNOWN_ERROR, so no change there.

afcclient patch (tested on macOS + Homebrew)

diff --git a/Makefile b/Makefile
index a0da076..330fb95 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 CC=clang
 CFLAGS=
-LDFLAGS=-limobiledevice -lplist
+LDFLAGS=-limobiledevice-1.0 -lplist-2.0
 
 OS := $(shell uname)
 ifeq ($(OS),Darwin)
diff --git a/afcclient.c b/afcclient.c
index 936f1f5..1c80293 100644
--- a/afcclient.c
+++ b/afcclient.c
@@ -566,10 +566,12 @@ int main(int argc, char **argv)
                 break;
 
             case 'u':
+                #if 0
                 if ((strlen(optarg) != 40)) {
                     fprintf(stderr, "Error: invalid udid (wrong length): %s\n", optarg);
                     return EXIT_FAILURE;
                 }
+                #endif
 
                 udid = optarg;
                 break;
diff --git a/libidev.c b/libidev.c
index fc7812a..70684a7 100644
--- a/libidev.c
+++ b/libidev.c
@@ -34,9 +34,10 @@ const char *idev_idevice_strerror(idevice_error_t errnum)
             return "NO_DEVICE";
         case IDEVICE_E_NOT_ENOUGH_DATA:
             return "NOT_ENOUGH_DATA";
-        case IDEVICE_E_BAD_HEADER:
-            return "BAD_HEADER";
         case IDEVICE_E_SSL_ERROR:
+            return "SSL_ERROR";
+        case IDEVICE_E_TIMEOUT:
+            return "TIMEOUT";
         default:
             return "UNKNOWN_EROR";
     }
@@ -59,8 +60,8 @@ const char *idev_lockdownd_strerror(lockdownd_error_t errnum)
             return "SSL_ERROR";
         case LOCKDOWN_E_DICT_ERROR:
             return "DICT_ERROR";
-        case LOCKDOWN_E_NOT_ENOUGH_DATA:
-            return "NOT_ENOUGH_DATA";
+        case LOCKDOWN_E_RECEIVE_TIMEOUT:
+            return "RECEIVE_TIMEOUT";
         case LOCKDOWN_E_MUX_ERROR:
             return "MUX_ERROR";
         case LOCKDOWN_E_NO_RUNNING_SESSION:
@@ -170,7 +171,7 @@ const char *idev_afc_strerror(afc_error_t errnum)
         case AFC_E_SUCCESS:
             return "SUCCESS";
         case AFC_E_UNKNOWN_ERROR:
-            return "UNKNOWN_ERROR";
+            return "AFC_E_UNKNOWN_ERROR";
         case AFC_E_OP_HEADER_INVALID:
             return "OP_HEADER_INVALID";
         case AFC_E_NO_RESOURCES:

vszakats avatar Jan 14 '21 23:01 vszakats

I ran into this issue and was able to fix it by setting the following in iOS: Settings -> Photos -> Download and Keep Originals I believe there's something weird going on inside iOS where it's displaying photos that are cloud backed as "real files" when mounted and not showing them at all via PTP. I noticed that all the missing files had an exclamation point on them when I had the Optimize iPhone Storage setting enabled. When I changed it to Download and Keep Originals, it started downloading the files and they showed up in the ifuse mounted folder.

A hero

ArensMyzyri avatar Jan 18 '21 21:01 ArensMyzyri

I ran into this issue and was able to fix it by setting the following in iOS: Settings -> Photos -> Download and Keep Originals I believe there's something weird going on inside iOS where it's displaying photos that are cloud backed as "real files" when mounted and not showing them at all via PTP. I noticed that all the missing files had an exclamation point on them when I had the Optimize iPhone Storage setting enabled. When I changed it to Download and Keep Originals, it started downloading the files and they showed up in the ifuse mounted folder.

A hero

After this change it started to download on ubuntu with 2-5 MB/s

ArensMyzyri avatar Jan 18 '21 21:01 ArensMyzyri

I too am having errors. On an Arch host with libimobiledevice 1.3.0-3 and ifuse 1.1.4-1, I pair with idevicepair, then mount with ifuse ~/mnt/iphone. I try to rsync ~/mnt/iphone to a local directory, and some files (I estimate less than 1/3rd) cannot be read. Here is an example of the error when trying to cat one of the problematic files:

$ strace -v cat /home/dan/mnt/iphone/DCIM/103APPLE/IMG_3316.HEIC
[...]
openat(AT_FDCWD, "/home/dan/mnt/iphone/DCIM/103APPLE/IMG_3316.HEIC", O_RDONLY) = -1 EIO (Input/output error)
[...]

I have confirmed with stat and ls that the problematic files have more than 1 hard link, as @vszakats and others have mentioned in this thread. I tried the Settings -> Photos -> Download and Keep Originals that worked for @brandonrobertz and others, but this did not work for me.

As a point of comparison, I then plugged the iphone into a Windows 10 host and it mounted (presumably in PTP mode). I was able to copy all files off of it without issues. (I spot checked several of the files I had issues copying with using libimobiledevice/ifuse and verified that they were copied on the Windows host.)

dlaflamme avatar Feb 17 '21 01:02 dlaflamme

I too am having errors. On an Arch host with libimobiledevice 1.3.0-3 and ifuse 1.1.4-1, I pair with idevicepair, then mount with ifuse ~/mnt/iphone. I try to rsync ~/mnt/iphone to a local directory, and some files (I estimate less than 1/3rd) cannot be read. Here is an example of the error when trying to cat one of the problematic files:

$ strace -v cat /home/dan/mnt/iphone/DCIM/103APPLE/IMG_3316.HEIC
[...]
openat(AT_FDCWD, "/home/dan/mnt/iphone/DCIM/103APPLE/IMG_3316.HEIC", O_RDONLY) = -1 EIO (Input/output error)
[...]

I have confirmed with stat and ls that the problematic files have more than 1 hard link, as @vszakats and others have mentioned in this thread. I tried the Settings -> Photos -> Download and Keep Originals that worked for @brandonrobertz and others, but this did not work for me.

As a point of comparison, I then plugged the iphone into a Windows 10 host and it mounted (presumably in PTP mode). I was able to copy all files off of it without issues. (I spot checked several of the files I had issues copying with using libimobiledevice/ifuse and verified that they were copied on the Windows host.)

Did you try mixmastamyk's workaround?

thermochromic avatar Jun 14 '21 17:06 thermochromic

I'm also having similar behavior, I also get the same error on files that have more than one hardlink. These files do seem copyable over scp though.

enricozb avatar May 22 '22 23:05 enricozb

I'm also having similar behavior, I also get the same error on files that have more than one hardlink. These files do seem copyable over scp though.

The workaround mentioned above https://github.com/libimobiledevice/ifuse/issues/54#issuecomment-655341823 worked for me. Not a real solution but it seems to work every time.

thermochromic avatar May 23 '22 17:05 thermochromic