]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commit - mkfs/xfs_mkfs.c
mkfs: don't treat files as though they are block devices
authorDave Chinner <dchinner@redhat.com>
Tue, 10 May 2016 07:16:07 +0000 (17:16 +1000)
committerDave Chinner <david@fromorbit.com>
Tue, 10 May 2016 07:16:07 +0000 (17:16 +1000)
commit06ac92fdf8571ea10a3df64c7456eace03cf14c3
treec774035f5b9cb5af70de884280e5f6a11062f893
parent27ae3a59498cd1c5dbc0effcc242901ee945901e
mkfs: don't treat files as though they are block devices

If the device is actually a file, and "-d file" is not specified,
mkfs will try to treat it as a block device and get stuff wrong.
Image files don't necessarily have the same sector sizes as the
block device or filesystem underlying the image file, nor should we
be issuing discard ioctls on image files.

To fix this sanely, only require "-d file" if the device name is
invalid to trigger creation of the file. Otherwise, use stat() to
determine if the device is a file or block device and deal with that
appropriately by setting the "isfile" variables and turning off
direct IO. Then ensure that we check the "isfile" options before
doing things that are specific to block devices.

Other file/blockdev issues fixed:
- use getstr to detect specifying the data device name
  twice.
- check file/size/name parameters before anything else.
- overwrite checks need to be done before the image file is
  opened and potentially truncated.
- blkid_get_topology() should not be called for image files,
  so warn when it is called that way.
- zero_old_xfs_structures() emits a spurious error:
"existing superblock read failed: Success"
  when it is run on a truncated image file. Don't warn if we
  see this problem on an image file.
- Don't issue discards on image files.
- Use fsync() for image files, not BLKFLSBUF in
  platform_flush_device() for Linux.

[ Eric Sandeen <sandeen@redhat.com>: move check for no mkfs target,
other minor fixes. ]

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Jan Tulak <jtulak@redhat.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
libxfs/init.c
libxfs/linux.c
mkfs/xfs_mkfs.c