options.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. * linux/fs/hfsplus/options.c
  3. *
  4. * Copyright (C) 2001
  5. * Brad Boyer (flar@allandria.com)
  6. * (C) 2003 Ardis Technologies <roman@ardistech.com>
  7. *
  8. * Option parsing
  9. */
  10. #include <linux/string.h>
  11. #include <linux/kernel.h>
  12. #include <linux/sched.h>
  13. #include <linux/parser.h>
  14. #include <linux/nls.h>
  15. #include <linux/mount.h>
  16. #include <linux/seq_file.h>
  17. #include <linux/slab.h>
  18. #include "hfsplus_fs.h"
  19. enum {
  20. opt_creator, opt_type,
  21. opt_umask, opt_uid, opt_gid,
  22. opt_part, opt_session, opt_nls,
  23. opt_nodecompose, opt_decompose,
  24. opt_barrier, opt_nobarrier,
  25. opt_force, opt_err
  26. };
  27. static const match_table_t tokens = {
  28. { opt_creator, "creator=%s" },
  29. { opt_type, "type=%s" },
  30. { opt_umask, "umask=%o" },
  31. { opt_uid, "uid=%u" },
  32. { opt_gid, "gid=%u" },
  33. { opt_part, "part=%u" },
  34. { opt_session, "session=%u" },
  35. { opt_nls, "nls=%s" },
  36. { opt_decompose, "decompose" },
  37. { opt_nodecompose, "nodecompose" },
  38. { opt_barrier, "barrier" },
  39. { opt_nobarrier, "nobarrier" },
  40. { opt_force, "force" },
  41. { opt_err, NULL }
  42. };
  43. /* Initialize an options object to reasonable defaults */
  44. void hfsplus_fill_defaults(struct hfsplus_sb_info *opts)
  45. {
  46. if (!opts)
  47. return;
  48. opts->creator = HFSPLUS_DEF_CR_TYPE;
  49. opts->type = HFSPLUS_DEF_CR_TYPE;
  50. opts->umask = current_umask();
  51. opts->uid = current_uid();
  52. opts->gid = current_gid();
  53. opts->part = -1;
  54. opts->session = -1;
  55. }
  56. /* convert a "four byte character" to a 32 bit int with error checks */
  57. static inline int match_fourchar(substring_t *arg, u32 *result)
  58. {
  59. if (arg->to - arg->from != 4)
  60. return -EINVAL;
  61. memcpy(result, arg->from, 4);
  62. return 0;
  63. }
  64. int hfsplus_parse_options_remount(char *input, int *force)
  65. {
  66. char *p;
  67. substring_t args[MAX_OPT_ARGS];
  68. int token;
  69. if (!input)
  70. return 0;
  71. while ((p = strsep(&input, ",")) != NULL) {
  72. if (!*p)
  73. continue;
  74. token = match_token(p, tokens, args);
  75. switch (token) {
  76. case opt_force:
  77. *force = 1;
  78. break;
  79. default:
  80. break;
  81. }
  82. }
  83. return 1;
  84. }
  85. /* Parse options from mount. Returns 0 on failure */
  86. /* input is the options passed to mount() as a string */
  87. int hfsplus_parse_options(char *input, struct hfsplus_sb_info *sbi)
  88. {
  89. char *p;
  90. substring_t args[MAX_OPT_ARGS];
  91. int tmp, token;
  92. if (!input)
  93. goto done;
  94. while ((p = strsep(&input, ",")) != NULL) {
  95. if (!*p)
  96. continue;
  97. token = match_token(p, tokens, args);
  98. switch (token) {
  99. case opt_creator:
  100. if (match_fourchar(&args[0], &sbi->creator)) {
  101. printk(KERN_ERR "hfs: creator requires a 4 character value\n");
  102. return 0;
  103. }
  104. break;
  105. case opt_type:
  106. if (match_fourchar(&args[0], &sbi->type)) {
  107. printk(KERN_ERR "hfs: type requires a 4 character value\n");
  108. return 0;
  109. }
  110. break;
  111. case opt_umask:
  112. if (match_octal(&args[0], &tmp)) {
  113. printk(KERN_ERR "hfs: umask requires a value\n");
  114. return 0;
  115. }
  116. sbi->umask = (umode_t)tmp;
  117. break;
  118. case opt_uid:
  119. if (match_int(&args[0], &tmp)) {
  120. printk(KERN_ERR "hfs: uid requires an argument\n");
  121. return 0;
  122. }
  123. sbi->uid = (uid_t)tmp;
  124. break;
  125. case opt_gid:
  126. if (match_int(&args[0], &tmp)) {
  127. printk(KERN_ERR "hfs: gid requires an argument\n");
  128. return 0;
  129. }
  130. sbi->gid = (gid_t)tmp;
  131. break;
  132. case opt_part:
  133. if (match_int(&args[0], &sbi->part)) {
  134. printk(KERN_ERR "hfs: part requires an argument\n");
  135. return 0;
  136. }
  137. break;
  138. case opt_session:
  139. if (match_int(&args[0], &sbi->session)) {
  140. printk(KERN_ERR "hfs: session requires an argument\n");
  141. return 0;
  142. }
  143. break;
  144. case opt_nls:
  145. if (sbi->nls) {
  146. printk(KERN_ERR "hfs: unable to change nls mapping\n");
  147. return 0;
  148. }
  149. p = match_strdup(&args[0]);
  150. if (p)
  151. sbi->nls = load_nls(p);
  152. if (!sbi->nls) {
  153. printk(KERN_ERR "hfs: unable to load "
  154. "nls mapping \"%s\"\n",
  155. p);
  156. kfree(p);
  157. return 0;
  158. }
  159. kfree(p);
  160. break;
  161. case opt_decompose:
  162. clear_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags);
  163. break;
  164. case opt_nodecompose:
  165. set_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags);
  166. break;
  167. case opt_barrier:
  168. clear_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags);
  169. break;
  170. case opt_nobarrier:
  171. set_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags);
  172. break;
  173. case opt_force:
  174. set_bit(HFSPLUS_SB_FORCE, &sbi->flags);
  175. break;
  176. default:
  177. return 0;
  178. }
  179. }
  180. done:
  181. if (!sbi->nls) {
  182. /* try utf8 first, as this is the old default behaviour */
  183. sbi->nls = load_nls("utf8");
  184. if (!sbi->nls)
  185. sbi->nls = load_nls_default();
  186. if (!sbi->nls)
  187. return 0;
  188. }
  189. return 1;
  190. }
  191. int hfsplus_show_options(struct seq_file *seq, struct dentry *root)
  192. {
  193. struct hfsplus_sb_info *sbi = HFSPLUS_SB(root->d_sb);
  194. if (sbi->creator != HFSPLUS_DEF_CR_TYPE)
  195. seq_show_option_n(seq, "creator", (char *)&sbi->creator, 4);
  196. if (sbi->type != HFSPLUS_DEF_CR_TYPE)
  197. seq_show_option_n(seq, "type", (char *)&sbi->type, 4);
  198. seq_printf(seq, ",umask=%o,uid=%u,gid=%u", sbi->umask,
  199. sbi->uid, sbi->gid);
  200. if (sbi->part >= 0)
  201. seq_printf(seq, ",part=%u", sbi->part);
  202. if (sbi->session >= 0)
  203. seq_printf(seq, ",session=%u", sbi->session);
  204. if (sbi->nls)
  205. seq_printf(seq, ",nls=%s", sbi->nls->charset);
  206. if (test_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags))
  207. seq_printf(seq, ",nodecompose");
  208. if (test_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags))
  209. seq_printf(seq, ",nobarrier");
  210. return 0;
  211. }