Beginning the refactoring my making the first separation of s3fs.cpp into s3fs.h. Many further divisions along logical boundaries will be coming soon.

git-svn-id: http://s3fs.googlecode.com/svn/trunk@215 df820570-a93a-0410-bd06-b72b767a4274
This commit is contained in:
apetresc 2010-10-24 08:32:15 +00:00
parent 639e087d4f
commit 22f260e582
2 changed files with 119 additions and 86 deletions

View File

@ -18,9 +18,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#define FUSE_USE_VERSION 26
#include "s3fs.h"
#include <fuse.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -30,40 +29,21 @@
#include <errno.h>
#include <sys/time.h>
#include <libgen.h>
#include <pthread.h>
#include <curl/curl.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <pwd.h>
#include <grp.h>
#include <syslog.h>
#include <fstream>
#include <iostream>
#include <map>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <strings.h>
using namespace std;
static long connect_timeout = 2;
static time_t readwrite_timeout = 10;
string urlEncode(const string &s);
#define VERIFY(s) if (true) { \
int result = (s); \
if (result != 0) \
return result; \
}
#define Yikes(result) if (true) { \
syslog(LOG_ERR,"%d###result=%d", __LINE__, result); \
return result; \
}
class auto_fd {
public:
auto_fd(int fd): fd(fd) { }
@ -79,15 +59,12 @@ class auto_fd {
int fd;
};
template<typename T>
string str(T value) {
template<typename T> string str(T value) {
stringstream tmp;
tmp << value;
return tmp.str();
}
#define SPACES " \t\r\n"
inline string trim_left(const string& s, const string& t = SPACES) {
string d(s);
return d.erase(0, s.find_first_not_of(t)) ;
@ -120,13 +97,6 @@ class auto_lock {
pthread_mutex_t& lock;
};
static stack<CURL*> curl_handles;
static pthread_mutex_t curl_handles_lock;
typedef pair<double, double> progress_t;
static map<CURL*, time_t> curl_times;
static map<CURL*, progress_t> curl_progress;
// homegrown timeout mechanism
static int my_curl_progress(
void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) {
@ -279,11 +249,6 @@ class auto_curl_slist {
struct curl_slist* slist;
};
// -oretries=2
static int retries = 2;
static string bucket;
static string prepare_url(const char* url) {
syslog(LOG_DEBUG, "URL is %s", url);
@ -341,28 +306,6 @@ static int my_curl_easy_perform(CURL* curl, FILE* f = 0) {
return -EIO;
}
static string AWSAccessKeyId;
static string AWSSecretAccessKey;
static string host = "http://s3.amazonaws.com";
static mode_t root_mode = 0;
static string service_path = "/";
// if .size()==0 then local file cache is disabled
static string use_cache;
static string use_rrs;
// private, public-read, public-read-write, authenticated-read
static string default_acl("private");
// key=path
typedef map<string, struct stat> stat_cache_t;
static stat_cache_t stat_cache;
static pthread_mutex_t stat_cache_lock;
static const char hexAlphabet[] = "0123456789ABCDEF";
/**
* urlEncode a fuse path,
* taking into special consideration "/",
@ -388,16 +331,6 @@ string urlEncode(const string &s) {
return result;
}
// http headers
typedef map<string, string> headers_t;
#include <openssl/bio.h>
#include <openssl/buffer.h>
#include <openssl/evp.h>
#include <openssl/hmac.h>
static const EVP_MD* evp_md = EVP_sha1();
/**
* Returns the current date
* in a format suitable for a HTTP request header.
@ -508,8 +441,6 @@ static int mkdirp(const string& path, mode_t mode) {
return 0;
}
#include <openssl/md5.h>
/**
* @return fuse return code
* TODO return pair<int, headers_t>?!?
@ -869,7 +800,6 @@ static int s3fs_getattr(const char *path, struct stat *stbuf) {
}
static int s3fs_readlink(const char *path, char *buf, size_t size) {
if (size > 0) {
--size; // reserve nil terminator
@ -1181,8 +1111,6 @@ static int s3fs_chmod(const char *path, mode_t mode) {
return put_headers(path, meta);
}
#include <pwd.h>
#include <grp.h>
static int s3fs_chown(const char *path, uid_t uid, gid_t gid) {
cout << "chown[path=" << path << "]" << endl;
@ -1218,11 +1146,6 @@ static int s3fs_truncate(const char *path, off_t size) {
return 0;
}
// fd -> flags
typedef map<int, int> s3fs_descriptors_t;
static s3fs_descriptors_t s3fs_descriptors;
static pthread_mutex_t s3fs_descriptors_lock;
static int s3fs_open(const char *path, struct fuse_file_info *fi) {
cout << "open[path=" << path << "][flags=" << fi->flags << "]" << endl;
@ -1238,7 +1161,8 @@ static int s3fs_open(const char *path, struct fuse_file_info *fi) {
return 0;
}
static int s3fs_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) {
static int s3fs_read(
const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) {
//###cout << "read: " << path << endl;
int res = pread(fi->fh, buf, size, offset);
if (res == -1)
@ -1566,8 +1490,6 @@ static int s3fs_readdir(
return 0;
}
static pthread_mutex_t *mutex_buf = NULL;
/**
* OpenSSL locking function.
*
@ -1730,8 +1652,6 @@ string StringToLower(string strToConvert) {
return strToConvert;
}
static struct fuse_operations s3fs_oper;
int main(int argc, char *argv[]) {
for (int i = 1; i < argc; ++i) {

113
s3fs/src/s3fs.h Normal file
View File

@ -0,0 +1,113 @@
#ifndef S3FS_S3_H_
#define S3FS_S3_H_
#define FUSE_USE_VERSION 26
#include <map>
#include <stack>
#include <string>
#include <curl/curl.h>
#include <fuse.h>
#include <openssl/bio.h>
#include <openssl/buffer.h>
#include <openssl/evp.h>
#include <openssl/hmac.h>
#include <openssl/md5.h>
#include <pthread.h>
#include <sys/time.h>
using namespace std;
#define VERIFY(s) if (true) { \
int result = (s); \
if (result != 0) \
return result; \
}
#define Yikes(result) if (true) { \
syslog(LOG_ERR, "%d###result=%d", __LINE__, result); \
return result; \
}
#define SPACES " \t\r\n"
typedef pair<double, double> progress_t;
static long connect_timeout = 2;
static time_t readwrite_timeout = 10;
static stack<CURL*> curl_handles;
static pthread_mutex_t curl_handles_lock;
static map<CURL*, time_t> curl_times;
static map<CURL*, progress_t> curl_progress;
static int retries = 2;
static string bucket;
static string AWSAccessKeyId;
static string AWSSecretAccessKey;
static string host = "http://s3.amazonaws.com";
static mode_t root_mode = 0;
static string service_path = "/";
// if .size()==0 then local file cache is disabled
static string use_cache;
static string use_rrs;
// TODO(apetresc): make this an enum
// private, public-read, public-read-write, authenticated-read
static string default_acl("private");
// key=path
typedef map<string, struct stat> stat_cache_t;
static stat_cache_t stat_cache;
static pthread_mutex_t stat_cache_lock;
static const char hexAlphabet[] = "0123456789ABCDEF";
// http headers
typedef map<string, string> headers_t;
static const EVP_MD* evp_md = EVP_sha1();
// fd -> flags
typedef map<int, int> s3fs_descriptors_t;
static s3fs_descriptors_t s3fs_descriptors;
static pthread_mutex_t s3fs_descriptors_lock;
static pthread_mutex_t *mutex_buf = NULL;
static struct fuse_operations s3fs_oper;
string urlEncode(const string &s);
static int s3fs_getattr(const char *path, struct stat *stbuf);
static int s3fs_readlink(const char *path, char *buf, size_t size);
static int s3fs_mknod(const char* path, mode_t mode, dev_t rdev);
static int s3fs_mkdir(const char *path, mode_t mode);
static int s3fs_unlink(const char *path);
static int s3fs_rmdir(const char *path);
static int s3fs_symlink(const char *from, const char *to);
static int s3fs_rename(const char *from, const char *to);
static int s3fs_link(const char *from, const char *to);
static int s3fs_chmod(const char *path, mode_t mode);
static int s3fs_chown(const char *path, uid_t uid, gid_t gid);
static int s3fs_truncate(const char *path, off_t size);
static int s3fs_open(const char *path, struct fuse_file_info *fi);
static int s3fs_read(
const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi);
static int s3fs_write(
const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi);
static int s3fs_statfs(const char *path, struct statvfs *stbuf);
static int s3fs_flush(const char *path, struct fuse_file_info *fi);
static int s3fs_release(const char *path, struct fuse_file_info *fi);
static int s3fs_readdir(
const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi);
static int s3fs_access(const char *path, int mask);
static int s3fs_utimens(const char *path, const struct timespec ts[2]);
static void* s3fs_init(struct fuse_conn_info *conn);
static void s3fs_destroy(void*);
#endif // S3FS_S3_H_