Esempio n. 1
0
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
}
Esempio n. 2
0
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
}
Esempio n. 3
0
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
}
Esempio n. 4
0
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
}
Esempio n. 5
0
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
}
Esempio n. 6
0
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
}