]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * ialloc.c | |
3 | * | |
4 | * PURPOSE | |
5 | * Inode allocation handling routines for the OSTA-UDF(tm) filesystem. | |
6 | * | |
1da177e4 LT |
7 | * COPYRIGHT |
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. | |
12 | * | |
13 | * (C) 1998-2001 Ben Fennema | |
14 | * | |
15 | * HISTORY | |
16 | * | |
17 | * 02/24/99 blf Created. | |
18 | * | |
19 | */ | |
20 | ||
21 | #include "udfdecl.h" | |
22 | #include <linux/fs.h> | |
23 | #include <linux/quotaops.h> | |
1da177e4 LT |
24 | #include <linux/sched.h> |
25 | #include <linux/slab.h> | |
26 | ||
27 | #include "udf_i.h" | |
28 | #include "udf_sb.h" | |
29 | ||
cb00ea35 | 30 | void udf_free_inode(struct inode *inode) |
1da177e4 LT |
31 | { |
32 | struct super_block *sb = inode->i_sb; | |
33 | struct udf_sb_info *sbi = UDF_SB(sb); | |
34 | ||
35 | /* | |
36 | * Note: we must free any quota before locking the superblock, | |
37 | * as writing the quota to disk may need the lock as well. | |
38 | */ | |
bacfb7c2 JK |
39 | vfs_dq_free_inode(inode); |
40 | vfs_dq_drop(inode); | |
1da177e4 LT |
41 | |
42 | clear_inode(inode); | |
43 | ||
1e7933de | 44 | mutex_lock(&sbi->s_alloc_mutex); |
6c79e987 MS |
45 | if (sbi->s_lvid_bh) { |
46 | struct logicalVolIntegrityDescImpUse *lvidiu = | |
47 | udf_sb_lvidiu(sbi); | |
1da177e4 | 48 | if (S_ISDIR(inode->i_mode)) |
c2104fda | 49 | le32_add_cpu(&lvidiu->numDirs, -1); |
1da177e4 | 50 | else |
c2104fda | 51 | le32_add_cpu(&lvidiu->numFiles, -1); |
146bca72 | 52 | udf_updated_lvid(sb); |
1da177e4 | 53 | } |
1e7933de | 54 | mutex_unlock(&sbi->s_alloc_mutex); |
1da177e4 | 55 | |
97e961fd | 56 | udf_free_blocks(sb, NULL, &UDF_I(inode)->i_location, 0, 1); |
1da177e4 LT |
57 | } |
58 | ||
cb00ea35 | 59 | struct inode *udf_new_inode(struct inode *dir, int mode, int *err) |
1da177e4 LT |
60 | { |
61 | struct super_block *sb = dir->i_sb; | |
62 | struct udf_sb_info *sbi = UDF_SB(sb); | |
cb00ea35 | 63 | struct inode *inode; |
1da177e4 | 64 | int block; |
c0b34438 | 65 | uint32_t start = UDF_I(dir)->i_location.logicalBlockNum; |
48d6d8ff MS |
66 | struct udf_inode_info *iinfo; |
67 | struct udf_inode_info *dinfo = UDF_I(dir); | |
1da177e4 LT |
68 | |
69 | inode = new_inode(sb); | |
70 | ||
cb00ea35 | 71 | if (!inode) { |
1da177e4 LT |
72 | *err = -ENOMEM; |
73 | return NULL; | |
74 | } | |
75 | *err = -ENOSPC; | |
76 | ||
48d6d8ff | 77 | iinfo = UDF_I(inode); |
97e1cfb0 JK |
78 | if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_EXTENDED_FE)) { |
79 | iinfo->i_efe = 1; | |
80 | if (UDF_VERS_USE_EXTENDED_FE > sbi->s_udfrev) | |
81 | sbi->s_udfrev = UDF_VERS_USE_EXTENDED_FE; | |
82 | iinfo->i_ext.i_data = kzalloc(inode->i_sb->s_blocksize - | |
83 | sizeof(struct extendedFileEntry), | |
84 | GFP_KERNEL); | |
85 | } else { | |
86 | iinfo->i_efe = 0; | |
87 | iinfo->i_ext.i_data = kzalloc(inode->i_sb->s_blocksize - | |
88 | sizeof(struct fileEntry), | |
89 | GFP_KERNEL); | |
90 | } | |
91 | if (!iinfo->i_ext.i_data) { | |
92 | iput(inode); | |
93 | *err = -ENOMEM; | |
94 | return NULL; | |
95 | } | |
225add61 | 96 | |
4b11111a | 97 | block = udf_new_block(dir->i_sb, NULL, |
48d6d8ff | 98 | dinfo->i_location.partitionReferenceNum, |
28de7948 | 99 | start, err); |
cb00ea35 | 100 | if (*err) { |
1da177e4 LT |
101 | iput(inode); |
102 | return NULL; | |
103 | } | |
104 | ||
1e7933de | 105 | mutex_lock(&sbi->s_alloc_mutex); |
6c79e987 | 106 | if (sbi->s_lvid_bh) { |
4b11111a MS |
107 | struct logicalVolIntegrityDesc *lvid = |
108 | (struct logicalVolIntegrityDesc *) | |
109 | sbi->s_lvid_bh->b_data; | |
110 | struct logicalVolIntegrityDescImpUse *lvidiu = | |
111 | udf_sb_lvidiu(sbi); | |
1da177e4 LT |
112 | struct logicalVolHeaderDesc *lvhd; |
113 | uint64_t uniqueID; | |
4b11111a MS |
114 | lvhd = (struct logicalVolHeaderDesc *) |
115 | (lvid->logicalVolContentsUse); | |
1da177e4 | 116 | if (S_ISDIR(mode)) |
c2104fda | 117 | le32_add_cpu(&lvidiu->numDirs, 1); |
1da177e4 | 118 | else |
c2104fda | 119 | le32_add_cpu(&lvidiu->numFiles, 1); |
48d6d8ff | 120 | iinfo->i_unique = uniqueID = le64_to_cpu(lvhd->uniqueID); |
1da177e4 LT |
121 | if (!(++uniqueID & 0x00000000FFFFFFFFUL)) |
122 | uniqueID += 16; | |
123 | lvhd->uniqueID = cpu_to_le64(uniqueID); | |
146bca72 | 124 | udf_updated_lvid(sb); |
1da177e4 | 125 | } |
db0badc5 | 126 | mutex_unlock(&sbi->s_alloc_mutex); |
1da177e4 | 127 | inode->i_mode = mode; |
7706bb39 | 128 | inode->i_uid = current_fsuid(); |
cb00ea35 | 129 | if (dir->i_mode & S_ISGID) { |
1da177e4 LT |
130 | inode->i_gid = dir->i_gid; |
131 | if (S_ISDIR(mode)) | |
132 | mode |= S_ISGID; | |
28de7948 | 133 | } else { |
7706bb39 | 134 | inode->i_gid = current_fsgid(); |
28de7948 | 135 | } |
1da177e4 | 136 | |
48d6d8ff MS |
137 | iinfo->i_location.logicalBlockNum = block; |
138 | iinfo->i_location.partitionReferenceNum = | |
139 | dinfo->i_location.partitionReferenceNum; | |
97e961fd | 140 | inode->i_ino = udf_get_lb_pblock(sb, &iinfo->i_location, 0); |
1da177e4 | 141 | inode->i_blocks = 0; |
48d6d8ff MS |
142 | iinfo->i_lenEAttr = 0; |
143 | iinfo->i_lenAlloc = 0; | |
144 | iinfo->i_use = 0; | |
1da177e4 | 145 | if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_AD_IN_ICB)) |
48d6d8ff | 146 | iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB; |
1da177e4 | 147 | else if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD)) |
48d6d8ff | 148 | iinfo->i_alloc_type = ICBTAG_FLAG_AD_SHORT; |
1da177e4 | 149 | else |
48d6d8ff | 150 | iinfo->i_alloc_type = ICBTAG_FLAG_AD_LONG; |
1da177e4 | 151 | inode->i_mtime = inode->i_atime = inode->i_ctime = |
48d6d8ff | 152 | iinfo->i_crtime = current_fs_time(inode->i_sb); |
1da177e4 LT |
153 | insert_inode_hash(inode); |
154 | mark_inode_dirty(inode); | |
1da177e4 | 155 | |
bacfb7c2 JK |
156 | if (vfs_dq_alloc_inode(inode)) { |
157 | vfs_dq_drop(inode); | |
1da177e4 LT |
158 | inode->i_flags |= S_NOQUOTA; |
159 | inode->i_nlink = 0; | |
160 | iput(inode); | |
161 | *err = -EDQUOT; | |
162 | return NULL; | |
163 | } | |
164 | ||
165 | *err = 0; | |
166 | return inode; | |
167 | } |