ialloc.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. udf_pblk_t 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. if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_SET))
  96. inode->i_uid = sbi->s_uid;
  97. if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_SET))
  98. inode->i_gid = sbi->s_gid;
  99. iinfo->i_location.logicalBlockNum = block;
  100. iinfo->i_location.partitionReferenceNum =
  101. dinfo->i_location.partitionReferenceNum;
  102. inode->i_ino = udf_get_lb_pblock(sb, &iinfo->i_location, 0);
  103. inode->i_blocks = 0;
  104. iinfo->i_lenEAttr = 0;
  105. iinfo->i_lenAlloc = 0;
  106. iinfo->i_use = 0;
  107. iinfo->i_checkpoint = 1;
  108. if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_AD_IN_ICB))
  109. iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB;
  110. else if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
  111. iinfo->i_alloc_type = ICBTAG_FLAG_AD_SHORT;
  112. else
  113. iinfo->i_alloc_type = ICBTAG_FLAG_AD_LONG;
  114. inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
  115. iinfo->i_crtime = inode->i_mtime;
  116. if (unlikely(insert_inode_locked(inode) < 0)) {
  117. make_bad_inode(inode);
  118. iput(inode);
  119. return ERR_PTR(-EIO);
  120. }
  121. mark_inode_dirty(inode);
  122. return inode;
  123. }