Пример #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
}
Пример #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
}
Пример #3
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
}
Пример #4
0
func datasize(file file.BlockDevice) int64 {
	return int64(file.BlockSize()) - METADATASIZE
}