aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ufs/inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ufs/inode.c')
-rw-r--r--fs/ufs/inode.c82
1 files changed, 48 insertions, 34 deletions
diff --git a/fs/ufs/inode.c b/fs/ufs/inode.c
index dd52eecdcb0f..fb34ad03e224 100644
--- a/fs/ufs/inode.c
+++ b/fs/ufs/inode.c
@@ -170,7 +170,7 @@ out:
170 * @locked_page - for ufs_new_fragments() 170 * @locked_page - for ufs_new_fragments()
171 */ 171 */
172static struct buffer_head * 172static struct buffer_head *
173ufs_inode_getfrag(struct inode *inode, unsigned int fragment, 173ufs_inode_getfrag(struct inode *inode, u64 fragment,
174 sector_t new_fragment, unsigned int required, int *err, 174 sector_t new_fragment, unsigned int required, int *err,
175 long *phys, int *new, struct page *locked_page) 175 long *phys, int *new, struct page *locked_page)
176{ 176{
@@ -178,12 +178,12 @@ ufs_inode_getfrag(struct inode *inode, unsigned int fragment,
178 struct super_block *sb = inode->i_sb; 178 struct super_block *sb = inode->i_sb;
179 struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi; 179 struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
180 struct buffer_head * result; 180 struct buffer_head * result;
181 unsigned block, blockoff, lastfrag, lastblock, lastblockoff; 181 unsigned blockoff, lastblockoff;
182 unsigned tmp, goal; 182 u64 tmp, goal, lastfrag, block, lastblock;
183 __fs32 * p, * p2; 183 void *p, *p2;
184 184
185 UFSD("ENTER, ino %lu, fragment %u, new_fragment %llu, required %u, " 185 UFSD("ENTER, ino %lu, fragment %llu, new_fragment %llu, required %u, "
186 "metadata %d\n", inode->i_ino, fragment, 186 "metadata %d\n", inode->i_ino, (unsigned long long)fragment,
187 (unsigned long long)new_fragment, required, !phys); 187 (unsigned long long)new_fragment, required, !phys);
188 188
189 /* TODO : to be done for write support 189 /* TODO : to be done for write support
@@ -193,17 +193,20 @@ ufs_inode_getfrag(struct inode *inode, unsigned int fragment,
193 193
194 block = ufs_fragstoblks (fragment); 194 block = ufs_fragstoblks (fragment);
195 blockoff = ufs_fragnum (fragment); 195 blockoff = ufs_fragnum (fragment);
196 p = ufsi->i_u1.i_data + block; 196 p = ufs_get_direct_data_ptr(uspi, ufsi, block);
197
197 goal = 0; 198 goal = 0;
198 199
199repeat: 200repeat:
200 tmp = fs32_to_cpu(sb, *p); 201 tmp = ufs_data_ptr_to_cpu(sb, p);
202
201 lastfrag = ufsi->i_lastfrag; 203 lastfrag = ufsi->i_lastfrag;
202 if (tmp && fragment < lastfrag) { 204 if (tmp && fragment < lastfrag) {
203 if (!phys) { 205 if (!phys) {
204 result = sb_getblk(sb, uspi->s_sbbase + tmp + blockoff); 206 result = sb_getblk(sb, uspi->s_sbbase + tmp + blockoff);
205 if (tmp == fs32_to_cpu(sb, *p)) { 207 if (tmp == ufs_data_ptr_to_cpu(sb, p)) {
206 UFSD("EXIT, result %u\n", tmp + blockoff); 208 UFSD("EXIT, result %llu\n",
209 (unsigned long long)tmp + blockoff);
207 return result; 210 return result;
208 } 211 }
209 brelse (result); 212 brelse (result);
@@ -224,10 +227,11 @@ repeat:
224 * We must reallocate last allocated block 227 * We must reallocate last allocated block
225 */ 228 */
226 if (lastblockoff) { 229 if (lastblockoff) {
227 p2 = ufsi->i_u1.i_data + lastblock; 230 p2 = ufs_get_direct_data_ptr(uspi, ufsi, lastblock);
228 tmp = ufs_new_fragments (inode, p2, lastfrag, 231 tmp = ufs_new_fragments(inode, p2, lastfrag,
229 fs32_to_cpu(sb, *p2), uspi->s_fpb - lastblockoff, 232 ufs_data_ptr_to_cpu(sb, p2),
230 err, locked_page); 233 uspi->s_fpb - lastblockoff,
234 err, locked_page);
231 if (!tmp) { 235 if (!tmp) {
232 if (lastfrag != ufsi->i_lastfrag) 236 if (lastfrag != ufsi->i_lastfrag)
233 goto repeat; 237 goto repeat;
@@ -237,27 +241,31 @@ repeat:
237 lastfrag = ufsi->i_lastfrag; 241 lastfrag = ufsi->i_lastfrag;
238 242
239 } 243 }
240 tmp = fs32_to_cpu(sb, ufsi->i_u1.i_data[lastblock]); 244 tmp = ufs_data_ptr_to_cpu(sb,
245 ufs_get_direct_data_ptr(uspi, ufsi,
246 lastblock));
241 if (tmp) 247 if (tmp)
242 goal = tmp + uspi->s_fpb; 248 goal = tmp + uspi->s_fpb;
243 tmp = ufs_new_fragments (inode, p, fragment - blockoff, 249 tmp = ufs_new_fragments (inode, p, fragment - blockoff,
244 goal, required + blockoff, 250 goal, required + blockoff,
245 err, 251 err,
246 phys != NULL ? locked_page : NULL); 252 phys != NULL ? locked_page : NULL);
247 } 253 } else if (lastblock == block) {
248 /* 254 /*
249 * We will extend last allocated block 255 * We will extend last allocated block
250 */ 256 */
251 else if (lastblock == block) { 257 tmp = ufs_new_fragments(inode, p, fragment -
252 tmp = ufs_new_fragments(inode, p, fragment - (blockoff - lastblockoff), 258 (blockoff - lastblockoff),
253 fs32_to_cpu(sb, *p), required + (blockoff - lastblockoff), 259 ufs_data_ptr_to_cpu(sb, p),
260 required + (blockoff - lastblockoff),
254 err, phys != NULL ? locked_page : NULL); 261 err, phys != NULL ? locked_page : NULL);
255 } else /* (lastblock > block) */ { 262 } else /* (lastblock > block) */ {
256 /* 263 /*
257 * We will allocate new block before last allocated block 264 * We will allocate new block before last allocated block
258 */ 265 */
259 if (block) { 266 if (block) {
260 tmp = fs32_to_cpu(sb, ufsi->i_u1.i_data[block-1]); 267 tmp = ufs_data_ptr_to_cpu(sb,
268 ufs_get_direct_data_ptr(uspi, ufsi, block - 1));
261 if (tmp) 269 if (tmp)
262 goal = tmp + uspi->s_fpb; 270 goal = tmp + uspi->s_fpb;
263 } 271 }
@@ -266,7 +274,7 @@ repeat:
266 phys != NULL ? locked_page : NULL); 274 phys != NULL ? locked_page : NULL);
267 } 275 }
268 if (!tmp) { 276 if (!tmp) {
269 if ((!blockoff && *p) || 277 if ((!blockoff && ufs_data_ptr_to_cpu(sb, p)) ||
270 (blockoff && lastfrag != ufsi->i_lastfrag)) 278 (blockoff && lastfrag != ufsi->i_lastfrag))
271 goto repeat; 279 goto repeat;
272 *err = -ENOSPC; 280 *err = -ENOSPC;
@@ -286,7 +294,7 @@ repeat:
286 if (IS_SYNC(inode)) 294 if (IS_SYNC(inode))
287 ufs_sync_inode (inode); 295 ufs_sync_inode (inode);
288 mark_inode_dirty(inode); 296 mark_inode_dirty(inode);
289 UFSD("EXIT, result %u\n", tmp + blockoff); 297 UFSD("EXIT, result %llu\n", (unsigned long long)tmp + blockoff);
290 return result; 298 return result;
291 299
292 /* This part : To be implemented .... 300 /* This part : To be implemented ....
@@ -320,20 +328,22 @@ repeat2:
320 */ 328 */
321static struct buffer_head * 329static struct buffer_head *
322ufs_inode_getblock(struct inode *inode, struct buffer_head *bh, 330ufs_inode_getblock(struct inode *inode, struct buffer_head *bh,
323 unsigned int fragment, sector_t new_fragment, int *err, 331 u64 fragment, sector_t new_fragment, int *err,
324 long *phys, int *new, struct page *locked_page) 332 long *phys, int *new, struct page *locked_page)
325{ 333{
326 struct super_block *sb = inode->i_sb; 334 struct super_block *sb = inode->i_sb;
327 struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi; 335 struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
328 struct buffer_head * result; 336 struct buffer_head * result;
329 unsigned tmp, goal, block, blockoff; 337 unsigned blockoff;
330 __fs32 * p; 338 u64 tmp, goal, block;
339 void *p;
331 340
332 block = ufs_fragstoblks (fragment); 341 block = ufs_fragstoblks (fragment);
333 blockoff = ufs_fragnum (fragment); 342 blockoff = ufs_fragnum (fragment);
334 343
335 UFSD("ENTER, ino %lu, fragment %u, new_fragment %llu, metadata %d\n", 344 UFSD("ENTER, ino %lu, fragment %llu, new_fragment %llu, metadata %d\n",
336 inode->i_ino, fragment, (unsigned long long)new_fragment, !phys); 345 inode->i_ino, (unsigned long long)fragment,
346 (unsigned long long)new_fragment, !phys);
337 347
338 result = NULL; 348 result = NULL;
339 if (!bh) 349 if (!bh)
@@ -344,14 +354,16 @@ ufs_inode_getblock(struct inode *inode, struct buffer_head *bh,
344 if (!buffer_uptodate(bh)) 354 if (!buffer_uptodate(bh))
345 goto out; 355 goto out;
346 } 356 }
347 357 if (uspi->fs_magic == UFS2_MAGIC)
348 p = (__fs32 *) bh->b_data + block; 358 p = (__fs64 *)bh->b_data + block;
359 else
360 p = (__fs32 *)bh->b_data + block;
349repeat: 361repeat:
350 tmp = fs32_to_cpu(sb, *p); 362 tmp = ufs_data_ptr_to_cpu(sb, p);
351 if (tmp) { 363 if (tmp) {
352 if (!phys) { 364 if (!phys) {
353 result = sb_getblk(sb, uspi->s_sbbase + tmp + blockoff); 365 result = sb_getblk(sb, uspi->s_sbbase + tmp + blockoff);
354 if (tmp == fs32_to_cpu(sb, *p)) 366 if (tmp == ufs_data_ptr_to_cpu(sb, p))
355 goto out; 367 goto out;
356 brelse (result); 368 brelse (result);
357 goto repeat; 369 goto repeat;
@@ -361,14 +373,16 @@ repeat:
361 } 373 }
362 } 374 }
363 375
364 if (block && (tmp = fs32_to_cpu(sb, ((__fs32*)bh->b_data)[block-1]))) 376 if (block && (uspi->fs_magic == UFS2_MAGIC ?
377 (tmp = fs64_to_cpu(sb, ((__fs64 *)bh->b_data)[block-1])) :
378 (tmp = fs32_to_cpu(sb, ((__fs32 *)bh->b_data)[block-1]))))
365 goal = tmp + uspi->s_fpb; 379 goal = tmp + uspi->s_fpb;
366 else 380 else
367 goal = bh->b_blocknr + uspi->s_fpb; 381 goal = bh->b_blocknr + uspi->s_fpb;
368 tmp = ufs_new_fragments(inode, p, ufs_blknum(new_fragment), goal, 382 tmp = ufs_new_fragments(inode, p, ufs_blknum(new_fragment), goal,
369 uspi->s_fpb, err, locked_page); 383 uspi->s_fpb, err, locked_page);
370 if (!tmp) { 384 if (!tmp) {
371 if (fs32_to_cpu(sb, *p)) 385 if (ufs_data_ptr_to_cpu(sb, p))
372 goto repeat; 386 goto repeat;
373 goto out; 387 goto out;
374 } 388 }
@@ -386,7 +400,7 @@ repeat:
386 sync_dirty_buffer(bh); 400 sync_dirty_buffer(bh);
387 inode->i_ctime = CURRENT_TIME_SEC; 401 inode->i_ctime = CURRENT_TIME_SEC;
388 mark_inode_dirty(inode); 402 mark_inode_dirty(inode);
389 UFSD("result %u\n", tmp + blockoff); 403 UFSD("result %llu\n", (unsigned long long)tmp + blockoff);
390out: 404out:
391 brelse (bh); 405 brelse (bh);
392 UFSD("EXIT\n"); 406 UFSD("EXIT\n");