本文整理汇总了Golang中github.com/jnwhiteh/minixfs/common.Inode.File方法的典型用法代码示例。如果您正苦于以下问题:Golang Inode.File方法的具体用法?Golang Inode.File怎么用?Golang Inode.File使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jnwhiteh/minixfs/common.Inode
的用法示例。
在下文中一共展示了Inode.File方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: do_open
func (fs *FileSystem) do_open(proc *Process, path string, oflags int, omode uint16) (common.Fd, error) {
// Remap the bottom two bits of oflags
bits := mode_map[oflags&common.O_ACCMODE]
var err error
var rip *common.Inode
var exist bool = false
// If O_CREATE is set, try to make the file
if oflags&common.O_CREAT > 0 {
// Create a new node by calling new_node()
omode := common.I_REGULAR | (omode & common.ALL_MODES & proc.umask)
dirp, newrip, _, err := fs.new_node(proc, path, omode, common.NO_ZONE)
if err == nil {
exist = false
} else if err != common.EEXIST {
return nil, err
} else {
exist = (oflags&common.O_EXCL == 0)
}
// we don't need the parent directory
fs.itable.PutInode(dirp)
rip = newrip
} else {
// grab the inode at the given path
rip, err = fs.eatPath(proc, path)
if err != nil {
return nil, err
}
}
// Find an available filp entry for the file descriptor
fdindex := -1
for i := 0; i < len(proc.files); i++ {
if proc.files[i] == nil {
fdindex = i
break
}
}
if fdindex == -1 {
return nil, common.EMFILE
}
err = nil // we'll use this to set error codes
if exist { // if the file existed already
// TODO: Check permissions here
switch rip.Type() {
case common.I_REGULAR:
if oflags&common.O_TRUNC > 0 {
common.Truncate(rip, 0, fs.bcache)
// Flush the inode so it gets written on next block cache
fs.itable.FlushInode(rip)
}
case common.I_DIRECTORY:
// Directories cannot be opened in this system
err = common.EISDIR
default:
panic("NYI: Process.Open with non regular/directory")
}
}
if err != nil {
// Something went wrong, so release the inode
fs.itable.PutInode(rip)
return nil, err
}
// Make sure there is a 'File' server running
if rip.File == nil {
// Spawn a file process to handle reading/writing
rip.File = file.NewFile(rip)
}
// Create a new 'filp' object to expose to the user
filp := &filp{1, 0, rip.File, rip, bits, new(sync.Mutex)}
proc.files[fdindex] = filp
return filp, nil
}