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
);
36 mutex_lock(&sbi
->s_alloc_mutex
);
38 struct logicalVolIntegrityDescImpUse
*lvidiu
=
40 if (S_ISDIR(inode
->i_mode
))
41 le32_add_cpu(&lvidiu
->numDirs
, -1);
43 le32_add_cpu(&lvidiu
->numFiles
, -1);
46 mutex_unlock(&sbi
->s_alloc_mutex
);
48 udf_free_blocks(sb
, NULL
, &UDF_I(inode
)->i_location
, 0, 1);
51 struct inode
*udf_new_inode(struct inode
*dir
, int mode
, int *err
)
53 struct super_block
*sb
= dir
->i_sb
;
54 struct udf_sb_info
*sbi
= UDF_SB(sb
);
57 uint32_t start
= UDF_I(dir
)->i_location
.logicalBlockNum
;
58 struct udf_inode_info
*iinfo
;
59 struct udf_inode_info
*dinfo
= UDF_I(dir
);
61 inode
= new_inode(sb
);
70 if (UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_USE_EXTENDED_FE
)) {
72 if (UDF_VERS_USE_EXTENDED_FE
> sbi
->s_udfrev
)
73 sbi
->s_udfrev
= UDF_VERS_USE_EXTENDED_FE
;
74 iinfo
->i_ext
.i_data
= kzalloc(inode
->i_sb
->s_blocksize
-
75 sizeof(struct extendedFileEntry
),
79 iinfo
->i_ext
.i_data
= kzalloc(inode
->i_sb
->s_blocksize
-
80 sizeof(struct fileEntry
),
83 if (!iinfo
->i_ext
.i_data
) {
89 block
= udf_new_block(dir
->i_sb
, NULL
,
90 dinfo
->i_location
.partitionReferenceNum
,
97 mutex_lock(&sbi
->s_alloc_mutex
);
99 struct logicalVolIntegrityDesc
*lvid
=
100 (struct logicalVolIntegrityDesc
*)
101 sbi
->s_lvid_bh
->b_data
;
102 struct logicalVolIntegrityDescImpUse
*lvidiu
=
104 struct logicalVolHeaderDesc
*lvhd
;
106 lvhd
= (struct logicalVolHeaderDesc
*)
107 (lvid
->logicalVolContentsUse
);
109 le32_add_cpu(&lvidiu
->numDirs
, 1);
111 le32_add_cpu(&lvidiu
->numFiles
, 1);
112 iinfo
->i_unique
= uniqueID
= le64_to_cpu(lvhd
->uniqueID
);
113 if (!(++uniqueID
& 0x00000000FFFFFFFFUL
))
115 lvhd
->uniqueID
= cpu_to_le64(uniqueID
);
116 udf_updated_lvid(sb
);
118 mutex_unlock(&sbi
->s_alloc_mutex
);
120 inode_init_owner(inode
, dir
, mode
);
122 iinfo
->i_location
.logicalBlockNum
= block
;
123 iinfo
->i_location
.partitionReferenceNum
=
124 dinfo
->i_location
.partitionReferenceNum
;
125 inode
->i_ino
= udf_get_lb_pblock(sb
, &iinfo
->i_location
, 0);
127 iinfo
->i_lenEAttr
= 0;
128 iinfo
->i_lenAlloc
= 0;
130 if (UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_USE_AD_IN_ICB
))
131 iinfo
->i_alloc_type
= ICBTAG_FLAG_AD_IN_ICB
;
132 else if (UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_USE_SHORT_AD
))
133 iinfo
->i_alloc_type
= ICBTAG_FLAG_AD_SHORT
;
135 iinfo
->i_alloc_type
= ICBTAG_FLAG_AD_LONG
;
136 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
=
137 iinfo
->i_crtime
= current_fs_time(inode
->i_sb
);
138 insert_inode_hash(inode
);
139 mark_inode_dirty(inode
);