PageRenderTime 53ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/src/flarefs/fuse_impl.cc

http://github.com/fujimoto/flare
C++ | 553 lines | 308 code | 115 blank | 130 comment | 10 complexity | 7358be479990b050330f7a4dc42c637a MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. /**
  2. * fuse_impl.cc
  3. *
  4. * implementation of gree::flare::fuse_impl (and some other global stuffs)
  5. *
  6. * @author Masaki Fujimoto <fujimoto@php.net>
  7. *
  8. * $Id$
  9. */
  10. #include "fuse_impl.h"
  11. namespace gree {
  12. namespace flare {
  13. static fuse_impl* fuse_obj = NULL;
  14. // {{{ global functions
  15. int fuse_impl_getattr(const char* path, struct stat* st) {
  16. return fuse_obj->getattr(path, st);
  17. }
  18. int fuse_impl_readlink(const char* src_path, char* dst_path, size_t dst_path_size) {
  19. return fuse_obj->readlink(src_path, dst_path, dst_path_size);
  20. }
  21. int fuse_impl_mknod(const char* path, mode_t m, dev_t d) {
  22. return fuse_obj->mknod(path, m, d);
  23. }
  24. int fuse_impl_mkdir(const char* path, mode_t m) {
  25. return fuse_obj->mkdir(path, m);
  26. }
  27. int fuse_impl_unlink(const char* path) {
  28. return fuse_obj->unlink(path);
  29. }
  30. int fuse_impl_rmdir(const char* path) {
  31. return fuse_obj->rmdir(path);
  32. }
  33. int fuse_impl_symlink(const char* src_path, const char* dst_path) {
  34. return fuse_obj->symlink(src_path, dst_path);
  35. }
  36. int fuse_impl_rename(const char* src_path, const char* dst_path) {
  37. return fuse_obj->rename(src_path, dst_path);
  38. }
  39. int fuse_impl_link(const char* src_path, const char* dst_path) {
  40. return fuse_obj->link(src_path, dst_path);
  41. }
  42. int fuse_impl_chmod(const char* path, mode_t m) {
  43. return fuse_obj->chmod(path, m);
  44. }
  45. int fuse_impl_chown(const char* path, uid_t u, gid_t g) {
  46. return fuse_obj->chown(path, u, g);
  47. }
  48. int fuse_impl_truncate(const char* path, off_t o) {
  49. return fuse_obj->truncate(path, o);
  50. }
  51. int fuse_impl_utime(const char* path, struct utimbuf* u) {
  52. return fuse_obj->utime(path, u);
  53. }
  54. int fuse_impl_open(const char* path, struct fuse_file_info* f) {
  55. return fuse_obj->open(path, f);
  56. }
  57. int fuse_impl_read(const char* path, char* buf, size_t buf_size, off_t o, struct fuse_file_info* f) {
  58. return fuse_obj->read(path, buf, buf_size, o, f);
  59. }
  60. int fuse_impl_write(const char* path, const char* buf, size_t buf_size, off_t o, struct fuse_file_info* f) {
  61. return fuse_obj->write(path, buf, buf_size, o, f);
  62. }
  63. int fuse_impl_statfs(const char* path, struct statvfs* st) {
  64. return fuse_obj->statfs(path, st);
  65. }
  66. int fuse_impl_flush(const char* path, struct fuse_file_info* f) {
  67. return fuse_obj->flush(path, f);
  68. }
  69. int fuse_impl_release(const char* path, struct fuse_file_info* f) {
  70. return fuse_obj->release(path, f);
  71. }
  72. int fuse_impl_fsync(const char* path, int m, struct fuse_file_info* f) {
  73. return fuse_obj->fsync(path, m, f);
  74. }
  75. int fuse_impl_setxattr(const char* path, const char* name, const char* value, size_t value_size, int flag) {
  76. return fuse_obj->setxattr(path, name, value, value_size, flag);
  77. }
  78. int fuse_impl_getxattr(const char* path, const char* name, char* value, size_t value_size) {
  79. return fuse_obj->getxattr(path, name, value, value_size);
  80. }
  81. int fuse_impl_listxattr(const char* path, char* buf, size_t buf_size) {
  82. return fuse_obj->listxattr(path, buf, buf_size);
  83. }
  84. int fuse_impl_removexattr(const char* path, const char* name) {
  85. return fuse_obj->removexattr(path, name);
  86. }
  87. int fuse_impl_opendir(const char* path, struct fuse_file_info* f) {
  88. return fuse_obj->opendir(path, f);
  89. }
  90. int fuse_impl_readdir(const char* path, void* buf, fuse_fill_dir_t d, off_t o, struct fuse_file_info* f) {
  91. return fuse_obj->readdir(path, buf, d, o, f);
  92. }
  93. int fuse_impl_fsyncdir(const char* path, int m, struct fuse_file_info* f) {
  94. return fuse_obj->fsyncdir(path, m, f);
  95. }
  96. void* fuse_impl_init() {
  97. return fuse_obj->init();
  98. }
  99. void fuse_impl_destroy(void* buf) {
  100. fuse_obj->destroy(buf);
  101. }
  102. int fuse_impl_access(const char* path, int m) {
  103. return fuse_obj->access(path, m);
  104. }
  105. int fuse_impl_create(const char* path, mode_t m, struct fuse_file_info* f) {
  106. return fuse_obj->create(path, m, f);
  107. }
  108. int fuse_impl_ftruncate(const char* path, off_t o, struct fuse_file_info* f) {
  109. return fuse_obj->ftruncate(path, o, f);
  110. }
  111. int fuse_impl_fgetattr(const char* path, struct stat* st, struct fuse_file_info* f) {
  112. return fuse_obj->fgetattr(path, st, f);
  113. }
  114. // }}}
  115. // {{{ ctor/dtor
  116. /**
  117. * ctor for fuse_impl
  118. */
  119. fuse_impl::fuse_impl(string mount_dir):
  120. _allow_other(false),
  121. _allow_root(false),
  122. _fs(NULL),
  123. _mount_dir(mount_dir) {
  124. }
  125. /**
  126. * dtor for fuse_impl
  127. */
  128. fuse_impl::~fuse_impl() {
  129. if (this->_fs != NULL) {
  130. _delete_(this->_fs);
  131. }
  132. }
  133. // }}}
  134. // {{{ operator overloads
  135. // }}}
  136. // {{{ public methods
  137. /**
  138. * fuse main
  139. */
  140. int fuse_impl::run() {
  141. if (fuse_obj != NULL) {
  142. log_err("fuse object seems to be already active -> skip running", 0);
  143. return -1;
  144. }
  145. fuse_obj = this;
  146. this->_fs = _new_ fuse_fs(ini_option_object().get_node_server_name(), ini_option_object().get_node_server_port(), ini_option_object().get_chunk_size(), ini_option_object().get_connection_pool_size());
  147. fuse_operations fo;
  148. memset(&fo, 0, sizeof(fo));
  149. fo.getattr = fuse_impl_getattr;
  150. fo.readlink = fuse_impl_readlink;
  151. fo.mknod = fuse_impl_mknod;
  152. fo.mkdir = fuse_impl_mkdir;
  153. fo.unlink = fuse_impl_unlink;
  154. fo.rmdir = fuse_impl_rmdir;
  155. fo.symlink = fuse_impl_symlink;
  156. fo.rename = fuse_impl_rename;
  157. fo.link = fuse_impl_link;
  158. fo.chmod = fuse_impl_chmod;
  159. fo.chown = fuse_impl_chown;
  160. fo.truncate = fuse_impl_truncate;
  161. fo.utime = fuse_impl_utime;
  162. fo.open = fuse_impl_open;
  163. fo.read = fuse_impl_read;
  164. fo.write = fuse_impl_write;
  165. fo.statfs = fuse_impl_statfs;
  166. fo.flush = fuse_impl_flush;
  167. fo.release = fuse_impl_release;
  168. fo.fsync = fuse_impl_fsync;
  169. fo.setxattr = fuse_impl_setxattr;
  170. fo.getxattr = fuse_impl_getxattr;
  171. fo.listxattr = fuse_impl_listxattr;
  172. fo.removexattr = fuse_impl_removexattr;
  173. fo.opendir = fuse_impl_opendir;
  174. fo.readdir = fuse_impl_readdir;
  175. fo.fsyncdir = fuse_impl_fsyncdir;
  176. fo.init = fuse_impl_init;
  177. fo.destroy = fuse_impl_destroy;
  178. fo.access = fuse_impl_access;
  179. fo.create = fuse_impl_create;
  180. fo.ftruncate = fuse_impl_ftruncate;
  181. fo.fgetattr = fuse_impl_fgetattr;
  182. int argc = 0;
  183. char* argv[BUFSIZ]; // BUFSIZ will do:)
  184. argv[argc++] = strdup(PACKAGE_NAME);
  185. argv[argc++] = strdup(this->_mount_dir.c_str());
  186. if (this->_allow_other || this->_allow_root) {
  187. argv[argc++] = strdup("-o");
  188. }
  189. if (this->_allow_other) {
  190. argv[argc++] = strdup("allow_other");
  191. } else if (this->_allow_root) {
  192. argv[argc++] = strdup("allow_root");
  193. }
  194. fuse_main(argc, argv, &fo);
  195. while (argc > 0) {
  196. free(argv[--argc]);
  197. }
  198. return 0;
  199. }
  200. /**
  201. * getattr
  202. */
  203. int fuse_impl::getattr(const char* path, struct stat* st) {
  204. log_debug("getattr() (path=%s)", path);
  205. return this->_fs->getattr(path, st);
  206. }
  207. /**
  208. * readlink
  209. */
  210. int fuse_impl::readlink(const char* src_path, char* dst_path, size_t dst_path_size) {
  211. log_debug("readlink() (src_path=%s)", src_path);
  212. return 0;
  213. }
  214. /**
  215. * mknod
  216. */
  217. int fuse_impl::mknod(const char* path, mode_t m, dev_t d) {
  218. log_debug("mknod() (path=%s)", path);
  219. return 0;
  220. }
  221. /**
  222. * mkdir
  223. */
  224. int fuse_impl::mkdir(const char* path, mode_t m) {
  225. log_debug("mkdir() (path=%s, mode=%d)", path, m);
  226. return this->_fs->mkdir(path, m);
  227. }
  228. /**
  229. * unlink
  230. */
  231. int fuse_impl::unlink(const char* path) {
  232. log_debug("unlink() (path=%s)", path);
  233. return 0;
  234. }
  235. /**
  236. * rmdir
  237. */
  238. int fuse_impl::rmdir(const char* path) {
  239. log_debug("rmdir() (path=%s)", path);
  240. return 0;
  241. }
  242. /**
  243. * symlink
  244. */
  245. int fuse_impl::symlink(const char* src_path, const char* dst_path) {
  246. log_debug("symlink() (src_path=%s, dst_path=%s)", src_path, dst_path);
  247. return 0;
  248. }
  249. /**
  250. * rename
  251. */
  252. int fuse_impl::rename(const char* src_path, const char* dst_path) {
  253. log_debug("rename() (src_path=%s, dst_path=%s)", src_path, dst_path);
  254. return 0;
  255. }
  256. /**
  257. * link
  258. */
  259. int fuse_impl::link(const char* src_path, const char* dst_path) {
  260. log_debug("link() (src_path=%s, dst_path=%s)", src_path, dst_path);
  261. return 0;
  262. }
  263. /**
  264. * chmod
  265. */
  266. int fuse_impl::chmod(const char* path, mode_t m) {
  267. log_debug("chmod() (path=%s, mode=%d)", path, m);
  268. return 0;
  269. }
  270. /**
  271. * chown
  272. */
  273. int fuse_impl::chown(const char* path, uid_t u, gid_t g) {
  274. log_debug("chown() (path=%s, uid=%d, gid=%d)", path, u, g);
  275. return 0;
  276. }
  277. /**
  278. * truncate
  279. */
  280. int fuse_impl::truncate(const char* path, off_t o) {
  281. log_debug("truncate() (path=%s, offset=%d)", path, o);
  282. return 0;
  283. }
  284. /**
  285. * utime
  286. */
  287. int fuse_impl::utime(const char* path, struct utimbuf* u) {
  288. log_debug("utime() (path=%s)", path);
  289. return 0;
  290. }
  291. /**
  292. * open
  293. */
  294. int fuse_impl::open(const char* path, struct fuse_file_info* f) {
  295. log_debug("open() (path=%s)", path);
  296. return 0;
  297. }
  298. /**
  299. * read
  300. */
  301. int fuse_impl::read(const char* path, char* buf, size_t buf_size, off_t o, struct fuse_file_info* f) {
  302. log_debug("read() (path=%s, offset=%d)", path, o);
  303. return 0;
  304. }
  305. /**
  306. * write
  307. */
  308. int fuse_impl::write(const char* path, const char* buf, size_t buf_size, off_t o, struct fuse_file_info* f) {
  309. log_debug("write() (path=%s, offset=%d)", path, o);
  310. return 0;
  311. }
  312. /**
  313. * statfs
  314. */
  315. int fuse_impl::statfs(const char* path, struct statvfs* st) {
  316. log_debug("statfs() (path=%s)", path);
  317. return 0;
  318. }
  319. /**
  320. * flush
  321. */
  322. int fuse_impl::flush(const char* path, struct fuse_file_info* f) {
  323. log_debug("flush() (path=%s)", path);
  324. return 0;
  325. }
  326. /**
  327. * release
  328. */
  329. int fuse_impl::release(const char* path, struct fuse_file_info* f) {
  330. log_debug("release() (path=%s)", path);
  331. return 0;
  332. }
  333. /**
  334. * fsync
  335. */
  336. int fuse_impl::fsync(const char* path, int m, struct fuse_file_info* f) {
  337. log_debug("fsync() (path=%s, mode=%d)", path, m);
  338. return 0;
  339. }
  340. /**
  341. * setxattr
  342. */
  343. int fuse_impl::setxattr(const char* path, const char* name, const char* value, size_t value_size, int flag) {
  344. log_debug("setxattr() (path=%s, name=%s, flag=%d)", path, name, flag);
  345. return this->_fs->setxattr(path, name, value, value_size, flag);
  346. }
  347. /**
  348. * getxattr
  349. */
  350. int fuse_impl::getxattr(const char* path, const char* name, char* value, size_t value_size) {
  351. log_debug("getxattr() (path=%s, name=%s)", path, name);
  352. return this->_fs->getxattr(path, name, value, value_size);
  353. }
  354. /**
  355. * listxattr
  356. */
  357. int fuse_impl::listxattr(const char* path, char* buf, size_t buf_size) {
  358. log_debug("listxattr() (path=%s)", path);
  359. return 0;
  360. }
  361. /**
  362. * removexattr
  363. */
  364. int fuse_impl::removexattr(const char* path, const char* name) {
  365. log_debug("removexattr() (path=%s, name=%s)", path, name);
  366. return 0;
  367. }
  368. /**
  369. * opendir
  370. */
  371. int fuse_impl::opendir(const char* path, struct fuse_file_info* fi) {
  372. log_debug("opendir() (path=%s)", path);
  373. return this->_fs->opendir(path, fi);
  374. }
  375. /**
  376. * readdir
  377. */
  378. int fuse_impl::readdir(const char* path, void* buf, fuse_fill_dir_t filler, off_t o, struct fuse_file_info* fi) {
  379. log_debug("readdir() (path=%s, offset=%d)", path, o);
  380. return this->_fs->readdir(path, buf, filler, o, fi);
  381. }
  382. /**
  383. * fsyncdir
  384. */
  385. int fuse_impl::fsyncdir(const char* path, int m, struct fuse_file_info* f) {
  386. log_debug("fsyncdir() (path=%s, mode=%d)", path, m);
  387. return 0;
  388. }
  389. /**
  390. * init
  391. */
  392. void* fuse_impl::init() {
  393. log_debug("init()", 0);
  394. this->_fs->init();
  395. return NULL;
  396. }
  397. /**
  398. * destroy
  399. */
  400. void fuse_impl::destroy(void* buf) {
  401. log_debug("destroy()", 0);
  402. }
  403. /**
  404. * access
  405. */
  406. int fuse_impl::access(const char* path, int m) {
  407. log_debug("access() (path=%s, mode=%d)", path, m);
  408. return 0;
  409. }
  410. /**
  411. * create
  412. */
  413. int fuse_impl::create(const char* path, mode_t m, struct fuse_file_info* f) {
  414. log_debug("create() (path=%s, mode=%d)", path, m);
  415. return 0;
  416. }
  417. /**
  418. * ftruncate
  419. */
  420. int fuse_impl::ftruncate(const char* path, off_t o, struct fuse_file_info* f) {
  421. log_debug("ftruncate() (path=%s, offset=%d)", path, o);
  422. return 0;
  423. }
  424. /**
  425. * fgetattr
  426. */
  427. int fuse_impl::fgetattr(const char* path, struct stat* st, struct fuse_file_info* f) {
  428. log_debug("fgetattr() (path=%s)", path);
  429. return 0;
  430. }
  431. // }}}
  432. // {{{ protected methods
  433. // }}}
  434. // {{{ private methods
  435. // }}}
  436. } // namespace flare
  437. } // namespace gree
  438. // vim: foldmethod=marker tabstop=2 shiftwidth=2 autoindent