Example #1
0
// 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
}
Example #2
0
// 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))

	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
}