a few times, for reasons unknown to me, asr restore processes broke with error 49244. Basically, the process get interrupted, most cases when is about to finish, with just a laconic message saying "Volume replication failed - error 49244".
Where can I get information on this error, what exactly means, what causes it and more important, how to troubleshoot it.
Any help will be appreciated,
Thanks!!
Files and Storage
RSS for tagAsk questions about file systems and block storage.
Posts under Files and Storage tag
200 Posts
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hi all,
I use the FileManager trashIitem function to put a file in the trash.
If it is only one file, then the option to put it back is available.
If, however, several files are deleted, the option to put it back is only available for the first
deleted file. All others cannot be put back.
The problem has been known for at least 10 years.
See Put back only works for the first file.
NSWorkspace recycle has the same problem.
It seems to be due to .DS_Store in the trash. The files that are in the trash are stored there. This may also lead you to believe that the trashItem function is working properly because the deleted files are still in the .DS_Store file.
If I call trashItem or recycle several times and wait 2 seconds between calls, then the option to put it back is available for all of them.
That obviously can't be the solution. Waiting less than 2 seconds only offers to put the first file back.
So trashItem and recycle are the same as remove, with the difference that you can look at the files in the trash can again, but not put them back.
Are there other ways?
The Finder can also delete multiple files and put them all back.
Some time ago I read somewhere that one can get a file icon on iOS like this:
UIDocumentInteractionController(url: url).icons.last!)
but this always returns the following image for every file:
Today I tried the following, which always returns nil:
(try? url.resourceValues(forKeys: [.effectiveIconKey]))?.allValues[.effectiveIconKey] as? UIImage
Is there any way to get a file icon on iOS?
You can try the above methods in this sample app:
struct ContentView: View {
@State private var isPresentingFilePicker = false
@State private var url: URL?
var body: some View {
VStack {
Button("Open") {
isPresentingFilePicker = true
}
if let url = url {
Image(uiImage: UIDocumentInteractionController(url: url).icons.last!)
if let image = (try? url.resourceValues(forKeys: [.effectiveIconKey]))?.allValues[.effectiveIconKey] as? UIImage {
Image(uiImage: image)
} else {
Text("none")
}
}
}
.padding()
.fileImporter(isPresented: $isPresentingFilePicker, allowedContentTypes: [.data]) { result in
do {
let url = try result.get()
if url.startAccessingSecurityScopedResource() {
self.url = url
}
} catch {
preconditionFailure(error.localizedDescription)
}
}
}
}
Before updating to macOS 15 Sequoia, I used to be able to create file bookmarks with this code:
let openPanel = NSOpenPanel()
openPanel.runModal()
let url = openPanel.urls[0]
do {
let _ = try url.bookmarkData(options: [.withSecurityScope])
} catch {
print(error)
}
Now I get an error
Error Domain=NSCocoaErrorDomain Code=256 "Failed to retrieve app-scope key"
These are the entitlements:
com.apple.security.app-sandbox
com.apple.security.files.user-selected.read-write
com.apple.security.files.bookmarks.app-scope
Strangely, my own apps continued working, after updating to macOS 15 some days ago, until a few moments ago. Then it seems that all of a sudden my existing bookmarks couldn't be resolved anymore, and no new bookmarks could be created. What could be the problem?
Hey fellow developers,
I’m developing an app that mounts network shares (SMB, AFP, Secure WebDAV, CIFS) using the NetFSMountURLAsync function.
Recently, mounting WebDAV shares has stopped working — it fails with error code 22, but I can’t find a definitive reason for the failure. It simply doesn’t work. However, using Finder to connect to the same WebDAV share works flawlessly, so it doesn’t appear to be a server-side issue.
Strange Behavior
I’ve noticed something interesting:
If I create a new Xcode project and set Signing Certificate to Sign to Run Locally, the app mounts the WebDAV share without any issues.
As soon as I change the signing option to anything else (e.g., Development), the share no longer mounts, and the app fails with error 22.
Even if I switch back to Sign to Run Locally, the app remains broken and refuses to mount the share.
Rebuilding the app, restarting Xcode, and clearing derived data/caches do not restore functionality. The only workaround I’ve found is to create a new Xcode project and copy the code over.
Additionally:
Mounting SMB and AFP shares always works without issues.
The app is properly sandboxed.
My certificates are valid until at least 2027.
Granting the app Full Disk Access does not resolve the issue.
System Log Insights
Looking at the system log, I found several mounting-related messages. On failure, one stands out:
System Policy: webdavfs_agent() deny(1) file-mount <Path to the mount directory in the Documents directory of the example project>
Questions
Does anyone have any idea how to debug or resolve this issue?
Is there a way to reset the example project to a working state? Are there any caches or system states I might have missed?
I’d prefer not to recreate all my certificates and configurations, as I don’t see any reason why they would affect only WebDAV mounting while everything else works fine.
Reproducing the Issue
I’ve created a minimal SwiftUI example to reproduce the problem. Just create a new macOS SwiftUI project, replace ContentView with my code, update the details to match your WebDAV share, and enable Outgoing Network Connections in the entitlements.
Any help or insights would be greatly appreciated!
Example Code
import SwiftUI
import NetFS
struct ContentView: View {
let mounter = WebDAVMounter()
var body: some View { VStack { Button("Test mount") { test() } } .padding() }
func test() { mounter.mount() }
}
class WebDAVMounter {
private var requestID: AsyncRequestID?
func mount() {
let username = <# username #>
let password = <#password#>
let serverURL = URL(string: "<#https://webfiles/Work~Home#>")!
let usedMountPoint = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let openOptions = NSMutableDictionary()
openOptions[kNAUIOptionKey] = kNAUIOptionNoUI
let mountOpts = NSMutableDictionary()
mountOpts[kNetFSSoftMountKey] = true
print("server URL: \(serverURL) usedMountPoint: \(usedMountPoint) username: \(username) password: \(password) sessionOpts: \(openOptions) mountOptions \(mountOpts)")
NetFSMountURLAsync(serverURL as CFURL,
usedMountPoint as CFURL,
username as CFString?,
password as CFString?,
openOptions as CFMutableDictionary,
mountOpts as CFMutableDictionary,
&requestID,
DispatchQueue.main,
{ status, asyncRequestId, mountedDirs in print("mount_report: \(status), mountedDirs: \(String(describing: mountedDirs))")})
}
}
The simple test case is this:
@max[git:master]$ /usr/bin/ssh max ls /Volumes
Macintosh HD
TM2
me
me9
@max[git:master]$
and
@max[git:master]$ /usr/bin/ssh max /bin/bash -c "ls /Volumes"
Applications
Calibre Library
Desktop
...
The latter is NOT doing an ls of /Volumes/ but of my $HOME directory.
This is a recent change. I've had a script that is > 10 years old that just started failing.
Here's another look:
@max[git:master]$ /usr/bin/ssh max /bin/bash -c "cd /Volumes && pwd"
/Users/layer
@max[git:master]$ echo $?
0
@max[git:master]$
It's weird that it just silently ignores the cd.
This is on
ProductVersion: 15.3
BuildVersion: 24D60
I'm trying to persist a bookmark to an external device (mass storage controller connected via camera adapter) across disconnection / reconnection, but it is failing at startAccessingSecurityScopedResource.
The URL is initially retrieved using
UIDocumentPickerViewController *documentProvider;
documentProvider = [[UIDocumentPickerViewController alloc] initForOpeningContentTypes:[NSArray arrayWithObjects:UTTypeFolder, nil]];
documentProvider.delegate = self;
documentProvider.modalPresentationStyle = UIModalPresentationOverFullScreen;
[self presentViewController:documentProvider animated:YES completion:nil];
and then persisted to a bookmark using
DeviceBookmark = [url bookmarkDataWithOptions:NSURLBookmarkCreationMinimalBookmark includingResourceValuesForKeys:nil relativeToURL:nil error:nil]
When accessing the resource I use
NSURL *url = [NSURL URLByResolvingBookmarkData:DeviceBookmark options:NSURLBookmarkResolutionWithoutUI relativeToURL:nil bookmarkDataIsStale:&isStale error:&error]
to retrieve the new URL.
If I don't remove the MSC then the retrieved URL remains the same and functions as expected. If I remove and reconnect the MSC then the URL changes, I get true for isStale and nil for error but startAccessingSecurityScopedResource fails.
I've been banging my head against this for about a day now, but can't see what the issue can be. I've tried adding some related permissions to the entitlements, but this seems to be macOS related as far as I can tell.
What am I missing?!
I'm working on a cross-platform application that needs to access file attributes, specifically for files and directories in sync drives like OneDrive. On Windows, I use the GetFileInformationByHandle API to retrieve attributes such as FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS and FILE_ATTRIBUTE_RECALL_ON_OPEN to identify files that are stored remotely or in the cloud.
Is there an equivalent API or mechanism on macOS to achieve the same? Specifically, I’m looking for a way to:
Identify attributes similar to cloud/offline storage status for files in synced drives (e.g., OneDrive, iCloud Drive).
Retrieve metadata to distinguish files/folders stored locally versus those stored remotely and downloaded on access.
If there’s a preferred macOS framework (like Core Services or FileManager in Swift) for such operations, examples would be greatly appreciated!
Topic:
App & System Services
SubTopic:
Core OS
Tags:
APFS
Files and Storage
Swift
Cloud and Local Storage
I'm working on a cross-platform application that needs to access file attributes, specifically for files and directories in sync drives like OneDrive. On Windows, I use the GetFileInformationByHandle API to retrieve attributes such as FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS and FILE_ATTRIBUTE_RECALL_ON_OPEN to identify files that are stored remotely or in the cloud.
Is there an equivalent API or mechanism on macOS to achieve the same? Specifically, I’m looking for a way to:
Identify attributes similar to cloud/offline storage status for files in synced drives (e.g., OneDrive, DropBox etc).
Retrieve metadata to distinguish files/folders stored locally versus those stored remotely and downloaded on access.
If there’s a preferred macOS framework (like Core Services or FileManager in Swift) for such operations, examples would be greatly appreciated!
Topic:
App & System Services
SubTopic:
Core OS
Tags:
APFS
Files and Storage
Swift
Cloud and Local Storage
SwiftData ModelContainer instances don't seem to have a value for setting the Data Protection class.
Is the best way to set that by setting the Data Protection in the app capabilities? Is that the only way?
I have a need for log data that would be "Complete unless open" and user data that would be "Complete", but how do I change one of the containers data protection class?
Hi,
I’m currently working on a project to sanitize data (Remove customer data) on MacBook storage devices (Refurbish). The NVMe SSD is embedded on the motherboard. I’ve created a simple proof-of-concept code (Running in terminal) with the following steps:
Check and Match the NVMe Device: Verify that the physical drive (disk0) exists on the system.
Open the Connection: Establish a connection to the device (disk0).
Send NVMe Admin Commands: For testing, I sent the IDENTIFY (0x06) command to confirm that the connection to the device works.
Close the Service and Connection: Terminate the connection after the test.
However, during runtime, I encountered an error when sending the command:
Error: Failed to send NVMe Admin Command with error: -536870206 ((iokit/common) invalid argument)
I’m unsure why this results in an "Invalid argument" error. Is the method I’m using to send the Admin Command incorrect? If so, what is the proper function call to use in the IOKit framework? Alternatively, are there any other recommended methods to achieve this?
In the future, I also need to send commands like ‘Sanitize (84h)’ and ‘Format NVM (80h).’ Since I’m new to macOS development, I’d greatly appreciate any advice or guidance from experts in this area.
I have attached the source code and related ioreg file for 'IOMedia' and 'IONVMeController' for you guy reference.
IOMedia
IONVMeController
sendAdminCommands.cpp
Thank you so much for your help!
Regards,
Winson
Not sure if my question is weird or not, but I didnt find any documentation about an sdks access to an apps documents directory.
Im assuming that because sdk is part of the sandbox that it can access and read from the documents directory? i.e. if i used
NSFileManager.defaultManager.URLForDirectory(
directory = NSCachesDirectory,
inDomain = NSUserDomainMask,
appropriateForURL = null,
create = false,
error = null,
)
to write a file called "file.txt", then any sdk my app used has the ability to access the contents of said directory?
If yes, why isnt this considered something more worth mentioning? usually in filemanager tutorials they never warn about this.
FYI: Im asking more for iOS and iPadOs then MacOs.
I need to render a PDF and then make it downloadable to the mobile device. I can generate the PDF but I'm unsure how to configure the download aspect. I have the following code:
let renderer = UIGraphicsPDFRenderer(bounds: CGRect(x: 0, y: 0, width: 612, height: 792))
let pdf = renderer.pdfData { (context) in
context.beginPage()
let text = "Test" as NSString
text.draw(in: CGRect(x: 0, y: 0, width: 100, height: 25))
I've developed a new Quicklook data-based preview extension for a custom file type that generates an image preview of the file. I previously used a Quick Look generator plug-in but support for it was deprecated and now removed in macOS Sequoia.
My app opens files using a
open(url.path, O_RDWR | O_NONBLOCK | O_EXLOCK)
call. The locking flags are used to prevent other clients from writing the file if it's already open.
I discovered that when Finder is showing the “large” file previews (such as when in column or gallery modes) from a SMB share, the open call fails with EWOULDBLOCK as if the file is locked.
It does work just fine on local files. Opening with O_SHLOCK also has the issue. Surprisingly it does work just fine for previews that return Plain Text data instead of Image data.
Using the lsof command, it seems like the Quicklook process has some kind of lock on the file.
This is the output of the lsof command:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE
QuickLook 48487 XXXX txt REG 1,15 125000611 3161369
Attached is a test project that tries a few different opening and locking functions. It also includes a test file and a sample image preview extension that displays a red square.
When everything is working, regular console messages show the progress of the tests. When the file is on a SMB share and selected in Finder Gallery mode, the open test will fail with a fault message in the console.
Notably, locking with flock works, which is weird because it should have similar semantics according to the man page for open(2).
Filed this as FB15051186
Topic:
App & System Services
SubTopic:
General
Tags:
Extensions
QuickLook
QuickLook Thumbnailing
Files and Storage
I'm just trying to display an image that is stored in the local filesystem, but the more I dig into this the more confused I get.
So previously I used this code (it's simplified):
func findImage(name: String) -> UIImage? {
do {
let url = try FileManager.default.url(for: .applicationSupportDirectory,
in: .userDomainMask,
appropriateFor: nil,
create: false)
.appendingPathComponent("MyFolder")
.appendingPathComponent("\(name).png")
guard let image = UIImage(contentsOfFile: url.path) else {
return nil
}
return image
} catch {
print(error.localizedDescription)
}
return nil
}
Notice I create the URL with just .appendingPathComponent() and turning URL to path via url.path.
It works! So what's the question?
In Improving performance and stability when accessing the file system I've read that you better use the new appendingPathComponent(_:isDirectory:), that's good, will do.
Also url.path is deprecated in iOS18. Should I use url.path(percentEncoded:) instead? What should be the value of percentEncoded when accessing the local filesystem?
In this adjacent thread I've read:
Don't use UIImage(contentsOfFile:) either, because it's a path-based API. There's no URL-based equivalent, which is an Apple clue that should be doing something else.
Is this true? Then how should I store and load my images?
Just FYI, I create images like this:
private func generateThumbnail(name: String) {
guard let drawingWidth = canvasGeo?.size.width,
let drawingHeight = canvasGeo?.size.height else { return }
let thumbnailRect = CGRect(x: 0, y: 0, width: drawingWidth, height: drawingHeight)
Task {
UITraitCollection(userInterfaceStyle: .light).performAsCurrent {
let image = self.canvasView.drawing.image(from: thumbnailRect, scale: UIScreen.main.scale)
guard let data = image.pngData() else { return } // -- HERE
do {
try FileManager.default.createDirectory(at: try FileManager.default.url(for: .applicationSupportDirectory,
in: .userDomainMask,
appropriateFor: nil,
create: true)
.appendingPathComponent("MyFolder"),
withIntermediateDirectories: true,
attributes: nil)
let filename = "\(name).png"
let url = try FileManager.default.url(for: .applicationSupportDirectory,
in: .userDomainMask,
appropriateFor: nil,
create: true)
.appendingPathComponent("MyFolder")
.appendingPathComponent(filename)
try data.write(to: url, options: .atomic) // -- and HERE
} catch {
print(error.localizedDescription)
}
}
}
}
My usecase — just save the user's PencilKit Canvas as an image and display it back to him on a different View. I'm on SwiftUI and iOS 16+.
Would be happy to learn the correct way, thanks!
When trying to use asr for restore my system disk ("/"), I'm getting a "resource busy error"
It's a very laconic message, that says very little about how solve or work around the issue. I'm attaching the screenshot of the error.
Any help on how to troubleshoot this error would be highly appreciated
Thanks!
This is using Xcode 16.2 (16C5032a), MacOS 15.2, on MacbookPro 16 M1 Pro.
I have two repositories, one for an application and another one for a framework. The repository framework is integrated into the application one as git submodule.
I was going to push the submodule to Github using Xcode git integration. It detects some conflicts and ask to pull. I pull. A window appears with some conflicting files (5 or 6). Review them. While reviewing something in Xcode crashed, but as Xcode was still up and running, ignored the crash. Decided to cancel the conflicts window and inspect my local files. Pull again but this time I decided to pull both repos. Review the conflicting changes and decided to cancel again to continue by hand in a terminal.
Then, I notice that the project for the submodule is in red and that the "Changes" tab shows a bunch of files with and admiration mark. I go to the submodule folder in Finder and... everything inside the submodule folder was gone, disappeared, lost... everything, even the ".git" folder (only remained a binary folder for a component I use for the framework but is empty).
I decided to run a recovery tool. It finds nothing to recover inside that folder, nothing. A lot of files even from years ago but nothing inside that folder? how is that possible?
I filled a Feedback assistant issue: FB16307182
Could it be possible that Xcode "moved" everything to another place (I'm desperate so I'm starting to think in absurd explanations)
Thanks
I have written an App with a fileIpmorter modifier.
I used TestFlight to pass it to friend for a test.
The App works fine until my friend uses the fileImporter function:
He can select the file to import (simple csv file), the fileImporter closes without having read out the csv file!
I was able to analyze that the do-catch-block within the fileImporter modifier throws an error at the mac of my friend.
The App behaves totally different to my Mac: On my Mac it works perfectly:
the csv file is read out and the data can be used within the APP.
Why does it behave like this?
Why does this happen to the mac of my friend but not on mine?
More strange:
The Apple team is not able to even use the csv-file I passed them in the App Store Connect process: They are not able to select the file in the downloads folder.
All three used MAC´s with three different behaviors? - How comes?
I have NTFS which is mounted on '/Volumes/usb_vol'
#mount
Filesystem Mounted on
/dev/disk5s1 /Volumes/usb_vol
The following simple code reports different values of device Id for device-file and mount point directory
struct stat buf;
for (int i = 1; i < argc; i++)
{
std::cout << argv[i] << std::endl;
if (stat(argv[i], &buf) < 0)
{
continue;
}
if (S_ISBLK(buf.st_mode))
{
std::cout << "st_rdev (" << major(buf.st_rdev) << "/" << minor(buf.st_rdev) << ") hex: " << std::hex << buf.st_rdev << std::endl;
}
else
{
std::cout << "st_dev (" << major(buf.st_dev) << "/" << minor(buf.st_dev) << ") hex: " << std::hex << buf.st_dev << std::endl;
}
}
Output:
/dev/disk5s1
st_rdev (1/22) hex: 1000016
/Volumes/usb_vol
st_dev (48/119) hex: 30000077
I believe this is expected but I have not found any explanation of this behaviour.
Are there any explanation of difference these values?
I can assume the stat() will report (48/119) for all objects which are located on this file system. Is it correct?
Thank you for the help!
Hello!
We currently require the development of an iOS system for encrypting and authorizing photos, videos, voice memos, or other files stored on our devices to a connected USB-C storage. The encrypted files can be accessed through authorization. We have already encrypted and authorized the files to be stored on the app's mobile storage, and cannot directly store them to USB-C (this requirement is based on the Apple camera RroRes, which uses external storage for direct storage). We are seeking technical support from Apple.