Example #1
0
func new_list_block(file file.BlockDevice, new_list bool) (self *list_block, err error) {
	key, err := file.Allocate()
	if err != nil {
		return nil, err
	}
	bytes := make(bs.ByteSlice, file.BlockSize())
	data := bytes[LIST_HEADER_LEN:]
	var header *list_header
	if new_list {
		header = &list_header{
			next:         0,
			head:         key,
			tail:         key,
			insert_point: key + LIST_HEADER_LEN,
			block_count:  1,
			list_length:  0,
		}
	} else {
		header = &list_header{next: 0}
	}
	self = &list_block{
		file:   file,
		key:    key,
		bytes:  bytes,
		data:   data,
		header: header,
	}
	return self, nil
}
Example #2
0
func allocBlock(file file.BlockDevice) (blk *block, err error) {
	key, err := file.Allocate()
	if err != nil {
		return nil, err
	}
	size := file.BlockSize()
	bytes := make(bs.ByteSlice, size)
	return load_block(key, bytes), nil
}
Example #3
0
func readBlock(file file.BlockDevice, key int64) (blk *block, err error) {
	bytes, err := file.ReadBlock(key)
	if err != nil {
		return nil, err
	}
	return load_block(key, bytes), err
}
Example #4
0
func allocBlock(file file.BlockDevice) (blk *block, err error) {
	key, err := file.Allocate()
	if err != nil {
		return nil, err
	}
	size := file.BlockSize()
	offset := size - METADATASIZE
	bytes := make(bs.ByteSlice, size)
	blk = &block{
		key:      key,
		block:    bytes,
		data:     bytes[:offset],
		metadata: bytes[offset:],
	}
	// fmt.Println("allocated", key)
	return blk, nil
}
Example #5
0
func load_list_block(file file.BlockDevice, key int64) (self *list_block, err error) {
	bytes, err := file.ReadBlock(key)
	if err != nil {
		return nil, err
	}
	data := bytes[LIST_HEADER_LEN:]
	header := load_list_header(bytes)
	self = &list_block{
		file:   file,
		key:    key,
		bytes:  bytes,
		data:   data,
		header: header,
	}
	return self, nil
}
Example #6
0
func (self *block) WriteBlock(file file.BlockDevice) error {
	return file.WriteBlock(self.key, self.block)
}
Example #7
0
func datasize(file file.BlockDevice) int64 {
	return int64(file.BlockSize()) - METADATASIZE
}