~daniel-mehrmann/e2fsprogs/master

« back to all changes in this revision

Viewing changes to lib/ext2fs/punch.c

  • Committer: Daniel Mehrmann
  • Date: 2014-12-16 09:16:59 UTC
  • mfrom: (1.2.25)
  • Revision ID: daniel.mehrmann@gmx.de-20141216091659-ymhbl4ualba43vuc
Tags: 1.43-SN-2014-12-16-0ubuntu1
* Merge in snapshot from the maint branch 

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
#include "ext2_fs.h"
21
21
#include "ext2fs.h"
 
22
#include "ext2fsP.h"
22
23
 
23
24
#undef PUNCH_DEBUG
24
25
 
343
344
                                        EXT2_EXTENT_INSERT_AFTER, &newex);
344
345
                        if (retval)
345
346
                                goto errout;
346
 
                        /* Now pointing at inserted extent; so go back */
347
 
                        retval = ext2fs_extent_get(handle,
348
 
                                                   EXT2_EXTENT_PREV_LEAF,
349
 
                                                   &newex);
 
347
                        retval = ext2fs_extent_fix_parents(handle);
 
348
                        if (retval)
 
349
                                goto errout;
 
350
                        /*
 
351
                         * Now pointing at inserted extent; so go back.
 
352
                         *
 
353
                         * We cannot use EXT2_EXTENT_PREV to go back; note the
 
354
                         * subtlety in the comment for fix_parents().
 
355
                         */
 
356
                        retval = ext2fs_extent_goto(handle, extent.e_lblk);
350
357
                        if (retval)
351
358
                                goto errout;
352
359
                } 
395
402
                                goto errout;
396
403
                        retval = 0;
397
404
 
398
 
                        /* Jump forward to the next extent. */
399
 
                        ext2fs_extent_goto(handle, next_lblk);
 
405
                        /*
 
406
                         * Jump forward to the next extent.  If there are
 
407
                         * errors, the ext2fs_extent_get down below will
 
408
                         * capture them for us.
 
409
                         */
 
410
                        (void)ext2fs_extent_goto(handle, next_lblk);
400
411
                        op = EXT2_EXTENT_CURRENT;
401
412
                }
402
413
                if (retval)
423
434
        return retval;
424
435
}
425
436
        
 
437
static errcode_t ext2fs_punch_inline_data(ext2_filsys fs, ext2_ino_t ino,
 
438
                                          struct ext2_inode *inode,
 
439
                                          blk64_t start, blk64_t end)
 
440
{
 
441
        errcode_t retval;
 
442
 
 
443
        /*
 
444
         * In libext2fs ext2fs_punch is based on block unit.  So that
 
445
         * means that if start > 0 we don't need to do nothing.  Due
 
446
         * to this we will remove all inline data in ext2fs_punch()
 
447
         * now.
 
448
         */
 
449
        if (start > 0)
 
450
                return 0;
 
451
 
 
452
        memset((char *)inode->i_block, 0, EXT4_MIN_INLINE_DATA_SIZE);
 
453
        inode->i_size = 0;
 
454
        retval = ext2fs_write_inode(fs, ino, inode);
 
455
        if (retval)
 
456
                return retval;
 
457
 
 
458
        return ext2fs_inline_data_ea_remove(fs, ino);
 
459
}
 
460
 
426
461
/*
427
462
 * Deallocate all logical blocks starting at start to end, inclusive.
428
463
 * If end is ~0, then this is effectively truncate.
445
480
                        return retval;
446
481
                inode = &inode_buf;
447
482
        }
448
 
        if (inode->i_flags & EXT4_EXTENTS_FL)
 
483
        if (inode->i_flags & EXT4_INLINE_DATA_FL)
 
484
                return ext2fs_punch_inline_data(fs, ino, inode, start, end);
 
485
        else if (inode->i_flags & EXT4_EXTENTS_FL)
449
486
                retval = ext2fs_punch_extent(fs, ino, inode, start, end);
450
487
        else {
451
488
                blk_t   count;