ialloc.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. mutex_lock(&sbi->s_alloc_mutex);
  31. if (sbi->s_lvid_bh) {
  32. struct logicalVolIntegrityDescImpUse *lvidiu =
  33. udf_sb_lvidiu(sbi);
  34. if (S_ISDIR(inode->i_mode))
  35. le32_add_cpu(&lvidiu->numDirs, -1);
  36. else
  37. le32_add_cpu(&lvidiu->numFiles, -1);
  38. udf_updated_lvid(sb);
  39. }
  40. mutex_unlock(&sbi->s_alloc_mutex);
  41. udf_free_blocks(sb, NULL, &UDF_I(inode)->i_location, 0, 1);
  42. }
  43. struct inode *udf_new_inode(struct inode *dir, umode_t mode, int *err)
  44. {
  45. struct super_block *sb = dir->i_sb;
  46. struct udf_sb_info *sbi = UDF_SB(sb);
  47. struct inode *inode;
  48. int block;
  49. uint32_t start = UDF_I(dir)->i_location.logicalBlockNum;
  50. struct udf_inode_info *iinfo;
  51. struct udf_inode_info *dinfo = UDF_I(dir);
  52. inode = new_inode(sb);
  53. if (!inode) {
  54. *err = -ENOMEM;
  55. return NULL;
  56. }
  57. *err = -ENOSPC;
  58. iinfo = UDF_I(inode);
  59. if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_EXTENDED_FE)) {
  60. iinfo->i_efe = 1;
  61. if (UDF_VERS_USE_EXTENDED_FE > sbi->s_udfrev)
  62. sbi->s_udfrev = UDF_VERS_USE_EXTENDED_FE;
  63. iinfo->i_ext.i_data = kzalloc(inode->i_sb->s_blocksize -
  64. sizeof(struct extendedFileEntry),
  65. GFP_KERNEL);
  66. } else {
  67. iinfo->i_efe = 0;
  68. iinfo->i_ext.i_data = kzalloc(inode->i_sb->s_blocksize -
  69. sizeof(struct fileEntry),
  70. GFP_KERNEL);
  71. }
  72. if (!iinfo->i_ext.i_data) {
  73. iput(inode);
  74. *err = -ENOMEM;
  75. return NULL;
  76. }
  77. block = udf_new_block(dir->i_sb, NULL,
  78. dinfo->i_location.partitionReferenceNum,
  79. start, err);
  80. if (*err) {
  81. iput(inode);
  82. return NULL;
  83. }
  84. if (sbi->s_lvid_bh) {
  85. struct logicalVolIntegrityDescImpUse *lvidiu;
  86. iinfo->i_unique = lvid_get_unique_id(sb);
  87. mutex_lock(&sbi->s_alloc_mutex);
  88. lvidiu = udf_sb_lvidiu(sbi);
  89. if (S_ISDIR(mode))
  90. le32_add_cpu(&lvidiu->numDirs, 1);
  91. else
  92. le32_add_cpu(&lvidiu->numFiles, 1);
  93. udf_updated_lvid(sb);
  94. mutex_unlock(&sbi->s_alloc_mutex);
  95. }
  96. inode_init_owner(inode, dir, mode);
  97. iinfo->i_location.logicalBlockNum = block;
  98. iinfo->i_location.partitionReferenceNum =
  99. dinfo->i_location.partitionReferenceNum;
  100. inode->i_ino = udf_get_lb_pblock(sb, &iinfo->i_location, 0);
  101. inode->i_blocks = 0;
  102. iinfo->i_lenEAttr = 0;
  103. iinfo->i_lenAlloc = 0;
  104. iinfo->i_use = 0;
  105. iinfo->i_checkpoint = 1;
  106. if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_AD_IN_ICB))
  107. iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB;
  108. else if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
  109. iinfo->i_alloc_type = ICBTAG_FLAG_AD_SHORT;
  110. else
  111. iinfo->i_alloc_type = ICBTAG_FLAG_AD_LONG;
  112. inode->i_mtime = inode->i_atime = inode->i_ctime =
  113. iinfo->i_crtime = current_fs_time(inode->i_sb);
  114. insert_inode_hash(inode);
  115. mark_inode_dirty(inode);
  116. *err = 0;
  117. return inode;
  118. }