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/quotaops.h>
24 #include <linux/udf_fs.h>
25 #include <linux/sched.h>
26 #include <linux/slab.h>
31 void udf_free_inode(struct inode
*inode
)
33 struct super_block
*sb
= inode
->i_sb
;
34 struct udf_sb_info
*sbi
= UDF_SB(sb
);
37 * Note: we must free any quota before locking the superblock,
38 * as writing the quota to disk may need the lock as well.
40 DQUOT_FREE_INODE(inode
);
45 mutex_lock(&sbi
->s_alloc_mutex
);
47 struct logicalVolIntegrityDescImpUse
*lvidiu
=
49 if (S_ISDIR(inode
->i_mode
))
51 cpu_to_le32(le32_to_cpu(lvidiu
->numDirs
) - 1);
54 cpu_to_le32(le32_to_cpu(lvidiu
->numFiles
) - 1);
56 mark_buffer_dirty(sbi
->s_lvid_bh
);
58 mutex_unlock(&sbi
->s_alloc_mutex
);
60 udf_free_blocks(sb
, NULL
, UDF_I(inode
)->i_location
, 0, 1);
63 struct inode
*udf_new_inode(struct inode
*dir
, int mode
, int *err
)
65 struct super_block
*sb
= dir
->i_sb
;
66 struct udf_sb_info
*sbi
= UDF_SB(sb
);
69 uint32_t start
= UDF_I(dir
)->i_location
.logicalBlockNum
;
70 struct udf_inode_info
*iinfo
;
71 struct udf_inode_info
*dinfo
= UDF_I(dir
);
73 inode
= new_inode(sb
);
83 iinfo
->i_lenExtents
= 0;
84 iinfo
->i_next_alloc_block
= 0;
85 iinfo
->i_next_alloc_goal
= 0;
86 iinfo
->i_strat4096
= 0;
88 block
= udf_new_block(dir
->i_sb
, NULL
,
89 dinfo
->i_location
.partitionReferenceNum
,
96 mutex_lock(&sbi
->s_alloc_mutex
);
98 struct logicalVolIntegrityDesc
*lvid
=
99 (struct logicalVolIntegrityDesc
*)
100 sbi
->s_lvid_bh
->b_data
;
101 struct logicalVolIntegrityDescImpUse
*lvidiu
=
103 struct logicalVolHeaderDesc
*lvhd
;
105 lvhd
= (struct logicalVolHeaderDesc
*)
106 (lvid
->logicalVolContentsUse
);
109 cpu_to_le32(le32_to_cpu(lvidiu
->numDirs
) + 1);
112 cpu_to_le32(le32_to_cpu(lvidiu
->numFiles
) + 1);
113 iinfo
->i_unique
= uniqueID
= le64_to_cpu(lvhd
->uniqueID
);
114 if (!(++uniqueID
& 0x00000000FFFFFFFFUL
))
116 lvhd
->uniqueID
= cpu_to_le64(uniqueID
);
117 mark_buffer_dirty(sbi
->s_lvid_bh
);
119 inode
->i_mode
= mode
;
120 inode
->i_uid
= current
->fsuid
;
121 if (dir
->i_mode
& S_ISGID
) {
122 inode
->i_gid
= dir
->i_gid
;
126 inode
->i_gid
= current
->fsgid
;
129 iinfo
->i_location
.logicalBlockNum
= block
;
130 iinfo
->i_location
.partitionReferenceNum
=
131 dinfo
->i_location
.partitionReferenceNum
;
132 inode
->i_ino
= udf_get_lb_pblock(sb
, iinfo
->i_location
, 0);
134 iinfo
->i_lenEAttr
= 0;
135 iinfo
->i_lenAlloc
= 0;
137 if (UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_USE_EXTENDED_FE
)) {
139 if (UDF_VERS_USE_EXTENDED_FE
> sbi
->s_udfrev
)
140 sbi
->s_udfrev
= UDF_VERS_USE_EXTENDED_FE
;
141 iinfo
->i_ext
.i_data
= kzalloc(inode
->i_sb
->s_blocksize
-
142 sizeof(struct extendedFileEntry
),
146 iinfo
->i_ext
.i_data
= kzalloc(inode
->i_sb
->s_blocksize
-
147 sizeof(struct fileEntry
),
150 if (!iinfo
->i_ext
.i_data
) {
153 mutex_unlock(&sbi
->s_alloc_mutex
);
156 if (UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_USE_AD_IN_ICB
))
157 iinfo
->i_alloc_type
= ICBTAG_FLAG_AD_IN_ICB
;
158 else if (UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_USE_SHORT_AD
))
159 iinfo
->i_alloc_type
= ICBTAG_FLAG_AD_SHORT
;
161 iinfo
->i_alloc_type
= ICBTAG_FLAG_AD_LONG
;
162 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
=
163 iinfo
->i_crtime
= current_fs_time(inode
->i_sb
);
164 insert_inode_hash(inode
);
165 mark_inode_dirty(inode
);
166 mutex_unlock(&sbi
->s_alloc_mutex
);
168 if (DQUOT_ALLOC_INODE(inode
)) {
170 inode
->i_flags
|= S_NOQUOTA
;