options.c 4.4 KB

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