func writeSectorMetadata(f modules.File, sectorIndex uint32, id sectorID, count uint16) error {
	writeData := make([]byte, sectorMetadataDiskSize)
	copy(writeData, id[:])
	binary.LittleEndian.PutUint16(writeData[12:], count)
	_, err := f.WriteAt(writeData, sectorMetadataDiskSize*int64(sectorIndex))
	if err != nil {
		return build.ExtendErr("unable to write in given file", err)
	}
	return nil
}
writeSectorMetadata will take a sector update and write the related metadata
to disk.
package contractmanager
import (
	"encoding/binary"
	"errors"
	"sync"
	"sync/atomic"
	"github.com/NebulousLabs/Sia/build"
	"github.com/NebulousLabs/Sia/crypto"
	"github.com/NebulousLabs/Sia/modules"
)
var (
	errDiskTrouble = errors.New("host unable to add sector despite having the storage capacity to do so")
	errInsufficientStorageForSector = errors.New("not enough storage remaining to accept sector")
	errMaxVirtualSectors = errors.New("sector collides with a physical sector that already has the maximum allowed number of virtual sectors")
	ErrSectorNotFound = errors.New("could not find the desired sector")
)
type (
	sectorID [12]byte
	sectorLocation struct {
		index uint32
		storageFolder uint16
		count uint16
	}
	sectorLock struct {
		waiting int
		mu      sync.Mutex
	}
)
func readSector(f modules.File, sectorIndex uint32) ([]byte, error) {
	b := make([]byte, modules.SectorSize)
	_, err := f.ReadAt(b, int64(uint64(sectorIndex)*modules.SectorSize))
	if err != nil {
		return nil, build.ExtendErr("unable to read within storage folder", err)
	}
	return b, nil
}
func readFullMetadata(f modules.File, numSectors int) ([]byte, error) {
	sectorLookupBytes := make([]byte, numSectors*sectorMetadataDiskSize)
	_, err := f.ReadAt(sectorLookupBytes, 0)
	if err != nil {
		return nil, build.ExtendErr("unable to read metadata file for target storage folder", err)
	}
	return sectorLookupBytes, nil
}
func writeSector(f modules.File, sectorIndex uint32, data []byte) error {
	_, err := f.WriteAt(data, int64(uint64(sectorIndex)*modules.SectorSize))
	if err != nil {
		return build.ExtendErr("unable to write within provided file", err)
	}
	return nil
}