Main Page | Data Structures | File List | Data Fields | Globals

hdfs.h File Reference

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <errno.h>
#include <jni.h>

Go to the source code of this file.

Data Structures

struct  hdfsFile_internal
struct  hdfsFileInfo

Defines

#define O_RDONLY   1
#define O_WRONLY   2
#define EINTERNAL   255

Typedefs

typedef int32_t tSize
typedef time_t tTime
 size of data for read/write io ops
typedef int64_t tOffset
 time type in seconds
typedef uint16_t tPort
 offset within the file
typedef enum tObjectKind tObjectKind
 port
typedef void * hdfsFS
typedef hdfsFile_internalhdfsFile

Enumerations

enum  hdfsStreamType { UNINITIALIZED = 0, INPUT = 1, OUTPUT = 2 }

Functions

hdfsFS hdfsConnectAsUser (const char *host, tPort port, const char *user, const char *groups[], int groups_size)
hdfsFS hdfsConnect (const char *host, tPort port)
int hdfsDisconnect (hdfsFS fs)
hdfsFile hdfsOpenFile (hdfsFS fs, const char *path, int flags, int bufferSize, short replication, tSize blocksize)
int hdfsCloseFile (hdfsFS fs, hdfsFile file)
int hdfsExists (hdfsFS fs, const char *path)
int hdfsSeek (hdfsFS fs, hdfsFile file, tOffset desiredPos)
tOffset hdfsTell (hdfsFS fs, hdfsFile file)
tSize hdfsRead (hdfsFS fs, hdfsFile file, void *buffer, tSize length)
tSize hdfsPread (hdfsFS fs, hdfsFile file, tOffset position, void *buffer, tSize length)
tSize hdfsWrite (hdfsFS fs, hdfsFile file, const void *buffer, tSize length)
int hdfsFlush (hdfsFS fs, hdfsFile file)
int hdfsAvailable (hdfsFS fs, hdfsFile file)
int hdfsCopy (hdfsFS srcFS, const char *src, hdfsFS dstFS, const char *dst)
int hdfsMove (hdfsFS srcFS, const char *src, hdfsFS dstFS, const char *dst)
int hdfsDelete (hdfsFS fs, const char *path)
int hdfsRename (hdfsFS fs, const char *oldPath, const char *newPath)
char * hdfsGetWorkingDirectory (hdfsFS fs, char *buffer, size_t bufferSize)
int hdfsSetWorkingDirectory (hdfsFS fs, const char *path)
int hdfsCreateDirectory (hdfsFS fs, const char *path)
int hdfsSetReplication (hdfsFS fs, const char *path, int16_t replication)
hdfsFileInfohdfsListDirectory (hdfsFS fs, const char *path, int *numEntries)
hdfsFileInfohdfsGetPathInfo (hdfsFS fs, const char *path)
void hdfsFreeFileInfo (hdfsFileInfo *hdfsFileInfo, int numEntries)
char *** hdfsGetHosts (hdfsFS fs, const char *path, tOffset start, tOffset length)
void hdfsFreeHosts (char ***blockHosts)
tOffset hdfsGetDefaultBlockSize (hdfsFS fs)
tOffset hdfsGetCapacity (hdfsFS fs)
tOffset hdfsGetUsed (hdfsFS fs)
int hdfsChown (hdfsFS fs, const char *path, const char *owner, const char *group)
int hdfsChmod (hdfsFS fs, const char *path, short mode)
int hdfsUtime (hdfsFS fs, const char *path, tTime mtime, tTime atime)


Define Documentation

#define EINTERNAL   255
 

#define O_RDONLY   1
 

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

#define O_WRONLY   2
 


Typedef Documentation

typedef struct hdfsFile_internal* hdfsFile
 

typedef void* hdfsFS
 

The C reflection of org.apache.org.hadoop.FileSystem .

typedef enum tObjectKind tObjectKind
 

port

typedef int64_t tOffset
 

time type in seconds

typedef uint16_t tPort
 

offset within the file

typedef int32_t tSize
 

Some utility decls used in libhdfs.

typedef time_t tTime
 

size of data for read/write io ops


Enumeration Type Documentation

enum hdfsStreamType
 

The C equivalent of org.apache.org.hadoop.FSData(Input|Output)Stream .

Enumerator:
UNINITIALIZED 
INPUT 
OUTPUT 


Function Documentation

int hdfsAvailable hdfsFS  fs,
hdfsFile  file
 

hdfsAvailable - Number of bytes that can be read from this input stream without blocking.

Parameters:
fs The configured filesystem handle.
file The file handle.
Returns:
Returns available bytes; -1 on error.

int hdfsChmod hdfsFS  fs,
const char *  path,
short  mode
 

hdfsChmod

Parameters:
fs The configured filesystem handle.
path the path to the file or directory
mode the bitmask to set it to
Returns:
0 on success else -1

int hdfsChown hdfsFS  fs,
const char *  path,
const char *  owner,
const char *  group
 

hdfsChown

Parameters:
fs The configured filesystem handle.
path the path to the file or directory
owner this is a string in Hadoop land. Set to null or "" if only setting group
group this is a string in Hadoop land. Set to null or "" if only setting user
Returns:
0 on success else -1

int hdfsCloseFile hdfsFS  fs,
hdfsFile  file
 

hdfsCloseFile - Close an open file.

Parameters:
fs The configured filesystem handle.
file The file handle.
Returns:
Returns 0 on success, -1 on error.

hdfsFS hdfsConnect const char *  host,
tPort  port
 

hdfsConnect - Connect to a hdfs file system. Connect to the hdfs.

Parameters:
host A string containing either a host name, or an ip address of the namenode of a hdfs cluster. 'host' should be passed as NULL if you want to connect to local filesystem. 'host' should be passed as 'default' (and port as 0) to used the 'configured' filesystem (hadoop-site/hadoop-default.xml).
port The port on which the server is listening.
Returns:
Returns a handle to the filesystem or NULL on error.

hdfsFS hdfsConnectAsUser const char *  host,
tPort  port,
const char *  user,
const char *  groups[],
int  groups_size
 

hdfsConnectAsUser - Connect to a hdfs file system as a specific user Connect to the hdfs.

Parameters:
host A string containing either a host name, or an ip address of the namenode of a hdfs cluster. 'host' should be passed as NULL if you want to connect to local filesystem. 'host' should be passed as 'default' (and port as 0) to used the 'configured' filesystem (hadoop-site/hadoop-default.xml).
port The port on which the server is listening.
user the user name (this is hadoop domain user). Or NULL is equivelant to hhdfsConnect(host, port)
groups the groups (these are hadoop domain groups)
Returns:
Returns a handle to the filesystem or NULL on error.

int hdfsCopy hdfsFS  srcFS,
const char *  src,
hdfsFS  dstFS,
const char *  dst
 

hdfsCopy - Copy file from one filesystem to another.

Parameters:
srcFS The handle to source filesystem.
src The path of source file.
dstFS The handle to destination filesystem.
dst The path of destination file.
Returns:
Returns 0 on success, -1 on error.

int hdfsCreateDirectory hdfsFS  fs,
const char *  path
 

hdfsCreateDirectory - Make the given file and all non-existent parents into directories.

Parameters:
fs The configured filesystem handle.
path The path of the directory.
Returns:
Returns 0 on success, -1 on error.

int hdfsDelete hdfsFS  fs,
const char *  path
 

hdfsDelete - Delete file.

Parameters:
fs The configured filesystem handle.
path The path of the file.
Returns:
Returns 0 on success, -1 on error.

int hdfsDisconnect hdfsFS  fs  ) 
 

hdfsDisconnect - Disconnect from the hdfs file system. Disconnect from hdfs.

Parameters:
fs The configured filesystem handle.
Returns:
Returns 0 on success, -1 on error.

int hdfsExists hdfsFS  fs,
const char *  path
 

hdfsExists - Checks if a given path exsits on the filesystem

Parameters:
fs The configured filesystem handle.
path The path to look for
Returns:
Returns 0 on success, -1 on error.

int hdfsFlush hdfsFS  fs,
hdfsFile  file
 

hdfsWrite - Flush the data.

Parameters:
fs The configured filesystem handle.
file The file handle.
Returns:
Returns 0 on success, -1 on error.

void hdfsFreeFileInfo hdfsFileInfo hdfsFileInfo,
int  numEntries
 

hdfsFreeFileInfo - Free up the hdfsFileInfo array (including fields)

Parameters:
hdfsFileInfo The array of dynamically-allocated hdfsFileInfo objects.
numEntries The size of the array.

void hdfsFreeHosts char ***  blockHosts  ) 
 

hdfsFreeHosts - Free up the structure returned by hdfsGetHosts

Parameters:
hdfsFileInfo The array of dynamically-allocated hdfsFileInfo objects.
numEntries The size of the array.

tOffset hdfsGetCapacity hdfsFS  fs  ) 
 

hdfsGetCapacity - Return the raw capacity of the filesystem.

Parameters:
fs The configured filesystem handle.
Returns:
Returns the raw-capacity; -1 on error.

tOffset hdfsGetDefaultBlockSize hdfsFS  fs  ) 
 

hdfsGetDefaultBlockSize - Get the optimum blocksize.

Parameters:
fs The configured filesystem handle.
Returns:
Returns the blocksize; -1 on error.

char*** hdfsGetHosts hdfsFS  fs,
const char *  path,
tOffset  start,
tOffset  length
 

hdfsGetHosts - Get hostnames where a particular block (determined by pos & blocksize) of a file is stored. The last element in the array is NULL. Due to replication, a single block could be present on multiple hosts.

Parameters:
fs The configured filesystem handle.
path The path of the file.
start The start of the block.
length The length of the block.
Returns:
Returns a dynamically-allocated 2-d array of blocks-hosts; NULL on error.

hdfsFileInfo* hdfsGetPathInfo hdfsFS  fs,
const char *  path
 

hdfsGetPathInfo - Get information about a path as a (dynamically allocated) single hdfsFileInfo struct. hdfsFreeFileInfo should be called when the pointer is no longer needed.

Parameters:
fs The configured filesystem handle.
path The path of the file.
Returns:
Returns a dynamically-allocated hdfsFileInfo object; NULL on error.

tOffset hdfsGetUsed hdfsFS  fs  ) 
 

hdfsGetUsed - Return the total raw size of all files in the filesystem.

Parameters:
fs The configured filesystem handle.
Returns:
Returns the total-size; -1 on error.

char* hdfsGetWorkingDirectory hdfsFS  fs,
char *  buffer,
size_t  bufferSize
 

hdfsGetWorkingDirectory - Get the current working directory for the given filesystem.

Parameters:
fs The configured filesystem handle.
buffer The user-buffer to copy path of cwd into.
bufferSize The length of user-buffer.
Returns:
Returns buffer, NULL on error.

hdfsFileInfo* hdfsListDirectory hdfsFS  fs,
const char *  path,
int *  numEntries
 

hdfsListDirectory - Get list of files/directories for a given directory-path. hdfsFreeFileInfo should be called to deallocate memory.

Parameters:
fs The configured filesystem handle.
path The path of the directory.
numEntries Set to the number of files/directories in path.
Returns:
Returns a dynamically-allocated array of hdfsFileInfo objects; NULL on error.

int hdfsMove hdfsFS  srcFS,
const char *  src,
hdfsFS  dstFS,
const char *  dst
 

hdfsMove - Move file from one filesystem to another.

Parameters:
srcFS The handle to source filesystem.
src The path of source file.
dstFS The handle to destination filesystem.
dst The path of destination file.
Returns:
Returns 0 on success, -1 on error.

hdfsFile hdfsOpenFile hdfsFS  fs,
const char *  path,
int  flags,
int  bufferSize,
short  replication,
tSize  blocksize
 

hdfsOpenFile - Open a hdfs file in given mode.

Parameters:
fs The configured filesystem handle.
path The full path to the file.
flags Either O_RDONLY or O_WRONLY, for read-only or write-only.
bufferSize Size of buffer for read/write - pass 0 if you want to use the default configured values.
replication Block replication - pass 0 if you want to use the default configured values.
blocksize Size of block - pass 0 if you want to use the default configured values.
Returns:
Returns the handle to the open file or NULL on error.

tSize hdfsPread hdfsFS  fs,
hdfsFile  file,
tOffset  position,
void *  buffer,
tSize  length
 

hdfsPread - Positional read of data from an open file.

Parameters:
fs The configured filesystem handle.
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:
Returns the number of bytes actually read, possibly less than than length;-1 on error.

tSize hdfsRead hdfsFS  fs,
hdfsFile  file,
void *  buffer,
tSize  length
 

hdfsRead - Read data from an open file.

Parameters:
fs The configured filesystem handle.
file The file handle.
buffer The buffer to copy read bytes into.
length The length of the buffer.
Returns:
Returns the number of bytes actually read, possibly less than than length;-1 on error.

int hdfsRename hdfsFS  fs,
const char *  oldPath,
const char *  newPath
 

hdfsRename - Rename file.

Parameters:
fs The configured filesystem handle.
oldPath The path of the source file.
newPath The path of the destination file.
Returns:
Returns 0 on success, -1 on error.

int hdfsSeek hdfsFS  fs,
hdfsFile  file,
tOffset  desiredPos
 

hdfsSeek - Seek to given offset in file. This works only for files opened in read-only mode.

Parameters:
fs The configured filesystem handle.
file The file handle.
desiredPos Offset into the file to seek into.
Returns:
Returns 0 on success, -1 on error.

int hdfsSetReplication hdfsFS  fs,
const char *  path,
int16_t  replication
 

hdfsSetReplication - Set the replication of the specified file to the supplied value

Parameters:
fs The configured filesystem handle.
path The path of the file.
Returns:
Returns 0 on success, -1 on error.

int hdfsSetWorkingDirectory hdfsFS  fs,
const char *  path
 

hdfsSetWorkingDirectory - Set the working directory. All relative paths will be resolved relative to it.

Parameters:
fs The configured filesystem handle.
path The path of the new 'cwd'.
Returns:
Returns 0 on success, -1 on error.

tOffset hdfsTell hdfsFS  fs,
hdfsFile  file
 

hdfsTell - Get the current offset in the file, in bytes.

Parameters:
fs The configured filesystem handle.
file The file handle.
Returns:
Current offset, -1 on error.

int hdfsUtime hdfsFS  fs,
const char *  path,
tTime  mtime,
tTime  atime
 

hdfsUtime

Parameters:
fs The configured filesystem handle.
path the path to the file or directory
mtime new modification time or 0 for only set access time in seconds
atime new access time or 0 for only set modification time in seconds
Returns:
0 on success else -1

tSize hdfsWrite hdfsFS  fs,
hdfsFile  file,
const void *  buffer,
tSize  length
 

hdfsWrite - Write data into an open file.

Parameters:
fs The configured filesystem handle.
file The file handle.
buffer The data.
length The no. of bytes to write.
Returns:
Returns the number of bytes written, -1 on error.


libhdfs - Hadoop