func (wal *writeAheadLog) commitStorageFolderExtension(sfe storageFolderExtension) {
	sf, exists := wal.cm.storageFolders[sfe.Index]
	if !exists || atomic.LoadUint64(&sf.atomicUnavailable) == 1 {
		wal.cm.log.Critical("ERROR: storage folder extension provided for storage folder that does not exist")
		return
	}
	newUsageSize := sfe.NewSectorCount / storageFolderGranularity
	appendUsage := make([]uint64, int(newUsageSize)-len(sf.usage))
	sf.usage = append(sf.usage, appendUsage...)
}
commitStorageFolderExtension will apply a storage folder extension to the
state.
package contractmanager
import (
	"errors"
	"sync"
	"sync/atomic"
	"github.com/NebulousLabs/Sia/build"
	"github.com/NebulousLabs/Sia/modules"
)
type (
	storageFolderExtension struct {
		Index          uint16
		NewSectorCount uint32
	}
	unfinishedStorageFolderExtension struct {
		Index          uint16
		OldSectorCount uint32
	}
)
func findUnfinishedStorageFolderExtensions(scs []stateChange) []unfinishedStorageFolderExtension {
	usfeMap := make(map[uint16]unfinishedStorageFolderExtension)
	for _, sc := range scs {
		for _, usfe := range sc.UnfinishedStorageFolderExtensions {
			usfeMap[usfe.Index] = usfe
		}
		for _, sfe := range sc.StorageFolderExtensions {
			delete(usfeMap, sfe.Index)
		}
		for _, index := range sc.ErroredStorageFolderExtensions {
			delete(usfeMap, index)
		}
		for _, sfr := range sc.StorageFolderRemovals {
			delete(usfeMap, sfr.Index)
		}
	}
	usfes := make([]unfinishedStorageFolderExtension, 0, len(usfeMap))
	for _, usfe := range usfeMap {
		usfes = append(usfes, usfe)
	}
	return usfes
}
func (wal *writeAheadLog) cleanupUnfinishedStorageFolderExtensions(scs []stateChange) {
	usfes := findUnfinishedStorageFolderExtensions(scs)
	for _, usfe := range usfes {
		sf, exists := wal.cm.storageFolders[usfe.Index]
		if !exists || atomic.LoadUint64(&sf.atomicUnavailable) == 1 {
			wal.cm.log.Critical("unfinished storage folder extension exists where the storage folder does not exist")
			continue
		}
		err := sf.metadataFile.Truncate(int64(len(sf.usage) * storageFolderGranularity * sectorMetadataDiskSize))
		if err != nil {
			wal.cm.log.Printf("Error: unable to truncate metadata file as storage folder %v is resized\n", sf.path)
		}
		err = sf.sectorFile.Truncate(int64(modules.SectorSize * storageFolderGranularity * uint64(len(sf.usage))))
		if err != nil {
			wal.cm.log.Printf("Error: unable to truncate sector file as storage folder %v is resized\n", sf.path)
		}
		wal.appendChange(stateChange{
			ErroredStorageFolderExtensions: []uint16{sf.index},
		})
	}
}