options.c 4.2 KB

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