Skip to content

Commit

Permalink
Allows to open disk from already existing os.File descriptor
Browse files Browse the repository at this point in the history
aol NB: i.e. in gin-disk
  • Loading branch information
aol-nnov committed Nov 9, 2024
1 parent f66ea89 commit 6a86542
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions diskfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ func Open(device string, opts ...OpenOpt) (*disk.Disk, error) {
return initDisk(f, ReadWriteExclusive, opt.sectorSize)
}

func OpenFile(f *os.File) (*disk.Disk, error) {
opt := openOptsDefaults()
return initDisk(f, ReadOnly, opt.sectorSize)
}

// Create a Disk from a path to a device
// Should pass a path to a block device e.g. /dev/sda or a path to a file /tmp/foo.img
// The provided device must not exist at the time you call Create()
Expand Down

0 comments on commit 6a86542

Please sign in to comment.