-
-
Notifications
You must be signed in to change notification settings - Fork 36
Description
Feature Request: Session.setFileSize(fileId:size:)
Hi! Thank you for this great library — it's been very useful for building SMB2 file access into our iOS/macOS app.
Problem:
I'm building an app that works with encrypted container files over SMB. Some container formats (BCA archives) need to grow or shrink the underlying file during
writes and on close — essentially a truncate() operation.
SMB2 supports this via SET_INFO with FileEndOfFileInformation (info class 0x14), and your library already has:
- SetInfo.Request infrastructure
- FileInfoClass.fileEndOfFileInformation enum case (0x14)
- FileInformationClass protocol
- A working example in FileDispositionInformation
However, there's no FileEndOfFileInformation struct, and Session has no method to set a file's size on an already-open file handle.
Since Session.send(), messageId, treeId, and sessionId are internal, this can't be implemented from outside the package via an extension — it requires changes inside the library.
Proposed Changes:
- New file: Sources/SMBClient/Messages/FileInformationClasses/FileEndOfFileInformation.swift
Same pattern as FileDispositionInformation:
import Foundation
public struct FileEndOfFileInformation: FileInformationClass {
public let endOfFile: UInt64
public let infoClass: FileInfoClass = .fileEndOfFileInformation
public init(endOfFile: UInt64) {
self.endOfFile = endOfFile
}
public func encoded() -> Data {
var value = endOfFile.littleEndian
return Data(bytes: &value, count: MemoryLayout<UInt64>.size)
}
}
- New method in Session.swift:
Same pattern as the existing deleteFile() which sends SetInfo.Request with FileDispositionInformation:
public func setFileSize(fileId: Data, size: UInt64) async throws {
let setInfoRequest = SetInfo.Request(
messageId: messageId.next(),
treeId: treeId,
sessionId: sessionId,
fileId: fileId,
infoType: .file,
fileInformation: FileEndOfFileInformation(endOfFile: size)
)
let response = try await send(setInfoRequest)
try SetInfo.Response(data: response[0])
}
Use Case:
This would allow library users to resize files that are already open for writing — a common need when working with archive formats, database files, or any format
where the file size changes during a session.
Currently the only workaround is to fork the library, which is unfortunate given how small the change is.
References:
- https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/ee9614c4-be54-4a3c-98f1-769a7032a36e
- https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/75241cca-3167-472f-8058-a52d77c6bb17 — info class 0x14, payload is a single LARGE_INTEGER (8 bytes, little-endian)