1 // SPDX-License-Identifier: GPL-2.0-only
6 * Inode allocation handling routines for the OSTA-UDF(tm) filesystem.
9 * (C) 1998-2001 Ben Fennema
13 * 02/24/99 blf Created.
19 #include <linux/sched.h>
20 #include <linux/slab.h>
25 void udf_free_inode(struct inode
*inode
)
27 udf_free_blocks(inode
->i_sb
, NULL
, &UDF_I(inode
)->i_location
, 0, 1);
30 struct inode
*udf_new_inode(struct inode
*dir
, umode_t mode
)
32 struct super_block
*sb
= dir
->i_sb
;
33 struct udf_sb_info
*sbi
= UDF_SB(sb
);
36 uint32_t start
= UDF_I(dir
)->i_location
.logicalBlockNum
;
37 struct udf_inode_info
*iinfo
;
38 struct udf_inode_info
*dinfo
= UDF_I(dir
);
41 inode
= new_inode(sb
);
44 return ERR_PTR(-ENOMEM
);
47 if (UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_USE_EXTENDED_FE
)) {
49 if (UDF_VERS_USE_EXTENDED_FE
> sbi
->s_udfrev
)
50 sbi
->s_udfrev
= UDF_VERS_USE_EXTENDED_FE
;
51 iinfo
->i_data
= kzalloc(inode
->i_sb
->s_blocksize
-
52 sizeof(struct extendedFileEntry
),
56 iinfo
->i_data
= kzalloc(inode
->i_sb
->s_blocksize
-
57 sizeof(struct fileEntry
),
61 make_bad_inode(inode
);
63 return ERR_PTR(-ENOMEM
);
67 block
= udf_new_block(dir
->i_sb
, NULL
,
68 dinfo
->i_location
.partitionReferenceNum
,
71 make_bad_inode(inode
);
76 iinfo
->i_unique
= lvid_get_unique_id(sb
);
77 inode
->i_generation
= iinfo
->i_unique
;
79 inode_init_owner(&nop_mnt_idmap
, inode
, dir
, mode
);
80 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UID_SET
))
81 inode
->i_uid
= sbi
->s_uid
;
82 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_GID_SET
))
83 inode
->i_gid
= sbi
->s_gid
;
85 iinfo
->i_location
.logicalBlockNum
= block
;
86 iinfo
->i_location
.partitionReferenceNum
=
87 dinfo
->i_location
.partitionReferenceNum
;
88 inode
->i_ino
= udf_get_lb_pblock(sb
, &iinfo
->i_location
, 0);
90 iinfo
->i_lenEAttr
= 0;
91 iinfo
->i_lenAlloc
= 0;
93 iinfo
->i_checkpoint
= 1;
94 iinfo
->i_extraPerms
= FE_PERM_U_CHATTR
;
95 udf_update_extra_perms(inode
, mode
);
97 if (UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_USE_AD_IN_ICB
))
98 iinfo
->i_alloc_type
= ICBTAG_FLAG_AD_IN_ICB
;
99 else if (UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_USE_SHORT_AD
))
100 iinfo
->i_alloc_type
= ICBTAG_FLAG_AD_SHORT
;
102 iinfo
->i_alloc_type
= ICBTAG_FLAG_AD_LONG
;
103 simple_inode_init_ts(inode
);
104 iinfo
->i_crtime
= inode_get_mtime(inode
);
105 if (unlikely(insert_inode_locked(inode
) < 0)) {
106 make_bad_inode(inode
);
108 return ERR_PTR(-EIO
);
110 mark_inode_dirty(inode
);