Beispiel #1
0
//Get the total raw size of all files in the filesystem.
//Returns the total-size; check on error.
func (fs *Fs) GetUsed() (int64, error) {
	ret, err := C.hdfsGetUsed(fs.cptr)
	if err != nil && ret == C.tOffset(-1) {
		return -1, err
	}
	return int64(ret), nil
}
Beispiel #2
0
//Get the optimum blocksize.
//Returns the blocksize; -1 on error.
func (fs *Fs) GetDefaultBlockSize() (int64, error) {
	ret, err := C.hdfsGetDefaultBlockSize(fs.cptr)
	if err != nil && ret == C.tOffset(-1) {
		return -1, err
	}
	return int64(ret), nil
}
Beispiel #3
0
//Get the current offset in the file, in bytes.
//file: The file handle.
//Returns current offset, or error.
func (fs *Fs) Tell(file *File) (int64, error) {
	ret, err := C.hdfsTell(fs.cptr, file.cptr)
	if err != nil && ret == C.tOffset(-1) {
		return -1, err
	}
	return int64(ret), nil
}
Beispiel #4
0
//Positional read of data from an open file.
//file: The file handle.
//position: Position from which to read.
//buffer: The buffer to copy read bytes into.
//length: The length of the buffer.
//Returns the number of bytes actually read, possibly less than length; or error.
func (fs *Fs) Pread(file *File, position int64, buffer []byte, length int) (uint32, error) {
	file.RLock()
	defer file.RUnlock()
	ret, err := C.hdfsPread(fs.cptr, file.cptr, C.tOffset(position), (unsafe.Pointer(&buffer[0])), C.tSize(length))
	if err != nil && ret == C.tSize(-1) {
		return 0, err
	}
	return uint32(ret), nil
}
Beispiel #5
0
//Seek to given offset in file. This works only for files opened in read-only mode.
//file: The file handle.
//pos: Offset into the file to seek into.
//Returns nil on success, or error.
func (fs *Fs) Seek(file *File, pos int64) error {
	file.Lock()
	defer file.Unlock()
	ret, err := C.hdfsSeek(fs.cptr, file.cptr, C.tOffset(pos))
	if err != nil && ret == C.int(-1) {
		return err
	}
	return nil
}
Beispiel #6
0
//Get hostnames where a particular block (determined by pos & blocksize) of a file is stored.
//path: The path of the file.
//start: The start of the block.
//length: The length of the block.
//Returns a 2-D slice of blocks-hosts, or nil on error.
func (fs *Fs) GetHosts(path string, start, length int64) ([][]string, error) {
	p := C.CString(path)
	defer C.free(unsafe.Pointer(p))
	ret, err := C.hdfsGetHosts(fs.cptr, p, C.tOffset(start), C.tOffset(length))
	if ret == (***C.char)(unsafe.Pointer(uintptr(0))) {
		return nil, err
	}
	defer C.hdfsFreeHosts(ret)
	i := int(C.getlen(ret))
	j := int(C.getl(ret))
	s := make([][]string, i)
	for k, _ := range s {
		s[k] = make([]string, j)
		for p, _ := range s[k] {
			s[k][p] = C.GoString(C.getstring(ret, C.int(k), C.int(p)))
		}
	}
	return s, nil
}