本文整理汇总了Golang中file-structures/block/file2.BlockDevice类的典型用法代码示例。如果您正苦于以下问题:Golang BlockDevice类的具体用法?Golang BlockDevice怎么用?Golang BlockDevice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BlockDevice类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: new_list_block
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: allocBlock
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: readBlock
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
}
示例4: allocBlock
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
}
示例5: load_list_block
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
}
示例6: WriteBlock
func (self *block) WriteBlock(file file.BlockDevice) error {
return file.WriteBlock(self.key, self.block)
}
示例7: datasize
func datasize(file file.BlockDevice) int64 {
return int64(file.BlockSize()) - METADATASIZE
}