1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
/*
* ialloc.c
*
* PURPOSE
* Inode allocation handling routines for the OSTA-UDF(tm) filesystem.
*
* CONTACTS
* E-mail regarding any portion of the Linux UDF file system should be
* directed to the development team mailing list (run by majordomo):
* linux_udf@hootie.lvld.hp.com
*
* COPYRIGHT
* This file is distributed under the terms of the GNU General Public
* License (GPL). Copies of the GPL can be obtained from:
* ftp://prep.ai.mit.edu/pub/gnu/GPL
* Each contributing author retains all rights to their own work.
*
* (C) 1998-2000 Ben Fennema
*
* HISTORY
*
* 02/24/99 blf Created.
*
*/
#include "udfdecl.h"
#include <linux/fs.h>
#include <linux/locks.h>
#include <linux/quotaops.h>
#include <linux/udf_fs.h>
#include "udf_i.h"
#include "udf_sb.h"
void udf_free_inode(struct inode * inode)
{
struct super_block * sb = inode->i_sb;
int is_directory;
unsigned long ino;
if (!inode->i_dev)
{
udf_debug("inode has no device\n");
return;
}
if (inode->i_count > 1)
{
udf_debug("inode has count=%d\n", inode->i_count);
return;
}
if (inode->i_nlink)
{
udf_debug("inode has nlink=%d\n", inode->i_nlink);
return;
}
if (!sb)
{
udf_debug("inode on nonexistent device\n");
return;
}
ino = inode->i_ino;
/*
* Note: we must free any quota before locking the superblock,
* as writing the quota to disk may need the lock as well.
*/
DQUOT_FREE_INODE(sb, inode);
DQUOT_DROP(inode);
lock_super(sb);
is_directory = S_ISDIR(inode->i_mode);
clear_inode(inode);
if (UDF_SB_LVIDBH(sb))
{
if (is_directory)
UDF_SB_LVIDIU(sb)->numDirs =
cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb)->numDirs) - 1);
else
UDF_SB_LVIDIU(sb)->numFiles =
cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles) - 1);
mark_buffer_dirty(UDF_SB_LVIDBH(sb), 1);
}
unlock_super(sb);
udf_free_blocks(inode, UDF_I_LOCATION(inode), 0, 1);
}
struct inode * udf_new_inode (const struct inode *dir, int mode, int * err)
{
struct super_block *sb;
struct inode * inode;
int block;
Uint32 start = UDF_I_LOCATION(dir).logicalBlockNum;
inode = get_empty_inode();
if (!inode)
{
*err = -ENOMEM;
return NULL;
}
sb = dir->i_sb;
inode->i_sb = sb;
inode->i_flags = 0;
*err = -ENOSPC;
block = udf_new_block(dir, UDF_I_LOCATION(dir).partitionReferenceNum,
start, err);
if (*err)
{
iput(inode);
return NULL;
}
lock_super(sb);
if (UDF_SB_LVIDBH(sb))
{
struct LogicalVolHeaderDesc *lvhd;
Uint64 uniqueID;
lvhd = (struct LogicalVolHeaderDesc *)(UDF_SB_LVID(sb)->logicalVolContentsUse);
if (S_ISDIR(mode))
UDF_SB_LVIDIU(sb)->numDirs =
cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb)->numDirs) + 1);
else
UDF_SB_LVIDIU(sb)->numFiles =
cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles) + 1);
UDF_I_UNIQUE(inode) = uniqueID = le64_to_cpu(lvhd->uniqueID);
if (!(++uniqueID & 0x00000000FFFFFFFFUL))
uniqueID += 16;
lvhd->uniqueID = cpu_to_le64(uniqueID);
mark_buffer_dirty(UDF_SB_LVIDBH(sb), 1);
}
inode->i_mode = mode;
inode->i_sb = sb;
inode->i_nlink = 1;
inode->i_dev = sb->s_dev;
inode->i_uid = current->fsuid;
if (test_opt (sb, GRPID))
inode->i_gid = dir->i_gid;
else if (dir->i_mode & S_ISGID)
{
inode->i_gid = dir->i_gid;
if (S_ISDIR(mode))
mode |= S_ISGID;
}
else
inode->i_gid = current->fsgid;
UDF_I_LOCATION(inode).logicalBlockNum = block;
UDF_I_LOCATION(inode).partitionReferenceNum = UDF_I_LOCATION(dir).partitionReferenceNum;
inode->i_ino = udf_get_lb_pblock(sb, UDF_I_LOCATION(inode), 0);
inode->i_blksize = PAGE_SIZE;
inode->i_blocks = 0;
inode->i_size = 0;
UDF_I_LENEATTR(inode) = 0;
UDF_I_LENALLOC(inode) = 0;
if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_EXTENDED_FE))
{
UDF_I_EXTENDED_FE(inode) = 1;
UDF_UPDATE_UDFREV(inode->i_sb, UDF_VERS_USE_EXTENDED_FE);
}
else
UDF_I_EXTENDED_FE(inode) = 0;
if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_AD_IN_ICB))
UDF_I_ALLOCTYPE(inode) = ICB_FLAG_AD_IN_ICB;
else if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
UDF_I_ALLOCTYPE(inode) = ICB_FLAG_AD_SHORT;
else
UDF_I_ALLOCTYPE(inode) = ICB_FLAG_AD_LONG;
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
UDF_I_UMTIME(inode) = UDF_I_UATIME(inode) = UDF_I_UCTIME(inode) = CURRENT_UTIME;
UDF_I_NEW_INODE(inode) = 1;
insert_inode_hash(inode);
mark_inode_dirty(inode);
unlock_super(sb);
if (DQUOT_ALLOC_INODE(sb, inode))
{
sb->dq_op->drop(inode);
inode->i_nlink = 0;
iput(inode);
*err = -EDQUOT;
return NULL;
}
*err = 0;
return inode;
}
|