options.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 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->fs->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. sbi->nls = load_nls(p);
  126. if (!sbi->nls) {
  127. printk(KERN_ERR "hfs: unable to load nls mapping \"%s\"\n", p);
  128. kfree(p);
  129. return 0;
  130. }
  131. kfree(p);
  132. break;
  133. case opt_decompose:
  134. sbi->flags &= ~HFSPLUS_SB_NODECOMPOSE;
  135. break;
  136. case opt_nodecompose:
  137. sbi->flags |= HFSPLUS_SB_NODECOMPOSE;
  138. break;
  139. case opt_force:
  140. sbi->flags |= HFSPLUS_SB_FORCE;
  141. break;
  142. default:
  143. return 0;
  144. }
  145. }
  146. done:
  147. if (!sbi->nls) {
  148. /* try utf8 first, as this is the old default behaviour */
  149. sbi->nls = load_nls("utf8");
  150. if (!sbi->nls)
  151. sbi->nls = load_nls_default();
  152. if (!sbi->nls)
  153. return 0;
  154. }
  155. return 1;
  156. }
  157. int hfsplus_show_options(struct seq_file *seq, struct vfsmount *mnt)
  158. {
  159. struct hfsplus_sb_info *sbi = &HFSPLUS_SB(mnt->mnt_sb);
  160. if (sbi->creator != HFSPLUS_DEF_CR_TYPE)
  161. seq_printf(seq, ",creator=%.4s", (char *)&sbi->creator);
  162. if (sbi->type != HFSPLUS_DEF_CR_TYPE)
  163. seq_printf(seq, ",type=%.4s", (char *)&sbi->type);
  164. seq_printf(seq, ",umask=%o,uid=%u,gid=%u", sbi->umask, sbi->uid, sbi->gid);
  165. if (sbi->part >= 0)
  166. seq_printf(seq, ",part=%u", sbi->part);
  167. if (sbi->session >= 0)
  168. seq_printf(seq, ",session=%u", sbi->session);
  169. if (sbi->nls)
  170. seq_printf(seq, ",nls=%s", sbi->nls->charset);
  171. if (sbi->flags & HFSPLUS_SB_NODECOMPOSE)
  172. seq_printf(seq, ",nodecompose");
  173. return 0;
  174. }