options.c 4.8 KB

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