ialloc.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * ialloc.c
  3. *
  4. * PURPOSE
  5. * Inode allocation handling routines for the OSTA-UDF(tm) filesystem.
  6. *
  7. * COPYRIGHT
  8. * This file is distributed under the terms of the GNU General Public
  9. * License (GPL). Copies of the GPL can be obtained from:
  10. * ftp://prep.ai.mit.edu/pub/gnu/GPL
  11. * Each contributing author retains all rights to their own work.
  12. *
  13. * (C) 1998-2001 Ben Fennema
  14. *
  15. * HISTORY
  16. *
  17. * 02/24/99 blf Created.
  18. *
  19. */
  20. #include "udfdecl.h"
  21. #include <linux/fs.h>
  22. #include <linux/sched.h>
  23. #include <linux/slab.h>
  24. #include "udf_i.h"
  25. #include "udf_sb.h"
  26. void udf_free_inode(struct inode *inode)
  27. {
  28. struct super_block *sb = inode->i_sb;
  29. struct udf_sb_info *sbi = UDF_SB(sb);
  30. struct logicalVolIntegrityDescImpUse *lvidiu = udf_sb_lvidiu(sb);
  31. if (lvidiu) {
  32. mutex_lock(&sbi->s_alloc_mutex);
  33. if (S_ISDIR(inode->i_mode))
  34. le32_add_cpu(&lvidiu->numDirs, -1);
  35. else
  36. le32_add_cpu(&lvidiu->numFiles, -1);
  37. udf_updated_lvid(sb);
  38. mutex_unlock(&sbi->s_alloc_mutex);
  39. }
  40. udf_free_blocks(sb, NULL, &UDF_I(inode)->i_location, 0, 1);
  41. }
  42. struct inode *udf_new_inode(struct inode *dir, umode_t mode)
  43. {
  44. struct super_block *sb = dir->i_sb;
  45. struct udf_sb_info *sbi = UDF_SB(sb);
  46. struct inode *inode;
  47. int block;
  48. uint32_t start = UDF_I(dir)->i_location.logicalBlockNum;
  49. struct udf_inode_info *iinfo;
  50. struct udf_inode_info *dinfo = UDF_I(dir);
  51. struct logicalVolIntegrityDescImpUse *lvidiu;
  52. int err;
  53. inode = new_inode(sb);
  54. if (!inode)
  55. return ERR_PTR(-ENOMEM);
  56. iinfo = UDF_I(inode);
  57. if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_EXTENDED_FE)) {
  58. iinfo->i_efe = 1;
  59. if (UDF_VERS_USE_EXTENDED_FE > sbi->s_udfrev)
  60. sbi->s_udfrev = UDF_VERS_USE_EXTENDED_FE;
  61. iinfo->i_ext.i_data = kzalloc(inode->i_sb->s_blocksize -
  62. sizeof(struct extendedFileEntry),
  63. GFP_KERNEL);
  64. } else {
  65. iinfo->i_efe = 0;
  66. iinfo->i_ext.i_data = kzalloc(inode->i_sb->s_blocksize -
  67. sizeof(struct fileEntry),
  68. GFP_KERNEL);
  69. }
  70. if (!iinfo->i_ext.i_data) {
  71. iput(inode);
  72. return ERR_PTR(-ENOMEM);
  73. }
  74. err = -ENOSPC;
  75. block = udf_new_block(dir->i_sb, NULL,
  76. dinfo->i_location.partitionReferenceNum,
  77. start, &err);
  78. if (err) {
  79. iput(inode);
  80. return ERR_PTR(err);
  81. }
  82. lvidiu = udf_sb_lvidiu(sb);
  83. if (lvidiu) {
  84. iinfo->i_unique = lvid_get_unique_id(sb);
  85. inode->i_generation = iinfo->i_unique;
  86. mutex_lock(&sbi->s_alloc_mutex);
  87. if (S_ISDIR(mode))
  88. le32_add_cpu(&lvidiu->numDirs, 1);
  89. else
  90. le32_add_cpu(&lvidiu->numFiles, 1);
  91. udf_updated_lvid(sb);
  92. mutex_unlock(&sbi->s_alloc_mutex);
  93. }
  94. inode_init_owner(inode, dir, mode);
  95. iinfo->i_location.logicalBlockNum = block;
  96. iinfo->i_location.partitionReferenceNum =
  97. dinfo->i_location.partitionReferenceNum;
  98. inode->i_ino = udf_get_lb_pblock(sb, &iinfo->i_location, 0);
  99. inode->i_blocks = 0;
  100. iinfo->i_lenEAttr = 0;
  101. iinfo->i_lenAlloc = 0;
  102. iinfo->i_use = 0;
  103. iinfo->i_checkpoint = 1;
  104. if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_AD_IN_ICB))
  105. iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB;
  106. else if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
  107. iinfo->i_alloc_type = ICBTAG_FLAG_AD_SHORT;
  108. else
  109. iinfo->i_alloc_type = ICBTAG_FLAG_AD_LONG;
  110. inode->i_mtime = inode->i_atime = inode->i_ctime =
  111. iinfo->i_crtime = current_fs_time(inode->i_sb);
  112. if (unlikely(insert_inode_locked(inode) < 0)) {
  113. make_bad_inode(inode);
  114. iput(inode);
  115. return ERR_PTR(-EIO);
  116. }
  117. mark_inode_dirty(inode);
  118. return inode;
  119. }