本文整理匯總了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
}