summaryrefslogtreecommitdiff
path: root/utils.c
Commit message (Collapse)AuthorAge
* Btrfs-progs: make two utility functions globally availableStefan Behrens2013-01-30
| | | | | | | | Two convenient utility functions that have so far been local to scrub are moved to utils.c. They will be used in the device stats code in a following commit. Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
* Btrfs-progs: move open_file_or_dir() to utils.cAnand Jain2013-01-30
| | | | | | | | | | | The definition of the function open_file_or_dir() is moved from common.c to utils.c in order to be able to share some common code between scrub and the device stats in the following step. That common code uses open_file_or_dir(). Since open_file_or_dir() makes use of the function dirfd(3), the required XOPEN version was raised from 6 to 7. Signed-off-by: Anand Jain <anand.jain@oracle.com> Original-Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
* Btrfs-progs: fix resolving of loop devicesNirbheek Chauhan2013-01-21
| | | | | | | | | | The LOOP_GET_STATUS ioctl truncates filenames to 64 characters. We should get the backing file for a given loop device from /sys/. This is how losetup does it as well. Signed-off-by: Nirbheek Chauhan <nirbheek.chauhan@collabora.co.uk> Signed-off-by: Gene Czarcinski <gene@czarc.net> Tested-By: Hector Oron <hector.oron@collabora.co.uk>
* Ignore the error ENXIO and ENOMEDIUM during a devs scanGoffredo Baroncelli2013-01-18
| | | | | | | | | | Ignore the error ENXIO (device don't exists) and ENOMEDIUM ( No medium found -> like a cd tray empty) in the function btrfs_scan_one_dir. This avoids spurios errors due to an empty CD or a block device node without a device (which is frequent in a static /dev). Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
* btrfs-progs: plug memory leaks in btrfs_scan_one_dir() reported by cppcheck.Kenji Okimoto2013-01-17
| | | | | | [utils.c:983]: (error) Memory leak: fullpath Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
* parse_size(): add new suffixesGoffredo Baroncelli2013-01-17
| | | | | | | | Add new suffixes in parse_size() function. New suffixes are: T as terabyte, P as petabyte, E as exabyte. Note these units are multiply of 2 . Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
* parse_size(): replace atoll() with strtoull()Goffredo Baroncelli2013-01-17
| | | | | | | Replace the function atoll with strtoull(); Check that the suffix for the parse_size() input is of only one character. Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
* Move parse_size() to utils.[hc]Goffredo Baroncelli2013-01-17
| | | | | | Move the function from cmds-filesystem.c and mkfs.c to utils.c Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
* pretty_sizes() returns incorrect valuesGoffredo Baroncelli2012-10-04
| | | | | | | | | | | | pretty_sizes() returns incorrect values if the argument is < 1024. pretty_sizes(0) -> 0.00 OK pretty_sizes(102) -> 0.10 WRONG pretty_sizes(1023) -> 1.00 WRONG pretty_sizes(1024) -> 1.00KB OK Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: only enforce a maximum size if we specify oneJosef Bacik2012-10-02
| | | | | | | | | | | | | | My patch 04609add88ef8428d725de6ef60f46a3ff0dbc8e introduced a regression where if you mkfs'ed a group of disks with different sizes it limited the disks to the size of the first one that is specified. This was not the intent of my patch, I only want it to limit the size based on the -b option, so I've reworked the code to pass in a max block count and that fixes the issue. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com>
* btrfs-progs: mkfs: create root directory with 755 permissionsDavid Sterba2012-10-02
| | | | | | That's what all other mkfs do and there's no reason for 0555. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: mkfs: add option to skip trimDavid Sterba2012-07-06
| | | | Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: enforce block count on all devices in mkfsJosef Bacik2012-07-03
| | | | | | | | | | I had a test that creates a 7gig raid1 device but it was ending up wonky because the second device that gets added is the full size of the disk instead of the limited size. So enforce the limited size on all disks passed in at mkfs time, otherwise our threshold calculations end up wonky when doing chunk allocations. Thanks, Signed-off-by: Josef Bacik <josef@redhat.com>
* avoid several strncpy-induced buffer overrunsJim Meyering2012-06-05
| | | | | | | | | | | | | | * restore.c (main): Ensure strncpy-copied dir_name is NUL-terminated. * btrfsctl.c (main): Likewise, for a command-line argument. * utils.c (multiple functions): Likewise. * btrfs-list.c (add_root): Likewise. * btrfslabel.c (change_label_unmounted): Likewise. * cmds-device.c (cmd_add_dev, cmd_rm_dev, cmd_scan_dev): Likewise. * cmds-filesystem.c (cmd_resize): Likewise. * cmds-subvolume.c (cmd_subvol_create, cmd_subvol_delete, cmd_snapshot): Likewise. Reviewed-by: Josef Bacik <josef@redhat.com>
* btrfs_scan_one_dir: avoid use-after-free on error pathJim Meyering2012-06-05
| | | | | | | | | | If we iterate the "goto again" loop, we've called "closedir(dirp)", yet at the top of the loop, upon malloc failure we "goto fail", where we test dirp and if non-NULL, call closedir(dirp) again. * utils.c (btrfs_scan_one_dir): Clear "dirp" after closedir to avoid use-after-free upon failed fullpath = malloc(... Signed-off-by: Jim Meyering <meyering@redhat.com>
* Scan /dev/md and device mapper devices lastChris Mason2012-02-22
| | | | | | | | | | | When we're using multipath or raid0, it is possible that btrfs dev scan will find one of the component devices instead of the proper virtual device the kernel creates. We want to make sure the kernel scans the virtual devices last, since it always remembers the last device it finds with a given fsid. Signed-off-by: Chris Mason <chris.mason@oracle.com>
* Btrfs: use /proc/partitions scanning for btrfs_scan_for_fsidChris Mason2012-02-21
| | | | | | | | btrfs_scan_for_fsid is used by open_ctree and by mkfs when it is checking for mounted devices. It currently scans all of /dev, which is rarely the right answer. Signed-off-by: Chris Mason <chris.mason@oracle.com>
* btrfs-progs: fixup is_mounted checksChris Mason2011-10-27
| | | | | | | | | | /proc/mounts contains device names that don't exist, we end up erroring out because we're not able to stat the device (that doesn't exist). Fix this by allowing the mkfs when the target device doesn't exist. Signed-off-by: Chris Mason <chris.mason@oracle.com>
* Scan the devices listed in /proc/partitionsGoffredo Baroncelli2011-10-25
| | | | | | | | | | | During the commands: - btrfs filesystem show - btrfs device scan the devices "scanned" are extracted from /proc/partitions. This should avoid to scan devices not suitable for a btrfs filesystem like cdrom and floppy or to scan not existant devices. The old behavior (scan all the block devices under /dev) may be forced passing the "--all-devices" switch.
* btrfs-progs: added check_mounted_whereJan Schmidt2011-10-25
| | | | | | | | | new version of check_mounted() returning more information gathered while searching. check_mounted() is now a wrapper for check_mounted_where(). the new version is needed by scrub.c Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net> Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
* mkfs should initialize unused fields properlyJan Schmidt2011-10-25
| | | | | | | | | | | we discovered speed setting is (probably unintentionally) initialized to 1 in make_btrfs(), while being initialized to 0 in btrfs_add_to_fsid(). initialization in make_btrfs() is due to reuse of buf after pwrite() without clearing it. consequently, code like btrfs_set_extent_generation(buf, extent_item, 1); writes to the same location in buf where speed will be placed, later. It may be a good idea to clear buf after each pwrite(), though leaving the struct btrfs_header intact. Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net> Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
* btrfs-progs: setting of time to the root directoryTsutomu Itoh2011-10-25
| | | | | | | | | | | | | | | | | | | | | | | | | | | This patch adds the setting of time to the root directory to the mkfs.btrfs command. As a result, the time of the mount point not correctly displayed comes to be displayed correctly. [before] # mkfs.btrfs /dev/sdd10 # mount /dev/sdd10 /test1 # ls -ld /test1 dr-xr-xr-x 1 root root 0 Jan 1 1970 /test1 [after] # date Tue Nov 16 18:06:05 JST 2010 # mkfs.btrfs /dev/sdd10 # mount /dev/sdd10 /test1 # ls -ld /test1 dr-xr-xr-x 1 root root 0 Nov 16 18:06 /test1 Thanks, Tsutomu Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com> Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
* btrfs-progs: add discard support to mkfsChristoph Hellwig2011-10-25
| | | | | | | | Discard the whole device before starting to create the filesystem structures. Modelled after similar support in mkfs.xfs. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Chris Mason <chris.mason@oracle.com>
* Add the "btrfs filesystem label" commandGoffredo Baroncelli2011-10-25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Hi all, this patch adds the command "btrfs filesystem label" to change (or show) the label of a filesystem. This patch is a subset of the one written previously by Morey Roof. I included the user space part only. So it is possible only to change/show a label of a *single device* and *unounted* filesystem. The reason of excluding the kernel space part, is to simplify the patch in order to speed the check and then the merging of the patch itself. In fact I have to point out that in the past there was almost three attempts to propose this patch, without success neither complaints. Chris, let me know how you want to proceed. I know that you are very busy, and you prefer to work to stabilize btrfs instead adding new feature. But I think that changing a label is a *essential* feature for a filesystem managing tool. Think about a mount by LABEL. To show a label $ btrfs filesystem label <device> To set a label $ btrfs filesystem label <device> <newlabel> Please guys, give a look to the source. Comments are welcome. You can pull the source from the branch "label" of the repository http://cassiopea.homelinux.net/git/btrfs-progs-unstable.git Regards G.Baroncelli Signed-off-by: Chris Mason <chris.mason@oracle.com>
* Btrfs-progs: add support for mixed data+metadata block groupsJosef Bacik2011-10-25
| | | | | | | | | | | | So alot of crazy people (I'm looking at you Meego) want to use btrfs on phones and such with small devices. Unfortunately the way we split out metadata/data chunks it makes space usage inefficient for volumes that are smaller than 1gigabyte. So add a -M option for mixing metadata+data, and default to this mixed mode if the filesystem is less than or equal to 1 gigabyte. I've tested this with xfstests on a 100mb filesystem and everything is a-ok. Signed-off-by: Josef Bacik <josef@redhat.com> Signed-off-by: Chris Mason <chris.mason@oracle.com>
* Btrfs-progs: update super fields for space cacheJosef Bacik2011-10-25
| | | | | | | | | This patch updates the super field to add the cache_generation member. It also makes us set it to -1 on mkfs so any new filesystem will get the space cache stuff turned on. Thanks, Signed-off-by: Josef Bacik <josef@redhat.com> Signed-off-by: Chris Mason <chris.mason@oracle.com>
* Improve error handling in the btrfs commandGoffredo Baroncelli2011-10-25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Hi Chris, below is enclosed a trivial patch, which has the aim to improve the error reporting of the "btrfs" command. You can pull from http://cassiopea.homelinux.net/git/btrfs-progs-unstable.git branch strerror I changed every printf("some-error") to something like: e = errno; fprintf(stderr, "ERROR: .... - %s", strerror(e)); so: 1) all the error are reported to standard error 2) At the end of the message is printed the error as returned by the system. The change is quite simple, I replaced every printf("some-error") to the line above. I don't touched anything other. I also integrated a missing "printf" on the basis of the Ben patch. This patch leads the btrfs command to be more "user friendly" :-) Regards G.Baroncelli btrfs-list.c | 40 ++++++++++++++++++++++-------- btrfs_cmds.c | 77 ++++++++++++++++++++++++++++++++++++++++----------------- utils.c | 6 ++++ 3 files changed, 89 insertions(+), 34 deletions(-) Signed-off-by: Chris Mason <chris.mason@oracle.com>
* Btrfs-progs utils Informative errorsGoldwyn Rodrigues2011-10-25
| | | | Signed-off-by: Chris Mason <chris.mason@oracle.com>
* Btrfs-progs use safe string manipulation functionsEduardo Silva2011-10-25
| | | | | Signed-off-by: Eduardo Silva <eduardo.silva@oracle.com> Signed-off-by: Chris Mason <chris.mason@oracle.com>
* multidevice support for check_mountedAndi Drebes2010-09-23
| | | | | | | | | | | | | | Check_mount() should also work with multi device filesystems. This patch adds checks that allow to detect if a file is a device file used by a mounted single or multi device btrfs or if it is a regular file used by a loopback device that is part of a mounted single or multi device btrfs. The single device checks also work for non-btrfs filesystems. This might be helpful to prevent users from running btrfs programs (e.g. mkfs.btrfs) accidentally on a filesystem used somewhere else. Signed-off-by: Andi Drebes <lists-receive@programmierforen.de>
* Mixed back reference (FORWARD ROLLING FORMAT CHANGE)Chris Mason2009-06-08
| | | | | | | | | | | | | | | | | This commit introduces a new kind of back reference for btrfs metadata. Once a filesystem has been mounted with this commit, IT WILL NO LONGER BE MOUNTABLE BY OLDER KERNELS. The new back ref provides information about pointer's key, level and in which tree the pointer lives. This information allow us to find the pointer by searching the tree. The shortcoming of the new back ref is that it only works for pointers in tree blocks referenced by their owner trees. This is mostly a problem for snapshots, where resolving one of these fuzzy back references would be O(number_of_snapshots) and quite slow. The solution used here is to use the fuzzy back references in the common case where a given tree block is only referenced by one root, and use the full back references when multiple roots have a reference
* Mention minimum size on devices that are considered too smallJan Engelhardt2009-01-21
| | | | | Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
* Fix ioctl arg size (userland incompatible change!)Chris Mason2009-01-16
| | | | | | | | | | | | | | | The structure used to send device in btrfs ioctl calls was not properly aligned, and so 32 bit ioctls would not work properly on 64 bit kernels. We could fix this with compat ioctls, but we're just one byte away and it doesn't make sense at this stage to carry about the compat ioctls forever at this stage in the project. This patch brings the ioctl arg up to an evenly aligned 4k. Signed-off-by: Chris Mason <chris.mason@oracle.com>
* Add error processing for btrfsctl -aShen Feng2009-01-07
| | | | | | | | | | | brfsctl -a will do nothing and no error is output if btrfs.ko is not inserted. Since no caller do error processing for btrfs_register_one_device, make its return void and do error processing inside. Signed-off-by: Shen Feng <shen@cn.fujitsu.com>
* Btrfs: update converter for the new disk formatYan Zheng2008-12-17
| | | | | | | | | | | This patch updates the ext3 to btrfs converter for the new disk format. This mainly involves changing the convert's data relocation and free space management code. This patch also ports some functions from kernel module to btrfs-progs. Thank you, Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
* superblock duplicationYan Zheng2008-12-05
| | | | | | | | | | This patch updates btrfs-progs for superblock duplication. Note: I didn't make this patch as complete as the one for kernel since updating the converter requires changing the code again. Thank you, Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
* Btrfs: move data checksumming into a dedicated treeChris Mason2008-12-08
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Btrfs stores checksums for each data block. Until now, they have been stored in the subvolume trees, indexed by the inode that is referencing the data block. This means that when we read the inode, we've probably read in at least some checksums as well. But, this has a few problems: * The checksums are indexed by logical offset in the file. When compression is on, this means we have to do the expensive checksumming on the uncompressed data. It would be faster if we could checksum the compressed data instead. * If we implement encryption, we'll be checksumming the plain text and storing that on disk. This is significantly less secure. * For either compression or encryption, we have to get the plain text back before we can verify the checksum as correct. This makes the raid layer balancing and extent moving much more expensive. * It makes the front end caching code more complex, as we have touch the subvolume and inodes as we cache extents. * There is potentitally one copy of the checksum in each subvolume referencing an extent. The solution used here is to store the extent checksums in a dedicated tree. This allows us to index the checksums by phyiscal extent start and length. It means: * The checksum is against the data stored on disk, after any compression or encryption is done. * The checksum is stored in a central location, and can be verified without following back references, or reading inodes. This makes compression significantly faster by reducing the amount of data that needs to be checksummed. It will also allow much faster raid management code in general. The checksums are indexed by a key with a fixed objectid (a magic value in ctree.h) and offset set to the starting byte of the extent. This allows us to copy the checksum items into the fsync log tree directly (or any other tree), without having to invent a second format for them. Signed-off-by: Chris Mason <chris.mason@oracle.com>
* btrfs-progs: support for different csum algorithimsJosef Bacik2008-12-02
| | | | | | | | | | | | | This is the btrfs-progs version of the patch to add the ability to have different csum algorithims. Note I didn't change the image maker since it seemed a bit more complicated than just changing some stuff around so I will let Yan take care of that. Everything else was converted and for now a mkfs just sets the type to be BTRFS_CSUM_TYPE_CRC32. Signed-off-by: Josef Bacik <jbacik@redhat.com>
* update btrfs-progs for seed device supportYan Zheng2008-11-18
| | | | | | | | | | | | This patch does the following: 1) Update device management code to match the kernel code. 2) Allocator fixes. 3) Add a program called btrfstune to set/clear the SEEDING super block flags.
* Add root tree pointer transaction idsYan Zheng2008-10-29
| | | | | | | | | | This patch adds transaction IDs to root tree pointers. Transaction IDs in tree pointers are compared with the generation numbers in block headers when reading root blocks of trees. This can detect some types of IO errors. Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
* Count space allocated to file in bytesYan Zheng2008-10-09
| | | | | | | | This patch updates btrfs-progs for counting space allocated to file in bytes. Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
* Remove offset field from struct btrfs_extent_refYan Zheng2008-10-09
| | | | | | | | | | | | | | The offset field in struct btrfs_extent_ref records the position inside file that file extent is referenced by. In the new back reference system, tree leaves holding reference to file extent are recorded explicitly. We can quickly scan these tree leaves, so the offset field is not required. This patch also makes the back reference system check the objectid when extents are being deleted Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
* Full back reference supportZheng Yan2008-09-23
| | | | | | | | This patch makes the back reference system to explicit record the location of parent node for all types of extents. The location of parent node is placed into the offset field of backref key. Every time a tree block is balanced, the back references for the affected lower level extents are updated.
* btrfs-progs new dir index supportJosef Bacik2008-07-24
|
* Fix the pretty print code for num_bytes == 0Chris Mason2008-05-12
|
* Fix uninitialized variables, and use -O so gcc starts checking for themChris Mason2008-05-01
| | | | | | | | Gcc only sends warnings for uninitialized variables when you compile with -O, and there were a couple of bugs sprinkled in the code. The biggest was the alloc_start variable for mkfs, which can cause strange things to happen. (thanks to Gabor Micsko for helping to find this)
* Update the Ext3 converterChris Mason2008-04-22
| | | | | | | | | | | The main changes in this patch are adding chunk handing and data relocation ability. In the last step of conversion, the converter relocates data in system chunk and move chunk tree into system chunk. In the rollback process, the converter remove chunk tree from system chunk and copy data back. Regards YZ ---
* Add a command to show all of the btrfs filesystems on the box (btrfs-show)Chris Mason2008-04-22
|
* Add checks to avoid adding the same device twice during mkfsChris Mason2008-04-18
|
* Add support for filesystem labels via mkfs.btrfs -LChris Mason2008-04-18
|