2010-11-13 23:59:23 +00:00
|
|
|
#ifndef S3FS_S3_H_
|
|
|
|
#define S3FS_S3_H_
|
|
|
|
|
|
|
|
#define FUSE_USE_VERSION 26
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2011-02-15 23:32:27 +00:00
|
|
|
#include <vector>
|
2010-11-13 23:59:23 +00:00
|
|
|
|
|
|
|
#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;
|
|
|
|
|
2010-12-19 22:27:56 +00:00
|
|
|
#define YIKES(result) if (true) { \
|
2010-11-13 23:59:23 +00:00
|
|
|
syslog(LOG_ERR, "%d###result=%d", __LINE__, result); \
|
|
|
|
return result; \
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef pair<double, double> progress_t;
|
|
|
|
|
2010-12-30 03:13:21 +00:00
|
|
|
static long connect_timeout = 10;
|
|
|
|
static time_t readwrite_timeout = 30;
|
2010-11-13 23:59:23 +00:00
|
|
|
|
2010-12-19 01:34:27 +00:00
|
|
|
// static stack<CURL*> curl_handles;
|
2010-11-13 23:59:23 +00:00
|
|
|
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 mountpoint;
|
|
|
|
static string program_name;
|
|
|
|
static string AWSAccessKeyId;
|
|
|
|
static string AWSSecretAccessKey;
|
|
|
|
static string host = "http://s3.amazonaws.com";
|
2010-11-26 03:13:53 +00:00
|
|
|
static string curl_ca_bundle;
|
2010-11-13 23:59:23 +00:00
|
|
|
static mode_t root_mode = 0;
|
|
|
|
static string service_path = "/";
|
|
|
|
static string passwd_file = "";
|
|
|
|
static bool debug = 0;
|
2010-12-09 20:56:29 +00:00
|
|
|
static bool foreground = 0;
|
2010-12-30 03:13:21 +00:00
|
|
|
static bool utility_mode = 0;
|
2011-02-12 15:02:44 +00:00
|
|
|
static unsigned long max_stat_cache_size = 10000;
|
2010-11-13 23:59:23 +00:00
|
|
|
|
|
|
|
// if .size()==0 then local file cache is disabled
|
|
|
|
static string use_cache;
|
|
|
|
static string use_rrs;
|
2010-11-26 22:11:48 +00:00
|
|
|
static string ssl_verify_hostname = "1";
|
2010-11-13 23:59:23 +00:00
|
|
|
static string public_bucket;
|
|
|
|
|
|
|
|
// TODO(apetresc): make this an enum
|
|
|
|
// private, public-read, public-read-write, authenticated-read
|
|
|
|
static string default_acl("private");
|
|
|
|
|
2011-02-12 15:02:44 +00:00
|
|
|
struct stat_cache_entry {
|
|
|
|
struct stat stbuf;
|
|
|
|
unsigned long hit_count;
|
|
|
|
|
|
|
|
stat_cache_entry() : hit_count(0) {}
|
|
|
|
};
|
2010-11-13 23:59:23 +00:00
|
|
|
// key=path
|
2011-02-12 15:02:44 +00:00
|
|
|
typedef map<string, struct stat_cache_entry> stat_cache_t;
|
2010-11-13 23:59:23 +00:00
|
|
|
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);
|
2010-12-28 04:15:23 +00:00
|
|
|
string lookupMimeType(string);
|
2011-02-15 23:32:27 +00:00
|
|
|
string initiate_multipart_upload(const char *path, off_t size, headers_t meta);
|
|
|
|
string upload_part(const char *path, const char *source, int part_number, string upload_id);
|
|
|
|
static int complete_multipart_upload(const char *path, string upload_id, int n_parts, vector <string> etags);
|
|
|
|
string md5sum(const char *path);
|
2010-11-13 23:59:23 +00:00
|
|
|
|
2011-02-12 15:02:44 +00:00
|
|
|
static int get_stat_cache_entry(const char *path, struct stat *buf);
|
|
|
|
static void add_stat_cache_entry(const char *path, struct stat *st);
|
2011-02-08 18:23:38 +00:00
|
|
|
static void delete_stat_cache_entry(const char *path);
|
2011-02-12 15:02:44 +00:00
|
|
|
static void truncate_stat_cache();
|
2011-02-08 18:23:38 +00:00
|
|
|
|
2010-11-13 23:59:23 +00:00
|
|
|
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*);
|
|
|
|
|
2010-12-28 04:15:23 +00:00
|
|
|
|
2010-11-13 23:59:23 +00:00
|
|
|
#endif // S3FS_S3_H_
|