trans.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * linux/fs/hfs/trans.c
  3. *
  4. * Copyright (C) 1995-1997 Paul H. Hargrove
  5. * This file may be distributed under the terms of the GNU General Public License.
  6. *
  7. * This file contains routines for converting between the Macintosh
  8. * character set and various other encodings. This includes dealing
  9. * with ':' vs. '/' as the path-element separator.
  10. */
  11. #include "hfs_fs.h"
  12. /*================ Global functions ================*/
  13. /*
  14. * hfs_mac2triv()
  15. *
  16. * Given a 'Pascal String' (a string preceded by a length byte) in
  17. * the Macintosh character set produce the corresponding filename using
  18. * the 'trivial' name-mangling scheme, returning the length of the
  19. * mangled filename. Note that the output string is not NULL
  20. * terminated.
  21. *
  22. * The name-mangling works as follows:
  23. * The character '/', which is illegal in Linux filenames is replaced
  24. * by ':' which never appears in HFS filenames. All other characters
  25. * are passed unchanged from input to output.
  26. */
  27. int hfs_mac2triv(char *out, const struct hfs_name *in)
  28. {
  29. const char *p;
  30. char c;
  31. int i, len;
  32. len = in->len;
  33. p = in->name;
  34. for (i = 0; i < len; i++) {
  35. c = *p++;
  36. *out++ = c == '/' ? ':' : c;
  37. }
  38. return i;
  39. }
  40. /*
  41. * hfs_triv2mac()
  42. *
  43. * Given an ASCII string (not null-terminated) and its length,
  44. * generate the corresponding filename in the Macintosh character set
  45. * using the 'trivial' name-mangling scheme, returning the length of
  46. * the mangled filename. Note that the output string is not NULL
  47. * terminated.
  48. *
  49. * This routine is a inverse to hfs_mac2triv().
  50. * A ':' is replaced by a '/'.
  51. */
  52. void hfs_triv2mac(struct hfs_name *out, struct qstr *in)
  53. {
  54. const char *src;
  55. char *dst, c;
  56. int i, len;
  57. out->len = len = min((unsigned int)HFS_NAMELEN, in->len);
  58. src = in->name;
  59. dst = out->name;
  60. for (i = 0; i < len; i++) {
  61. c = *src++;
  62. *dst++ = c == ':' ? '/' : c;
  63. }
  64. for (; i < HFS_NAMELEN; i++)
  65. *dst++ = 0;
  66. }