xfs_da_format.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc.
  3. * Copyright (c) 2013 Red Hat, Inc.
  4. * All Rights Reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it would be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write the Free Software Foundation,
  17. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #include "xfs.h"
  20. #include "xfs_fs.h"
  21. #include "xfs_format.h"
  22. #include "xfs_log_format.h"
  23. #include "xfs_trans_resv.h"
  24. #include "xfs_sb.h"
  25. #include "xfs_ag.h"
  26. #include "xfs_mount.h"
  27. #include "xfs_da_format.h"
  28. #include "xfs_inode.h"
  29. #include "xfs_dir2.h"
  30. static int
  31. xfs_dir2_sf_entsize(
  32. struct xfs_dir2_sf_hdr *hdr,
  33. int len)
  34. {
  35. int count = sizeof(struct xfs_dir2_sf_entry); /* namelen + offset */
  36. count += len; /* name */
  37. count += hdr->i8count ? sizeof(xfs_dir2_ino8_t) :
  38. sizeof(xfs_dir2_ino4_t); /* ino # */
  39. return count;
  40. }
  41. static int
  42. xfs_dir3_sf_entsize(
  43. struct xfs_dir2_sf_hdr *hdr,
  44. int len)
  45. {
  46. return xfs_dir2_sf_entsize(hdr, len) + sizeof(__uint8_t);
  47. }
  48. static struct xfs_dir2_sf_entry *
  49. xfs_dir2_sf_nextentry(
  50. struct xfs_dir2_sf_hdr *hdr,
  51. struct xfs_dir2_sf_entry *sfep)
  52. {
  53. return (struct xfs_dir2_sf_entry *)
  54. ((char *)sfep + xfs_dir2_sf_entsize(hdr, sfep->namelen));
  55. }
  56. static struct xfs_dir2_sf_entry *
  57. xfs_dir3_sf_nextentry(
  58. struct xfs_dir2_sf_hdr *hdr,
  59. struct xfs_dir2_sf_entry *sfep)
  60. {
  61. return (struct xfs_dir2_sf_entry *)
  62. ((char *)sfep + xfs_dir3_sf_entsize(hdr, sfep->namelen));
  63. }
  64. const struct xfs_dir_ops xfs_dir2_ops = {
  65. .sf_entsize = xfs_dir2_sf_entsize,
  66. .sf_nextentry = xfs_dir2_sf_nextentry,
  67. };
  68. const struct xfs_dir_ops xfs_dir2_ftype_ops = {
  69. .sf_entsize = xfs_dir3_sf_entsize,
  70. .sf_nextentry = xfs_dir3_sf_nextentry,
  71. };
  72. const struct xfs_dir_ops xfs_dir3_ops = {
  73. .sf_entsize = xfs_dir3_sf_entsize,
  74. .sf_nextentry = xfs_dir3_sf_nextentry,
  75. };