github.com/johnnyeven/libtools@v0.0.0-20191126065708-61829c1adf46/third_party/hadoop/hdfs.h (about)

     1  /**
     2   * Licensed to the Apache Software Foundation (ASF) under one
     3   * or more contributor license agreements.  See the NOTICE file
     4   * distributed with this work for additional information
     5   * regarding copyright ownership.  The ASF licenses this file
     6   * to you under the Apache License, Version 2.0 (the
     7   * "License"); you may not use this file except in compliance
     8   * with the License.  You may obtain a copy of the License at
     9   *
    10   *     http://www.apache.org/licenses/LICENSE-2.0
    11   *
    12   * Unless required by applicable law or agreed to in writing, software
    13   * distributed under the License is distributed on an "AS IS" BASIS,
    14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15   * See the License for the specific language governing permissions and
    16   * limitations under the License.
    17   */
    18  
    19  #ifndef TENSORFLOW_THIRD_PARTY_HADOOP_HDFS_H_
    20  #define TENSORFLOW_THIRD_PARTY_HADOOP_HDFS_H_
    21  
    22  #include <errno.h>  /* for EINTERNAL, etc. */
    23  #include <fcntl.h>  /* for O_RDONLY, O_WRONLY */
    24  #include <stdint.h> /* for uint64_t, etc. */
    25  #include <time.h>   /* for time_t */
    26  
    27  /*
    28   * Support export of DLL symbols during libhdfs build, and import of DLL symbols
    29   * during client application build.  A client application may optionally define
    30   * symbol LIBHDFS_DLL_IMPORT in its build.  This is not strictly required, but
    31   * the compiler can produce more efficient code with it.
    32   */
    33  #ifdef WIN32
    34  #ifdef LIBHDFS_DLL_EXPORT
    35  #define LIBHDFS_EXTERNAL __declspec(dllexport)
    36  #elif LIBHDFS_DLL_IMPORT
    37  #define LIBHDFS_EXTERNAL __declspec(dllimport)
    38  #else
    39  #define LIBHDFS_EXTERNAL
    40  #endif
    41  #else
    42  #ifdef LIBHDFS_DLL_EXPORT
    43  #define LIBHDFS_EXTERNAL __attribute__((visibility("default")))
    44  #elif LIBHDFS_DLL_IMPORT
    45  #define LIBHDFS_EXTERNAL __attribute__((visibility("default")))
    46  #else
    47  #define LIBHDFS_EXTERNAL
    48  #endif
    49  #endif
    50  
    51  #ifndef O_RDONLY
    52  #define O_RDONLY 1
    53  #endif
    54  
    55  #ifndef O_WRONLY
    56  #define O_WRONLY 2
    57  #endif
    58  
    59  #ifndef EINTERNAL
    60  #define EINTERNAL 255
    61  #endif
    62  
    63  #define ELASTIC_BYTE_BUFFER_POOL_CLASS \
    64    "org/apache/hadoop/io/ElasticByteBufferPool"
    65  
    66  /** All APIs set errno to meaningful values */
    67  
    68  #ifdef __cplusplus
    69  extern "C" {
    70  #endif
    71  /**
    72   * Some utility decls used in libhdfs.
    73   */
    74  struct hdfsBuilder;
    75  typedef int32_t tSize;    /// size of data for read/write io ops
    76  typedef time_t tTime;     /// time type in seconds
    77  typedef int64_t tOffset;  /// offset within the file
    78  typedef uint16_t tPort;   /// port
    79  typedef enum tObjectKind {
    80    kObjectKindFile = 'F',
    81    kObjectKindDirectory = 'D',
    82  } tObjectKind;
    83  
    84  /**
    85   * The C reflection of org.apache.org.hadoop.FileSystem .
    86   */
    87  struct hdfs_internal;
    88  typedef struct hdfs_internal *hdfsFS;
    89  
    90  struct hdfsFile_internal;
    91  typedef struct hdfsFile_internal *hdfsFile;
    92  
    93  struct hadoopRzOptions;
    94  
    95  struct hadoopRzBuffer;
    96  
    97  /**
    98   * Determine if a file is open for read.
    99   *
   100   * @param file     The HDFS file
   101   * @return         1 if the file is open for read; 0 otherwise
   102   */
   103  LIBHDFS_EXTERNAL
   104  int hdfsFileIsOpenForRead(hdfsFile file);
   105  
   106  /**
   107   * Determine if a file is open for write.
   108   *
   109   * @param file     The HDFS file
   110   * @return         1 if the file is open for write; 0 otherwise
   111   */
   112  LIBHDFS_EXTERNAL
   113  int hdfsFileIsOpenForWrite(hdfsFile file);
   114  
   115  struct hdfsReadStatistics {
   116    uint64_t totalBytesRead;
   117    uint64_t totalLocalBytesRead;
   118    uint64_t totalShortCircuitBytesRead;
   119    uint64_t totalZeroCopyBytesRead;
   120  };
   121  
   122  /**
   123   * Get read statistics about a file.  This is only applicable to files
   124   * opened for reading.
   125   *
   126   * @param file     The HDFS file
   127   * @param stats    (out parameter) on a successful return, the read
   128   *                 statistics.  Unchanged otherwise.  You must free the
   129   *                 returned statistics with hdfsFileFreeReadStatistics.
   130   * @return         0 if the statistics were successfully returned,
   131   *                 -1 otherwise.  On a failure, please check errno against
   132   *                 ENOTSUP.  webhdfs, LocalFilesystem, and so forth may
   133   *                 not support read statistics.
   134   */
   135  LIBHDFS_EXTERNAL
   136  int hdfsFileGetReadStatistics(hdfsFile file, struct hdfsReadStatistics **stats);
   137  
   138  /**
   139   * @param stats    HDFS read statistics for a file.
   140   *
   141   * @return the number of remote bytes read.
   142   */
   143  LIBHDFS_EXTERNAL
   144  int64_t hdfsReadStatisticsGetRemoteBytesRead(
   145      const struct hdfsReadStatistics *stats);
   146  
   147  /**
   148   * Clear the read statistics for a file.
   149   *
   150   * @param file      The file to clear the read statistics of.
   151   *
   152   * @return          0 on success; the error code otherwise.
   153   *                  EINVAL: the file is not open for reading.
   154   *                  ENOTSUP: the file does not support clearing the read
   155   *                  statistics.
   156   *                  Errno will also be set to this code on failure.
   157   */
   158  LIBHDFS_EXTERNAL
   159  int hdfsFileClearReadStatistics(hdfsFile file);
   160  
   161  /**
   162   * Free some HDFS read statistics.
   163   *
   164   * @param stats    The HDFS read statistics to free.
   165   */
   166  LIBHDFS_EXTERNAL
   167  void hdfsFileFreeReadStatistics(struct hdfsReadStatistics *stats);
   168  
   169  /**
   170   * hdfsConnectAsUser - Connect to a hdfs file system as a specific user
   171   * Connect to the hdfs.
   172   * @param nn   The NameNode.  See hdfsBuilderSetNameNode for details.
   173   * @param port The port on which the server is listening.
   174   * @param user the user name (this is hadoop domain user). Or NULL is equivalent
   175   * to hhdfsConnect(host, port)
   176   * @return Returns a handle to the filesystem or NULL on error.
   177   * @deprecated Use hdfsBuilderConnect instead.
   178   */
   179  LIBHDFS_EXTERNAL
   180  hdfsFS hdfsConnectAsUser(const char *nn, tPort port, const char *user);
   181  
   182  /**
   183   * hdfsConnect - Connect to a hdfs file system.
   184   * Connect to the hdfs.
   185   * @param nn   The NameNode.  See hdfsBuilderSetNameNode for details.
   186   * @param port The port on which the server is listening.
   187   * @return Returns a handle to the filesystem or NULL on error.
   188   * @deprecated Use hdfsBuilderConnect instead.
   189   */
   190  LIBHDFS_EXTERNAL
   191  hdfsFS hdfsConnect(const char *nn, tPort port);
   192  
   193  /**
   194   * hdfsConnect - Connect to an hdfs file system.
   195   *
   196   * Forces a new instance to be created
   197   *
   198   * @param nn     The NameNode.  See hdfsBuilderSetNameNode for details.
   199   * @param port   The port on which the server is listening.
   200   * @param user   The user name to use when connecting
   201   * @return       Returns a handle to the filesystem or NULL on error.
   202   * @deprecated   Use hdfsBuilderConnect instead.
   203   */
   204  LIBHDFS_EXTERNAL
   205  hdfsFS hdfsConnectAsUserNewInstance(const char *nn, tPort port,
   206                                      const char *user);
   207  
   208  /**
   209   * hdfsConnect - Connect to an hdfs file system.
   210   *
   211   * Forces a new instance to be created
   212   *
   213   * @param nn     The NameNode.  See hdfsBuilderSetNameNode for details.
   214   * @param port   The port on which the server is listening.
   215   * @return       Returns a handle to the filesystem or NULL on error.
   216   * @deprecated   Use hdfsBuilderConnect instead.
   217   */
   218  LIBHDFS_EXTERNAL
   219  hdfsFS hdfsConnectNewInstance(const char *nn, tPort port);
   220  
   221  /**
   222   * Connect to HDFS using the parameters defined by the builder.
   223   *
   224   * The HDFS builder will be freed, whether or not the connection was
   225   * successful.
   226   *
   227   * Every successful call to hdfsBuilderConnect should be matched with a call
   228   * to hdfsDisconnect, when the hdfsFS is no longer needed.
   229   *
   230   * @param bld    The HDFS builder
   231   * @return       Returns a handle to the filesystem, or NULL on error.
   232   */
   233  LIBHDFS_EXTERNAL
   234  hdfsFS hdfsBuilderConnect(struct hdfsBuilder *bld);
   235  
   236  /**
   237   * Create an HDFS builder.
   238   *
   239   * @return The HDFS builder, or NULL on error.
   240   */
   241  LIBHDFS_EXTERNAL
   242  struct hdfsBuilder *hdfsNewBuilder(void);
   243  
   244  /**
   245   * Force the builder to always create a new instance of the FileSystem,
   246   * rather than possibly finding one in the cache.
   247   *
   248   * @param bld The HDFS builder
   249   */
   250  LIBHDFS_EXTERNAL
   251  void hdfsBuilderSetForceNewInstance(struct hdfsBuilder *bld);
   252  
   253  /**
   254   * Set the HDFS NameNode to connect to.
   255   *
   256   * @param bld  The HDFS builder
   257   * @param nn   The NameNode to use.
   258   *
   259   *             If the string given is 'default', the default NameNode
   260   *             configuration will be used (from the XML configuration files)
   261   *
   262   *             If NULL is given, a LocalFileSystem will be created.
   263   *
   264   *             If the string starts with a protocol type such as file:// or
   265   *             hdfs://, this protocol type will be used.  If not, the
   266   *             hdfs:// protocol type will be used.
   267   *
   268   *             You may specify a NameNode port in the usual way by
   269   *             passing a string of the format hdfs://<hostname>:<port>.
   270   *             Alternately, you may set the port with
   271   *             hdfsBuilderSetNameNodePort.  However, you must not pass the
   272   *             port in two different ways.
   273   */
   274  LIBHDFS_EXTERNAL
   275  void hdfsBuilderSetNameNode(struct hdfsBuilder *bld, const char *nn);
   276  
   277  /**
   278   * Set the port of the HDFS NameNode to connect to.
   279   *
   280   * @param bld The HDFS builder
   281   * @param port The port.
   282   */
   283  LIBHDFS_EXTERNAL
   284  void hdfsBuilderSetNameNodePort(struct hdfsBuilder *bld, tPort port);
   285  
   286  /**
   287   * Set the username to use when connecting to the HDFS cluster.
   288   *
   289   * @param bld The HDFS builder
   290   * @param userName The user name.  The string will be shallow-copied.
   291   */
   292  LIBHDFS_EXTERNAL
   293  void hdfsBuilderSetUserName(struct hdfsBuilder *bld, const char *userName);
   294  
   295  /**
   296   * Set the path to the Kerberos ticket cache to use when connecting to
   297   * the HDFS cluster.
   298   *
   299   * @param bld The HDFS builder
   300   * @param kerbTicketCachePath The Kerberos ticket cache path.  The string
   301   *                            will be shallow-copied.
   302   */
   303  LIBHDFS_EXTERNAL
   304  void hdfsBuilderSetKerbTicketCachePath(struct hdfsBuilder *bld,
   305                                         const char *kerbTicketCachePath);
   306  
   307  /**
   308   * Free an HDFS builder.
   309   *
   310   * It is normally not necessary to call this function since
   311   * hdfsBuilderConnect frees the builder.
   312   *
   313   * @param bld The HDFS builder
   314   */
   315  LIBHDFS_EXTERNAL
   316  void hdfsFreeBuilder(struct hdfsBuilder *bld);
   317  
   318  /**
   319   * Set a configuration string for an HdfsBuilder.
   320   *
   321   * @param key      The key to set.
   322   * @param val      The value, or NULL to set no value.
   323   *                 This will be shallow-copied.  You are responsible for
   324   *                 ensuring that it remains valid until the builder is
   325   *                 freed.
   326   *
   327   * @return         0 on success; nonzero error code otherwise.
   328   */
   329  LIBHDFS_EXTERNAL
   330  int hdfsBuilderConfSetStr(struct hdfsBuilder *bld, const char *key,
   331                            const char *val);
   332  
   333  /**
   334   * Get a configuration string.
   335   *
   336   * @param key      The key to find
   337   * @param val      (out param) The value.  This will be set to NULL if the
   338   *                 key isn't found.  You must free this string with
   339   *                 hdfsConfStrFree.
   340   *
   341   * @return         0 on success; nonzero error code otherwise.
   342   *                 Failure to find the key is not an error.
   343   */
   344  LIBHDFS_EXTERNAL
   345  int hdfsConfGetStr(const char *key, char **val);
   346  
   347  /**
   348   * Get a configuration integer.
   349   *
   350   * @param key      The key to find
   351   * @param val      (out param) The value.  This will NOT be changed if the
   352   *                 key isn't found.
   353   *
   354   * @return         0 on success; nonzero error code otherwise.
   355   *                 Failure to find the key is not an error.
   356   */
   357  LIBHDFS_EXTERNAL
   358  int hdfsConfGetInt(const char *key, int32_t *val);
   359  
   360  /**
   361   * Free a configuration string found with hdfsConfGetStr.
   362   *
   363   * @param val      A configuration string obtained from hdfsConfGetStr
   364   */
   365  LIBHDFS_EXTERNAL
   366  void hdfsConfStrFree(char *val);
   367  
   368  /**
   369   * hdfsDisconnect - Disconnect from the hdfs file system.
   370   * Disconnect from hdfs.
   371   * @param fs The configured filesystem handle.
   372   * @return Returns 0 on success, -1 on error.
   373   *         Even if there is an error, the resources associated with the
   374   *         hdfsFS will be freed.
   375   */
   376  LIBHDFS_EXTERNAL
   377  int hdfsDisconnect(hdfsFS fs);
   378  
   379  /**
   380   * hdfsOpenFile - Open a hdfs file in given mode.
   381   * @param fs The configured filesystem handle.
   382   * @param path The full path to the file.
   383   * @param flags - an | of bits/fcntl.h file flags - supported flags are
   384   * O_RDONLY, O_WRONLY (meaning create or overwrite i.e., implies O_TRUNCAT),
   385   * O_WRONLY|O_APPEND. Other flags are generally ignored other than (O_RDWR ||
   386   * (O_EXCL & O_CREAT)) which return NULL and set errno equal ENOTSUP.
   387   * @param bufferSize Size of buffer for read/write - pass 0 if you want
   388   * to use the default configured values.
   389   * @param replication Block replication - pass 0 if you want to use
   390   * the default configured values.
   391   * @param blocksize Size of block - pass 0 if you want to use the
   392   * default configured values.
   393   * @return Returns the handle to the open file or NULL on error.
   394   */
   395  LIBHDFS_EXTERNAL
   396  hdfsFile hdfsOpenFile(hdfsFS fs, const char *path, int flags, int bufferSize,
   397                        short replication, tSize blocksize);
   398  
   399  /**
   400   * hdfsTruncateFile - Truncate a hdfs file to given length.
   401   * @param fs The configured filesystem handle.
   402   * @param path The full path to the file.
   403   * @param newlength The size the file is to be truncated to
   404   * @return 1 if the file has been truncated to the desired newlength
   405   *         and is immediately available to be reused for write operations
   406   *         such as append.
   407   *         0 if a background process of adjusting the length of the last
   408   *         block has been started, and clients should wait for it to
   409   *         complete before proceeding with further file updates.
   410   *         -1 on error.
   411   */
   412  int hdfsTruncateFile(hdfsFS fs, const char *path, tOffset newlength);
   413  
   414  /**
   415   * hdfsUnbufferFile - Reduce the buffering done on a file.
   416   *
   417   * @param file  The file to unbuffer.
   418   * @return      0 on success
   419   *              ENOTSUP if the file does not support unbuffering
   420   *              Errno will also be set to this value.
   421   */
   422  LIBHDFS_EXTERNAL
   423  int hdfsUnbufferFile(hdfsFile file);
   424  
   425  /**
   426   * hdfsCloseFile - Close an open file.
   427   * @param fs The configured filesystem handle.
   428   * @param file The file handle.
   429   * @return Returns 0 on success, -1 on error.
   430   *         On error, errno will be set appropriately.
   431   *         If the hdfs file was valid, the memory associated with it will
   432   *         be freed at the end of this call, even if there was an I/O
   433   *         error.
   434   */
   435  LIBHDFS_EXTERNAL
   436  int hdfsCloseFile(hdfsFS fs, hdfsFile file);
   437  
   438  /**
   439   * hdfsExists - Checks if a given path exsits on the filesystem
   440   * @param fs The configured filesystem handle.
   441   * @param path The path to look for
   442   * @return Returns 0 on success, -1 on error.
   443   */
   444  LIBHDFS_EXTERNAL
   445  int hdfsExists(hdfsFS fs, const char *path);
   446  
   447  /**
   448   * hdfsSeek - Seek to given offset in file.
   449   * This works only for files opened in read-only mode.
   450   * @param fs The configured filesystem handle.
   451   * @param file The file handle.
   452   * @param desiredPos Offset into the file to seek into.
   453   * @return Returns 0 on success, -1 on error.
   454   */
   455  LIBHDFS_EXTERNAL
   456  int hdfsSeek(hdfsFS fs, hdfsFile file, tOffset desiredPos);
   457  
   458  /**
   459   * hdfsTell - Get the current offset in the file, in bytes.
   460   * @param fs The configured filesystem handle.
   461   * @param file The file handle.
   462   * @return Current offset, -1 on error.
   463   */
   464  LIBHDFS_EXTERNAL
   465  tOffset hdfsTell(hdfsFS fs, hdfsFile file);
   466  
   467  /**
   468   * hdfsRead - Read data from an open file.
   469   * @param fs The configured filesystem handle.
   470   * @param file The file handle.
   471   * @param buffer The buffer to copy read bytes into.
   472   * @param length The length of the buffer.
   473   * @return      On success, a positive number indicating how many bytes
   474   *              were read.
   475   *              On end-of-file, 0.
   476   *              On error, -1.  Errno will be set to the error code.
   477   *              Just like the POSIX read function, hdfsRead will return -1
   478   *              and set errno to EINTR if data is temporarily unavailable,
   479   *              but we are not yet at the end of the file.
   480   */
   481  LIBHDFS_EXTERNAL
   482  tSize hdfsRead(hdfsFS fs, hdfsFile file, void *buffer, tSize length);
   483  
   484  /**
   485   * hdfsPread - Positional read of data from an open file.
   486   * @param fs The configured filesystem handle.
   487   * @param file The file handle.
   488   * @param position Position from which to read
   489   * @param buffer The buffer to copy read bytes into.
   490   * @param length The length of the buffer.
   491   * @return      See hdfsRead
   492   */
   493  LIBHDFS_EXTERNAL
   494  tSize hdfsPread(hdfsFS fs, hdfsFile file, tOffset position, void *buffer,
   495                  tSize length);
   496  
   497  /**
   498   * hdfsWrite - Write data into an open file.
   499   * @param fs The configured filesystem handle.
   500   * @param file The file handle.
   501   * @param buffer The data.
   502   * @param length The no. of bytes to write.
   503   * @return Returns the number of bytes written, -1 on error.
   504   */
   505  LIBHDFS_EXTERNAL
   506  tSize hdfsWrite(hdfsFS fs, hdfsFile file, const void *buffer, tSize length);
   507  
   508  /**
   509   * hdfsWrite - Flush the data.
   510   * @param fs The configured filesystem handle.
   511   * @param file The file handle.
   512   * @return Returns 0 on success, -1 on error.
   513   */
   514  LIBHDFS_EXTERNAL
   515  int hdfsFlush(hdfsFS fs, hdfsFile file);
   516  
   517  /**
   518   * hdfsHFlush - Flush out the data in client's user buffer. After the
   519   * return of this call, new readers will see the data.
   520   * @param fs configured filesystem handle
   521   * @param file file handle
   522   * @return 0 on success, -1 on error and sets errno
   523   */
   524  LIBHDFS_EXTERNAL
   525  int hdfsHFlush(hdfsFS fs, hdfsFile file);
   526  
   527  /**
   528   * hdfsHSync - Similar to posix fsync, Flush out the data in client's
   529   * user buffer. all the way to the disk device (but the disk may have
   530   * it in its cache).
   531   * @param fs configured filesystem handle
   532   * @param file file handle
   533   * @return 0 on success, -1 on error and sets errno
   534   */
   535  LIBHDFS_EXTERNAL
   536  int hdfsHSync(hdfsFS fs, hdfsFile file);
   537  
   538  /**
   539   * hdfsAvailable - Number of bytes that can be read from this
   540   * input stream without blocking.
   541   * @param fs The configured filesystem handle.
   542   * @param file The file handle.
   543   * @return Returns available bytes; -1 on error.
   544   */
   545  LIBHDFS_EXTERNAL
   546  int hdfsAvailable(hdfsFS fs, hdfsFile file);
   547  
   548  /**
   549   * hdfsCopy - Copy file from one filesystem to another.
   550   * @param srcFS The handle to source filesystem.
   551   * @param src The path of source file.
   552   * @param dstFS The handle to destination filesystem.
   553   * @param dst The path of destination file.
   554   * @return Returns 0 on success, -1 on error.
   555   */
   556  LIBHDFS_EXTERNAL
   557  int hdfsCopy(hdfsFS srcFS, const char *src, hdfsFS dstFS, const char *dst);
   558  
   559  /**
   560   * hdfsMove - Move file from one filesystem to another.
   561   * @param srcFS The handle to source filesystem.
   562   * @param src The path of source file.
   563   * @param dstFS The handle to destination filesystem.
   564   * @param dst The path of destination file.
   565   * @return Returns 0 on success, -1 on error.
   566   */
   567  LIBHDFS_EXTERNAL
   568  int hdfsMove(hdfsFS srcFS, const char *src, hdfsFS dstFS, const char *dst);
   569  
   570  /**
   571   * hdfsDelete - Delete file.
   572   * @param fs The configured filesystem handle.
   573   * @param path The path of the file.
   574   * @param recursive if path is a directory and set to
   575   * non-zero, the directory is deleted else throws an exception. In
   576   * case of a file the recursive argument is irrelevant.
   577   * @return Returns 0 on success, -1 on error.
   578   */
   579  LIBHDFS_EXTERNAL
   580  int hdfsDelete(hdfsFS fs, const char *path, int recursive);
   581  
   582  /**
   583   * hdfsRename - Rename file.
   584   * @param fs The configured filesystem handle.
   585   * @param oldPath The path of the source file.
   586   * @param newPath The path of the destination file.
   587   * @return Returns 0 on success, -1 on error.
   588   */
   589  LIBHDFS_EXTERNAL
   590  int hdfsRename(hdfsFS fs, const char *oldPath, const char *newPath);
   591  
   592  /**
   593   * hdfsGetWorkingDirectory - Get the current working directory for
   594   * the given filesystem.
   595   * @param fs The configured filesystem handle.
   596   * @param buffer The user-buffer to copy path of cwd into.
   597   * @param bufferSize The length of user-buffer.
   598   * @return Returns buffer, NULL on error.
   599   */
   600  LIBHDFS_EXTERNAL
   601  char *hdfsGetWorkingDirectory(hdfsFS fs, char *buffer, size_t bufferSize);
   602  
   603  /**
   604   * hdfsSetWorkingDirectory - Set the working directory. All relative
   605   * paths will be resolved relative to it.
   606   * @param fs The configured filesystem handle.
   607   * @param path The path of the new 'cwd'.
   608   * @return Returns 0 on success, -1 on error.
   609   */
   610  LIBHDFS_EXTERNAL
   611  int hdfsSetWorkingDirectory(hdfsFS fs, const char *path);
   612  
   613  /**
   614   * hdfsCreateDirectory - Make the given file and all non-existent
   615   * parents into directories.
   616   * @param fs The configured filesystem handle.
   617   * @param path The path of the directory.
   618   * @return Returns 0 on success, -1 on error.
   619   */
   620  LIBHDFS_EXTERNAL
   621  int hdfsCreateDirectory(hdfsFS fs, const char *path);
   622  
   623  /**
   624   * hdfsSetReplication - Set the replication of the specified
   625   * file to the supplied value
   626   * @param fs The configured filesystem handle.
   627   * @param path The path of the file.
   628   * @return Returns 0 on success, -1 on error.
   629   */
   630  LIBHDFS_EXTERNAL
   631  int hdfsSetReplication(hdfsFS fs, const char *path, int16_t replication);
   632  
   633  /**
   634   * hdfsFileInfo - Information about a file/directory.
   635   */
   636  typedef struct {
   637    tObjectKind mKind;  /* file or directory */
   638    char *mName;        /* the name of the file */
   639    tTime mLastMod;     /* the last modification time for the file in seconds */
   640    tOffset mSize;      /* the size of the file in bytes */
   641    short mReplication; /* the count of replicas */
   642    tOffset mBlockSize; /* the block size for the file */
   643    char *mOwner;       /* the owner of the file */
   644    char *mGroup;       /* the group associated with the file */
   645    short mPermissions; /* the permissions associated with the file */
   646    tTime mLastAccess;  /* the last access time for the file in seconds */
   647  } hdfsFileInfo;
   648  
   649  /**
   650   * hdfsListDirectory - Get list of files/directories for a given
   651   * directory-path. hdfsFreeFileInfo should be called to deallocate memory.
   652   * @param fs The configured filesystem handle.
   653   * @param path The path of the directory.
   654   * @param numEntries Set to the number of files/directories in path.
   655   * @return Returns a dynamically-allocated array of hdfsFileInfo
   656   * objects; NULL on error.
   657   */
   658  LIBHDFS_EXTERNAL
   659  hdfsFileInfo *hdfsListDirectory(hdfsFS fs, const char *path, int *numEntries);
   660  
   661  /**
   662   * hdfsGetPathInfo - Get information about a path as a (dynamically
   663   * allocated) single hdfsFileInfo struct. hdfsFreeFileInfo should be
   664   * called when the pointer is no longer needed.
   665   * @param fs The configured filesystem handle.
   666   * @param path The path of the file.
   667   * @return Returns a dynamically-allocated hdfsFileInfo object;
   668   * NULL on error.
   669   */
   670  LIBHDFS_EXTERNAL
   671  hdfsFileInfo *hdfsGetPathInfo(hdfsFS fs, const char *path);
   672  
   673  /**
   674   * hdfsFreeFileInfo - Free up the hdfsFileInfo array (including fields)
   675   * @param hdfsFileInfo The array of dynamically-allocated hdfsFileInfo
   676   * objects.
   677   * @param numEntries The size of the array.
   678   */
   679  LIBHDFS_EXTERNAL
   680  void hdfsFreeFileInfo(hdfsFileInfo *hdfsFileInfo, int numEntries);
   681  
   682  /**
   683   * hdfsFileIsEncrypted: determine if a file is encrypted based on its
   684   * hdfsFileInfo.
   685   * @return -1 if there was an error (errno will be set), 0 if the file is
   686   *         not encrypted, 1 if the file is encrypted.
   687   */
   688  LIBHDFS_EXTERNAL
   689  int hdfsFileIsEncrypted(hdfsFileInfo *hdfsFileInfo);
   690  
   691  /**
   692   * hdfsGetHosts - Get hostnames where a particular block (determined by
   693   * pos & blocksize) of a file is stored. The last element in the array
   694   * is NULL. Due to replication, a single block could be present on
   695   * multiple hosts.
   696   * @param fs The configured filesystem handle.
   697   * @param path The path of the file.
   698   * @param start The start of the block.
   699   * @param length The length of the block.
   700   * @return Returns a dynamically-allocated 2-d array of blocks-hosts;
   701   * NULL on error.
   702   */
   703  LIBHDFS_EXTERNAL
   704  char ***hdfsGetHosts(hdfsFS fs, const char *path, tOffset start,
   705                       tOffset length);
   706  
   707  /**
   708   * hdfsFreeHosts - Free up the structure returned by hdfsGetHosts
   709   * @param hdfsFileInfo The array of dynamically-allocated hdfsFileInfo
   710   * objects.
   711   * @param numEntries The size of the array.
   712   */
   713  LIBHDFS_EXTERNAL
   714  void hdfsFreeHosts(char ***blockHosts);
   715  
   716  /**
   717   * hdfsGetDefaultBlockSize - Get the default blocksize.
   718   *
   719   * @param fs            The configured filesystem handle.
   720   * @deprecated          Use hdfsGetDefaultBlockSizeAtPath instead.
   721   *
   722   * @return              Returns the default blocksize, or -1 on error.
   723   */
   724  LIBHDFS_EXTERNAL
   725  tOffset hdfsGetDefaultBlockSize(hdfsFS fs);
   726  
   727  /**
   728   * hdfsGetDefaultBlockSizeAtPath - Get the default blocksize at the
   729   * filesystem indicated by a given path.
   730   *
   731   * @param fs            The configured filesystem handle.
   732   * @param path          The given path will be used to locate the actual
   733   *                      filesystem.  The full path does not have to exist.
   734   *
   735   * @return              Returns the default blocksize, or -1 on error.
   736   */
   737  LIBHDFS_EXTERNAL
   738  tOffset hdfsGetDefaultBlockSizeAtPath(hdfsFS fs, const char *path);
   739  
   740  /**
   741   * hdfsGetCapacity - Return the raw capacity of the filesystem.
   742   * @param fs The configured filesystem handle.
   743   * @return Returns the raw-capacity; -1 on error.
   744   */
   745  LIBHDFS_EXTERNAL
   746  tOffset hdfsGetCapacity(hdfsFS fs);
   747  
   748  /**
   749   * hdfsGetUsed - Return the total raw size of all files in the filesystem.
   750   * @param fs The configured filesystem handle.
   751   * @return Returns the total-size; -1 on error.
   752   */
   753  LIBHDFS_EXTERNAL
   754  tOffset hdfsGetUsed(hdfsFS fs);
   755  
   756  /**
   757   * Change the user and/or group of a file or directory.
   758   *
   759   * @param fs            The configured filesystem handle.
   760   * @param path          the path to the file or directory
   761   * @param owner         User string.  Set to NULL for 'no change'
   762   * @param group         Group string.  Set to NULL for 'no change'
   763   * @return              0 on success else -1
   764   */
   765  LIBHDFS_EXTERNAL
   766  int hdfsChown(hdfsFS fs, const char *path, const char *owner,
   767                const char *group);
   768  
   769  /**
   770   * hdfsChmod
   771   * @param fs The configured filesystem handle.
   772   * @param path the path to the file or directory
   773   * @param mode the bitmask to set it to
   774   * @return 0 on success else -1
   775   */
   776  LIBHDFS_EXTERNAL
   777  int hdfsChmod(hdfsFS fs, const char *path, short mode);
   778  
   779  /**
   780   * hdfsUtime
   781   * @param fs The configured filesystem handle.
   782   * @param path the path to the file or directory
   783   * @param mtime new modification time or -1 for no change
   784   * @param atime new access time or -1 for no change
   785   * @return 0 on success else -1
   786   */
   787  LIBHDFS_EXTERNAL
   788  int hdfsUtime(hdfsFS fs, const char *path, tTime mtime, tTime atime);
   789  
   790  /**
   791   * Allocate a zero-copy options structure.
   792   *
   793   * You must free all options structures allocated with this function using
   794   * hadoopRzOptionsFree.
   795   *
   796   * @return            A zero-copy options structure, or NULL if one could
   797   *                    not be allocated.  If NULL is returned, errno will
   798   *                    contain the error number.
   799   */
   800  LIBHDFS_EXTERNAL
   801  struct hadoopRzOptions *hadoopRzOptionsAlloc(void);
   802  
   803  /**
   804   * Determine whether we should skip checksums in read0.
   805   *
   806   * @param opts        The options structure.
   807   * @param skip        Nonzero to skip checksums sometimes; zero to always
   808   *                    check them.
   809   *
   810   * @return            0 on success; -1 plus errno on failure.
   811   */
   812  LIBHDFS_EXTERNAL
   813  int hadoopRzOptionsSetSkipChecksum(struct hadoopRzOptions *opts, int skip);
   814  
   815  /**
   816   * Set the ByteBufferPool to use with read0.
   817   *
   818   * @param opts        The options structure.
   819   * @param className   If this is NULL, we will not use any
   820   *                    ByteBufferPool.  If this is non-NULL, it will be
   821   *                    treated as the name of the pool class to use.
   822   *                    For example, you can use
   823   *                    ELASTIC_BYTE_BUFFER_POOL_CLASS.
   824   *
   825   * @return            0 if the ByteBufferPool class was found and
   826   *                    instantiated;
   827   *                    -1 plus errno otherwise.
   828   */
   829  LIBHDFS_EXTERNAL
   830  int hadoopRzOptionsSetByteBufferPool(struct hadoopRzOptions *opts,
   831                                       const char *className);
   832  
   833  /**
   834   * Free a hadoopRzOptionsFree structure.
   835   *
   836   * @param opts        The options structure to free.
   837   *                    Any associated ByteBufferPool will also be freed.
   838   */
   839  LIBHDFS_EXTERNAL
   840  void hadoopRzOptionsFree(struct hadoopRzOptions *opts);
   841  
   842  /**
   843   * Perform a byte buffer read.
   844   * If possible, this will be a zero-copy (mmap) read.
   845   *
   846   * @param file       The file to read from.
   847   * @param opts       An options structure created by hadoopRzOptionsAlloc.
   848   * @param maxLength  The maximum length to read.  We may read fewer bytes
   849   *                   than this length.
   850   *
   851   * @return           On success, we will return a new hadoopRzBuffer.
   852   *                   This buffer will continue to be valid and readable
   853   *                   until it is released by readZeroBufferFree.  Failure to
   854   *                   release a buffer will lead to a memory leak.
   855   *                   You can access the data within the hadoopRzBuffer with
   856   *                   hadoopRzBufferGet.  If you have reached EOF, the data
   857   *                   within the hadoopRzBuffer will be NULL.  You must still
   858   *                   free hadoopRzBuffer instances containing NULL.
   859   *
   860   *                   On failure, we will return NULL plus an errno code.
   861   *                   errno = EOPNOTSUPP indicates that we could not do a
   862   *                   zero-copy read, and there was no ByteBufferPool
   863   *                   supplied.
   864   */
   865  LIBHDFS_EXTERNAL
   866  struct hadoopRzBuffer *hadoopReadZero(hdfsFile file,
   867                                        struct hadoopRzOptions *opts,
   868                                        int32_t maxLength);
   869  
   870  /**
   871   * Determine the length of the buffer returned from readZero.
   872   *
   873   * @param buffer     a buffer returned from readZero.
   874   * @return           the length of the buffer.
   875   */
   876  LIBHDFS_EXTERNAL
   877  int32_t hadoopRzBufferLength(const struct hadoopRzBuffer *buffer);
   878  
   879  /**
   880   * Get a pointer to the raw buffer returned from readZero.
   881   *
   882   * To find out how many bytes this buffer contains, call
   883   * hadoopRzBufferLength.
   884   *
   885   * @param buffer     a buffer returned from readZero.
   886   * @return           a pointer to the start of the buffer.  This will be
   887   *                   NULL when end-of-file has been reached.
   888   */
   889  LIBHDFS_EXTERNAL
   890  const void *hadoopRzBufferGet(const struct hadoopRzBuffer *buffer);
   891  
   892  /**
   893   * Release a buffer obtained through readZero.
   894   *
   895   * @param file       The hdfs stream that created this buffer.  This must be
   896   *                   the same stream you called hadoopReadZero on.
   897   * @param buffer     The buffer to release.
   898   */
   899  LIBHDFS_EXTERNAL
   900  void hadoopRzBufferFree(hdfsFile file, struct hadoopRzBuffer *buffer);
   901  
   902  #ifdef __cplusplus
   903  }
   904  #endif
   905  
   906  #undef LIBHDFS_EXTERNAL
   907  #endif  // TENSORFLOW_THIRD_PARTY_HADOOP_HDFS_H_
   908  
   909  /**
   910   * vim: ts=4: sw=4: et
   911   */