本文整理汇总了Golang中syscall.Truncate函数的典型用法代码示例。如果您正苦于以下问题:Golang Truncate函数的具体用法?Golang Truncate怎么用?Golang Truncate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Truncate函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: open
func (fe *fileEntry) open(name string, length int64) (err os.Error) {
fe.length = length
fe.fd, err = os.Open(name, os.O_RDWR|os.O_CREAT, 0666)
if err != nil {
return
}
errno := syscall.Truncate(name, length)
if errno != 0 {
err = os.NewError("Could not truncate file.")
}
return
}
示例2: Truncate
// Truncate changes the size of the named file.
// If the file is a symbolic link, it changes the size of the link's target.
// If there is an error, it will be of type *PathError.
func Truncate(name string, size int64) error {
if e := syscall.Truncate(name, size); e != nil {
return &PathError{"truncate", name, e}
}
return nil
}
示例3: Truncate
// Truncate changes the size of the named file.
// If the file is a symbolic link, it changes the size of the link's target.
func Truncate(name string, size int64) Error {
if e := syscall.Truncate(name, size); e != 0 {
return &PathError{"truncate", name, Errno(e)}
}
return nil
}
示例4: SetAttr
//.........这里部分代码省略.........
attr.Ino = idtoino(inode.id)
return fuse.OK
}
if inode.layer == -1 {
return fuse.ENOENT
}
if inode.layer != 0 {
err = constor.copyup(inode)
if err != nil {
constor.error("copyup failed for %s - %s", inode.id, err)
return fuse.ToStatus(err)
}
}
stat := syscall.Stat_t{}
path := constor.getPath(0, inode.id)
// just to satisfy PJD tests
if input.Valid == 0 {
err = syscall.Lchown(path, uid, gid)
if err != nil {
return fuse.ToStatus(err)
}
}
if input.Valid&fuse.FATTR_MODE != 0 {
permissions := uint32(07777) & input.Mode
err = syscall.Chmod(path, permissions)
if err != nil {
constor.error("Lchmod failed on %s - %d : %s", path, permissions, err)
return fuse.ToStatus(err)
}
}
if input.Valid&(fuse.FATTR_UID) != 0 {
uid = int(input.Uid)
}
if input.Valid&(fuse.FATTR_GID) != 0 {
gid = int(input.Gid)
}
if input.Valid&(fuse.FATTR_UID|fuse.FATTR_GID) != 0 {
constor.log("%s %d %d", path, uid, gid)
err = syscall.Lchown(path, uid, gid)
if err != nil {
constor.error("Lchown failed on %s - %d %d : %s", path, uid, gid, err)
return fuse.ToStatus(err)
}
}
if input.Valid&fuse.FATTR_SIZE != 0 {
err = syscall.Truncate(path, int64(input.Size))
if err != nil {
constor.error("Truncate failed on %s - %d : %s", path, input.Size, err)
return fuse.ToStatus(err)
}
}
if input.Valid&(fuse.FATTR_ATIME|fuse.FATTR_MTIME|fuse.FATTR_ATIME_NOW|fuse.FATTR_MTIME_NOW) != 0 {
now := time.Now()
var atime *time.Time
var mtime *time.Time
if input.Valid&fuse.FATTR_ATIME_NOW != 0 {
atime = &now
} else {
t := time.Unix(int64(input.Atime), int64(input.Atimensec))
atime = &t
}
if input.Valid&fuse.FATTR_MTIME_NOW != 0 {
mtime = &now
} else {
t := time.Unix(int64(input.Mtime), int64(input.Mtimensec))
mtime = &t
}
fi, err := os.Lstat(path)
if err != nil {
return fuse.ToStatus(err)
}
if fi.Mode()&os.ModeSymlink != os.ModeSymlink {
// FIXME: there is no Lchtimes
err = os.Chtimes(path, *atime, *mtime)
if err != nil {
constor.error("Chtimes failed on %s : %s", path, err)
return fuse.ToStatus(err)
}
} else {
constor.error("Chtimes on Symlink not supported")
}
}
attr := (*fuse.Attr)(&out.Attr)
err = constor.Lstat(inode.layer, inode.id, &stat)
if err != nil {
constor.error("Lstat failed on %s : %s", inode.id, err)
return fuse.ToStatus(err)
}
attr.FromStat(&stat)
attr.Ino = stat.Ino
return fuse.ToStatus(err)
}