Advertisement
Guest User

Untitled

a guest
May 30th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3.  
  4. #include <string.h>
  5.  
  6. #include <stdlib.h>
  7.  
  8. #include <sys/types.h>
  9. #include <sys/stat.h>
  10. #include <fcntl.h>
  11. #include <fuse.h>
  12.  
  13. #include "fuu_walk.h"
  14. #include "jsmnload.h"
  15.  
  16. #define _JSMN_TOKEN_SIZE_ 256
  17. #define _JSMN_BUFFER_SIZE_ 4096
  18. #define MYFS_OPT(t, p, v) { t, offsetof(struct myfs_config, p), v }
  19.  
  20. struct myfs_config {
  21. char *mystring;
  22. } conf;
  23.  
  24. static struct fuse_opt myfs_opts[] = {
  25. MYFS_OPT("-c %s", mystring, 1),
  26.  
  27. //FUSE_OPT_KEY("-c", 1), FUSE_OPT_KEY как я понял используется для перегрузки уже заложенных библиотекой опций, но пробовал и его подпихивать - ни в какую.
  28. FUSE_OPT_END
  29. };
  30.  
  31. jsmntok_t t[_JSMN_TOKEN_SIZE_];
  32. char buf[_JSMN_BUFFER_SIZE_];
  33. #if 0
  34. = ""
  35. "{"root": ["
  36. "{"path":"/", "mode":"drw-------"},"
  37. "{"path":"/12ABC345DE67", "mode":"drw-------"},"
  38. "{"path":"/12ABC345DE67/_XQ01", "mode":"-rw-------"},"
  39. "{"path":"/12ABC345DE67/_XQ02", "mode":"-rw-------"},"
  40. "{"path":"/12ABC345DE78", "mode":"drw-------"},"
  41. "{"path":"/12ABC345DE89", "mode":"drw-------"}"
  42. "]}";
  43. #endif
  44.  
  45.  
  46. static int myfs_opt_proc(void *data, const char *arg, int key, struct fuse_args *outargs)
  47. {
  48. struct myfs_config *ptr = (struct myfs_config *)data;
  49. FILE *conf;
  50. int rc = 0;
  51.  
  52. //Хочу проверить сколько раз я зашел в эту функцию принтфом.
  53. printf("arg = %st string %st key = %in", arg, ptr->mystring, key);
  54. switch (key) {
  55. case 1:
  56. conf = fopen(ptr->mystring, "r");
  57. rc = read(fileno(conf), buf, _JSMN_BUFFER_SIZE_);
  58.  
  59. if ( jsmnload(buf, t, _JSMN_TOKEN_SIZE_, fuu_mkfstree) < 0 ) {
  60. printf("Error load configurationn");
  61. exit(-1);
  62. }
  63.  
  64. }
  65.  
  66. return 1;
  67. }
  68.  
  69. int main(int argc, char *argv[])
  70. {
  71. struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
  72.  
  73. memset(&conf, 0, sizeof(conf));
  74.  
  75. fuse_opt_parse(&args, &conf, myfs_opts, myfs_opt_proc);
  76.  
  77. return fuu_main(args.argc, args.argv);
  78. }
  79.  
  80. ./appendix/fuu /mnt/cdrom/ -c /mnt/fs.json
  81.  
  82. arg = /mnt/cdrom/ string (null) key = -2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement