2015-05-01 19:35:40 +00:00
|
|
|
package cephfs
|
|
|
|
|
|
|
|
/*
|
|
|
|
#cgo LDFLAGS: -lcephfs
|
|
|
|
#cgo CPPFLAGS: -D_FILE_OFFSET_BITS=64
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <cephfs/libcephfs.h>
|
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
import "fmt"
|
|
|
|
import "unsafe"
|
|
|
|
|
|
|
|
//
|
|
|
|
type CephError int
|
|
|
|
|
|
|
|
func (e CephError) Error() string {
|
2015-07-08 08:34:54 +00:00
|
|
|
return fmt.Sprintf("cephfs: ret=%d", e)
|
2015-05-01 19:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
type MountInfo struct {
|
2015-07-08 08:34:54 +00:00
|
|
|
mount *C.struct_ceph_mount_info
|
2015-05-01 19:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func CreateMount() (*MountInfo, error) {
|
2015-07-08 08:34:54 +00:00
|
|
|
mount := &MountInfo{}
|
|
|
|
ret := C.ceph_create(&mount.mount, nil)
|
|
|
|
if ret == 0 {
|
|
|
|
return mount, nil
|
|
|
|
} else {
|
|
|
|
return nil, CephError(ret)
|
|
|
|
}
|
2015-05-01 19:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mount *MountInfo) ReadDefaultConfigFile() error {
|
2015-07-08 08:34:54 +00:00
|
|
|
ret := C.ceph_conf_read_file(mount.mount, nil)
|
|
|
|
if ret == 0 {
|
|
|
|
return nil
|
|
|
|
} else {
|
|
|
|
return CephError(ret)
|
|
|
|
}
|
2015-05-01 19:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mount *MountInfo) Mount() error {
|
2015-07-08 08:34:54 +00:00
|
|
|
ret := C.ceph_mount(mount.mount, nil)
|
|
|
|
if ret == 0 {
|
|
|
|
return nil
|
|
|
|
} else {
|
|
|
|
return CephError(ret)
|
|
|
|
}
|
2015-05-01 19:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mount *MountInfo) SyncFs() error {
|
2015-07-08 08:34:54 +00:00
|
|
|
ret := C.ceph_sync_fs(mount.mount)
|
|
|
|
if ret == 0 {
|
|
|
|
return nil
|
|
|
|
} else {
|
|
|
|
return CephError(ret)
|
|
|
|
}
|
2015-05-01 19:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mount *MountInfo) CurrentDir() string {
|
2015-07-08 08:34:54 +00:00
|
|
|
c_dir := C.ceph_getcwd(mount.mount)
|
|
|
|
return C.GoString(c_dir)
|
2015-05-01 19:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mount *MountInfo) ChangeDir(path string) error {
|
2015-07-08 08:34:54 +00:00
|
|
|
c_path := C.CString(path)
|
|
|
|
defer C.free(unsafe.Pointer(c_path))
|
2015-05-01 19:35:40 +00:00
|
|
|
|
2015-07-08 08:34:54 +00:00
|
|
|
ret := C.ceph_chdir(mount.mount, c_path)
|
|
|
|
if ret == 0 {
|
|
|
|
return nil
|
|
|
|
} else {
|
|
|
|
return CephError(ret)
|
|
|
|
}
|
2015-05-01 19:35:40 +00:00
|
|
|
}
|
2015-05-01 19:54:38 +00:00
|
|
|
|
|
|
|
func (mount *MountInfo) MakeDir(path string, mode uint32) error {
|
2015-07-08 08:34:54 +00:00
|
|
|
c_path := C.CString(path)
|
|
|
|
defer C.free(unsafe.Pointer(c_path))
|
2015-05-01 19:54:38 +00:00
|
|
|
|
2015-07-08 08:34:54 +00:00
|
|
|
ret := C.ceph_mkdir(mount.mount, c_path, C.mode_t(mode))
|
|
|
|
if ret == 0 {
|
|
|
|
return nil
|
|
|
|
} else {
|
|
|
|
return CephError(ret)
|
|
|
|
}
|
2015-05-01 19:54:38 +00:00
|
|
|
}
|