Ejemplo n.º 1
0
Archivo: main.go Proyecto: c-fs/cfuse
func NewCFile(client *client.Client, name string) nodefs.File {
	f := new(CFile)
	f.client = client
	f.File = nodefs.NewDefaultFile()
	f.name = name
	return f
}
Ejemplo n.º 2
0
func (rfs *ReverseFS) newVirtualFile(content []byte, parentFile string) (nodefs.File, fuse.Status) {
	return &virtualFile{
		File:       nodefs.NewDefaultFile(),
		content:    content,
		parentFile: parentFile,
		ino:        rfs.inoGen.next(),
	}, fuse.OK
}
Ejemplo n.º 3
0
Archivo: fs.go Proyecto: hanwen/gitfs
func (n *blobNode) LoadMemory() (nodefs.File, error) {
	blob, err := n.fs.repo.LookupBlob(n.id)
	if err != nil {
		return nil, err
	}
	return &memoryFile{
		File: nodefs.NewDefaultFile(),
		blob: blob,
	}, nil
}
Ejemplo n.º 4
0
func (n *folderNode) Create(name string, flags uint32, mode uint32, context *fuse.Context) (nodefs.File, *nodefs.Inode, fuse.Status) {
	if !n.fetch() {
		return nil, nil, fuse.EIO
	}

	obj := mtp.ObjectInfo{
		StorageID:        n.StorageID(),
		Filename:         name,
		ObjectFormat:     mtp.OFC_Undefined,
		ModificationDate: time.Now(),
		ParentObject:     n.Handle(),
		CompressedSize:   0,
	}

	var file nodefs.File
	var fsNode nodefs.Node
	if n.fs.options.Android {
		_, _, handle, err := n.fs.dev.SendObjectInfo(n.StorageID(), n.Handle(), &obj)
		if err != nil {
			log.Println("SendObjectInfo failed", err)
			return nil, nil, fuse.EIO
		}

		err = n.fs.dev.SendObject(&bytes.Buffer{}, 0)
		if err != nil {
			log.Println("SendObject failed:", err)
			return nil, nil, fuse.EIO
		}

		aNode := &androidNode{
			mtpNodeImpl: mtpNodeImpl{
				Node:   nodefs.NewDefaultNode(),
				obj:    &obj,
				fs:     n.fs,
				handle: handle,
			},
		}

		if !aNode.startEdit() {
			return nil, nil, fuse.EIO
		}
		file = &androidFile{
			File: nodefs.NewDefaultFile(),
			node: aNode,
		}
		fsNode = aNode
	} else {
		var err error
		file, fsNode, err = n.fs.createClassicFile(obj)
		if err != nil {
			return nil, nil, fuse.ToStatus(err)
		}
	}
	return file, n.Inode().NewChild(name, false, fsNode), fuse.OK
}
Ejemplo n.º 5
0
func (m *MNode) Open(flags uint32, context *fuse.Context) (file nodefs.File, code fuse.Status) {
	m.obj.Lock()
	defer m.obj.Unlock()
	j,ok := m.obj.Obj.(*joinf.JoinFile)
	if !ok { return nil,fuse.EINVAL }
	if (flags&uint32(os.O_TRUNC))!=0 {
		e := j.Truncate(0)
		if e!=nil { return nil,fuse.ToStatus(e) }
	}
	return &MFile{nodefs.NewDefaultFile(),m.obj,j},fuse.OK
}
Ejemplo n.º 6
0
// NewAdbFile returns a File that reads and writes to name on the device.
// perms should be set from the existing file if it exists, or to the desired new permissions if new.
func NewAdbFile(opts AdbFileOpenOptions) nodefs.File {
	logEntry := StartFileOperation("New", opts.FileBuffer.Path, fmt.Sprint(opts))
	defer logEntry.FinishOperation()

	adbFile := &AdbFile{
		// Log all the operations we don't implement.
		File:               newLoggingFile(nodefs.NewDefaultFile(), opts.FileBuffer.Path),
		AdbFileOpenOptions: opts,
	}

	return nodefs.NewReadOnlyFile(adbFile)
}
Ejemplo n.º 7
0
func NewObjectFile(name string, obj mapper.Object) *ObjectFile {
	f := &ObjectFile{
		name:       name,
		object:     obj,
		lock:       sync.Mutex{},
		needUpload: false,

		File: nodefs.NewDefaultFile(),
	}

	return f
}
Ejemplo n.º 8
0
func (fs *nomsFS) Open(path string, flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
	fs.mdLock.Lock()
	defer fs.mdLock.Unlock()
	np, code := fs.getPath(path)
	if code != fuse.OK {
		return nil, code
	}

	nfile := nomsFile{
		File: nodefs.NewDefaultFile(),

		fs:   fs,
		node: np,
	}

	return nfile, fuse.OK
}
Ejemplo n.º 9
0
func (fs *nomsFS) Create(path string, flags uint32, mode uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
	fs.mdLock.Lock()
	defer fs.mdLock.Unlock()
	np, code := fs.createCommon(path, mode, func() types.Value {
		blob := types.NewEmptyBlob()
		return types.NewStructWithType(fileType, types.ValueSlice{fs.ds.Database().WriteValue(blob)})
	})
	if code != fuse.OK {
		return nil, code
	}

	nfile := nomsFile{
		File: nodefs.NewDefaultFile(),

		fs:   fs,
		node: np,
	}
	return nfile, fuse.OK
}
Ejemplo n.º 10
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
}
Ejemplo n.º 11
0
func (fs *objectFileSystem) Create(name string, flags uint32, mode uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
	log.Debugf("Create: %s, flags: %d", name, flags)

	fs.lock.Lock()
	defer fs.lock.Unlock()

	// Add to mapper
	obj, err := fs.mapper.Create(name)
	if err != nil {
		log.Warnf("Can't append to mapper %v", err)
		return nodefs.NewDefaultFile(), fuse.EIO
	}

	file := NewObjectFile(name, obj)
	if err := file.OpenLocalFile(flags, mode); err != nil {
		log.Warnf("Create: OpenLocalFile() error %v", err)
		return file, fuse.EIO
	}

	return file, fuse.OK
}
Ejemplo n.º 12
0
func (rfs *ReverseFS) newFile(relPath string, flags uint32) (nodefs.File, fuse.Status) {
	absPath, err := rfs.abs(rfs.decryptPath(relPath))
	if err != nil {
		return nil, fuse.ToStatus(err)
	}
	fd, err := os.OpenFile(absPath, int(flags), 0666)
	if err != nil {
		return nil, fuse.ToStatus(err)
	}
	id := derivePathIV(relPath, ivPurposeFileID)
	header := contentenc.FileHeader{
		Version: contentenc.CurrentVersion,
		ID:      id,
	}
	return &reverseFile{
		File:       nodefs.NewDefaultFile(),
		fd:         fd,
		header:     header,
		block0IV:   derivePathIV(relPath, ivPurposeBlock0IV),
		contentEnc: rfs.contentEnc,
	}, fuse.OK
}
Ejemplo n.º 13
0
func (n *androidNode) Open(flags uint32, context *fuse.Context) (file nodefs.File, code fuse.Status) {
	return &androidFile{
		node: n,
		File: nodefs.NewDefaultFile(),
	}, fuse.OK
}
Ejemplo n.º 14
0
func NewOssFile(bucket string, fileName string, ossClient *oss.Client, lock *sync.Mutex, size int64, bufFile *BufFile) (ossFile *OssFile) {
	ossFile = &OssFile{bucket: bucket, fileName: fileName, ossClient: ossClient, lock: lock, size: size, bufFile: bufFile}
	ossFile.File = nodefs.NewDefaultFile()
	return ossFile
}
Ejemplo n.º 15
0
func (n *classicNode) Open(flags uint32, context *fuse.Context) (file nodefs.File, code fuse.Status) {
	return &pendingFile{
		File: nodefs.NewDefaultFile(),
		node: n,
	}, fuse.OK
}
Ejemplo n.º 16
0
func newFile(s store.Store, kv *store.KVPair) nodefs.File {
	return &file{s, kv, nodefs.NewDefaultFile()}
}
Ejemplo n.º 17
0
func NewFile() *MutableDataFile {
	return &MutableDataFile{File: nodefs.NewDefaultFile()}
}
Ejemplo n.º 18
0
func (fs *DefaultReadFS) Open(name string, f uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
	return nodefs.NewDefaultFile(), fuse.OK
}
Ejemplo n.º 19
0
func (f *FileObj) Init() {
	f.File = nodefs.NewDefaultFile()
}