udf: fix sparse warnings (shadowing & mismatch between declaration and definition)
[deliverable/linux.git] / fs / udf / ialloc.c
CommitLineData
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>
24#include <linux/udf_fs.h>
25#include <linux/sched.h>
26#include <linux/slab.h>
27
28#include "udf_i.h"
29#include "udf_sb.h"
30
cb00ea35 31void udf_free_inode(struct inode *inode)
1da177e4
LT
32{
33 struct super_block *sb = inode->i_sb;
34 struct udf_sb_info *sbi = UDF_SB(sb);
35
36 /*
37 * Note: we must free any quota before locking the superblock,
38 * as writing the quota to disk may need the lock as well.
39 */
40 DQUOT_FREE_INODE(inode);
41 DQUOT_DROP(inode);
42
43 clear_inode(inode);
44
1e7933de 45 mutex_lock(&sbi->s_alloc_mutex);
6c79e987
MS
46 if (sbi->s_lvid_bh) {
47 struct logicalVolIntegrityDescImpUse *lvidiu =
48 udf_sb_lvidiu(sbi);
1da177e4 49 if (S_ISDIR(inode->i_mode))
6c79e987
MS
50 lvidiu->numDirs =
51 cpu_to_le32(le32_to_cpu(lvidiu->numDirs) - 1);
1da177e4 52 else
6c79e987
MS
53 lvidiu->numFiles =
54 cpu_to_le32(le32_to_cpu(lvidiu->numFiles) - 1);
c9c64155 55
6c79e987 56 mark_buffer_dirty(sbi->s_lvid_bh);
1da177e4 57 }
1e7933de 58 mutex_unlock(&sbi->s_alloc_mutex);
1da177e4
LT
59
60 udf_free_blocks(sb, NULL, UDF_I_LOCATION(inode), 0, 1);
61}
62
cb00ea35 63struct inode *udf_new_inode(struct inode *dir, int mode, int *err)
1da177e4
LT
64{
65 struct super_block *sb = dir->i_sb;
66 struct udf_sb_info *sbi = UDF_SB(sb);
cb00ea35 67 struct inode *inode;
1da177e4
LT
68 int block;
69 uint32_t start = UDF_I_LOCATION(dir).logicalBlockNum;
70
71 inode = new_inode(sb);
72
cb00ea35 73 if (!inode) {
1da177e4
LT
74 *err = -ENOMEM;
75 return NULL;
76 }
77 *err = -ENOSPC;
78
225add61
ES
79 UDF_I_UNIQUE(inode) = 0;
80 UDF_I_LENEXTENTS(inode) = 0;
81 UDF_I_NEXT_ALLOC_BLOCK(inode) = 0;
82 UDF_I_NEXT_ALLOC_GOAL(inode) = 0;
83 UDF_I_STRAT4096(inode) = 0;
84
28de7948
CG
85 block = udf_new_block(dir->i_sb, NULL, UDF_I_LOCATION(dir).partitionReferenceNum,
86 start, err);
cb00ea35 87 if (*err) {
1da177e4
LT
88 iput(inode);
89 return NULL;
90 }
91
1e7933de 92 mutex_lock(&sbi->s_alloc_mutex);
6c79e987
MS
93 if (sbi->s_lvid_bh) {
94 struct logicalVolIntegrityDesc *lvid = (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data;
95 struct logicalVolIntegrityDescImpUse *lvidiu = udf_sb_lvidiu(sbi);
1da177e4
LT
96 struct logicalVolHeaderDesc *lvhd;
97 uint64_t uniqueID;
6c79e987 98 lvhd = (struct logicalVolHeaderDesc *)(lvid->logicalVolContentsUse);
1da177e4 99 if (S_ISDIR(mode))
6c79e987
MS
100 lvidiu->numDirs =
101 cpu_to_le32(le32_to_cpu(lvidiu->numDirs) + 1);
1da177e4 102 else
6c79e987
MS
103 lvidiu->numFiles =
104 cpu_to_le32(le32_to_cpu(lvidiu->numFiles) + 1);
1da177e4
LT
105 UDF_I_UNIQUE(inode) = uniqueID = le64_to_cpu(lvhd->uniqueID);
106 if (!(++uniqueID & 0x00000000FFFFFFFFUL))
107 uniqueID += 16;
108 lvhd->uniqueID = cpu_to_le64(uniqueID);
6c79e987 109 mark_buffer_dirty(sbi->s_lvid_bh);
1da177e4
LT
110 }
111 inode->i_mode = mode;
112 inode->i_uid = current->fsuid;
cb00ea35 113 if (dir->i_mode & S_ISGID) {
1da177e4
LT
114 inode->i_gid = dir->i_gid;
115 if (S_ISDIR(mode))
116 mode |= S_ISGID;
28de7948 117 } else {
1da177e4 118 inode->i_gid = current->fsgid;
28de7948 119 }
1da177e4
LT
120
121 UDF_I_LOCATION(inode).logicalBlockNum = block;
28de7948 122 UDF_I_LOCATION(inode).partitionReferenceNum = UDF_I_LOCATION(dir).partitionReferenceNum;
1da177e4 123 inode->i_ino = udf_get_lb_pblock(sb, UDF_I_LOCATION(inode), 0);
1da177e4
LT
124 inode->i_blocks = 0;
125 UDF_I_LENEATTR(inode) = 0;
126 UDF_I_LENALLOC(inode) = 0;
127 UDF_I_USE(inode) = 0;
cb00ea35 128 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_EXTENDED_FE)) {
1da177e4 129 UDF_I_EFE(inode) = 1;
6c79e987
MS
130 if (UDF_VERS_USE_EXTENDED_FE > sbi->s_udfrev)
131 sbi->s_udfrev = UDF_VERS_USE_EXTENDED_FE;
28de7948 132 UDF_I_DATA(inode) = kzalloc(inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry), GFP_KERNEL);
cb00ea35 133 } else {
1da177e4 134 UDF_I_EFE(inode) = 0;
28de7948 135 UDF_I_DATA(inode) = kzalloc(inode->i_sb->s_blocksize - sizeof(struct fileEntry), GFP_KERNEL);
1da177e4 136 }
cb00ea35 137 if (!UDF_I_DATA(inode)) {
c9c64155
CG
138 iput(inode);
139 *err = -ENOMEM;
140 mutex_unlock(&sbi->s_alloc_mutex);
141 return NULL;
142 }
1da177e4
LT
143 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_AD_IN_ICB))
144 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB;
145 else if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
146 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT;
147 else
148 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_LONG;
149 inode->i_mtime = inode->i_atime = inode->i_ctime =
28de7948 150 UDF_I_CRTIME(inode) = current_fs_time(inode->i_sb);
1da177e4
LT
151 insert_inode_hash(inode);
152 mark_inode_dirty(inode);
1e7933de 153 mutex_unlock(&sbi->s_alloc_mutex);
1da177e4 154
cb00ea35 155 if (DQUOT_ALLOC_INODE(inode)) {
1da177e4
LT
156 DQUOT_DROP(inode);
157 inode->i_flags |= S_NOQUOTA;
158 inode->i_nlink = 0;
159 iput(inode);
160 *err = -EDQUOT;
161 return NULL;
162 }
163
164 *err = 0;
165 return inode;
166}
This page took 0.328527 seconds and 5 git commands to generate.