-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ext4 filesystem detection logic
This simply detects the ext filesystem superblock. Signed-off-by: Andrey Smirnov <[email protected]>
- Loading branch information
Showing
5 changed files
with
85 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// 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 ext4 provides functions for working with the ext filesystems. | ||
package ext4 |
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,51 @@ | ||
// 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 ext4 | ||
|
||
import ( | ||
"unsafe" | ||
) | ||
|
||
const ( | ||
// Magic is the ext magic signature. | ||
Magic = 0xef53 | ||
) | ||
|
||
// SuperBlock represents the ext filesystem super block. | ||
// | ||
// See https://ext4.wiki.kernel.org/index.php/Ext4_Disk_Layout#The_Super_Block for the reference. | ||
type SuperBlock struct { | ||
_ [0x38]uint8 | ||
Magic [2]uint8 | ||
_ [0x3e]uint8 | ||
Label [0x10]uint8 | ||
_ [0x378]uint8 | ||
} | ||
|
||
// Is implements the SuperBlocker interface. | ||
func (sb *SuperBlock) Is() bool { | ||
return sb.Magic[1] == Magic>>8 && sb.Magic[0] == Magic&0xff | ||
} | ||
|
||
// Offset implements the SuperBlocker interface. | ||
func (sb *SuperBlock) Offset() int64 { | ||
return 0x400 | ||
} | ||
|
||
// Type implements the SuperBlocker interface. | ||
func (sb *SuperBlock) Type() string { | ||
return "ext4" | ||
} | ||
|
||
// Encrypted implements the SuperBlocker interface. | ||
func (sb *SuperBlock) Encrypted() bool { | ||
return false | ||
} | ||
|
||
func init() { | ||
if unsafe.Sizeof(SuperBlock{}) != 0x400 { | ||
panic("ext4: SuperBlock size is not 0x400") | ||
} | ||
} |
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