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/sched.h>
25 #include <linux/slab.h>
30 void udf_free_inode(struct inode
*inode
)
32 struct super_block
*sb
= inode
->i_sb
;
33 struct udf_sb_info
*sbi
= UDF_SB(sb
);
36 * Note: we must free any quota before locking the superblock,
37 * as writing the quota to disk may need the lock as well.
39 vfs_dq_free_inode(inode
);
44 mutex_lock(&sbi
->s_alloc_mutex
);
46 struct logicalVolIntegrityDescImpUse
*lvidiu
=
48 if (S_ISDIR(inode
->i_mode
))
49 le32_add_cpu(&lvidiu
->numDirs
, -1);
51 le32_add_cpu(&lvidiu
->numFiles
, -1);
53 mark_buffer_dirty(sbi
->s_lvid_bh
);
55 mutex_unlock(&sbi
->s_alloc_mutex
);
57 udf_free_blocks(sb
, NULL
, UDF_I(inode
)->i_location
, 0, 1);
60 struct inode
*udf_new_inode(struct inode
*dir
, int mode
, int *err
)
62 struct super_block
*sb
= dir
->i_sb
;
63 struct udf_sb_info
*sbi
= UDF_SB(sb
);
66 uint32_t start
= UDF_I(dir
)->i_location
.logicalBlockNum
;
67 struct udf_inode_info
*iinfo
;
68 struct udf_inode_info
*dinfo
= UDF_I(dir
);
70 inode
= new_inode(sb
);
79 if (UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_USE_EXTENDED_FE
)) {
81 if (UDF_VERS_USE_EXTENDED_FE
> sbi
->s_udfrev
)
82 sbi
->s_udfrev
= UDF_VERS_USE_EXTENDED_FE
;
83 iinfo
->i_ext
.i_data
= kzalloc(inode
->i_sb
->s_blocksize
-
84 sizeof(struct extendedFileEntry
),
88 iinfo
->i_ext
.i_data
= kzalloc(inode
->i_sb
->s_blocksize
-
89 sizeof(struct fileEntry
),
92 if (!iinfo
->i_ext
.i_data
) {
98 block
= udf_new_block(dir
->i_sb
, NULL
,
99 dinfo
->i_location
.partitionReferenceNum
,
106 mutex_lock(&sbi
->s_alloc_mutex
);
107 if (sbi
->s_lvid_bh
) {
108 struct logicalVolIntegrityDesc
*lvid
=
109 (struct logicalVolIntegrityDesc
*)
110 sbi
->s_lvid_bh
->b_data
;
111 struct logicalVolIntegrityDescImpUse
*lvidiu
=
113 struct logicalVolHeaderDesc
*lvhd
;
115 lvhd
= (struct logicalVolHeaderDesc
*)
116 (lvid
->logicalVolContentsUse
);
118 le32_add_cpu(&lvidiu
->numDirs
, 1);
120 le32_add_cpu(&lvidiu
->numFiles
, 1);
121 iinfo
->i_unique
= uniqueID
= le64_to_cpu(lvhd
->uniqueID
);
122 if (!(++uniqueID
& 0x00000000FFFFFFFFUL
))
124 lvhd
->uniqueID
= cpu_to_le64(uniqueID
);
125 mark_buffer_dirty(sbi
->s_lvid_bh
);
127 mutex_unlock(&sbi
->s_alloc_mutex
);
128 inode
->i_mode
= mode
;
129 inode
->i_uid
= current_fsuid();
130 if (dir
->i_mode
& S_ISGID
) {
131 inode
->i_gid
= dir
->i_gid
;
135 inode
->i_gid
= current_fsgid();
138 iinfo
->i_location
.logicalBlockNum
= block
;
139 iinfo
->i_location
.partitionReferenceNum
=
140 dinfo
->i_location
.partitionReferenceNum
;
141 inode
->i_ino
= udf_get_lb_pblock(sb
, iinfo
->i_location
, 0);
143 iinfo
->i_lenEAttr
= 0;
144 iinfo
->i_lenAlloc
= 0;
146 if (UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_USE_AD_IN_ICB
))
147 iinfo
->i_alloc_type
= ICBTAG_FLAG_AD_IN_ICB
;
148 else if (UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_USE_SHORT_AD
))
149 iinfo
->i_alloc_type
= ICBTAG_FLAG_AD_SHORT
;
151 iinfo
->i_alloc_type
= ICBTAG_FLAG_AD_LONG
;
152 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
=
153 iinfo
->i_crtime
= current_fs_time(inode
->i_sb
);
154 insert_inode_hash(inode
);
155 mark_inode_dirty(inode
);
157 if (vfs_dq_alloc_inode(inode
)) {
159 inode
->i_flags
|= S_NOQUOTA
;