Exemplo n.º 1
0
func (fs *loopbackFileSystem) Open(name string, flags uint32, context *fuse.Context) (fuseFile nodefs.File, status fuse.Status) {
	f, err := os.OpenFile(fs.GetPath(name), int(flags), 0)
	if err != nil {
		return nil, fuse.ToStatus(err)
	}
	return nodefs.NewLoopbackFile(f), fuse.OK
}
Exemplo n.º 2
0
func (me *memNode) Open(flags uint32, context *fuse.Context) (file nodefs.File, code fuse.Status) {
	me.mutex.Lock()
	defer me.mutex.Unlock()
	if flags&fuse.O_ANYWRITE != 0 {
		me.promote()
		me.touch()
	}

	if me.backing != "" {
		f, err := os.OpenFile(me.backing, int(flags), 0666)
		if err != nil {
			return nil, fuse.ToStatus(err)
		}
		wr := flags&fuse.O_ANYWRITE != 0
		if wr {
			me.fs.openWritable++
		}
		return me.newFile(nodefs.NewLoopbackFile(f), wr), fuse.OK
	}

	file, code = me.fs.readonly.Open(me.original, flags, context)
	if !code.Ok() {
		return nil, code
	}

	return me.newFile(file, false), fuse.OK
}
Exemplo n.º 3
0
Arquivo: fs.go Projeto: hanwen/p4fuse
func (n *p4File) Open(flags uint32, context *fuse.Context) (file nodefs.File, code fuse.Status) {
	if flags&fuse.O_ANYWRITE != 0 {
		return nil, fuse.EROFS
	}

	n.fetch()
	f, err := os.OpenFile(n.backing, int(flags), 0644)
	if err != nil {
		return nil, fuse.ToStatus(err)
	}
	return nodefs.NewLoopbackFile(f), fuse.OK
}
Exemplo n.º 4
0
func (p *pendingFile) Read(data []byte, off int64) (fuse.ReadResult, fuse.Status) {
	if p.loopback == nil {
		if err := p.node.fetch(); err != nil {
			log.Printf("fetch failed: %v", err)
			return nil, fuse.EIO
		}
		f, err := os.OpenFile(p.node.backing, os.O_RDWR|os.O_CREATE, 0644)
		if err != nil {
			return nil, fuse.ToStatus(err)
		}
		p.loopback = nodefs.NewLoopbackFile(f)
	}
	return p.loopback.Read(data, off)
}
Exemplo n.º 5
0
func (p *pendingFile) rwLoopback() (nodefs.File, fuse.Status) {
	if p.loopback == nil {
		if err := p.node.fetch(); err != nil {
			return nil, fuse.ToStatus(err)
		}
		f, err := os.OpenFile(p.node.backing, os.O_RDWR|os.O_CREATE, 0644)
		if err != nil {
			return nil, fuse.ToStatus(err)
		}

		p.loopback = nodefs.NewLoopbackFile(f)
	}
	return p.loopback, fuse.OK
}
Exemplo n.º 6
0
func (me *memNode) Create(name string, flags uint32, mode uint32, context *fuse.Context) (file nodefs.File, ch *nodefs.Inode, code fuse.Status) {
	me.mutex.Lock()
	defer me.mutex.Unlock()

	n := me.fs.newNode(false)
	n.info.Mode = mode | fuse.S_IFREG
	n.changed = true
	n.backing = me.fs.getFilename()
	f, err := os.Create(n.backing)
	if err != nil {
		log.Printf("Backing store error %q: %v", n.backing, err)
		return nil, nil, fuse.ToStatus(err)
	}
	ch = me.Inode().NewChild(name, false, n)
	me.touch()
	me.fs.openWritable++
	return n.newFile(nodefs.NewLoopbackFile(f), true), ch, fuse.OK
}
Exemplo n.º 7
0
func (fs *deviceFS) createClassicFile(obj mtp.ObjectInfo) (file nodefs.File, node nodefs.Node, err error) {
	backingFile, err := ioutil.TempFile(fs.options.Dir, "")
	cl := &classicNode{
		mtpNodeImpl: mtpNodeImpl{
			Node: nodefs.NewDefaultNode(),
			obj:  &obj,
			fs:   fs,
		},
		dirty:   true,
		backing: backingFile.Name(),
	}
	file = &pendingFile{
		loopback: nodefs.NewLoopbackFile(backingFile),
		node:     cl,
		File:     nodefs.NewDefaultFile(),
	}

	node = cl
	return
}
Exemplo n.º 8
0
// NewFile returns a new go-fuse File instance.
func NewFile(fd *os.File, writeOnly bool, fs *FS) (nodefs.File, fuse.Status) {
	var st syscall.Stat_t
	err := syscall.Fstat(int(fd.Fd()), &st)
	if err != nil {
		tlog.Warn.Printf("NewFile: Fstat on fd %d failed: %v\n", fd.Fd(), err)
		return nil, fuse.ToStatus(err)
	}
	di := DevInoFromStat(&st)
	t := openFileMap.register(di)

	return &file{
		fd:             fd,
		writeOnly:      writeOnly,
		contentEnc:     fs.contentEnc,
		devIno:         di,
		fileTableEntry: t,
		loopbackFile:   nodefs.NewLoopbackFile(fd),
		fs:             fs,
	}, fuse.OK
}
Exemplo n.º 9
0
Arquivo: fs.go Projeto: hanwen/gitfs
func (n *blobNode) LoadDisk() (nodefs.File, error) {
	p := filepath.Join(n.fs.opts.TempDir, n.id.String())
	if _, err := os.Lstat(p); os.IsNotExist(err) {
		blob, err := n.fs.repo.LookupBlob(n.id)
		if err != nil {
			return nil, err
		}
		defer blob.Free()

		// TODO - atomic, use content store to share content.
		if err := ioutil.WriteFile(p, blob.Contents(), 0644); err != nil {
			return nil, err
		}
	}
	f, err := os.Open(p)
	if err != nil {
		return nil, err
	}

	return nodefs.NewLoopbackFile(f), nil
}
Exemplo n.º 10
0
// Must run inside mutex.
func (me *memNode) promote() {
	if me.backing == "" {
		me.backing = me.fs.getFilename()
		destfs := pathfs.NewLoopbackFileSystem("/")
		pathfs.CopyFile(me.fs.readonly, destfs,
			me.original, strings.TrimLeft(me.backing, "/"), nil)
		me.original = ""
		files := me.Inode().Files(0)
		for _, f := range files {
			mf := f.File.(*memNodeFile)
			inner := mf.File
			osFile, err := os.Open(me.backing)
			if err != nil {
				panic("error opening backing file")
			}
			mf.File = nodefs.NewLoopbackFile(osFile)
			inner.Flush()
			inner.Release()
		}
	}
}
Exemplo n.º 11
0
func (fs *loopbackFileSystem) Create(path string, flags uint32, mode uint32, context *fuse.Context) (fuseFile nodefs.File, code fuse.Status) {
	f, err := os.OpenFile(fs.GetPath(path), int(flags)|os.O_CREATE, os.FileMode(mode))
	return nodefs.NewLoopbackFile(f), fuse.ToStatus(err)
}