UGreen NAS - Unable to enumerate contents of directory on iOS, works on macOS

I have a UGreen NAS. My app can read the contents of a folder on the NAS from macOS, but it cannot read the contents of a folder from iOS.

I bring up a UIDocumentPickerViewController(forOpeningContentTypes: [UTType.folder], asCopy: false).

I can pick a folder on the iPad’s internal storage, and successfully enumerate its contents. On the UGreen, I can pick a folder, but the content enumeration always returns zero items (no errors).

Enumeration of the UGreen works from macOS. It also works on the iPad when connecting to a Mac mini, or a Synology NAS. .

Files.app is able to view the UGreen folder and its contents. Oddly, my app cannot enumerate the contents, but it IS able to write a file to that UGreen folder.

Since Files.app can enumerate and I can write to the UGreen folder (and I can enumerate contents on other servers) - how can I get the enumeration to work? Feedback is FB22955130

Answered by DTS Engineer in 891953022

I can pick a folder on the iPad’s internal storage, and successfully enumerate its contents. On the UGreen, I can pick a folder, but the content enumeration always returns zero items (no errors).

So, based on what you've described, this sounds like a known (r.150542999) and fairly weird bug which I mentioned here.

In any case, the basic behavior was exactly what you've described (enumeration returns an empty directory), however, the odd part is that it ONLY did so on the first enumeration attempt. That is, enumerator(at:) returned an empty enumerator but if you then immediately tried again, it succeeded.

Note that I DON'T mean presenting the document picker again, I just mean directly retrieving the contents of the directory again. In terms of your code, doing something like this;

do {
	let contents = try fileManager.contentsOfDirectory(at: url, includingPropertiesForKeys: nil)
	let contents2 = try fileManager.contentsOfDirectory(at: url, includingPropertiesForKeys: nil)
	self.numberOfFilesLabel.text = "\(contents.count):\(contents2.count) items found"
}

Assuming it the issue above, then you'll get something like:

0:<#> items found

Please test with the retry above and let me know what you find.

Finally, it's still unclear what exactly is causing this issue. When I originally reproduced the issue in late iOS 18 it was specifically happening when macOS was presenting an external USB device over USB, but when I tested today I could not reproduce the issue. My guess is there is an underlying factor which ultimately triggers the issue, but at this point we haven't identified it.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

I'm assuming you are mounting the UGreen NAS using SMB?

Yes, it's mounted using SMB. The NAS supports either SMB2.x or SMB 3.

That's unexpected. The fact that Files.app can enumerate seems like that SMB is working fine against that NAS. The fact that UIDocumentPickerViewController() is working for you on macOS, but only fails on iOS and only against that particular server is very odd. I think we are going to need a bug report from you containing packet captures and iOS sysdiagnose when the problem occurs. Would be useful to have same packet captures and iOS sysdiagnose for a working situation so we can easily compare to see what's different.

How would I collect packet captures? I don't have experience with that. There is a feedback already in the system. FB22955130

I should mention that my customers are reporting the same thing with their UGreen, so it's not specific to my unit.

Found the bug report. If you can add a sysdiagnose for the "working" case (like on iOS, using your app against a server that is working), that should be good enough to start with. If we can't determine what is going wrong from the failing sysdiagnose vs working sysdiagnose, then we can give you instructions on how to get a packet trace later.

I just made one. But Feedback Assistant is down, so I will have to add it when it comes back up.

OK - I was able to upload three different sysdiagnoses:

  1. iPad -> Mac mini (works)
  2. Mac -> UGreen (works)
  3. iPad -> UGreen (doesn't work) - just to give an updated one

I can pick a folder on the iPad’s internal storage, and successfully enumerate its contents. On the UGreen, I can pick a folder, but the content enumeration always returns zero items (no errors).

So, based on what you've described, this sounds like a known (r.150542999) and fairly weird bug which I mentioned here.

In any case, the basic behavior was exactly what you've described (enumeration returns an empty directory), however, the odd part is that it ONLY did so on the first enumeration attempt. That is, enumerator(at:) returned an empty enumerator but if you then immediately tried again, it succeeded.

Note that I DON'T mean presenting the document picker again, I just mean directly retrieving the contents of the directory again. In terms of your code, doing something like this;

do {
	let contents = try fileManager.contentsOfDirectory(at: url, includingPropertiesForKeys: nil)
	let contents2 = try fileManager.contentsOfDirectory(at: url, includingPropertiesForKeys: nil)
	self.numberOfFilesLabel.text = "\(contents.count):\(contents2.count) items found"
}

Assuming it the issue above, then you'll get something like:

0:<#> items found

Please test with the retry above and let me know what you find.

Finally, it's still unclear what exactly is causing this issue. When I originally reproduced the issue in late iOS 18 it was specifically happening when macOS was presenting an external USB device over USB, but when I tested today I could not reproduce the issue. My guess is there is an underlying factor which ultimately triggers the issue, but at this point we haven't identified it.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

I am experiencing exactly the same issue with my app on a QNAP NAS. The Files App on iOS shows the correct content, but the FileManager api's ( return empty enumerations. Interestingly I could check it with a synology was and it works there flawlessly.

I have also tried the retry mentioned above with calling the same method twice, with no success.

Did someone found a different workaround?

The workaround did not solve the problem for me either and I have no other workarounds.

I am experiencing exactly the same issue with my app on a QNAP NAS.

Have you filed a bug and, if so, what's the bug number?

Did someone find a different workaround?

So, the other thing you could try is directly iterating the directory using getattrlistbulk. The API is a bit painful to use, but there's a small example function at the bottom of its man page you can borrow to avoid writing it yourself.

Also, the focus here has been on directories, but does it work if you select individual files?

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

We hit the same issue in our app with a UGREEN NAS, and we have narrowed it down to one server setting. We reproduced it on Samba 4.23.6 in a VM, on both iPadOS and iOS 27.2.

Trigger: With vfs_fruit loaded and the AAPL create context negotiated, Samba's fruit:zero_file_id = yes sets the FileId of every entry in the QUERY_DIRECTORY responses (FileIdBothDirectoryInformation) to 0. That has been Samba's default since 2022, so a NAS on a recent Samba with "macOS compatibility" turned on probably sends zero IDs out of the box. In that state:

  • Every listing on the LiveFS mount returns 0 entries with no error: FileManager.enumerator, contentsOfDirectory(at:), a raw opendir/readdir, and a coordinated read.
  • Lookups by path keep working, and the Files app still shows the folder's contents.
  • Packet captures on the server show complete, successful QUERY_DIRECTORY responses (STATUS_SUCCESS with all entries, then STATUS_NO_MORE_FILES). The entries reach the device, and the client drops them somewhere before they get to the app.

Counter-tests, each after a reboot of the device so it reconnects:

  • fruit:aapl = yes, fruit:zero_file_id = yes: all FileIds 0, the listing in the app is empty
  • fruit:aapl = yes, fruit:zero_file_id = no: real FileIds, the listing is correct
  • fruit:aapl = no: real FileIds, the listing is correct

None of these changed the result: readdir_attr:aapl_rsize/aapl_finder_info/aapl_max_access = no, fruit:nfs_aces = no, hide unreadable = no, or different permissions.

A side effect: removing a directory tree fails with ENOTEMPTY (STATUS_DIRECTORY_NOT_EMPTY), because the recursive delete sees no children.

Server-side workaround: fruit:zero_file_id = no, or turn off the NAS's macOS/fruit option. Most NAS UIs don't offer the setting on its own. Turning fruit off has costs of its own: without streams_xattr, iPadOS mounts the share read-only. We found no client-side workaround. Retrying the enumeration doesn't help, because the result stays empty.

Filed as FB25503064, with packet captures for each setting on both devices, iPad console log archives and our app's diagnostics.