Skip to content

Commit 9d38219

Browse files
authored
Add support for setting a FAT32 label (#154)
* Extract fat structure writes out of the Create function The addition of ``SetLabel()`` will require to re-use some of the write path currently only in the ``Create()`` function. To avoid code duplication and for consistency, this function extract the various internal structures write paths to dedicated functions. * Add function to set filesystem label This commit adds ```SetLabel()` to the filesystem interface. For read-only filesystems, it returns an error. For FAT32, ``SetLabel()`` writes the label in the boot sector, the backup bootsector and the special file in the root directory. * Make FAT32 label read consistent with Windows While there are 2 possibles locations for the FAT32 label, in practice, Windows only considers the special file in the root directory and completely ignores the bootsector. For consistency purposes, Linux' ``fatlabel`` decided to follow this behavior as well. To avoid any quirks, this commit moves the label read to the special file. This should not pose compatibility issue with images previously generated with this library since it was already setting the label in both possible locations. * Add FAT32 SetLabel() tests
1 parent e183dc8 commit 9d38219

File tree

10 files changed

+366
-121
lines changed

10 files changed

+366
-121
lines changed

filesystem/fat32/directoryentry_internal_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ func getValidDirectoryEntries() ([]*directoryEntry, [][]byte, error) {
9494
t30, _ := time.Parse(time.RFC3339, "2017-11-26T00:00:00Z")
9595
t4, _ := time.Parse(time.RFC3339, "2017-11-26T08:01:44Z")
9696
t40, _ := time.Parse(time.RFC3339, "2017-11-26T00:00:00Z")
97+
t5, _ := time.Parse(time.RFC3339, "2022-10-14T17:38:42Z")
98+
t50, _ := time.Parse(time.RFC3339, "2022-10-14T00:00:00Z")
9799
entries := []*directoryEntry{
98100
{
99101
filenameShort: "FOO",
@@ -180,6 +182,28 @@ func getValidDirectoryEntries() ([]*directoryEntry, [][]byte, error) {
180182
longFilenameSlots: 3,
181183
isNew: false,
182184
},
185+
{
186+
filenameShort: "go-diskf",
187+
fileExtension: "s",
188+
filenameLong: "",
189+
isReadOnly: false,
190+
isHidden: false,
191+
isSystem: false,
192+
isVolumeLabel: true,
193+
isSubdirectory: false,
194+
isArchiveDirty: false,
195+
isDevice: false,
196+
lowercaseShortname: false,
197+
createTime: t5,
198+
modifyTime: t5,
199+
accessTime: t50,
200+
acccessRights: accessRightsUnlimited,
201+
clusterLocation: 0,
202+
fileSize: 0,
203+
// start: uint32,
204+
longFilenameSlots: 0,
205+
isNew: false,
206+
},
183207
}
184208

185209
// read correct bytes off of disk

filesystem/fat32/dos71bpb_internal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func getValidDos71EBPB() *dos71EBPB {
2222
reservedFlags: 0x00,
2323
extendedBootSignature: 0x29,
2424
volumeSerialNumber: 2712131608,
25-
volumeLabel: "NO NAME",
25+
volumeLabel: "go-diskfs",
2626
fileSystemType: "FAT32",
2727
}
2828
}

0 commit comments

Comments
 (0)