Make less functions exported

This commit is contained in:
Terence Boldt 2021-06-28 22:26:20 -04:00
parent e802ee7ceb
commit 057cd5fd7b
4 changed files with 30 additions and 30 deletions

View File

@ -24,7 +24,7 @@ func ReadVolumeBitmap(file *os.File) []byte {
return bitmap
}
func WriteVolumeBitmap(file *os.File, bitmap []byte) {
func writeVolumeBitmap(file *os.File, bitmap []byte) {
headerBlock := ReadBlock(file, 2)
volumeHeader := parseVolumeHeader(headerBlock)
@ -34,7 +34,7 @@ func WriteVolumeBitmap(file *os.File, bitmap []byte) {
}
}
func CreateVolumeBitmap(numberOfBlocks int) []byte {
func createVolumeBitmap(numberOfBlocks int) []byte {
volumeBitmapBlocks := numberOfBlocks / 512 / 8
if volumeBitmapBlocks*8*512 < numberOfBlocks {
volumeBitmapBlocks++
@ -47,18 +47,18 @@ func CreateVolumeBitmap(numberOfBlocks int) []byte {
}
// boot blocks
MarkBlockInVolumeBitmap(volumeBitmap, 0)
MarkBlockInVolumeBitmap(volumeBitmap, 1)
markBlockInVolumeBitmap(volumeBitmap, 0)
markBlockInVolumeBitmap(volumeBitmap, 1)
// root directory
MarkBlockInVolumeBitmap(volumeBitmap, 2)
MarkBlockInVolumeBitmap(volumeBitmap, 3)
MarkBlockInVolumeBitmap(volumeBitmap, 4)
MarkBlockInVolumeBitmap(volumeBitmap, 5)
markBlockInVolumeBitmap(volumeBitmap, 2)
markBlockInVolumeBitmap(volumeBitmap, 3)
markBlockInVolumeBitmap(volumeBitmap, 4)
markBlockInVolumeBitmap(volumeBitmap, 5)
// volume bitmap blocks
for i := 0; i < volumeBitmapBlocks; i++ {
MarkBlockInVolumeBitmap(volumeBitmap, 6+i)
markBlockInVolumeBitmap(volumeBitmap, 6+i)
}
// blocks beyond the volume
@ -66,7 +66,7 @@ func CreateVolumeBitmap(numberOfBlocks int) []byte {
blocksBeyondEnd := totalBlocksInBitmap - numberOfBlocks
if blocksBeyondEnd > 0 {
for i := totalBlocksInBitmap - blocksBeyondEnd; i < totalBlocksInBitmap; i++ {
MarkBlockInVolumeBitmap(volumeBitmap, i)
markBlockInVolumeBitmap(volumeBitmap, i)
}
}
//DumpBlock(volumeBitmap)
@ -74,13 +74,13 @@ func CreateVolumeBitmap(numberOfBlocks int) []byte {
return volumeBitmap
}
func FindFreeBlocks(volumeBitmap []byte, numberOfBlocks int) []int {
func findFreeBlocks(volumeBitmap []byte, numberOfBlocks int) []int {
blocks := make([]int, numberOfBlocks)
blocksFound := 0
for i := 0; i < len(volumeBitmap)*8; i++ {
if CheckFreeBlockInVolumeBitmap(volumeBitmap, i) {
if checkFreeBlockInVolumeBitmap(volumeBitmap, i) {
blocks[blocksFound] = i
blocksFound++
if blocksFound == numberOfBlocks {
@ -92,7 +92,7 @@ func FindFreeBlocks(volumeBitmap []byte, numberOfBlocks int) []int {
return nil
}
func MarkBlockInVolumeBitmap(volumeBitmap []byte, blockNumber int) {
func markBlockInVolumeBitmap(volumeBitmap []byte, blockNumber int) {
bitToChange := blockNumber % 8
byteToChange := blockNumber / 8
@ -121,7 +121,7 @@ func MarkBlockInVolumeBitmap(volumeBitmap []byte, blockNumber int) {
volumeBitmap[byteToChange] &= byte(byteToAnd)
}
func FreeBlockInVolumeBitmap(volumeBitmap []byte, blockNumber int) {
func freeBlockInVolumeBitmap(volumeBitmap []byte, blockNumber int) {
bitToChange := blockNumber % 8
byteToChange := blockNumber / 8
@ -149,7 +149,7 @@ func FreeBlockInVolumeBitmap(volumeBitmap []byte, blockNumber int) {
volumeBitmap[byteToChange] |= byte(byteToOr)
}
func CheckFreeBlockInVolumeBitmap(volumeBitmap []byte, blockNumber int) bool {
func checkFreeBlockInVolumeBitmap(volumeBitmap []byte, blockNumber int) bool {
bitToCheck := blockNumber % 8
byteToCheck := blockNumber / 8

View File

@ -18,7 +18,7 @@ func TestCreateVolumeBitmap(t *testing.T) {
for _, tt := range tests {
testname := fmt.Sprintf("%d", tt.blocks)
t.Run(testname, func(t *testing.T) {
volumeBitMap := CreateVolumeBitmap(tt.blocks)
volumeBitMap := createVolumeBitmap(tt.blocks)
ans := len(volumeBitMap)
if ans != tt.want {
t.Errorf("got %d, want %d", ans, tt.want)
@ -45,8 +45,8 @@ func TestCheckFreeBlockInVolumeBitmap(t *testing.T) {
for _, tt := range tests {
testname := fmt.Sprintf("%d", tt.blocks)
t.Run(testname, func(t *testing.T) {
volumeBitMap := CreateVolumeBitmap(65535)
ans := CheckFreeBlockInVolumeBitmap(volumeBitMap, tt.blocks)
volumeBitMap := createVolumeBitmap(65535)
ans := checkFreeBlockInVolumeBitmap(volumeBitMap, tt.blocks)
if ans != tt.want {
t.Errorf("got %t, want %t", ans, tt.want)
}

View File

@ -9,7 +9,7 @@ import (
func LoadFile(file *os.File, path string) []byte {
fileEntry := GetFileEntry(file, path)
blockList := GetBlocklist(file, fileEntry)
blockList := getBlocklist(file, fileEntry)
buffer := make([]byte, fileEntry.EndOfFile)
@ -29,7 +29,7 @@ func WriteFile(file *os.File, path string, fileType int, auxType int, buffer []b
DeleteFile(file, path)
// get list of blocks to write file to
blockList := CreateBlockList(file, len(buffer))
blockList := createBlockList(file, len(buffer))
fileEntry := GetFreeFileEntryInDirectory(file, directory)
@ -88,7 +88,7 @@ func WriteFile(file *os.File, path string, fileType int, auxType int, buffer []b
writeFileEntry(file, fileEntry)
}
func GetBlocklist(file *os.File, fileEntry FileEntry) []int {
func getBlocklist(file *os.File, fileEntry FileEntry) []int {
blocks := make([]int, fileEntry.BlocksUsed)
switch fileEntry.StorageType {
@ -112,7 +112,7 @@ func GetBlocklist(file *os.File, fileEntry FileEntry) []int {
return blocks
}
func CreateBlockList(file *os.File, fileSize int) []int {
func createBlockList(file *os.File, fileSize int) []int {
numberOfBlocks := fileSize / 512
if fileSize%512 > 0 {
numberOfBlocks++
@ -131,7 +131,7 @@ func CreateBlockList(file *os.File, fileSize int) []int {
}
}
volumeBitmap := ReadVolumeBitmap(file)
blockList := FindFreeBlocks(volumeBitmap, numberOfBlocks)
blockList := findFreeBlocks(volumeBitmap, numberOfBlocks)
return blockList
}
@ -180,12 +180,12 @@ func DeleteFile(file *os.File, path string) {
}
// free the blocks
blocks := GetBlocklist(file, fileEntry)
blocks := getBlocklist(file, fileEntry)
volumeBitmap := ReadVolumeBitmap(file)
for i := 0; i < len(blocks); i++ {
FreeBlockInVolumeBitmap(volumeBitmap, blocks[i])
freeBlockInVolumeBitmap(volumeBitmap, blocks[i])
}
WriteVolumeBitmap(file, volumeBitmap)
writeVolumeBitmap(file, volumeBitmap)
// zero out directory entry
fileEntry.StorageType = 0

View File

@ -64,7 +64,7 @@ func CreateVolume(fileName string, volumeName string, numberOfBlocks int) {
file.Sync()
// boot block 0
WriteBlock(file, 0, GetBootBlock())
WriteBlock(file, 0, getBootBlock())
// pointers to volume directory blocks
for i := 2; i < 6; i++ {
@ -85,13 +85,13 @@ func CreateVolume(fileName string, volumeName string, numberOfBlocks int) {
}
// volume bit map starting at block 6
volumeBitmap := CreateVolumeBitmap(numberOfBlocks)
WriteVolumeBitmap(file, volumeBitmap)
volumeBitmap := createVolumeBitmap(numberOfBlocks)
writeVolumeBitmap(file, volumeBitmap)
file.Close()
}
func GetBootBlock() []byte {
func getBootBlock() []byte {
bootBlock := []byte{
0x01, 0x38, 0xb0, 0x03, 0x4c, 0x1c, 0x09, 0x78, 0x86, 0x43, 0xc9, 0x03, 0x08, 0x8a, 0x29, 0x70,
0x4a, 0x4a, 0x4a, 0x4a, 0x09, 0xc0, 0x85, 0x49, 0xa0, 0xff, 0x84, 0x48, 0x28, 0xc8, 0xb1, 0x48,