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


Golang Inode.Size方法代码示例

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


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

示例1: search_dir

func search_dir(dirp *common.Inode, path string, inum *int, op dirop) error {
	// TODO: Check permissions (see minix source)
	devinfo := dirp.Devinfo
	blocksize := devinfo.Blocksize

	// step through the directory on block at a time
	var bp *common.CacheBlock
	var dp *common.Disk_dirent
	old_slots := int(dirp.Size / common.DIR_ENTRY_SIZE)
	new_slots := 0
	e_hit := false
	match := false
	extended := false

	for pos := 0; pos < int(dirp.Size); pos += blocksize {
		b := common.ReadMap(dirp, pos, dirp.Bcache) // get block number
		if dirp.Bcache == nil {
			panic(fmt.Sprintf("No block cache: %q", dirp))
		}
		bp = dirp.Bcache.GetBlock(devinfo.Devnum, b, common.DIRECTORY_BLOCK, common.NORMAL)
		if bp == nil {
			panic("get_block returned NO_BLOCK")
		}

		// Search the directory block
		dirarr := bp.Block.(common.DirectoryBlock)
		for i := 0; i < len(dirarr); i++ {
			dp = &dirarr[i]
			new_slots++
			if new_slots > old_slots { // not found, but room left
				if op == ENTER {
					e_hit = true
				}
				break
			}

			// Match occurs if string found
			if op != ENTER && dp.Inum != 0 {
				if op == IS_EMPTY {
					// If this succeeds, dir is not empty
					if !dp.HasName(".") && !dp.HasName("..") {
						log.Printf("Found entry: %s (%d)", dp.String(), dp.Inum)
						match = true
					}
				} else {
					if dp.HasName(path) {
						match = true
					}
				}
			}

			if match {
				var r error = nil
				// LOOK_UP or DELETE found what it wanted
				if op == IS_EMPTY {
					r = common.ENOTEMPTY
				} else if op == DELETE {
					// TODO: Save inode for recovery
					dp.Inum = 0 // erase entry
					bp.Dirty = true
					dirp.Dirty = true
				} else {
					*inum = int(dp.Inum)
				}
				dirp.Bcache.PutBlock(bp, common.DIRECTORY_BLOCK)
				return r
			}

			// Check for free slot for the benefit of ENTER
			if op == ENTER && dp.Inum == 0 {
				e_hit = true // we found a free slot
				break
			}
		}

		// The whole block has been searched or ENTER has a free slot
		if e_hit { // e_hit set if ENTER can be performed now
			break
		}
		dirp.Bcache.PutBlock(bp, common.DIRECTORY_BLOCK) // otherwise continue searching dir
	}

	// The whole directory has now been searched
	if op != ENTER {
		if op == IS_EMPTY {
			return nil
		} else {
			return common.ENOENT
		}
	}

	// This call is for ENTER. If no free slot has been found so far, try to
	// extend directory.
	if !e_hit { // directory is full and no room left in last block
		new_slots++ // increase directory size by 1 entry
		// TODO: Does this rely on overflow? Does it work?
		if new_slots == 0 { // dir size limited by slot count (overflow?)
			return common.EFBIG
		}
		var err error
//.........这里部分代码省略.........
开发者ID:jnwhiteh,项目名称:minixfs,代码行数:101,代码来源:search.go


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