コード例 #1
0
ファイル: volume.go プロジェクト: kshlm/gogfapi
// OpenFile opens the named file on the the Volume v.
// The Volume must be mounted before calling OpenFile.
// OpenFile is similar to os.OpenFile in its functioning.
//
// name is the name of the file to be open.
// flags is the access mode of the file.
// perm is the permissions for the opened file.
//
// Returns a File object on success and a os.PathError on failure.
//
// BUG : perm is not used for opening the file.
// NOTE: It is better to use Open, Create etc. instead of using OpenFile directly
func (v *Volume) OpenFile(name string, flags int, perm os.FileMode) (*File, error) {
	isDir := false

	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))

	var cfd *C.glfs_fd_t
	var err error
	if (os.O_CREATE & flags) == os.O_CREATE {
		cfd, err = C.glfs_creat(v.fs, cname, C.int(flags), C.mode_t(posixMode(perm)))
	} else {
		cfd, err = C.glfs_open(v.fs, cname, C.int(flags))
	}

	// Try to reopen using glfs_opendir if the given path is a directory
	if err == syscall.EISDIR {
		isDir = true
		cfd, err = C.glfs_opendir(v.fs, cname)
	}

	if cfd == nil {
		return nil, &os.PathError{"open", name, err}
	}

	return &File{name, Fd{cfd}, isDir}, nil
}
コード例 #2
0
ファイル: volume.go プロジェクト: vbellur/gogfapi
// Chmod changes the mode of the named file to given mode
//
// Returns an error on failure
func (v *Volume) Chmod(name string, mode os.FileMode) error {
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))

	_, err := C.glfs_chmod(v.fs, cname, C.mode_t(posixMode(mode)))

	return err
}
コード例 #3
0
ファイル: env.go プロジェクト: Crest/gomdb
// Open an environment handle. If this function fails Close() must be called to discard the Env handle.
func (env *Env) Open(path string, flags uint, mode uint) error {
	cpath := C.CString(path)
	defer C.free(unsafe.Pointer(cpath))
	ret := C.mdb_env_open(env._env, cpath, C.uint(flags), C.mode_t(mode))
	if ret != SUCCESS {
		return Errno(ret)
	}
	return nil
}
コード例 #4
0
ファイル: sem.go プロジェクト: SiroDiaz/csuf
func sem_open(name string, oflag, mode, value int) (*sem_t, error) {
	c_name := C.CString(name)
	defer C.free(unsafe.Pointer(c_name))
	c_oflag := C.int(oflag)
	c_mode := C.mode_t(mode)
	c_value := C.uint(value)
	r, err := C.sem_open_(c_name, c_oflag, c_mode, c_value)
	return (*sem_t)(r), err
}
コード例 #5
0
ファイル: selinux_impl.go プロジェクト: roacobb/geard
func Matchpathcon(path string, mode os.FileMode) (string, error) {
	var con C.security_context_t
	var scon string
	rc, err := C.matchpathcon(C.CString(path), C.mode_t(mode), &con)
	if rc == 0 {
		scon = C.GoString(con)
		C.free(unsafe.Pointer(con))
	}
	return scon, err
}
コード例 #6
0
ファイル: volume.go プロジェクト: vbellur/gogfapi
// Mkdir creates a new directory with given name and permission bits
//
// Returns an error on failure
func (v *Volume) Mkdir(name string, perm os.FileMode) error {
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))

	ret, err := C.glfs_mkdir(v.fs, cname, C.mode_t(posixMode(perm)))

	if ret != 0 {
		return &os.PathError{"mkdir", name, err}
	}
	return nil
}
コード例 #7
0
ファイル: shm.go プロジェクト: vasiliyl/playwand
func Open(name string, flag int, perm os.FileMode) (o Object, err error) {
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))

	fd, err := C.shm_open(cname, C.int(flag), C.mode_t(perm))
	if err != nil {
		return o, err
	}

	return Object{File: os.NewFile(uintptr(fd), name), name: name}, nil
}
コード例 #8
0
ファイル: shm.go プロジェクト: SiroDiaz/csuf
func shm_open(name string, oflag, mode int) (*os.File, error) {
	c_name := C.CString(name)
	defer C.free(unsafe.Pointer(c_name))
	c_oflag := C.int(oflag)
	c_mode := C.mode_t(mode)
	c_res, err := C.c_shm_open(c_name, c_oflag, c_mode)
	if err != nil {
		return nil, err
	}
	return os.NewFile(uintptr(c_res), name), nil
}
コード例 #9
0
ファイル: cephfs.go プロジェクト: mittalms/go-ceph
func (mount *MountInfo) MakeDir(path string, mode uint32) error {
	c_path := C.CString(path)
	defer C.free(unsafe.Pointer(c_path))

	ret := C.ceph_mkdir(mount.mount, c_path, C.mode_t(mode))
	if ret == 0 {
		return nil
	} else {
		return CephError(ret)
	}
}
コード例 #10
0
ファイル: ndbm.go プロジェクト: SteelPangolin/go-ndbm
// Open lets you specify how the database is opened, for example, if you want read-only mode.
func Open(path string, flags, mode int) (*NDBM, error) {
	cPath := C.CString(path)
	cDbm, err := C.dbm_open(cPath, C.int(flags), C.mode_t(mode))
	C.free(unsafe.Pointer(cPath))
	if cDbm == nil {
		return nil, err
	}
	ndbm := &NDBM{
		cDbm: cDbm,
	}
	return ndbm, nil
}
コード例 #11
0
ファイル: tdb.go プロジェクト: ypb/gotdb
// Open is used by New with some reasonable default initial values apart from
// path name. Following is a signature of libtdb's original C tdb_open() function
// written in cgo convention:
//
// func tdb_open(name const *C.char, hash_size, tdb_flags, open_flags C.int, mode C.mode_t) *C.struct_tdb_context
//
//  /* tdb_flags */
//  DEFAULT           /* just a readability place holder */
//  CLEAR_IF_FIRST    /* beats me... */
//  INTERNAL          /* don't store on disk */
//  NOLOCK            /* don't do any locking */
//  NOMMAP            /* don't use mmap */
//  CONVERT           /* convert endian (internal use) */
//  BIGENDIAN         /* header is big-endian (internal use) */
//  NOSYNC            /* don't use synchronous transactions */
//  SEQNUM            /* maintain a sequence number */
//  VOLATILE          /* Activate the per-hashchain freelist, default 5 */
//  ALLOW_NESTING     /* Allow transactions to nest */
//  DISALLOW_NESTING  /* Disallow transactions to nest */
//  INCOMPATIBLE_HASH /* Better hashing: can't be opened by tdb < 1.2.6. */
//
//  /* open_flags */
//  /* 'man 2 open' on *nix, but what of pkg/os? TOPONDER */
//  O_RDONLY
//  /* O_WRONLY *//* is invalid */
//  O_RDWR
//  O_CREAT, O_TRUNC, O_APPEND
//  /* well, Ay dunno... */
//  O_CLOEXEC, O_EXCL
//  /* O_NOATIME *//* #define __USE_GNU */
//  O_NOFOLLOW, O_NONBLOCK = O_NDELAY
//
//  /* O_CREAT mode */
//  USR_RW = (S_IWUSR | S_IRUSR) /* helpful shortcut */
//  USR_RWX                      /* 00700 user (file owner) has read, write and execute permission */
//  USR_R                        /* 00400 user has read permission */
//  USR_W                        /* 00200 user has write permission */
//  USR_X                        /* 00100 user has execute permission */
//  GRP_RWX                      /* 00070 group has read, write and execute permission */
//  GRP_R                        /* 00040 group has read permission */
//  GRP_W                        /* 00020 group has write permission */
//  GRP_X                        /* 00010 group has execute permission */
//  OTH_RWX                      /* 00007 others have read, write and execute permission */
//  OTH_R                        /* 00004 others have read permission */
//  OTH_W                        /* 00002 others have write permission */
//  OTH_X                        /* 00001 others have execute permission */
//
func Open(path string, hash_size, tdb_flags, open_flags int, mode uint32) (DB, Error) {
	name := C.CString(path)
	defer C.free(unsafe.Pointer(name))
	var ctx tdb_CTX
	if old := ns[path]; old != nil { // now, what do we do?
		// if db is still "here" in the ns but closed we
		if old.cld {
			ctx = C.tdb_open(name, C.int(hash_size), C.int(tdb_flags), C.int(open_flags), C.mode_t(mode))
			if ctx == nil {
				return DB{old}, mkError(1, "tdb.Open() tdb_open old failed")
			} else {
				old.cld = false
				old.ctx = ctx
				return DB{old}, nil
			}
			// if it's not closed perhaps we should to something "more"
			// intelligent, like closing and reopening with new params
			// TODO: later?
		} else {
			return DB{old}, nil
		}
	} else {
		var fresh *db
		ctx = C.tdb_open(name, C.int(hash_size), C.int(tdb_flags), C.int(open_flags), C.mode_t(mode))
		if ctx == nil {
			println("Open() new ctx == nil")
			fresh = &db{&path, false, true, ctx}
			ns[path] = fresh
			return DB{fresh}, mkError(1, "tdb.Open() tdb_open fresh failed")
		} else {
			fresh = &db{pth: &path, cld: false, dbg: false, ctx: ctx}
			ns[path] = fresh
			return DB{fresh}, nil
		}
	}
	panic("unreachable")
	// return &DB{path, false, ctx}
}
コード例 #12
0
ファイル: mq.go プロジェクト: SiroDiaz/csuf
func mq_open(name string, oflag int, mode int, attr mq_attr) (mqd_t, error) {
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))
	var cattr C.struct_mq_attr
	cattr.mq_flags = C.__syscall_slong_t(attr.mq_flags)
	cattr.mq_maxmsg = C.__syscall_slong_t(attr.mq_maxmsg)
	cattr.mq_msgsize = C.__syscall_slong_t(attr.mq_msgsize)
	cattr.mq_curmsgs = C.__syscall_slong_t(attr.mq_curmsgs)
	q, err := C._mq_open(cname, C.int(oflag), C.mode_t(mode), &cattr)
	if err != nil {
		log.Printf("%d\n", err)
		return mqd_t(q), err
	}
	return mqd_t(q), nil
}
コード例 #13
0
func (a *InoAttr) toCStat(o *C.struct_stat, timeout *C.double) {
	o.st_ino = C.__darwin_ino64_t(a.Ino)
	o.st_mode = C.mode_t(a.Mode)
	o.st_nlink = C.nlink_t(a.Nlink)
	o.st_size = C.off_t(a.Size)
	if a.Uid != nil {
		o.st_uid = C.uid_t(*a.Uid)
	}
	if a.Gid != nil {
		o.st_gid = C.gid_t(*a.Gid)
	}
	toCTime(&o.st_ctimespec, a.Ctim)
	toCTime(&o.st_mtimespec, a.Mtim)
	toCTime(&o.st_atimespec, a.Atim)
	if timeout != nil {
		(*timeout) = C.double(a.Timeout)
	}
}
コード例 #14
0
ファイル: cgroup.go プロジェクト: NodePrime/open-mininet
/*
Stores given file permissions of the group's control and tasks files
into the cgroup data structure. Use NO_PERMS if permissions shouldn't
be changed or a value which applicable to chmod(2). Please note that
the given permissions are masked with the file owner's permissions.
For example if a control file has permissions 640 and control_fperm is
471 the result will be 460.

control_dperm Directory permission for the group.
control_fperm File permission for the control files.
task_fperm File permissions for task file.

  g := cgroup.NewCgroup("foo")
  g.SetPermissions(cgroup.Mode(0777), cgroup.Mode(0777), cgroup.Mode(0777))
*/
func (cg Cgroup) SetPermissions(control_dperm, control_fperm, task_fperm Mode) {
	C.cgroup_set_permissions(cg.g, C.mode_t(control_dperm),
		C.mode_t(control_fperm), C.mode_t(task_fperm))
}
コード例 #15
0
ファイル: cg.go プロジェクト: vbatts/go-cgroup
/*
SetPermissions stores given file permissions of the group's control and tasks files
into the cgroup data structure. Use NoPerms if permissions shouldn't
be changed or a value which applicable to chmod(2). Please note that
the given permissions are masked with the file owner's permissions.
For example if a control file has permissions 640 and controlFilePerm is
471 the result will be 460.

controlDirPerm Directory permission for the group.
controlFilePerm File permission for the control files.
taskFilePerm File permissions for task file.

  g := cgroup.NewCgroup("foo")
  g.SetPermissions(cgroup.Mode(0777), cgroup.Mode(0777), cgroup.Mode(0777))
*/
func (cg Cgroup) SetPermissions(controlDirPerm, controlFilePerm, taskFilePerm Mode) {
	C.cgroup_set_permissions(cg.g, C.mode_t(controlDirPerm),
		C.mode_t(controlFilePerm), C.mode_t(taskFilePerm))
}
コード例 #16
0
ファイル: fd.go プロジェクト: vbellur/gogfapi
// Fchmod changes the mode of the Fd to the given mode
//
// Returns error on failure
func (fd *Fd) Fchmod(mode uint32) error {
	_, err := C.glfs_fchmod(fd.fd, C.mode_t(mode))

	return err
}