5 * Inode allocation handling routines for the OSTA-UDF(tm) filesystem.
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
17 * 02/24/99 blf Created.
23 #include <linux/sched.h>
24 #include <linux/slab.h>
29 void udf_free_inode(struct inode *inode)
31 udf_free_blocks(inode->i_sb, NULL, &UDF_I(inode)->i_location, 0, 1);
34 struct inode *udf_new_inode(struct inode *dir, umode_t mode)
36 struct super_block *sb = dir->i_sb;
37 struct udf_sb_info *sbi = UDF_SB(sb);
40 uint32_t start = UDF_I(dir)->i_location.logicalBlockNum;
41 struct udf_inode_info *iinfo;
42 struct udf_inode_info *dinfo = UDF_I(dir);
45 inode = new_inode(sb);
48 return ERR_PTR(-ENOMEM);
51 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_EXTENDED_FE)) {
53 if (UDF_VERS_USE_EXTENDED_FE > sbi->s_udfrev)
54 sbi->s_udfrev = UDF_VERS_USE_EXTENDED_FE;
55 iinfo->i_data = kzalloc(inode->i_sb->s_blocksize -
56 sizeof(struct extendedFileEntry),
60 iinfo->i_data = kzalloc(inode->i_sb->s_blocksize -
61 sizeof(struct fileEntry),
65 make_bad_inode(inode);
67 return ERR_PTR(-ENOMEM);
71 block = udf_new_block(dir->i_sb, NULL,
72 dinfo->i_location.partitionReferenceNum,
75 make_bad_inode(inode);
80 iinfo->i_unique = lvid_get_unique_id(sb);
81 inode->i_generation = iinfo->i_unique;
83 inode_init_owner(&nop_mnt_idmap, inode, dir, mode);
84 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_SET))
85 inode->i_uid = sbi->s_uid;
86 if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_SET))
87 inode->i_gid = sbi->s_gid;
89 iinfo->i_location.logicalBlockNum = block;
90 iinfo->i_location.partitionReferenceNum =
91 dinfo->i_location.partitionReferenceNum;
92 inode->i_ino = udf_get_lb_pblock(sb, &iinfo->i_location, 0);
94 iinfo->i_lenEAttr = 0;
95 iinfo->i_lenAlloc = 0;
97 iinfo->i_checkpoint = 1;
98 iinfo->i_extraPerms = FE_PERM_U_CHATTR;
99 udf_update_extra_perms(inode, mode);
101 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_AD_IN_ICB))
102 iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB;
103 else if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
104 iinfo->i_alloc_type = ICBTAG_FLAG_AD_SHORT;
106 iinfo->i_alloc_type = ICBTAG_FLAG_AD_LONG;
107 inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
108 iinfo->i_crtime = inode->i_mtime;
109 if (unlikely(insert_inode_locked(inode) < 0)) {
110 make_bad_inode(inode);
112 return ERR_PTR(-EIO);
114 mark_inode_dirty(inode);