-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This replaces the serde package. The serialization/deserialization process was rigid and made doing precision work on GPT impossible. This PR allows for serialization/deserialization of specific fields of the GPT header and partitions. Signed-off-by: Andrew Rynhard <[email protected]>
- Loading branch information
1 parent
2a1baad
commit 98754ec
Showing
24 changed files
with
1,811 additions
and
1,675 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
package lba | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
// Buffer is an in-memory buffer for writing to byte slices in units of LBA. | ||
type Buffer struct { | ||
lba *LBA | ||
b []byte | ||
} | ||
|
||
// NewBuffer intializes and returns a `Buffer`. | ||
func NewBuffer(lba *LBA, b []byte) *Buffer { | ||
return &Buffer{lba: lba, b: b} | ||
} | ||
|
||
// Read reads from a `Buffer`. | ||
func (buf *Buffer) Read(off, length int64) (b []byte, err error) { | ||
b = make([]byte, length) | ||
|
||
n := copy(b, buf.b[off:off+length]) | ||
|
||
if n != len(buf.b[off:off+length]) { | ||
return nil, fmt.Errorf("expected to write %d bytes, read %d", len(b), n) | ||
} | ||
|
||
return b, nil | ||
} | ||
|
||
// Write writes to a `Buffer`. | ||
func (buf *Buffer) Write(b []byte, off int64) (err error) { | ||
n := copy(buf.b[off:off+int64(len(b))], b) | ||
|
||
if n != len(b) { | ||
return fmt.Errorf("expected to write %d bytes, read %d", len(b), n) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Bytes returns the buffer bytes. | ||
func (buf *Buffer) Bytes() []byte { | ||
return buf.b | ||
} | ||
|
||
// LBA represents logical block addressing. | ||
type LBA struct { | ||
PhysicalBlockSize int64 | ||
LogicalBlockSize int64 | ||
TotalSectors int64 | ||
|
||
f *os.File | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.