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 }
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 }
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 }
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 }
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 }
func (self *block) WriteBlock(file file.BlockDevice) error { return file.WriteBlock(self.key, self.block) }
func datasize(file file.BlockDevice) int64 { return int64(file.BlockSize()) - METADATASIZE }