Example #1
0
func (v *volume) AddBlock(blk maggiefs.Block) error {
	// TODO should blow up here if blk already exists
	// create file representing block
	f, err := os.Create(v.resolvePath(blk.Id))
	if err != nil {
		return fmt.Errorf("Error creating block for %d : %s\n", blk.Id, err.Error())
	}
	defer f.Close()
	// add to blockmeta db
	key := make([]byte, 8)
	binary.LittleEndian.PutUint64(key, blk.Id)
	binSize := blk.BinSize()
	val := make([]byte, binSize)
	blk.ToBytes(val)
	err = v.blockData.Put(writeOpts, key, val)
	return err
}