summaryrefslogtreecommitdiff
path: root/mkfs/main.c
Commit message (Collapse)AuthorAge
* btrfs-progs: mkfs: Only zero out the first 1M for rootdirQu Wenruo2018-01-03
| | | | | | | | | It's a waste of IO to fill the whole image before creating btrfs on it, just wiping the first 1M, and then write 1 byte to the last position to create a sparse file. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: Enhance minimal device size calculation to fix mkfs ↵Qu Wenruo2018-01-03
| | | | | | | | | | | | | | | | | | | | | | failure on small file Since commit c11e36a29e84 ("Btrfs-progs: Do not force mixed block group creation unless '-M' option is specified"), mkfs no longer use mixed block group unless specified manually. This breaks the minimal device size calculation, which only considered mixed block group use case. This patch enhances minimal device size calculation for mkfs, by using different minimal stripe length (calculated from code) for different profiles, and use them to calculate minimal device size. Reported-by: Wesley Aptekar-Cassels <W.Aptekar@gmail.com> Fixes: c11e36a29e84 ("Btrfs-progs: Do not force mixed block group creation unless '-M' option is specified") Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com> [ updated comments ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: check the status of file at mkfsMisono, Tomohiro2018-01-03
| | | | | | | | | | | | | Currently, only the status of block devices is checked at mkfs, but we should also check for regular files whether they are already formatted or mounted to prevent overwrite accidentally. Device status is checked by test_dev_for_mkfs(). The part which is not related to block device is split from this and used for both block device and regular file. Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: refactor test_minimum_size to use the calculated minimal sizeQu Wenruo2017-11-14
| | | | | | | | | | | | | | test_minimum_size() function is only called to check if provided device is large enough. However the minimal device size only needs to be calculated once, and can be reused everywhere. Refactor that function to make later modification easier. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: error out gracefully for --rootdirQu Wenruo2017-11-14
| | | | | | | | | | | | | | | | | | | | | | | | --rootdir option will start a transaction to fill the fs, however if something goes wrong, from ENOSPC to lack of permission, we won't commit the transaction and cause BUG_ON triggered by uncommitted transaction: ------ extent buffer leak: start 29392896 len 16384 extent_io.c:579: free_extent_buffer: BUG_ON `eb->flags & EXTENT_DIRTY` triggered, value 1 ------ The root fix is to introduce btrfs_abort_transaction() in btrfs-progs, however in this particular case, we can workaround it by force committing the transaction. Since during mkfs, the magic of btrfs is set to an invalid one, without setting fs_info->finalize_on_close() the fs is never able to be mounted. So even we force to commit wrong transaction we won't screw up things worse. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: fix overwritten return value for mkfsQu Wenruo2017-11-14
| | | | | | | | | For mkfs failure, especially --rootdir errors like EPERM/ENOSPC, the out branch will overwrite the return value, causing wrong status code. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: avoid positive return value from cleanup_temp_chunksQu Wenruo2017-11-14
| | | | | | | | | | | | | Since we're calling btrfs_search_slot() the return value can be positive. However we just pass that return value out, causing undefined return value. This can cause mkfs to return 1, which indicates something wrong. Fix it. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: remove unused functionDavid Sterba2017-10-06
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: use existing helper for path concatenationDavid Sterba2017-10-06
| | | | | | | Mkfs uses make_path that is duplicate of path_cat* functions, so we can switch to them and add the error handling. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: refactor create_data_reloc_treeyingyil2017-09-25
| | | | | | | | | Add an objectid parameter to make the function a general one for inserting root items and rename it to create_tree. The change cascades down to the callchain. Signed-off-by: yingyil <yingyil@google.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: Fix wrong file type for dir items and indexes when ↵Qu Wenruo2017-09-08
| | | | | | | | | | | | | | | | | | | | | | | | | | | specifying root directory [Bug] If using mkfs.btrfs with "-r" parameter and specified directory has fifo/socket/char/block special file, then created filesystem can't pass fsck: ------ checking fs roots unresolved ref dir 241158 index 3 namelen 9 name S.dirmngr filetype 0 errors 80, filetype mismatch ERROR: errors found in fs roots ------ [Reason] Btrfs dir items/indexes records inode type, while "-r" only handles directories, regular files and symlink, it makes such special files type to be regular file and caused the problem. [Fix] Add missing types for add_directory_items(), so that result of "mkfs.btrfs -r" can pass mkfs. Signed-off-by: Qu Wenruo <quwenruo.btrfs@gmx.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: add crude error handling when transaction start failsDavid Sterba2017-09-08
| | | | | | | | | | Currently transaction bugs out insided btrfs_start_transaction in case of error, we want to lift the error handling to the callers. This patch adds the BUG_ON anywhere it's been missing so far. This is not the best way of course. Transforming BUG_ON to a proper error handling highly depends on the caller and should be dealt with case by case. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Use named constants for common sizesNikolay Borisov2017-09-08
| | | | | | | | | There multiple places where we use well-known sizes - 1,8,16,32 megabytes. We also have them defined as constants in the sizes.h header. So let's use them. No functional changes. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: Make in-place exit to a common exit blockGu Jinxiang2017-08-24
| | | | | | | | Replace in-place exit with a common exit block in the main function. Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com> [ update changelog ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: delete un-used parameter fdGu Jinxiang2017-08-24
| | | | | | | | Parameter fd is not used in function make_image and traverse_directory of mkfs. Delete it. Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Refactor chunk creation functions to use btrfs_fs_infoQu Wenruo2017-07-12
| | | | | | | | 4 functions are involved in this refactor: btrfs_make_block_group() btrfs_make_block_groups(), btrfs_alloc_chunk, btrfs_alloc_data_chunk(). Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Refactor write_and_map_eb to use btrfs_fs_infoQu Wenruo2017-07-12
| | | | | Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Refactor sectorsize users in mkfs/main.cQu Wenruo2017-07-03
| | | | Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
* btrfs-progs: mkfs: remove unused argument from add_file_itemsDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: remove unused arguments from add_inode_itemsDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: remove unused argument from make_root_dirDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: remove unused argument from set_extent_dirtyDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: remove unused argument from write_and_map_ebDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: make make_cfg::blocks an internal memberDavid Sterba2017-03-08
| | | | | | | The caller of make_btrfs does not need to set it, it's for internal use and can be read after mkfs ends. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move fs features declarations to own header from utilsDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move mkfs definitions to own headerDavid Sterba2017-03-08
| | | | | | | Create a header for filesystem creation API, the config and the main entry function. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move help defines to own headerDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs/convert: separate the convert part from make_btrfsDavid Sterba2017-01-27
| | | | | | | The regulare mkfs_btrfs does not anything special about convert and just passes the arguments. Make that two functions. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Fix spelling/typos in user-facing stringsNicholas D Steeves2017-01-25
| | | | | Signed-off-by: Nicholas D Steeves <nsteeves@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: annotation of a caseDavid Sterba2016-12-14
| | | | | | | Annotate to silence static analysis warning. Resolves-coverity-id: 1396656 Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move mkfs.btrfs sources to own directoryDavid Sterba2016-12-14
Signed-off-by: David Sterba <dsterba@suse.com>