summaryrefslogtreecommitdiffstats
path: root/src/server/helper.c
diff options
context:
space:
mode:
authorSimon Rettberg2013-08-28 17:54:19 +0200
committerSimon Rettberg2013-08-28 17:54:19 +0200
commitbfdac5b274d8ca371307d2b4b417092ba25f11ab (patch)
treec62b57b0d56995057f152f1e1273dc3383a709a1 /src/server/helper.c
parent[SERVER] On-the-fly transparent proxying (diff)
downloaddnbd3-bfdac5b274d8ca371307d2b4b417092ba25f11ab.tar.gz
dnbd3-bfdac5b274d8ca371307d2b4b417092ba25f11ab.tar.xz
dnbd3-bfdac5b274d8ca371307d2b4b417092ba25f11ab.zip
[SERVER] Copy CRC-32 list from uplink server if available
Split up helper.c, move file/disk related functions to fileutil.c Uplink: Make sure relayed requests are at least 1MiB
Diffstat (limited to 'src/server/helper.c')
-rw-r--r--src/server/helper.c53
1 files changed, 1 insertions, 52 deletions
diff --git a/src/server/helper.c b/src/server/helper.c
index bc723e3..6c0e822 100644
--- a/src/server/helper.c
+++ b/src/server/helper.c
@@ -2,11 +2,9 @@
#include <arpa/inet.h>
#include <string.h>
#include <stdlib.h>
-#include <fcntl.h>
#include <assert.h>
-#include <sys/stat.h>
#include <sys/prctl.h> // For thread names
-#include "../types.h"
+
#include "../config.h"
/**
@@ -125,55 +123,6 @@ void trim_right(char * const string)
*end-- = '\0';
}
-int file_exists(char *file)
-{
- int fd = open( file, O_RDONLY );
- if ( fd < 0 ) return FALSE;
- close( fd );
- return TRUE;
-}
-
-int file_writable(char *file)
-{
- int fd = open( file, O_WRONLY );
- if ( fd >= 0 ) {
- close( fd );
- return TRUE;
- }
- fd = open( file, O_WRONLY | O_CREAT, 0600 );
- if ( fd < 0 ) return FALSE;
- close( fd );
- unlink( file );
- return TRUE;
-}
-
-int mkdir_p(const char* path)
-{
- assert( path != NULL );
- if ( *path == '\0' ) return TRUE;
- char buffer[strlen( path ) + 1];
- strcpy( buffer, path );
- char *current = buffer;
- char *slash;
- while ( (slash = strchr( current, '/' )) != NULL ) {
- *slash = '\0';
- if ( *buffer != '\0' && mkdir( buffer, 0750 ) != 0 && errno != EEXIST ) return FALSE;
- *slash = '/';
- current = slash + 1;
- }
- if ( mkdir( buffer, 0750 ) != 0 && errno != EEXIST ) return FALSE;
- return TRUE;
-}
-
-int file_alloc(int fd, uint64_t offset, uint64_t size)
-{
- if ( fallocate( fd, 0, offset, size ) == 0 ) return TRUE; // fast way
- if ( posix_fallocate( fd, offset, size ) == 0 ) return TRUE; // slow way
- if ( lseek( fd, offset + size - 1, SEEK_SET ) != offset ) return FALSE; // dumb way
- if ( write( fd, "", 1 ) != 1 ) return FALSE;
- return TRUE;
-}
-
void setThreadName(char *name)
{
if ( strlen( name ) > 16 ) name[16] = '\0';