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

hdfs.h

Go to the documentation of this file.
00001 
00019 #ifndef LIBHDFS_HDFS_H
00020 #define LIBHDFS_HDFS_H
00021 
00022 #include <sys/types.h>
00023 #include <sys/stat.h>
00024 
00025 #include <fcntl.h>
00026 #include <stdio.h>
00027 #include <stdint.h>
00028 #include <string.h>
00029 #include <stdlib.h>
00030 #include <time.h>
00031 #include <errno.h>
00032 
00033 #include <jni.h>
00034 
00035 #ifndef O_RDONLY
00036 #define O_RDONLY 1
00037 #endif
00038 
00039 #ifndef O_WRONLY 
00040 #define O_WRONLY 2
00041 #endif
00042 
00043 #ifndef EINTERNAL
00044 #define EINTERNAL 255 
00045 #endif
00046 
00047 
00049 #ifdef __cplusplus
00050 extern  "C" {
00051 #endif
00052 
00057     typedef int32_t   tSize; 
00058     typedef time_t    tTime; 
00059     typedef int64_t   tOffset;
00060     typedef uint16_t  tPort; 
00061     typedef enum tObjectKind {
00062         kObjectKindFile = 'F',
00063         kObjectKindDirectory = 'D',
00064     } tObjectKind;
00065 
00066 
00070     typedef void* hdfsFS;
00071 
00072     
00076     enum hdfsStreamType
00077     {
00078         UNINITIALIZED = 0,
00079         INPUT = 1,
00080         OUTPUT = 2,
00081     };
00082 
00083     
00087     struct hdfsFile_internal {
00088         void* file;
00089         enum hdfsStreamType type;
00090     };
00091     typedef struct hdfsFile_internal* hdfsFile;
00092       
00093 
00107      hdfsFS hdfsConnectAsUser(const char* host, tPort port, const char *user , const char *groups[], int groups_size );
00108 
00109 
00121      hdfsFS hdfsConnect(const char* host, tPort port);
00122 
00123 
00130     int hdfsDisconnect(hdfsFS fs);
00131         
00132 
00146     hdfsFile hdfsOpenFile(hdfsFS fs, const char* path, int flags,
00147                           int bufferSize, short replication, tSize blocksize);
00148 
00149 
00156     int hdfsCloseFile(hdfsFS fs, hdfsFile file);
00157 
00158 
00165     int hdfsExists(hdfsFS fs, const char *path);
00166 
00167 
00176     int hdfsSeek(hdfsFS fs, hdfsFile file, tOffset desiredPos); 
00177 
00178 
00185     tOffset hdfsTell(hdfsFS fs, hdfsFile file);
00186 
00187 
00197     tSize hdfsRead(hdfsFS fs, hdfsFile file, void* buffer, tSize length);
00198 
00199 
00210     tSize hdfsPread(hdfsFS fs, hdfsFile file, tOffset position,
00211                     void* buffer, tSize length);
00212 
00213 
00222     tSize hdfsWrite(hdfsFS fs, hdfsFile file, const void* buffer,
00223                     tSize length);
00224 
00225 
00232     int hdfsFlush(hdfsFS fs, hdfsFile file);
00233 
00234 
00242     int hdfsAvailable(hdfsFS fs, hdfsFile file);
00243 
00244 
00253     int hdfsCopy(hdfsFS srcFS, const char* src, hdfsFS dstFS, const char* dst);
00254 
00255 
00264     int hdfsMove(hdfsFS srcFS, const char* src, hdfsFS dstFS, const char* dst);
00265 
00266 
00273     int hdfsDelete(hdfsFS fs, const char* path);
00274 
00275 
00283     int hdfsRename(hdfsFS fs, const char* oldPath, const char* newPath);
00284 
00285 
00294     char* hdfsGetWorkingDirectory(hdfsFS fs, char *buffer, size_t bufferSize);
00295 
00296 
00304     int hdfsSetWorkingDirectory(hdfsFS fs, const char* path);
00305 
00306 
00314     int hdfsCreateDirectory(hdfsFS fs, const char* path);
00315 
00316 
00324     int hdfsSetReplication(hdfsFS fs, const char* path, int16_t replication);
00325 
00326 
00330     typedef struct  {
00331         tObjectKind mKind;   /* file or directory */
00332         char *mName;         /* the name of the file */
00333         tTime mLastMod;      /* the last modification time for the file in seconds */
00334         tOffset mSize;       /* the size of the file in bytes */
00335         short mReplication;    /* the count of replicas */
00336         tOffset mBlockSize;  /* the block size for the file */
00337         char *mOwner;        /* the owner of the file */
00338         char *mGroup;        /* the group associated with the file */
00339         short mPermissions;  /* the permissions associated with the file */
00340         tTime mLastAccess;    /* the last access time for the file in seconds */
00341     } hdfsFileInfo;
00342 
00343 
00353     hdfsFileInfo *hdfsListDirectory(hdfsFS fs, const char* path,
00354                                     int *numEntries);
00355 
00356 
00366     hdfsFileInfo *hdfsGetPathInfo(hdfsFS fs, const char* path);
00367 
00368 
00375     void hdfsFreeFileInfo(hdfsFileInfo *hdfsFileInfo, int numEntries);
00376 
00377 
00390     char*** hdfsGetHosts(hdfsFS fs, const char* path, 
00391             tOffset start, tOffset length);
00392 
00393 
00400     void hdfsFreeHosts(char ***blockHosts);
00401 
00402 
00408     tOffset hdfsGetDefaultBlockSize(hdfsFS fs);
00409 
00410 
00416     tOffset hdfsGetCapacity(hdfsFS fs);
00417 
00418 
00424     tOffset hdfsGetUsed(hdfsFS fs);
00425 
00434     int hdfsChown(hdfsFS fs, const char* path, const char *owner, const char *group);
00435 
00443       int hdfsChmod(hdfsFS fs, const char* path, short mode);
00444 
00453     int hdfsUtime(hdfsFS fs, const char* path, tTime mtime, tTime atime);
00454     
00455 #ifdef __cplusplus
00456 }
00457 #endif
00458 
00459 #endif /*LIBHDFS_HDFS_H*/
00460 


libhdfs - Hadoop