Files and Storage

RSS for tag

Ask questions about file systems and block storage.

Posts under Files and Storage tag

200 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

App doesn't have permission to open files
Here's how my app used to work: On one device, generate a text file with a custom extension. Send it via AirDrop or in Messages to another device. Open the file in another copy of my app. The app processes the data correctly the way I want. Now, when I try to do this, I get this: Error Domain=NSCocoaErrorDomain Code=257 "The file “Shopping List.sld” couldn’t be opened because you don’t have permission to view it." UserInfo={NSFilePath=/private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/Downloads/Shopping List.sld, NSUnderlyingError=0x282280a50 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}} file:///private/var/mobile/Library/Mobile%20Documents/com~apple~CloudDocs/Downloads/Shopping%20List.sld I think this broke with the iOS 17 upgrade. What permissions or capabilities do I need to add to my app to do that, and how do I go about adding them? I am quite new to xCode and iOS developement, but I had this working before.
1
0
566
Mar ’24
Xcode 'New File' default location issue when the path contains a Finder tag
Recently I've had a project which always had behaved normally start placing new files in my home folder. I'm not sure what started this, but I've found out that the issue occurs if the project folder or one of its parents have a Finder tag. I don't know if the same happens with the 'old' Finder labels. I'm surprised this hasn't been discussed yet, one would think at least one developer would be using tags in their filesystem. Xcode 15.1 seems to default to the first parent it can find that doesn't hava a tag. I don't know about earlier versions. Apparently, the solution is to remove the tag AND clear the build data. An Xcode restart seems not to be needed.
2
0
406
Mar ’24
UIDocumentPickerViewController: Cannot access file from OneDrive
Hello everybody, I am struggling with accessing files from the Location OneDrive through UIDocumentViewController. The error says: Error Domain=NSCocoaErrorDomain Code=260 "Die Datei „Testfile.txt“ konnte nicht geöffnet werden, da sie nicht existiert." UserInfo={NSFilePath=/private/var/mobile/Containers/Shared/AppGroup/11E04153-649E-416F-9860-2EA9C0913A18/File Provider Storage/item|1|18a17c69%2D5d6d%2D4b16%2Db388%2D4a9834e9440b/Testfile.txt, NSUnderlyingError=0x281202310 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}} The Controller is initialised the following way: let ctrl = UIDocumentPickerViewController(forOpeningContentTypes: [.image, .audio, .video, .item, .content]) And in the delegate method I do the following: func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) { guard let documentUrl = urls.first else { return } guard documentUrl.startAccessingSecurityScopedResource() else { parent.errorText = "Developer Error: Can't access security scoped resource." return } defer { documentUrl.stopAccessingSecurityScopedResource() } do { let data = try Data(contentsOf: documentUrl) } catch { parent.errorText = error.localizedDescription } } Any help is appreciated! Thanks
4
0
434
Mar ’24
help for DB
good day everyone, I'm new to Xcode and I would like to start the first steps with a DB. I have two problems: 1) I have no idea which free practice DB you can use. 2) consequently I am not yet familiar with any use of the DB. I would be useful for an indication of a free DB that can be used with Xcode and possibly an example of code to be able to write and read it. I thank anyone who wants to help me
1
0
279
Mar ’24
Available Storage displayed in iOS setting is not correct
Hi~recently I have storage issue as follows: Go to iOS Settings -> iPhone Storage , it shows available  storage  is enough (ex.180.38 GB) But app will get disk full error when trying to write large file (ex. 26 GB) Error Domain=NSCocoaErrorDomain Code=640 "The file couldn’t be saved because there isn’t enough space." UserInfo={NSUnderlyingError=0x282db8ae0 {Error Domain=NSPOSIXErrorDomain Code=28 "No space left on device"}} Then I write the following  code to log available space and found it is only 26.95 GB available not 180.38 GB as UI displayed NSError *error = nil; NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:path error: &error]; NSNumber *sizeValue = [dictionary objectForKey:NSFileSystemFreeSize]; uint64_t totalFreeSpace = [sizeValue unsignedLongLongValue]; print(@“ %@ Free space available.", [NSByteCountFormatter stringFromByteCount:totalFreeSpace countStyle:NSByteCountFormatterCountStyleFile]); Does any one know what reason  may cause this strange situation and how can I do to make available space displayed in UI could be reliable? Any suggestion will be very appreciated!
2
0
386
Mar ’24
The right way to use start/stop AccessingSecurityScopedResource in swift-cpp interop
Hi, so I have this case where I would like the user to pick a folder where they want to create a file/folder using UIDocumentPicker/Browser and I make the file using open() in cpp and use its fd to read/write to the file. Now, the first thing is I have to call startAccessingSecurityScopedResource() on the directory url, then I make the file, get its fd(file descriptor) and I leave this makefile() function. Every startAccessingSecurityScopedResource() needs to be matched with a stopstartAccessingSecurityScopedResource(). So my question is do I 'have' to call stopAccessingSecurityScopedResource() 'just before' calling close() on the fd. Or is it fine to call it after I have made the fd i.e., at the end of the makefile() function? In the tests I did it seems that once the fd is opened, even if stopAccessingSecurityScopedResource() is called on it(the directory), I can continue to read/write from the fd until I close() the fd?
1
0
433
Mar ’24
Deny Mac system using cached data when copy
I'm developing a encrypte&decrypt filesystem on Mac. I use MacFuse to realize this filesystem and mount it under a folder. By doing this I can hook the open file method when user are trying to open the encrypted file(such as A.rtf) under the mounted folder. Then I will decrypt A.rtf and generate a new decrypted file, let's call it as B.rtf. In the hooked open file method, I will return B.rtf file descriptor so that the user can open the decrypted file. All works fine, until I opend the encrypted file once and copy it. It seems Mac system directly using the decrypted cache data when doing copy, so the decrypted content will be copied. I tried add fcntl(fd, F_NOCACHE, 1); fcntl(fd, F_NODIRECT, 1) after int fd = open([p UTF8String], mode);, but it not work. So is there a way to clearly tell the Mac system, do not cache my data when open files?
1
0
351
Mar ’24
Optimizing I/O operations in kernel (VFS)
Hey everyone, I'm currently working on developing a kernel extension (kext) for the custom file system on macOS. I opted for a kernel extension due to its potential for higher performance compared to using FileProvider. However, during development, I've noticed a significant performance bottleneck related to synchronous I/O operations within the VFS subsystem. It appears that all I/O operations in the macOS kernel, such as vnop_read/vnop_write (sock_receive/sock_send), are executed synchronously. (https://forums.swift.org/t/task-safe-way-to-write-a-file-asynchronously/54639/7) For example, the Linux kernel supports asynchronous I/O operations, which utilize struct file_operations.read_iter/write_iter. This discrepancy in implementation leads to a considerable performance gap, with macOS performing approximately 8-15 times slower than Linux implementation. Given this performance difference, I'm reaching out to seek advice and insights from the community. Are there any known strategies or best practices for improving the performance of kernel extensions related to file systems on macOS? Any guidance or suggestions on how to optimize the performance of file system operations on macOS kext would be greatly appreciated. Thank you in advance for your assistance!
0
0
357
Mar ’24
Is it possible to develop a Transparent Data Encryption(TDE) system on macOS now?
I'm currently trying to develop a transparent data encryption(TDE) system on MacOS 12.6.8. Our company has its own file encryption format. In order to facilitate safe and convenient file transfer between Windows and Mac platforms, we need to develop a TDE system on the Mac platform (on the Windows platform, we have developed such a system based on the Minifilter framework). I tried to implement this system using a MacFuse based file system and the Endpoint Security system extension, but found that this did not allow complete control of files on the Mac system. For example, when you use Finder to copy an encrypted file, the decrypted data will be copied out. I'm guessing this might be due to Finder or some other system process cache. By referring to the current product introductions of other companies, I learned that the current TDE systems on Mac systems are all based on kernel extension. But I noticed that Apple no longer encourages kernel extension development, and the Mac kernel has fewer and fewer APIs open to development. So I would like to ask is it still feasible to develop a TDE system based on the kernel extension?
1
0
408
Mar ’24
SwiftUI fileImporter vs dropDestination logic
If I drag something into my SwiftUI Mac app the .dropDestination gets an array of URLs that I can do with what I want. If I use .fileImporter to get an identical array of URLs I should wrap start/stop securityScopedResource() calls around each URL before I do anything with it. Can anyone explain the logic behind that? Is there some reason I'm not seeing? It is especially annoying in that the requirement for security scoping also doesn't exist if I use an NSOpenPanel instead of .fileImporter.
4
0
610
Apr ’24
UIFileSharingEnabled isnt working on iOS 15.0
Hi, so following other tutorials on sharing app files to user I added and enabled LSSupportsOpeningDocumentsInPlace and UIFileSharingEnabled in info.plist. On app launch I create a sample file in the Documents Directory so that it shows up on the "On my iPhone" storage. I check this with the simulators for iOS17, iOS16 and it works fine, but for iOS15 it does not display the folder for my app. Does anyone have an idea on how to fix this?
0
0
399
Apr ’24
Questions about isExcludedFromBackup option and device migration
Questions about isExcludedFromBackup option and device migration I posted a similar question a year ago, but I still haven't found a solution that I like, so I'm leaving this question. If anyone knows how, please let me know. In our app, we set the isExcludedFromBackup option to true so that files currently in the Documents path are not backed up to iCloud. In the current situation, I am just curious as to whether the files of our app can be backed up in the two situations below. (with isExcludedFromBackup option set to true ) Migrate iPhone to new iPhone Backup and restore the entire device to iTunes If you set the isExcludedFromBackup option to true in the file, iCloud backup will not be possible, and the app's internal files will not be copied even in the two situations mentioned above. Is there an option or method in the app's internal code to prevent automatic backup only to iCloud and allow files to be copied or synchronized in the above two situations?
2
0
392
Apr ’24
How to get the new created vnode since kauth_listen_scope is invalid now
I'm finding a way to hook vnode operations, following is a snippet of the code: IOReturn FltIOKitKAuthVnodeGate::RegisterVnodeScopeCallback(void) { // // register our listener // this->VnodeListener = kauth_listen_scope( KAUTH_SCOPE_VNODE, // for the vnode scope FltIOKitKAuthVnodeGate::VnodeAuthorizeCallback, // using this callback this ); // give a cookie to callback if( NULL == this->VnodeListener ){ DBG_PRINT_ERROR( ( "kauth_listen_scope failed\n" ) ); return kIOReturnInternalError; } return kIOReturnSuccess; } Here use kauth_listen_scope to get the newly created vnode object, then will hook on it. But now kauth_listen_scope is deprecated, and there is no way to get the vnode by using EndpointSecurity. So is there any other way to get the newly created vnode object?
8
0
729
Apr ’24
Open custom file extension in my app.
Hello. I have the following question. I have a program that creates files with its own extension and reads them. When I select a file with my extension in the Files app, it automatically opens my app. But if a file with my extension is attached to an email, when I click on my file it shows me a screen with programs to open (actually it shows my program the second time I click on the file, if I click the first time, my program is not listed) . I have a question, is it possible to make the file with my extension attached to the letter immediately open in my program without additional screens or is it not allowed. If possible, then what did I miss, based on the fact that it opens immediately from the Files program. Thank you. P.S. File how it works below: ![] [Image Edited by Moderator to Remove Personal Information]
0
1
421
Apr ’24
URL.checkResourceIsReachable() throws error if file is on FTP server and name contains special characters
I have a file named ä.txt (with German umlaut) on my FTP server. I select it like this: let openPanel = NSOpenPanel() openPanel.runModal() let source = openPanel.urls[0] Running this code unexpectedly throws an error: do { print(try source.checkResourceIsReachable()) } catch { print(error) // Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory” } Manipulating the URL also seems to change the underlying characters: print(source) // file:///Volumes/abc.com/httpdocs/%C3%A4.txt print(URL(fileURLWithPath: source.path)) // file:///Volumes/abc.com/httpdocs/a%CC%88.txt Note that both variants of the URL above also throw the same error when running URL.checkResourceIsReachable(). If I download the file to my Mac, then both variants print file:///Users/me/Downloads/a%CC%88.txt and neither of them throws an error when running URL.checkResourceIsReachable(). What is the problem? How can I correctly access this file on the FTP server?
6
0
535
Apr ’24
Unable to open more than 2560 Pipe() (even if I close them)
Hi, I have an issue that I don't understand, and I need help. I am using Pipe() in Swift, and I found that if I create more than 2560 (more or less) pipes, I cannot create more. The call fails with Too many open files, even though I closed all the files associated with the pipes. This is a minimal code to reproduce the issue: for i in 0...1278 { NSLog("Testing: \(i)") let stdin_pipe = Pipe() let stdin_file = fdopen(stdin_pipe.fileHandleForReading.fileDescriptor, "r") var stdout_pipe = Pipe() var stdout_file = fdopen(stdout_pipe.fileHandleForWriting.fileDescriptor, "w") if (stdout_file == nil) { let errorString = String(cString: strerror(errno)) NSLog("Could not create an output stream. Error: \(errorString)") } do { // I'm really trying to close everything (but it doesn't matter): close(stdout_pipe.fileHandleForWriting.fileDescriptor) close(stdin_pipe.fileHandleForReading.fileDescriptor) try stdout_pipe.fileHandleForWriting.close() try stdin_pipe.fileHandleForReading.close() try stdout_pipe.fileHandleForReading.close() try stdin_pipe.fileHandleForWriting.close() } catch { NSLog("Error in closing pipes in MyExtension: \(error.localizedDescription)") } } It will work for i going to 0 to 1277, and fail for i == 1278. The error (obtained from strerror(errno) is Too many files open, even though there are around 6 file descriptors opened (I checked). What am I doing wrong?
1
0
304
Apr ’24
A user is unable to download content in app
I have an app with IAP which uses a URLSession object to download files from a server. The download part of the code is: let request = URLRequest(url: fromURL, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: timeoutInterval) let (data, response) = try await downloadSession.data(for: request) This code has been working without trouble for over a year with thousands of downloads. Now I have a user with a new iPhone (iOS 17.3.1) which refuses to download, failing at the above code (judging by the high level logs). My question is this: What sort of things should we be looking at in order to diagnose this issue? So far we have done the following: He has no general download issue (eg Safari works fine) His network access is 'normal' and the problem persists when the network is changed (4G, wifi etc) He runs a VPN (Nord) but the problem persists when this is off He has no 3rd party AV software His phone is not in lockdown mode Any pointers would be appreciated! NB I have no physical access to his device (yet!)
2
0
462
Apr ’24