本文整理匯總了Golang中github.com/hanwen/go-fuse/fuse.File類的典型用法代碼示例。如果您正苦於以下問題:Golang File類的具體用法?Golang File怎麽用?Golang File使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了File類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetAttr
func (n *fileNode) GetAttr(file fuse.File, context *fuse.Context) (fi *fuse.Attr, code fuse.Status) {
if file != nil {
return file.GetAttr()
}
a := &fuse.Attr{Mode: fuse.S_IFREG | 0644}
if n.backing != "" {
fi, err := os.Stat(n.backing)
if err != nil {
return nil, fuse.ToStatus(err)
}
a.Size = uint64(fi.Size())
t := n.file.Mtime()
if n.dirty {
t = fi.ModTime()
}
a.SetTimes(&t, &t, &t)
} else if n.file != nil {
a.Size = uint64(n.file.filesize)
t := n.file.Mtime()
a.SetTimes(&t, &t, &t)
}
return a, fuse.OK
}
示例2: GetAttr
func (n *fileNode) GetAttr(out *fuse.Attr, file fuse.File, context *fuse.Context) (code fuse.Status) {
if file != nil {
return file.GetAttr(out)
}
out.Mode = fuse.S_IFREG | 0644
f := n.File()
if n.backing != "" {
fi, err := os.Stat(n.backing)
if err != nil {
return fuse.ToStatus(err)
}
out.Size = uint64(fi.Size())
t := f.Mtime()
if n.dirty {
t = fi.ModTime()
}
out.SetTimes(&t, &t, &t)
} else if f != nil {
out.Size = uint64(f.filesize)
t := f.Mtime()
out.SetTimes(&t, &t, &t)
}
return fuse.OK
}
示例3: Truncate
func (n *fileNode) Truncate(file fuse.File, size uint64, context *fuse.Context) (code fuse.Status) {
if file != nil {
return file.Truncate(size)
} else if n.backing != "" {
return fuse.ToStatus(os.Truncate(n.backing, int64(size)))
}
return fuse.OK
}
示例4: Truncate
func (me *memNode) Truncate(file fuse.File, size uint64, context *fuse.Context) (code fuse.Status) {
me.mutex.Lock()
defer me.mutex.Unlock()
me.promote()
if file != nil {
code = file.Truncate(size)
} else {
code = fuse.ToStatus(os.Truncate(me.backing, int64(size)))
}
if code.Ok() {
me.info.Size = size
me.touch()
}
return code
}
示例5: putDeletion
func (me *UnionFs) putDeletion(name string) (code fuse.Status) {
marker := me.deletionPath(name)
me.deletionCache.AddEntry(path.Base(marker))
// Is there a WriteStringToFileOrDie ?
writable := me.fileSystems[0]
fi, code := writable.GetAttr(marker)
if code.Ok() && fi.Size == int64(len(name)) {
return fuse.OK
}
var f fuse.File
if code == fuse.ENOENT {
f, code = writable.Create(marker, uint32(os.O_TRUNC|os.O_WRONLY), 0644)
} else {
writable.Chmod(marker, 0644)
f, code = writable.Open(marker, uint32(os.O_TRUNC|os.O_WRONLY))
}
if !code.Ok() {
log.Printf("could not create deletion file %v: %v", marker, code)
return fuse.EPERM
}
defer f.Release()
defer f.Flush()
n, code := f.Write(&fuse.WriteIn{}, []byte(name))
if int(n) != len(name) || !code.Ok() {
panic(fmt.Sprintf("Error for writing %v: %v, %v (exp %v) %v", name, marker, n, len(name), code))
}
return fuse.OK
}
示例6: GetAttr
func (me *memNode) GetAttr(file fuse.File, context *fuse.Context) (fi *fuse.Attr, code fuse.Status) {
var sz uint64
if file != nil {
fi, code := file.GetAttr()
if code.Ok() {
sz = fi.Size
} else {
msg := fmt.Sprintf("File.GetAttr(%s) = %v, %v", file.String(), fi, code)
panic(msg)
}
}
me.mutex.RLock()
defer me.mutex.RUnlock()
info := me.info
if file != nil {
info.Size = sz
}
return &info, fuse.OK
}