Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
[linux/fpc-iii.git] / fs / udf / ialloc.c
blob6eaf5edf1ea1577e88cafc60184963e1b18df5a5
1 /*
2 * ialloc.c
4 * PURPOSE
5 * Inode allocation handling routines for the OSTA-UDF(tm) filesystem.
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.
13 * (C) 1998-2001 Ben Fennema
15 * HISTORY
17 * 02/24/99 blf Created.
21 #include "udfdecl.h"
22 #include <linux/fs.h>
23 #include <linux/sched.h>
24 #include <linux/slab.h>
26 #include "udf_i.h"
27 #include "udf_sb.h"
29 void udf_free_inode(struct inode *inode)
31 struct super_block *sb = inode->i_sb;
32 struct udf_sb_info *sbi = UDF_SB(sb);
33 struct logicalVolIntegrityDescImpUse *lvidiu = udf_sb_lvidiu(sb);
35 if (lvidiu) {
36 mutex_lock(&sbi->s_alloc_mutex);
37 if (S_ISDIR(inode->i_mode))
38 le32_add_cpu(&lvidiu->numDirs, -1);
39 else
40 le32_add_cpu(&lvidiu->numFiles, -1);
41 udf_updated_lvid(sb);
42 mutex_unlock(&sbi->s_alloc_mutex);
45 udf_free_blocks(sb, NULL, &UDF_I(inode)->i_location, 0, 1);
48 struct inode *udf_new_inode(struct inode *dir, umode_t mode, int *err)
50 struct super_block *sb = dir->i_sb;
51 struct udf_sb_info *sbi = UDF_SB(sb);
52 struct inode *inode;
53 int block;
54 uint32_t start = UDF_I(dir)->i_location.logicalBlockNum;
55 struct udf_inode_info *iinfo;
56 struct udf_inode_info *dinfo = UDF_I(dir);
57 struct logicalVolIntegrityDescImpUse *lvidiu;
59 inode = new_inode(sb);
61 if (!inode) {
62 *err = -ENOMEM;
63 return NULL;
65 *err = -ENOSPC;
67 iinfo = UDF_I(inode);
68 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_EXTENDED_FE)) {
69 iinfo->i_efe = 1;
70 if (UDF_VERS_USE_EXTENDED_FE > sbi->s_udfrev)
71 sbi->s_udfrev = UDF_VERS_USE_EXTENDED_FE;
72 iinfo->i_ext.i_data = kzalloc(inode->i_sb->s_blocksize -
73 sizeof(struct extendedFileEntry),
74 GFP_KERNEL);
75 } else {
76 iinfo->i_efe = 0;
77 iinfo->i_ext.i_data = kzalloc(inode->i_sb->s_blocksize -
78 sizeof(struct fileEntry),
79 GFP_KERNEL);
81 if (!iinfo->i_ext.i_data) {
82 iput(inode);
83 *err = -ENOMEM;
84 return NULL;
87 block = udf_new_block(dir->i_sb, NULL,
88 dinfo->i_location.partitionReferenceNum,
89 start, err);
90 if (*err) {
91 iput(inode);
92 return NULL;
95 lvidiu = udf_sb_lvidiu(sb);
96 if (lvidiu) {
97 iinfo->i_unique = lvid_get_unique_id(sb);
98 mutex_lock(&sbi->s_alloc_mutex);
99 if (S_ISDIR(mode))
100 le32_add_cpu(&lvidiu->numDirs, 1);
101 else
102 le32_add_cpu(&lvidiu->numFiles, 1);
103 udf_updated_lvid(sb);
104 mutex_unlock(&sbi->s_alloc_mutex);
107 inode_init_owner(inode, dir, mode);
109 iinfo->i_location.logicalBlockNum = block;
110 iinfo->i_location.partitionReferenceNum =
111 dinfo->i_location.partitionReferenceNum;
112 inode->i_ino = udf_get_lb_pblock(sb, &iinfo->i_location, 0);
113 inode->i_blocks = 0;
114 iinfo->i_lenEAttr = 0;
115 iinfo->i_lenAlloc = 0;
116 iinfo->i_use = 0;
117 iinfo->i_checkpoint = 1;
118 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_AD_IN_ICB))
119 iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB;
120 else if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
121 iinfo->i_alloc_type = ICBTAG_FLAG_AD_SHORT;
122 else
123 iinfo->i_alloc_type = ICBTAG_FLAG_AD_LONG;
124 inode->i_mtime = inode->i_atime = inode->i_ctime =
125 iinfo->i_crtime = current_fs_time(inode->i_sb);
126 insert_inode_hash(inode);
127 mark_inode_dirty(inode);
129 *err = 0;
130 return inode;