Skip to content

Add FileEndOfFileInformation support (SetInfo for file size / truncate) #214

@isabsent

Description

@isabsent

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:

  1. 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)
  }
}
  1. 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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions