summaryrefslogtreecommitdiff
path: root/lib
Commit message (Collapse)AuthorAgeFilesLines
* libext2fs: avoid buffer overflow if s_first_meta_bg is too bigTheodore Ts'o2014-08-102-4/+8
| | | | | | | | | | | | If s_first_meta_bg is greater than the of number block group descriptor blocks, then reading or writing the block group descriptors will end up overruning the memory buffer allocated for the descriptors. Fix this by limiting first_meta_bg to no more than fs->desc_blocks. This doesn't correct the bad s_first_meta_bg value, but it avoids causing the e2fsprogs userspace programs from potentially crashing. Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* libext2fs: have UNIX IO manager use pread64/pwrite64Theodore Ts'o2014-08-082-2/+28
| | | | | | | | | | | Commit baa3544609da3c ("libext2fs: have UNIX IO manager use pread/pwrite) causes a breakage on 32-bit systems where off_t is 32-bits for file systems larger than 4GB. Fix this by using pread64/pwrite64 if possible, and if pread64/pwrite64 is not present, using pread/pwrite only if the size of off_t is at least as big as ext2_loff_t. Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* libext2fs: place metadata blocks in the last flex_bg so they are contiguousTheodore Ts'o2014-08-041-3/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Place the allocation bitmaps and inode table blocks so they are adjacent, even in the last flexbg. Previously, after running "mke2fs -t ext4 DEV 286720", the layout of the last few block groups would look like this: Group 32: (Blocks 262145-270336) [INODE_UNINIT, ITABLE_ZEROED] Block bitmap at 262145 (+0), Inode bitmap at 262161 (+16) Inode table at 262177-262432 (+32) Group 33: (Blocks 270337-278528) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED] Block bitmap at 262146 (bg #32 + 1), Inode bitmap at 262162 (bg #32 + 17) Inode table at 262433-262688 (bg #32 + 288) Group 34: (Blocks 278529-286719) [INODE_UNINIT, ITABLE_ZEROED] Block bitmap at 262147 (bg #32 + 2), Inode bitmap at 262163 (bg #32 + 18) Inode table at 262689-262944 (bg #32 + 544) Now, they look like this: Group 32: (Blocks 262145-270336) [INODE_UNINIT, ITABLE_ZEROED] Block bitmap at 262145 (+0), Inode bitmap at 262148 (+3) Inode table at 262151-262406 (+6) Group 33: (Blocks 270337-278528) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED] Block bitmap at 262146 (bg #32 + 1), Inode bitmap at 262149 (bg #32 + 4) Inode table at 262407-262662 (bg #32 + 262) Group 34: (Blocks 278529-286719) [INODE_UNINIT, ITABLE_ZEROED] Block bitmap at 262147 (bg #32 + 2), Inode bitmap at 262150 (bg #32 + 5) Inode table at 262663-262918 (bg #32 + 518) This reduces the free space fragmentation in a freshly created file system. It also allows the following mke2fs command to succeed: mke2fs -t ext4 -b 4096 -O ^resize_inode -G $((2**20)) DEV 2130483 (Note that while this allows people to run mke2fs with insanely large flexbg sizes, this is not a recommended practice, as the kernel may refuse to resize such a file system while mounted, since it currently tries to allocate an in-memory data structure based on the size of the flexbg, and so a file system with a very large flexbg size will cause the memory allocation to fail. This will hopefully be fixed in a future kernel release, but if the goal is to force all of the metadata blocks to be at the beginning of the file system, it's better to use the packed_meta_blocks configuration parameter in mke2fs.conf.) Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* Revert "mke2fs: prevent creation of unmountable ext4 with large flex_bg count"Theodore Ts'o2014-08-041-24/+0
| | | | | | | | | | | | | | | | | | | | | | | This reverts commit d988201ef9cb6f7b521e544061976ab4270a3f89. The problem with this commit is that causes common small file system configurations to fail. For example: mke2fs -O flex_bg -b 4096 -I 1024 -F /tmp/tt 79106 mke2fs 1.42.11 (09-Jul-2014) /tmp/tt: Invalid argument passed to ext2 library while setting up superblock This check in ext2fs_initialize() was added to prevent the metadata from being allocated beyond the end of the filesystem, but it is also causing a wide range of failures for small filesystems. We'll address this in a different way, by using a smarter algorithm for deciding the layout of metadata blocks for the last flex block group. Reported-by: Andreas Dilger <andreas.dilger@intel.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* libext2fs: when appending to a file, don't split an index block in equal halvesDarrick J. Wong2014-08-021-7/+72
| | | | | | | | | | | | | | | | When we're appending an extent to the end of a file and the index block is full, don't split the index block into two half-full index blocks because this leaves us with under utilized index blocks, at least in the fallocate case. Instead, copy the last extent from the full block into the new block. This isn't perfect utilization, but there's a lot of work involved in teaching extent.c to be able to goto a nonexistent node in a newly allocated (and empty) extent block. This patch does not fix the general problem of keeping the extent tree balanced. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* libext2fs: have UNIX IO manager use pread/pwriteDarrick J. Wong2014-08-022-0/+30
| | | | | | | | | If pread/pwrite are present, have the UNIX IO manager use them for aligned IOs (instead of the current seek -> read/write), thereby saving us a (minor) amount of system call overhead. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* tune2fs: update journal users while updating fs UUID (with external journal)Azat Khuzhin2014-07-282-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When we have fs with external journal device, and updating it's UUID, we should update UUID in users list for that external journal device. Before: $ tune2fs -U clear /tmp/dev tune2fs 1.42.10 (18-May-2014) $ dumpe2fs /tmp/dev | fgrep UUID dumpe2fs 1.42.10 (18-May-2014) Filesystem UUID: <none> Journal UUID: da1f2ed0-60f6-aaaa-92fd-738701418523 $ dumpe2fs /tmp/journal | fgrep users -A10 dumpe2fs 1.42.10 (18-May-2014) Journal number of users: 2 Journal users: 0707762d-638e-4bc6-944e-ae8ee7a3359e 0ad849df-1041-4f0a-b1c1-2f949d6a1e37 After: $ sudo tune2fs -U clear /tmp/dev tune2fs 1.43-WIP (18-May-2014) $ dumpe2fs /tmp/dev | fgrep UUID dumpe2fs 1.42.10 (18-May-2014) Filesystem UUID: <none> Journal UUID: da1f2ed0-60f6-aaaa-92fd-738701418523 $ dumpe2fs /tmp/journal | fgrep users -A10 dumpe2fs 1.42.10 (18-May-2014) Journal number of users: 2 Journal users: 0707762d-638e-4bc6-944e-ae8ee7a3359e 00000000-0000-0000-0000-000000000000 Also add some consts to avoid *magic numbers*: - UUID_STR_SIZE - UUID_SIZE - JFS_USERS_MAX - JFS_USERS_SIZE Proposed-by: Andreas Dilger <adilger@dilger.ca> Signed-off-by: Azat Khuzhin <a3at.mail@gmail.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* journal: use consts instead of 1024 and add helper for journal with 1k blocksizeAzat Khuzhin2014-07-282-12/+17
| | | | | | | | | | | Use EXT2_MIN_BLOCK_SIZE, JFS_MIN_JOURNAL_BLOCKS, SUPERBLOCK_SIZE, and SUPERBLOCK_OFFSET instead of hardcoded 1024 when it is okay, and also add a helper ext2fs_journal_sb_start() that will return start of journal sb with special case for fs with 1k block size. Signed-off-by: Azat Khuzhin <a3at.mail@gmail.com> Reviewed-by: Andreas Dilger <adilger@dilger.ca> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* libext2fs: provide a function to set inode sizeDarrick J. Wong2014-07-267-26/+44
| | | | | | | | | | | | | | Provide an API to set i_size in an inode and take care of all required feature flag modifications. Refactor the code to use this new function. [ Moved the function to lib/ext2fs/blk_num.c, which is the rest of these sorts of functions live, and renamed it to be ext2fs_inode_size_set() instead of ext2fs_inode_set_size() to be consistent with the other functions in in blk_num.c -- tytso ] Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* libext2fs: fix free block accounting for 64-bit file systemsTheodore Ts'o2014-07-261-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | We rely on a nasty hack to adjust the free block count where we pass signed value into ext2fs_free_blocks_count_add(), which takes an 64-bit unsigned value, and relies on overflow and C's signed->unsigned semantics to do the subtraction. This works, so long as a 64-bit signed value is used. Unfortunately, ext2fs_block_alloc_stats2() and ext2fs_block_alloc_stats_range(), this is not true, so on a 64-bit file system, the free blocks accounting can get screwed up. A simple way to demonstrate the problem is: mke2fs -F -t ext4 -O 64bit /tmp/foo.img 1M e2fsck -fy /tmp/foo.img ... which will result in the following e2fsck complaint: Pass 5: Checking group summary information Free blocks count wrong (4294968278, counted=982). Fix? yes Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* Fix 32/64-bit overflow when multiplying by blocks/clusters per groupTheodore Ts'o2014-07-264-10/+15
| | | | | | | | | | | | | | | | | There are a number of places where we need convert groups to blocks or clusters by multiply the groups by blocks/clusters per group. Unfortunately, both quantities are 32-bit, but the result needs to be 64-bit, and very often the cast to 64-bit gets lost. Fix this by adding new macros, EXT2_GROUPS_TO_BLOCKS() and EXT2_GROUPS_TO_CLUSTERS(). This should fix a bug where resizing a 64bit file system can result in calculate_minimum_resize_size() looping forever. Addresses-Launchpad-Bug: #1321958 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* libext2fs: use C99 initializers for the io_manager structureTheodore Ts'o2014-07-266-72/+69
| | | | | | | Using C99 initializers makes the code a bit more readable, and it avoids some gcc -Wall warnings regarding missing initializers. Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* libext2fs: fix rb_resize_bmap to handle the padding bitsTheodore Ts'o2014-07-261-8/+6
| | | | | | | | | The bits between end and real_end are set as a safety measure for the kernel when it uses the bit scan instructions. We need to take this into account when shrinking or growing the block allocation bitmap, before we can safely use rbtree bitmaps in resize2fs. Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* build: fix unused/uninitialized variable warningsAndreas Dilger2014-07-252-2/+1
| | | | | | | | | | Fix a few warnings about unused and uninitialized variables. Also fix util/subst.c to include <sys/time.h> to avoid using undeclared functions gettimeofday() and futimes(). Signed-off-by: Andreas Dilger <adilger@dilger.ca> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* libext2fs: fix bounds check of the bitmap test range in get_free_blocks2Darrick J. Wong2014-07-251-1/+4
| | | | | | | | | | | | | | | | | | | | | In the loop in ext2fs_get_free_blocks2, we ask the bitmap if there's a range of free blocks starting at "b" and ending at "b + num - 1". That quantity is the number of the last block in the range. Since ext2fs_blocks_count() returns the number of blocks and not the number of the last block in the filesystem, the check is incorrect. Put in a shortcut to exit the loop if finish > start, because in that case it's obvious that we don't need to reset to the beginning of the FS to continue the search for blocks. This is needed to terminate the loop because the broken test meant that b could get large enough to equal finish, which would end the while loop. The attached testcase shows that with the off by one error, it is possible to throw e2fsck into an infinite loop while it tries to find space for the inode table even though there's no space for one. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* lib/ext2fs: Only build tst_libext2fs for make checkTheodore Ts'o2014-07-101-15/+16
| | | | | | | | | It's only necessary to build tst_libext2fs when running "make check". Also make sure the links of the tst_* programs are done with $(ALL_LDFLAGS). Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* Use sys/syscall.h instead of syscall.hTheodore Ts'o2014-07-102-2/+2
| | | | | | | | | Most systems have a backwards compatibility symlink in /usr/include/syscall.h to /usr/include/sys/syscall.h, but sys/syscall.h is the documented location of the header file. Fix two locations where we were using <syscall.h> instead of <sys/syscall.h>. Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* mke2fs: prevent creation of unmountable ext4 with large flex_bg countAkira Fujita2014-07-051-0/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In mke2fs command, if flex_bg count is too large to filesystem blocks count, unmountable ext4 which has the out of filesystem block offset is created (Case1). Moreover this large flex_bg count causes an unintentional metadata layout (bmap-imap-itable-bmap-imap-itable .. in block group) (Case2). To fix these issues and keep healthy flex_bg layout, disallow creating ext4 with obviously large flex_bg count to filesystem blocks count. Steps to reproduce: (Case1) 1. # mke2fs -t ext4 -b 4096 -O ^resize_inode -G $((2**20)) DEV 2130483 2. # mount -t ext4 DEV MP mount: wrong fs type, bad option, bad superblock on /dev/sdb4, missing codepage or helper program, or other error In some cases useful info is found in syslog - try dmesg | tail or so 3. # dumpe2fs DEV ... Block count: 2130483 ... Flex block group size: 1048576 ... Group 65: (Blocks 2129920-2130482) [INODE_UNINIT] Checksum 0x4cb3, unused inodes 8080 Block bitmap at 67 (bg #0 + 67), Inode bitmap at 1048643 (bg #32 + 67) Inode table at 2129979-2130483 (+59) ^^^^^^^ 2130483 is out of FS! 65535 free blocks, 8080 free inodes, 0 directories, 8080 unused inodes Free blocks: Free inodes: 525201-533280 (Case2) 1. # mke2fs -t ext4 -G 2147483648 DEV 3145728 2. # debugfs -R stats DEV ... Block count: 786432 ... Flex block group size: 2147483648 ... Group 0: block bitmap at 193, inode bitmap at 194, inode table at 195 ... Group 1: block bitmap at 707, inode bitmap at 708, inode table at 709 ... Group 2: block bitmap at 1221, inode bitmap at 1222, inode table at 1223 ... Signed-off-by: Akira Fujita <a-fujita@rs.jp.nec.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Reviewed-by: Andreas Dilger <adilger@dilger.ca>
* mke2fs: handle flex_bg collision with backup descriptorsAndreas Dilger2014-07-051-6/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If a large flex_bg factor is specified and the block allocator was laying out block or inode bitmaps or inode tables, and collides with previously allocated metadata (for example the backup superblock or group descriptors) it would reset the allocator back to the beginning of the flex_bg instead of continuing past the obstruction. For example, with "-G 131072" the inode table will hit the backup descriptors in groups 1, 3, 5, 7, 9 and start interleaving with the block and inode bitmaps. That results in poorly allocated bitmaps and inode tables that are interleaved and not contiguous as was intended for flex_bg: Group 0: (Blocks 0-32767) Primary superblock at 0, Group descriptors at 1-2048 Block bitmap 2049 (+2049), Inode bitmap at 133121 (bg #4+2049) Inode table 264193-264200 (bg #8+2049) : : Group 3838: (Blocks 125763584-125796351) [INODE_UNINIT, BLOCK_UNINIT] Block bitmap 5887 (bg #0+5887), Inode bitmap 136959 (bg #4+5887) Inode table 294897-294904 (bg #8 + 32753) Group 3839: (Blocks 125796352-125829119) [INODE_UNINIT, BLOCK_UNINIT] Block bitmap 5888 (bg #0+5888), Inode bitmap 136960 (bg #4+5888) Inode table 5889-5896 (bg #0 + 5889) Group 3840: (Blocks 125829120-125861887) [INODE_UNINIT, BLOCK_UNINIT] Block bitmap 5897 (bg #0+5897), Inode bitmap 136961 (bg #4+5889) Inode table 5898-5905 (bg #0 + 5898) : : Instead, skip the intervening blocks if there aren't too many of them. That mostly keeps the flex_bg allocations from colliding, though still not perfect because there is still some overlap with the backups. This patch addresses the majority of the problem, allowing about 124k groups to be layed out perfectly, instead of less than 4k groups with the previous code. Signed-off-by: Andreas Dilger <adilger@dilger.ca> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* e2fsprogs: introduce ext2fs_close_free() helperLukas Czerner2014-07-054-9/+18
| | | | | | | | | | | | | | | | | | | | | | | | | Currently there are many uses of ext2fs_close() which might be wrong. First of all ext2fs_close() does not set the ext2_filsys pointer to NULL so the caller is responsible for clearing it, however there are some cases there we do not do it. Second of all very small number of users of ext2fs_close() actually check the return value. If there is a problem in ext2fs_close() it will not even free the ext2_filsys structure, but majority of users expect it to do so. To fix both problems this commit introduces a new helper ext2fs_close_free() which will not only check for the return value and free the ext2_filsys structure if the call to ext2fs_close2() failed, but it will also set the ext2_filsys pointer to NULL. Replace every use of ext2fs_close() in e2fsprogs tools with ext2fs_close_free() - there is no real reason to keep using ext2fs_close(). Signed-off-by: Lukas Czerner <lczerner@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
* blkid,ext2fs: avoid name clash with __u{8,16,32,64}Andreas Dilger2014-07-042-4/+70
| | | | | | | | | | | | | | | | | Try to avoid name clashes with definitions of __u8, __u16, __u32, and __u64 in userspace, in case other headers also define these types. Define HAVE___{S,U}{8,16,32,64} preprocessor macros to show that these types are already defined. This would avoid the need to check for _BLKID_TYPES_H in ext2_types.h and _EXT2_TYPES_H in blkid_types.h, but since older versions of these headers did not use HAVE___U8 et.al. keep these checks around for now. Report an error if there are no 64-bit types available. The code will not compile if these are not available. Signed-off-by: Andreas Dilger <adilger@dilger.ca> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* blkid: remove unnecessary header and commentAndreas Dilger2014-07-043-10/+0
| | | | | | | | | | | | | | | | | | The LIST_HEAD macro is not directly used in getsize.c, so <sys/queue.h> is not needed at all, and could cause confusion at some later point if the Linux-style list macros are ever used. Build was verified on MacOS which defined HAVE_SYS_DISK_H true. I manually inspected the sources for recent *BSD headers to check if this was needed there or not. MacOS and FreeBSD <sys/disk.h> do not use lists at all. NetBSD and OpenBSD <sys/disk.h> and all of the <sys/mount.h> headers include <sys/queue.h> internally. I used http://fxr.watson.org/fxr/source/sys/mount.h?v={OSTYPE} as a reference, checking both old and new *BSD versions. Signed-off-by: Andreas Dilger <adilger@dilger.ca> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* e2fsprogs: remove checker infrastructureEric Sandeen2014-07-048-38/+8
| | | | | | | | | | | | Per http://www.gnu.org/software/checker/ the gcc "-checker" option is long deprecated. Nuke it from e2fsprogs. Most people would never hit this, but people who love to turn knobs, such as the reporter of kernel.org bz#74171, might run into it and be sad. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* aclocal.m4: update to newer versions of autoconf macrosTheodore Ts'o2014-07-045-44/+221
| | | | Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* misc: quiet minor build warnings, ignore generated filesAndreas Dilger2014-07-041-2/+2
| | | | | | | | | | Quiet a couple of build warnings in tst_libext2fs.c Add missing unistd.h header for misc/util.c. Ignore generated files for lib/ext2fs/tst_libext2fs and intl/ files. Signed-off-by: Andreas Dilger <adilger@dilger.ca> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* lib/ext2fs: clean and build ext2_types.h as necessaryTheodore Ts'o2014-05-271-1/+6
| | | | Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* tst_libext2fs: add new debug program which used for libext2fs unit testsTheodore Ts'o2014-05-273-13/+305
| | | | Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
* quota: support storing the quota file handles in the quota contextTheodore Ts'o2014-05-133-21/+66
| | | | | | | | This makes memory management easier because when the quota context is released, all of the quota file handles get released automatically. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Reviewed-by: Aditya Kali <adityakali@google.com>
* quota: integrate mkquota.h into quotaio.hTheodore Ts'o2014-05-135-120/+71
| | | | | | | | | | | | | | | | | | There are interfaces that are used by mke2fs.c and tune2fs.c which are in quotaio.h, and some future changes will be much simpler if we can combine the two header files together. Also the guard #ifdef for mkquota.h was incorrect, which caused problems when both header files needed to be included. Also remove quota.pc and installation rules for libquota, since this library is never going to be something that we can export externally anyway. Eventually we'll want to clean up the interfaces and move the external publishable interfaces to the libext2fs library, and then rename what's left from libquota.a to libsupport.a for internal use only. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Reviewed-by: Aditya Kali <adityakali@google.com>
* quota: fix memory leak in quota_compare_and_update()Theodore Ts'o2014-05-132-3/+15
| | | | | | | | | | | The quota_handle wasn't getting closed in quota_compare_and_update(). Fix this, and also make sure that quota_file_close() doesn't unnecessarily modify the quota inode if it's not necessary. Otherwise e2fsck will claim that the file system is modified when it didn't need to be. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Reviewed-by: Aditya Kali <adityakali@google.com>
* quota: fix e2fsck to notice missing quota entriesTheodore Ts'o2014-05-132-1/+18
| | | | | | | | | | | | | | Previously if there was a missing quota entry --- i.e., if there were files owned by group "eng", but there was no quota record for group "eng", e2fsck would not notice the missing entry. This means that the usage informtion would not be properly repaired. This is unfortunate. Fix this by marking each quota record in quota_dict that has a corresponding record on disk, and then check to see if there are any records in quota_dict that have not been marked as having been seen. In that case, we know we need to update the relevant quota inode. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Reviewed-by: Aditya Kali <adityakali@google.com>
* quota: fix e2fsck so we update the quota file correctlyTheodore Ts'o2014-05-131-1/+0
| | | | | | | | | | | | | | | | | | | | | In scan_dquota_callback() we were copying dqb_off from the on-disk dquot structure to the dqot structure that we have constructed in memory. This is a bad idea, because if we detect that the quota inode is corrupted and needs to be replaced, when we later write out the inode, the fact that we have a non-zero dqb_off value means that quota routines will not bother updating the quota tree index, since presumably the quota tree index already has an entry for this dqot. The problem is that e2fsck, the only user of these functions, has zapped the quota inode so it can be written from scratch. So this means the index for the quota records are not written out, so the kernel can not find any of the records in the quota inodes. Oops. The fix is simple; there is no reason to copy the dqb_off field into the quota_dict copy of struct dquot. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Reviewed-by: Aditya Kali <adityakali@google.com>
* quota: add debugging code to print the dquot structureTheodore Ts'o2014-05-132-0/+20
| | | | | Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Reviewed-by: Aditya Kali <adityakali@google.com>
* libquota: fix dict_uint_cmp()Niu Yawei2014-05-091-1/+6
| | | | | | | | | dict_uint_cmp() returns an usigned int value in int type, which could mess the dict key comparison when the difference of two keys is greater than INT_MAX. Signed-off-by: Niu Yawei <yawei.niu@intel.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
* Add a make variable for the pkgconfig install dirDavid Michael2014-05-077-28/+28
| | | | | | | | Adding the pkgconfigdir variable allows specifying an installation location for pkg-config files independent of libdir. Signed-off-by: David Michael <fedora.dm0@gmail.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
* mke2fs: check for a partition table and warn if presentTheodore Ts'o2014-05-071-0/+3
| | | | | | | | This supercedes the "whole disk" check, since it does a better job and there are times when it is quite legitimate to want to use the whole disk. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
* libext2fs: fix alloc_allocate_group_table() if the flexbg_offset wrapsTheodore Ts'o2014-05-041-2/+2
| | | | | | | | | | | | | | | | | | | | | | | If the previous block group's inode table ends at the very end of file system, wrap around to the beginning of the flex_bg. This fixes a bug was tickled by: mke2fs.conf: frontload = { features = extent,huge_file,flex_bg,uninit_bg,dir_nlink,extra_isize,^resize_inode,sparse_super2 hash_alg = half_md4 num_backup_sb = 0 packed_meta_blocks = 1 inode_ratio = 4194304 flex_bg_size = 262144 } mke2fs -T frontload /tmp/foo.img 2T resize2fs -M /tmp/foo.img resize2fs -M /tmp/foo.img Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
* e2fsprogs/filefrag: print shared extent flagMark Fasheh2014-05-041-0/+2
| | | | | | | | Filefrag doesn't catch and print the shared extent flag. Add this for users of filefrag on file systems with shared extents (such as btrfs). Signed-off-by: Mark Fasheh <mfasheh@suse.de> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
* fix miscellaneous build warningsAndreas Dilger2014-04-145-9/+3
| | | | | | | | | Fix various unused variable and use-uninitialized warnings. Add generated files into .gitignore. Signed-off-by: Andreas Dilger <andreas.dilger@intel.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
* Add coverage testing using gcovTheodore Ts'o2014-02-232-8/+8
| | | | | | | | | | | | | To check the coverage of e2fsprogs's regression test, do the following: configure --enable-gcov make -j8 ; make -j8 check ; make coverage.txt The coverage information will be the coverage.txt and *.gcov files in the build directories. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
* Set pointer to NULL after ext2fs_freeLukas Czerner2014-02-201-3/+4
| | | | | | | | | | | | ext2fs_free() does not set the ext2_filsys pointer to null so the caller is responsible to setting it himself if it is needed. This patch fixes some places where caller did not set ext2_filsys pointer to NULL after ext2fs_free() which might result in use after free. Fix it. Signed-off-by: Lukas Czerner <lczerner@redhat.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
* libext2fs: delete unused "handle" variablejon ernst2014-02-201-1/+0
| | | | | | | | After commit 62f17f36031102a2a40fac338e063c556f73b94a, variable "handle" has no use. So delete it. Signed-off-by: Jon Enrst <jonernst07@gmail.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
* ext2fs: declare struct_io_manager at end of fileAndreas Dilger2014-02-183-150/+91
| | | | | | | | | | | | | | | Declare struct_io_manager at the end of unix_io.c, undo_io.c, and test_io.c files so that there isn't a need to forward declare every member of this structure. That avoids a lot of redundant code at the start of every one of these files. Move the test_flush() function above test_abort() to avoid the need for a forward declaration. Fix a few instances of space before tab in these files. Signed-off-by: Andreas Dilger <adilger@dilger.ca> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
* tests: skip unsupported tests on MacOS systemsAndreas Dilger2014-02-181-2/+2
| | | | | | | | | | | | | | | | | | | | | | The "mkswap" program is not available on MacOS, so just use the existing swap0.img.bz2 and swap1.img.bz2 files directly. Because MacOS HFS+ doesn't support sparse files (welcome to the 80's) the m_bigjournal test takes forever to zero out the whole 42GB test filesystem. Skip this test for Darwin kernels for now. Unfortunately, neither "df -T" nor "stat -f -c %T" is available on MacOS to directly determine the filesystem type, and I'm too lazy to parse the output of "mount" and match it to the path of the test directory in shell, so it just checks the kernel type and assumes the filesystem type is HFS and skips the test. Since this test runs on Linux the majority of the time, the loss of test coverage is minimal. If MacOS should ever get a real filesystem, this can be revisited. Signed-off-by: Andreas Dilger <adilger@dilger.ca> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
* build: fix LLVM compiler warningsAndreas Dilger2014-02-181-10/+10
| | | | | | | | | | | | | | | | | | Fix a number of non-literal string format warnings from LLVM due to the use of _() that were not fixed in commit 45ff69ffeb. Fix mismatched int vs. __u64 format warnings in blkmap64_rb.c. There were also some comparisons of __u64 start or count <= 0. Change them to be comparisons == 0, or start + count overflow. Fix operator precedence warning for (value & (value - 1) != 0) introduced in 11d1116a7c0b. It seems "&" is lower precedence than "!=", so the above didn't fail for power-of-two values, but only odd values. Fortunately, either s_desc_size nor s_inode_size is valid if odd. Signed-off-by: Andreas Dilger <adilger@dilger.ca> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
* libe2p: allow libe2p.h to be used in C++ programsTheodore Ts'o2014-02-071-1/+1
| | | | | | | In C++, "private" is a reserved keyword, so don't use it in the header file as a function parameter name. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
* libext2fs: try to roll back when splitting an extent failsDarrick J. Wong2014-02-061-3/+22
| | | | | | | | | | | | | If a client asks us to remap a block in the middle of an extent, we potentially have to allocate a fair number of blocks to handle extent tree splits. A failure in either of the ext2fs_extent_insert calls leaves us with an extent tree that no longer maps the logical block in question and everything that came after it! Therefore, try to roll back the extent tree changes before returning an error code. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Zheng Liu <wenqing.lz@taobao.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* libext2fs: don't hang on to unmapped block if extent tree update failsDarrick J. Wong2014-02-061-1/+3
| | | | | | | | | | If we're doing a BMAP_ALLOC allocation and the extent tree update fails, there's no point in hanging on to the newly allocated block. So, free it to make fsck happy. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Zheng Liu <wenqing.lz@taobao.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* libext2fs: during punch, fix parent extents after modifying extentDarrick J. Wong2014-02-061-0/+8
| | | | | | | | | When modifying/removing an extent during punch, don't forget to update the extent's parents. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Zheng Liu <wenqing.lz@taobao.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
* libext2fs: iterate past lower extents during punchDarrick J. Wong2014-02-061-2/+11
| | | | | | | | | | | | | | When we're iterating extents during a punch operation, the loop exits if the punch region is entirely to the right of the extent we're looking at. This can happen if the punch region starts in the middle of a hole and covers mapped extents. When this happens, we want to skip to the next extent, because it might be punchable. Also, if we've totally passed the punch range, stop. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Zheng Liu <wenqing.lz@taobao.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>