コード例 #1
0
ファイル: main.go プロジェクト: krishnasrinivas/constor
func (constor *Constor) Create(input *fuse.CreateIn, name string, out *fuse.CreateOut) (code fuse.Status) {
	dirpath, err := constor.dentrymap.getPath(input.NodeId)
	if err != nil {
		constor.error("%s", err)
		return fuse.ToStatus(err)
	}
	constor.log("%s%s %d %d %d", dirpath, name, input.Mode, input.Uid, input.Gid)
	if err := constor.createPath(dirpath); err != nil {
		constor.error("%s", err)
		return fuse.ToStatus(err)
	}
	pathl := Path.Join(constor.layers[0], dirpath, name)
	// remove any deleted place holder entries
	if constor.isdeleted(pathl) {
		syscall.Unlink(pathl)
	}
	fd, err := syscall.Open(pathl, syscall.O_CREAT|syscall.O_RDWR, input.Mode)
	if err != nil {
		constor.error("%s", err)
		return fuse.ToStatus(err)
	}

	err = syscall.Chown(pathl, int(input.Uid), int(input.Gid))
	if err != nil {
		constor.error("%s", err)
		return fuse.ToStatus(err)
	}
	F := new(FD)
	F.fd = fd
	F.layer = 0
	constor.putfd(F)
	out.Fh = uint64(uintptr(unsafe.Pointer(F)))
	constor.log("%d", out.Fh)
	return constor.Lookup((*fuse.InHeader)(unsafe.Pointer(input)), name, &out.EntryOut)
}
コード例 #2
0
ファイル: main.go プロジェクト: krishnasrinivas/confs
func (constor *Constor) Create(input *fuse.CreateIn, name string, out *fuse.CreateOut) (code fuse.Status) {
	flags := 0

	inode := constor.inodemap.findInodePtr(input.NodeId)
	if inode == nil {
		constor.error("inode == nil")
		return fuse.ENOENT
	}
	err := constor.copyup(inode)
	if err != nil {
		constor.error("copyup failed for %s - %s", inode.id, err)
		return fuse.ToStatus(err)
	}
	dirpath := constor.getPath(0, inode.id)
	entrypath := Path.Join(dirpath, name)

	if constor.isdeleted(entrypath, nil) {
		if err := syscall.Unlink(entrypath); err != nil {
			constor.error("Unlink %s : %s", entrypath, err)
			return fuse.ToStatus(err)
		}
	}

	fd, err := syscall.Creat(entrypath, input.Mode)
	if err != nil {
		constor.error("Creat %s : %s", entrypath, err)
		return fuse.ToStatus(err)
	}
	syscall.Close(fd)
	id := constor.setid(entrypath, "")
	if id == "" {
		constor.error("setid %s : %s", entrypath, err)
		return fuse.EIO
	}
	constor.log("%s : %s", entrypath, id)
	if err := constor.createPath(id); err != nil {
		constor.error("createPath %s : %s", id, err)
		return fuse.ToStatus(err)
	}
	path := constor.getPath(0, id)
	if input.Flags != 0 {
		flags = int(input.Flags) | syscall.O_CREAT
	} else {
		flags = syscall.O_CREAT | syscall.O_RDWR | syscall.O_EXCL
	}
	fd, err = syscall.Open(path, flags, input.Mode)
	// fd, err = syscall.Open(path, int(input.Flags), input.Mode)
	if err != nil {
		constor.error("open %s : %s", path, err)
		return fuse.ToStatus(err)
	}
	err = syscall.Chown(path, int(input.Uid), int(input.Gid))
	if err != nil {
		constor.error("Chown %s : %s", path, err)
		return fuse.ToStatus(err)
	}
	F := new(FD)
	F.fd = fd
	F.layer = 0
	F.id = id
	F.pid = input.Pid
	constor.putfd(F)
	if flags&syscall.O_DIRECT != 0 {
		out.OpenFlags = fuse.FOPEN_DIRECT_IO
	} else {
		out.OpenFlags = fuse.FOPEN_KEEP_CACHE
	}

	out.Fh = uint64(uintptr(unsafe.Pointer(F)))
	constor.log("%d", out.Fh)
	return constor.Lookup((*fuse.InHeader)(unsafe.Pointer(input)), name, &out.EntryOut)
}