2014-09-07 15:08:27 +00:00
|
|
|
/*
|
|
|
|
* s3fs - FUSE-based file system backed by Amazon S3
|
|
|
|
*
|
2017-05-07 11:24:17 +00:00
|
|
|
* Copyright(C) 2007 Randy Rizun <rrizun@gmail.com>
|
2014-09-07 15:08:27 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
2015-08-21 16:19:31 +00:00
|
|
|
|
2013-03-30 13:37:14 +00:00
|
|
|
#ifndef S3FS_COMMON_H_
|
|
|
|
#define S3FS_COMMON_H_
|
|
|
|
|
2018-03-02 20:58:41 +00:00
|
|
|
#include <stdlib.h>
|
2015-08-21 16:19:31 +00:00
|
|
|
#include "../config.h"
|
|
|
|
|
2016-10-02 07:23:19 +00:00
|
|
|
//
|
|
|
|
// Extended attribute
|
|
|
|
//
|
|
|
|
#ifdef HAVE_SYS_EXTATTR_H
|
|
|
|
#include <sys/extattr.h>
|
|
|
|
#elif HAVE_ATTR_XATTR_H
|
|
|
|
#include <attr/xattr.h>
|
|
|
|
#elif HAVE_SYS_XATTR_H
|
|
|
|
#include <sys/xattr.h>
|
|
|
|
#endif
|
|
|
|
|
2013-03-30 13:37:14 +00:00
|
|
|
//
|
|
|
|
// Macro
|
|
|
|
//
|
2017-11-18 03:50:36 +00:00
|
|
|
static inline const char *SAFESTRPTR(const char *strptr) { return strptr ? strptr : ""; }
|
2013-08-10 15:29:39 +00:00
|
|
|
|
2015-09-30 19:41:27 +00:00
|
|
|
//
|
|
|
|
// Debug level
|
|
|
|
//
|
|
|
|
enum s3fs_log_level{
|
|
|
|
S3FS_LOG_CRIT = 0, // LOG_CRIT
|
|
|
|
S3FS_LOG_ERR = 1, // LOG_ERR
|
|
|
|
S3FS_LOG_WARN = 3, // LOG_WARNING
|
|
|
|
S3FS_LOG_INFO = 7, // LOG_INFO
|
|
|
|
S3FS_LOG_DBG = 15 // LOG_DEBUG
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// Debug macros
|
|
|
|
//
|
|
|
|
#define IS_S3FS_LOG_CRIT() (S3FS_LOG_CRIT == debug_level)
|
|
|
|
#define IS_S3FS_LOG_ERR() (S3FS_LOG_ERR == (debug_level & S3FS_LOG_DBG))
|
|
|
|
#define IS_S3FS_LOG_WARN() (S3FS_LOG_WARN == (debug_level & S3FS_LOG_DBG))
|
|
|
|
#define IS_S3FS_LOG_INFO() (S3FS_LOG_INFO == (debug_level & S3FS_LOG_DBG))
|
|
|
|
#define IS_S3FS_LOG_DBG() (S3FS_LOG_DBG == (debug_level & S3FS_LOG_DBG))
|
|
|
|
|
|
|
|
#define S3FS_LOG_LEVEL_TO_SYSLOG(level) \
|
|
|
|
( S3FS_LOG_DBG == (level & S3FS_LOG_DBG) ? LOG_DEBUG : \
|
|
|
|
S3FS_LOG_INFO == (level & S3FS_LOG_DBG) ? LOG_INFO : \
|
|
|
|
S3FS_LOG_WARN == (level & S3FS_LOG_DBG) ? LOG_WARNING : \
|
|
|
|
S3FS_LOG_ERR == (level & S3FS_LOG_DBG) ? LOG_ERR : LOG_CRIT )
|
|
|
|
|
|
|
|
#define S3FS_LOG_LEVEL_STRING(level) \
|
|
|
|
( S3FS_LOG_DBG == (level & S3FS_LOG_DBG) ? "[DBG] " : \
|
|
|
|
S3FS_LOG_INFO == (level & S3FS_LOG_DBG) ? "[INF] " : \
|
|
|
|
S3FS_LOG_WARN == (level & S3FS_LOG_DBG) ? "[WAN] " : \
|
|
|
|
S3FS_LOG_ERR == (level & S3FS_LOG_DBG) ? "[ERR] " : "[CRT] " )
|
|
|
|
|
|
|
|
#define S3FS_LOG_NEST_MAX 4
|
|
|
|
#define S3FS_LOG_NEST(nest) (nest < S3FS_LOG_NEST_MAX ? s3fs_log_nest[nest] : s3fs_log_nest[S3FS_LOG_NEST_MAX - 1])
|
|
|
|
|
|
|
|
#define S3FS_LOW_LOGPRN(level, fmt, ...) \
|
2019-04-17 11:41:50 +00:00
|
|
|
do{ \
|
2015-09-30 19:41:27 +00:00
|
|
|
if(S3FS_LOG_CRIT == level || (S3FS_LOG_CRIT != debug_level && level == (debug_level & level))){ \
|
|
|
|
if(foreground){ \
|
2015-11-03 16:34:02 +00:00
|
|
|
fprintf(stdout, "%s%s:%s(%d): " fmt "%s\n", S3FS_LOG_LEVEL_STRING(level), __FILE__, __func__, __LINE__, __VA_ARGS__); \
|
2015-09-30 19:41:27 +00:00
|
|
|
}else{ \
|
2018-02-28 07:51:35 +00:00
|
|
|
syslog(S3FS_LOG_LEVEL_TO_SYSLOG(level), "%s%s:%s(%d): " fmt "%s", instance_name.c_str(), __FILE__, __func__, __LINE__, __VA_ARGS__); \
|
2015-09-30 19:41:27 +00:00
|
|
|
} \
|
2019-04-17 11:41:50 +00:00
|
|
|
} \
|
|
|
|
}while(0)
|
2015-09-30 19:41:27 +00:00
|
|
|
|
|
|
|
#define S3FS_LOW_LOGPRN2(level, nest, fmt, ...) \
|
2019-04-17 11:41:50 +00:00
|
|
|
do{ \
|
2015-09-30 19:41:27 +00:00
|
|
|
if(S3FS_LOG_CRIT == level || (S3FS_LOG_CRIT != debug_level && level == (debug_level & level))){ \
|
|
|
|
if(foreground){ \
|
2015-11-03 16:34:02 +00:00
|
|
|
fprintf(stdout, "%s%s%s:%s(%d): " fmt "%s\n", S3FS_LOG_LEVEL_STRING(level), S3FS_LOG_NEST(nest), __FILE__, __func__, __LINE__, __VA_ARGS__); \
|
2015-09-30 19:41:27 +00:00
|
|
|
}else{ \
|
2018-02-28 07:51:35 +00:00
|
|
|
syslog(S3FS_LOG_LEVEL_TO_SYSLOG(level), "%s%s" fmt "%s", instance_name.c_str(), S3FS_LOG_NEST(nest), __VA_ARGS__); \
|
2015-09-30 19:41:27 +00:00
|
|
|
} \
|
2019-04-17 11:41:50 +00:00
|
|
|
} \
|
|
|
|
}while(0)
|
2015-09-30 19:41:27 +00:00
|
|
|
|
|
|
|
#define S3FS_LOW_LOGPRN_EXIT(fmt, ...) \
|
2019-04-17 11:41:50 +00:00
|
|
|
do{ \
|
2015-09-30 19:41:27 +00:00
|
|
|
if(foreground){ \
|
|
|
|
fprintf(stderr, "s3fs: " fmt "%s\n", __VA_ARGS__); \
|
|
|
|
}else{ \
|
2015-11-25 21:46:24 +00:00
|
|
|
fprintf(stderr, "s3fs: " fmt "%s\n", __VA_ARGS__); \
|
2018-02-28 07:51:35 +00:00
|
|
|
syslog(S3FS_LOG_LEVEL_TO_SYSLOG(S3FS_LOG_CRIT), "%ss3fs: " fmt "%s", instance_name.c_str(), __VA_ARGS__); \
|
2019-04-17 11:41:50 +00:00
|
|
|
} \
|
|
|
|
}while(0)
|
2015-09-30 19:41:27 +00:00
|
|
|
|
2017-10-15 06:45:19 +00:00
|
|
|
// Special macro for init message
|
|
|
|
#define S3FS_PRN_INIT_INFO(fmt, ...) \
|
2019-04-17 11:41:50 +00:00
|
|
|
do{ \
|
2017-10-15 06:45:19 +00:00
|
|
|
if(foreground){ \
|
|
|
|
fprintf(stdout, "%s%s%s:%s(%d): " fmt "%s\n", S3FS_LOG_LEVEL_STRING(S3FS_LOG_INFO), S3FS_LOG_NEST(0), __FILE__, __func__, __LINE__, __VA_ARGS__, ""); \
|
|
|
|
}else{ \
|
2018-02-28 07:51:35 +00:00
|
|
|
syslog(S3FS_LOG_LEVEL_TO_SYSLOG(S3FS_LOG_INFO), "%s%s" fmt "%s", instance_name.c_str(), S3FS_LOG_NEST(0), __VA_ARGS__, ""); \
|
2019-04-17 11:41:50 +00:00
|
|
|
} \
|
|
|
|
}while(0)
|
2017-10-15 06:45:19 +00:00
|
|
|
|
2015-09-30 19:41:27 +00:00
|
|
|
// [NOTE]
|
|
|
|
// small trick for VA_ARGS
|
|
|
|
//
|
|
|
|
#define S3FS_PRN_EXIT(fmt, ...) S3FS_LOW_LOGPRN_EXIT(fmt, ##__VA_ARGS__, "")
|
|
|
|
#define S3FS_PRN_CRIT(fmt, ...) S3FS_LOW_LOGPRN(S3FS_LOG_CRIT, fmt, ##__VA_ARGS__, "")
|
|
|
|
#define S3FS_PRN_ERR(fmt, ...) S3FS_LOW_LOGPRN(S3FS_LOG_ERR, fmt, ##__VA_ARGS__, "")
|
|
|
|
#define S3FS_PRN_WARN(fmt, ...) S3FS_LOW_LOGPRN(S3FS_LOG_WARN, fmt, ##__VA_ARGS__, "")
|
|
|
|
#define S3FS_PRN_DBG(fmt, ...) S3FS_LOW_LOGPRN(S3FS_LOG_DBG, fmt, ##__VA_ARGS__, "")
|
|
|
|
#define S3FS_PRN_INFO(fmt, ...) S3FS_LOW_LOGPRN2(S3FS_LOG_INFO, 0, fmt, ##__VA_ARGS__, "")
|
|
|
|
#define S3FS_PRN_INFO0(fmt, ...) S3FS_LOG_INFO(fmt, __VA_ARGS__)
|
|
|
|
#define S3FS_PRN_INFO1(fmt, ...) S3FS_LOW_LOGPRN2(S3FS_LOG_INFO, 1, fmt, ##__VA_ARGS__, "")
|
|
|
|
#define S3FS_PRN_INFO2(fmt, ...) S3FS_LOW_LOGPRN2(S3FS_LOG_INFO, 2, fmt, ##__VA_ARGS__, "")
|
|
|
|
#define S3FS_PRN_INFO3(fmt, ...) S3FS_LOW_LOGPRN2(S3FS_LOG_INFO, 3, fmt, ##__VA_ARGS__, "")
|
|
|
|
#define S3FS_PRN_CURL(fmt, ...) S3FS_LOW_LOGPRN2(S3FS_LOG_CRIT, 0, fmt, ##__VA_ARGS__, "")
|
2013-07-05 02:28:31 +00:00
|
|
|
|
2013-03-30 13:37:14 +00:00
|
|
|
//
|
|
|
|
// Typedef
|
|
|
|
//
|
2016-10-23 14:14:19 +00:00
|
|
|
struct header_nocase_cmp : public std::binary_function<std::string, std::string, bool>{
|
|
|
|
bool operator()(const std::string &strleft, const std::string &strright) const
|
|
|
|
{
|
|
|
|
return (strcasecmp(strleft.c_str(), strright.c_str()) < 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
typedef std::map<std::string, std::string, header_nocase_cmp> headers_t;
|
2013-03-30 13:37:14 +00:00
|
|
|
|
2015-04-20 17:24:57 +00:00
|
|
|
//
|
|
|
|
// Header "x-amz-meta-xattr" is for extended attributes.
|
2014-04-05 05:11:55 +00:00
|
|
|
// This header is url encoded string which is json formatted.
|
|
|
|
// x-amz-meta-xattr:urlencode({"xattr-1":"base64(value-1)","xattr-2":"base64(value-2)","xattr-3":"base64(value-3)"})
|
2015-04-20 17:24:57 +00:00
|
|
|
//
|
2015-06-06 16:39:39 +00:00
|
|
|
typedef struct xattr_value{
|
|
|
|
unsigned char* pvalue;
|
|
|
|
size_t length;
|
|
|
|
|
2015-08-06 06:38:06 +00:00
|
|
|
explicit xattr_value(unsigned char* pval = NULL, size_t len = 0) : pvalue(pval), length(len) {}
|
2015-06-06 16:39:39 +00:00
|
|
|
~xattr_value()
|
|
|
|
{
|
2019-04-07 06:07:34 +00:00
|
|
|
delete[] pvalue;
|
2015-06-06 16:39:39 +00:00
|
|
|
}
|
|
|
|
}XATTRVAL, *PXATTRVAL;
|
|
|
|
|
|
|
|
typedef std::map<std::string, PXATTRVAL> xattrs_t;
|
2015-04-20 17:24:57 +00:00
|
|
|
|
2013-03-30 13:37:14 +00:00
|
|
|
//
|
2014-04-05 05:11:55 +00:00
|
|
|
// Global variables
|
2013-03-30 13:37:14 +00:00
|
|
|
//
|
2018-12-16 01:42:38 +00:00
|
|
|
// TODO: namespace these
|
2015-09-30 19:41:27 +00:00
|
|
|
extern bool foreground;
|
|
|
|
extern bool nomultipart;
|
|
|
|
extern bool pathrequeststyle;
|
2017-05-04 03:41:24 +00:00
|
|
|
extern bool complement_stat;
|
2015-09-30 19:41:27 +00:00
|
|
|
extern std::string program_name;
|
|
|
|
extern std::string service_path;
|
|
|
|
extern std::string host;
|
|
|
|
extern std::string bucket;
|
|
|
|
extern std::string mount_prefix;
|
|
|
|
extern std::string endpoint;
|
2017-04-04 12:32:53 +00:00
|
|
|
extern std::string cipher_suites;
|
2018-02-28 07:51:35 +00:00
|
|
|
extern std::string instance_name;
|
2015-09-30 19:41:27 +00:00
|
|
|
extern s3fs_log_level debug_level;
|
|
|
|
extern const char* s3fs_log_nest[S3FS_LOG_NEST_MAX];
|
2013-03-30 13:37:14 +00:00
|
|
|
|
|
|
|
#endif // S3FS_COMMON_H_
|
2014-09-07 15:08:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
|
|
|
* vim600: noet sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: noet sw=4 ts=4
|
|
|
|
*/
|