当前位置: 首页>>代码示例>>Golang>>正文


Golang Inode.Length方法代码示例

本文整理汇总了Golang中github.com/jbooth/maggiefs/maggiefs.Inode.Length方法的典型用法代码示例。如果您正苦于以下问题:Golang Inode.Length方法的具体用法?Golang Inode.Length怎么用?Golang Inode.Length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/jbooth/maggiefs/maggiefs.Inode的用法示例。


在下文中一共展示了Inode.Length方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: addBlocksForFileWrite

// acquires lease, then adds the blocks to the namenode,
// patching up the referenced inode to match
func (w *InodeWriter) addBlocksForFileWrite(inode *maggiefs.Inode, off uint64, length uint32) error {
	//	fmt.Printf("Adding/extending blocks for write at off %d length %d\n", off, length)
	newEndPos := off + uint64(length)
	if newEndPos > inode.Length {
		// if we have a last block and it's less than max length,
		// extend last block to max block length first
		//		fmt.Printf("Adding/extending blocks for file write to inode %+v\n", inode)
		if inode.Blocks != nil && len(inode.Blocks) > 0 {
			idx := int(len(inode.Blocks) - 1)
			lastBlock := inode.Blocks[idx]
			if lastBlock.Length() < BLOCKLENGTH {
				extendLength := BLOCKLENGTH - lastBlock.Length()
				if lastBlock.EndPos+extendLength > off+uint64(length) {
					// only extend as much as we need to
					extendLength = off + uint64(length) - lastBlock.EndPos
				}
				lastBlock.EndPos = lastBlock.EndPos + extendLength
				inode.Blocks[idx] = lastBlock
				inode.Length += extendLength
			}
		}
		// and add new blocks as necessary
		for newEndPos > inode.Length {
			//			fmt.Printf("New end pos %d still greater than inode length %d\n", newEndPos, inode.Length)
			newBlockLength := newEndPos - inode.Length
			if newBlockLength > BLOCKLENGTH {
				newBlockLength = BLOCKLENGTH
			}
			newBlock, err := w.names.AddBlock(inode.Inodeid, uint32(newBlockLength))
			if err != nil {
				return err
			}
			inode.Blocks = append(inode.Blocks, newBlock)
			inode.Length += newBlockLength
		}
	}
	inode.Mtime = time.Now().Unix()
	err := w.names.SetInode(inode)
	return err
}
开发者ID:jonpugh,项目名称:maggiefs,代码行数:42,代码来源:writer.go


注:本文中的github.com/jbooth/maggiefs/maggiefs.Inode.Length方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。