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 struct super_block
*sb
= inode
->i_sb
;
32 struct udf_sb_info
*sbi
= UDF_SB(sb
);
34 mutex_lock(&sbi
->s_alloc_mutex
);
36 struct logicalVolIntegrityDescImpUse
*lvidiu
=
38 if (S_ISDIR(inode
->i_mode
))
39 le32_add_cpu(&lvidiu
->numDirs
, -1);
41 le32_add_cpu(&lvidiu
->numFiles
, -1);
44 mutex_unlock(&sbi
->s_alloc_mutex
);
46 udf_free_blocks(sb
, NULL
, &UDF_I(inode
)->i_location
, 0, 1);
49 struct inode
*udf_new_inode(struct inode
*dir
, int mode
, int *err
)
51 struct super_block
*sb
= dir
->i_sb
;
52 struct udf_sb_info
*sbi
= UDF_SB(sb
);
55 uint32_t start
= UDF_I(dir
)->i_location
.logicalBlockNum
;
56 struct udf_inode_info
*iinfo
;
57 struct udf_inode_info
*dinfo
= UDF_I(dir
);
59 inode
= new_inode(sb
);
68 if (UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_USE_EXTENDED_FE
)) {
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
),
77 iinfo
->i_ext
.i_data
= kzalloc(inode
->i_sb
->s_blocksize
-
78 sizeof(struct fileEntry
),
81 if (!iinfo
->i_ext
.i_data
) {
87 block
= udf_new_block(dir
->i_sb
, NULL
,
88 dinfo
->i_location
.partitionReferenceNum
,
95 mutex_lock(&sbi
->s_alloc_mutex
);
97 struct logicalVolIntegrityDesc
*lvid
=
98 (struct logicalVolIntegrityDesc
*)
99 sbi
->s_lvid_bh
->b_data
;
100 struct logicalVolIntegrityDescImpUse
*lvidiu
=
102 struct logicalVolHeaderDesc
*lvhd
;
104 lvhd
= (struct logicalVolHeaderDesc
*)
105 (lvid
->logicalVolContentsUse
);
107 le32_add_cpu(&lvidiu
->numDirs
, 1);
109 le32_add_cpu(&lvidiu
->numFiles
, 1);
110 iinfo
->i_unique
= uniqueID
= le64_to_cpu(lvhd
->uniqueID
);
111 if (!(++uniqueID
& 0x00000000FFFFFFFFUL
))
113 lvhd
->uniqueID
= cpu_to_le64(uniqueID
);
114 udf_updated_lvid(sb
);
116 mutex_unlock(&sbi
->s_alloc_mutex
);
118 inode_init_owner(inode
, dir
, mode
);
120 iinfo
->i_location
.logicalBlockNum
= block
;
121 iinfo
->i_location
.partitionReferenceNum
=
122 dinfo
->i_location
.partitionReferenceNum
;
123 inode
->i_ino
= udf_get_lb_pblock(sb
, &iinfo
->i_location
, 0);
125 iinfo
->i_lenEAttr
= 0;
126 iinfo
->i_lenAlloc
= 0;
128 if (UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_USE_AD_IN_ICB
))
129 iinfo
->i_alloc_type
= ICBTAG_FLAG_AD_IN_ICB
;
130 else if (UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_USE_SHORT_AD
))
131 iinfo
->i_alloc_type
= ICBTAG_FLAG_AD_SHORT
;
133 iinfo
->i_alloc_type
= ICBTAG_FLAG_AD_LONG
;
134 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
=
135 iinfo
->i_crtime
= current_fs_time(inode
->i_sb
);
136 insert_inode_hash(inode
);
137 mark_inode_dirty(inode
);