]>
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> | |
1da177e4 LT |
23 | #include <linux/sched.h> |
24 | #include <linux/slab.h> | |
25 | ||
26 | #include "udf_i.h" | |
27 | #include "udf_sb.h" | |
28 | ||
cb00ea35 | 29 | void udf_free_inode(struct inode *inode) |
1da177e4 LT |
30 | { |
31 | struct super_block *sb = inode->i_sb; | |
32 | struct udf_sb_info *sbi = UDF_SB(sb); | |
33 | ||
1e7933de | 34 | mutex_lock(&sbi->s_alloc_mutex); |
6c79e987 MS |
35 | if (sbi->s_lvid_bh) { |
36 | struct logicalVolIntegrityDescImpUse *lvidiu = | |
37 | udf_sb_lvidiu(sbi); | |
1da177e4 | 38 | if (S_ISDIR(inode->i_mode)) |
c2104fda | 39 | le32_add_cpu(&lvidiu->numDirs, -1); |
1da177e4 | 40 | else |
c2104fda | 41 | le32_add_cpu(&lvidiu->numFiles, -1); |
146bca72 | 42 | udf_updated_lvid(sb); |
1da177e4 | 43 | } |
1e7933de | 44 | mutex_unlock(&sbi->s_alloc_mutex); |
1da177e4 | 45 | |
97e961fd | 46 | udf_free_blocks(sb, NULL, &UDF_I(inode)->i_location, 0, 1); |
1da177e4 LT |
47 | } |
48 | ||
cb00ea35 | 49 | struct inode *udf_new_inode(struct inode *dir, int mode, int *err) |
1da177e4 LT |
50 | { |
51 | struct super_block *sb = dir->i_sb; | |
52 | struct udf_sb_info *sbi = UDF_SB(sb); | |
cb00ea35 | 53 | struct inode *inode; |
36350462 | 54 | int block; |
c0b34438 | 55 | uint32_t start = UDF_I(dir)->i_location.logicalBlockNum; |
48d6d8ff MS |
56 | struct udf_inode_info *iinfo; |
57 | struct udf_inode_info *dinfo = UDF_I(dir); | |
1da177e4 LT |
58 | |
59 | inode = new_inode(sb); | |
60 | ||
cb00ea35 | 61 | if (!inode) { |
1da177e4 LT |
62 | *err = -ENOMEM; |
63 | return NULL; | |
64 | } | |
65 | *err = -ENOSPC; | |
66 | ||
48d6d8ff | 67 | iinfo = UDF_I(inode); |
97e1cfb0 JK |
68 | if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_EXTENDED_FE)) { |
69 | iinfo->i_efe = 1; | |
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), | |
74 | GFP_KERNEL); | |
75 | } else { | |
76 | iinfo->i_efe = 0; | |
77 | iinfo->i_ext.i_data = kzalloc(inode->i_sb->s_blocksize - | |
78 | sizeof(struct fileEntry), | |
79 | GFP_KERNEL); | |
80 | } | |
81 | if (!iinfo->i_ext.i_data) { | |
82 | iput(inode); | |
83 | *err = -ENOMEM; | |
84 | return NULL; | |
85 | } | |
225add61 | 86 | |
4b11111a | 87 | block = udf_new_block(dir->i_sb, NULL, |
48d6d8ff | 88 | dinfo->i_location.partitionReferenceNum, |
28de7948 | 89 | start, err); |
cb00ea35 | 90 | if (*err) { |
1da177e4 LT |
91 | iput(inode); |
92 | return NULL; | |
93 | } | |
94 | ||
1e7933de | 95 | mutex_lock(&sbi->s_alloc_mutex); |
6c79e987 | 96 | if (sbi->s_lvid_bh) { |
4b11111a MS |
97 | struct logicalVolIntegrityDesc *lvid = |
98 | (struct logicalVolIntegrityDesc *) | |
99 | sbi->s_lvid_bh->b_data; | |
100 | struct logicalVolIntegrityDescImpUse *lvidiu = | |
101 | udf_sb_lvidiu(sbi); | |
1da177e4 LT |
102 | struct logicalVolHeaderDesc *lvhd; |
103 | uint64_t uniqueID; | |
4b11111a MS |
104 | lvhd = (struct logicalVolHeaderDesc *) |
105 | (lvid->logicalVolContentsUse); | |
1da177e4 | 106 | if (S_ISDIR(mode)) |
c2104fda | 107 | le32_add_cpu(&lvidiu->numDirs, 1); |
1da177e4 | 108 | else |
c2104fda | 109 | le32_add_cpu(&lvidiu->numFiles, 1); |
48d6d8ff | 110 | iinfo->i_unique = uniqueID = le64_to_cpu(lvhd->uniqueID); |
1da177e4 LT |
111 | if (!(++uniqueID & 0x00000000FFFFFFFFUL)) |
112 | uniqueID += 16; | |
113 | lvhd->uniqueID = cpu_to_le64(uniqueID); | |
146bca72 | 114 | udf_updated_lvid(sb); |
1da177e4 | 115 | } |
db0badc5 | 116 | mutex_unlock(&sbi->s_alloc_mutex); |
a6c5a034 DM |
117 | |
118 | inode_init_owner(inode, dir, mode); | |
1da177e4 | 119 | |
48d6d8ff MS |
120 | iinfo->i_location.logicalBlockNum = block; |
121 | iinfo->i_location.partitionReferenceNum = | |
122 | dinfo->i_location.partitionReferenceNum; | |
97e961fd | 123 | inode->i_ino = udf_get_lb_pblock(sb, &iinfo->i_location, 0); |
1da177e4 | 124 | inode->i_blocks = 0; |
48d6d8ff MS |
125 | iinfo->i_lenEAttr = 0; |
126 | iinfo->i_lenAlloc = 0; | |
127 | iinfo->i_use = 0; | |
1da177e4 | 128 | if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_AD_IN_ICB)) |
48d6d8ff | 129 | iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB; |
1da177e4 | 130 | else if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD)) |
48d6d8ff | 131 | iinfo->i_alloc_type = ICBTAG_FLAG_AD_SHORT; |
1da177e4 | 132 | else |
48d6d8ff | 133 | iinfo->i_alloc_type = ICBTAG_FLAG_AD_LONG; |
1da177e4 | 134 | inode->i_mtime = inode->i_atime = inode->i_ctime = |
48d6d8ff | 135 | iinfo->i_crtime = current_fs_time(inode->i_sb); |
1da177e4 LT |
136 | insert_inode_hash(inode); |
137 | mark_inode_dirty(inode); | |
1da177e4 | 138 | |
1da177e4 LT |
139 | *err = 0; |
140 | return inode; | |
141 | } |