/*
This file is part of GNUnet.
- (C) 2001, 2002, 2003, 2004, 2005, 2006 Christian Grothoff (and other contributing authors)
+ (C) 2001, 2002, 2003, 2004, 2005, 2006, 2009 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
#include "gnunet_configuration_lib.h"
#include "gnunet_scheduler_lib.h"
-#include "gnunet_io_lib.h"
/* we need size_t, and since it can be both unsigned int
or unsigned long long, this IS platform dependent;
#define GNUNET_DISK_PERM_OTHER_WRITE 128
#define GNUNET_DISK_PERM_OTHER_EXEC 256
-enum GNUNET_DISK_Seek {GNUNET_SEEK_SET, GNUNET_SEEK_CUR, GNUNET_SEEK_END};
+enum GNUNET_DISK_Seek
+ {
+ GNUNET_DISK_SEEK_SET,
+ GNUNET_DISK_SEEK_CUR,
+ GNUNET_DISK_SEEK_END
+ };
+
+struct GNUNET_DISK_FileHandle;
+
+struct GNUNET_DISK_PipeHandle;
/**
* Get the number of blocks that are left on the partition that
long GNUNET_DISK_get_blocks_available (const char *part);
+/**
+ * Checks whether a handle is invalid
+ * @param h handle to check
+ * @return GNUNET_YES if invalid, GNUNET_NO if valid
+ */
+int GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h);
+
+
/**
* Check that fil corresponds to a filename
* (of a file that exists and that is not a directory).
* @return the new position on success, GNUNET_SYSERR otherwise
*/
off_t
-GNUNET_DISK_file_seek (const struct GNUNET_IO_Handle *h, off_t offset,
+GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, off_t offset,
enum GNUNET_DISK_Seek whence);
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
int GNUNET_DISK_file_size (const char *filename,
- unsigned long long *size, int includeSymLinks);
+ unsigned long long *size, int includeSymLinks);
+
+
+/**
+ * Create an (empty) temporary file on disk.
+ *
+ * @param template component to use for the name;
+ * does NOT contain "XXXXXX" or "/tmp/".
+ * @return NULL on error, otherwise name of fresh
+ * file on disk in directory for temporary files
+ */
+char *
+GNUNET_DISK_mktemp (const char *template);
/**
* @param perm permissions for the newly created file
* @return IO handle on success, NULL on error
*/
-struct GNUNET_IO_Handle *GNUNET_DISK_file_open (const char *fn, int flags, ...);
+struct GNUNET_DISK_FileHandle *GNUNET_DISK_file_open (const char *fn, int flags, ...);
+/**
+ * Creates an interprocess channel
+ * @param blocking creates an asynchronous pipe if set to GNUNET_NO
+ * @return handle to the new pipe, NULL on error
+ */
+struct GNUNET_DISK_PipeHandle *GNUNET_DISK_pipe (int blocking);
/**
- * Close an open file
+ * Closes an interprocess channel
+ * @param p pipe
+ * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
+ */
+int GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p);
+
+/**
+ * Close an open file.
+ *
* @param h file handle
* @return GNUNET_OK on success, GNUNET_SYSERR otherwise
*/
-int GNUNET_DISK_file_close (struct GNUNET_IO_Handle **h);
+int GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h);
+/**
+ * Get the handle to a particular pipe end
+ * @param p pipe
+ * @param n number of the end
+ */
+const struct GNUNET_DISK_FileHandle *GNUNET_DISK_pipe_handle (const struct
+ GNUNET_DISK_PipeHandle
+ *p, int n);
/**
* Read the contents of a binary file into a buffer.
* @param len the maximum number of bytes to read
* @return the number of bytes read on success, GNUNET_SYSERR on failure
*/
-int GNUNET_DISK_file_read (const struct GNUNET_IO_Handle *h, void *result, int len);
+ssize_t GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h, void *result,
+ size_t len);
/**
* @param fn file name
* @param result the buffer to write the result to
* @param len the maximum number of bytes to read
- * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ * @return number of bytes read, GNUNET_SYSERR on failure
*/
-int GNUNET_DISK_fn_read (const char * const fn, void *result, int len);
+ssize_t GNUNET_DISK_fn_read (const char * const fn, void *result,
+ size_t len);
/**
* Write a buffer to a file.
+ *
* @param h handle to open file
* @param buffer the data to write
* @param n number of bytes to write
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
-int GNUNET_DISK_file_write (const struct GNUNET_IO_Handle *h, const void *buffer,
- unsigned int n);
+ssize_t GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h,
+ const void *buffer,
+ size_t n);
/**
- * Write a buffer to a file.
+ * Write a buffer to a file. If the file is longer than
+ * the given buffer size, it will be truncated.
+ *
* @param fn file name
* @param buffer the data to write
* @param n number of bytes to write
* @return number of bytes written on success, GNUNET_SYSERR on error
*/
-int GNUNET_DISK_fn_write (const char * const fn, const void *buffer,
- unsigned int n, int mode);
+ssize_t GNUNET_DISK_fn_write (const char * fn,
+ const void *buffer,
+ size_t n,
+ int mode);
/**
* @return the number of files found, -1 on error
*/
int GNUNET_DISK_directory_scan (const char *dirName,
- GNUNET_FileNameCallback callback, void *data);
+ GNUNET_FileNameCallback callback,
+ void *data);
/**
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
int
-GNUNET_DISK_file_lock(struct GNUNET_IO_Handle *fh, off_t lockStart,
+GNUNET_DISK_file_lock(struct GNUNET_DISK_FileHandle *fh, off_t lockStart,
off_t lockEnd);
* private directory name.
* @return the constructed filename
*/
-char *GNUNET_DISK_get_home_filename (struct GNUNET_CONFIGURATION_Handle *cfg,
+char *GNUNET_DISK_get_home_filename (const struct GNUNET_CONFIGURATION_Handle *cfg,
const char *serviceName, ...);
+
+/**
+ * Opaque handle for a memory-mapping operation.
+ */
+struct GNUNET_DISK_MapHandle;
+
/**
* Map a file into memory
* @param h open file handle
- * @param m handle to the new mapping
+ * @param m handle to the new mapping (will be set)
* @param access access specification, GNUNET_DISK_MAP_xxx
* @param len size of the mapping
* @return pointer to the mapped memory region, NULL on failure
*/
-void *GNUNET_DISK_file_map (const struct GNUNET_IO_Handle *h, struct GNUNET_IO_Handle **m,
- int access, size_t len);
+void *GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h,
+ struct GNUNET_DISK_MapHandle **m,
+ int access, size_t len);
/**
* Unmap a file
+ *
* @param h mapping handle
- * @param addr pointer to the mapped memory region
- * @param len size of the mapping
* @return GNUNET_OK on success, GNUNET_SYSERR otherwise
*/
-int GNUNET_DISK_file_unmap (struct GNUNET_IO_Handle **h, void *addr, size_t len);
+int GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h);
/**
* Write file changes to disk
* @param h handle to an open file
* @return GNUNET_OK on success, GNUNET_SYSERR otherwise
*/
-int GNUNET_DISK_file_sync (const struct GNUNET_IO_Handle *h);
+int GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h);
#if 0 /* keep Emacsens' auto-indent happy */
{