mkfs.f2fs: enforce alias_filename to match device name

The kernel expects the device alias file in the root directory to match
the device basename (strrchr(path, '/') + 1) to identify the target device
both during mount in f2fs_restore_device_alias() and during reserve in
f2fs_ioc_reserve_dev_alias().

If a custom alias filename that differs from the device name is used,
the kernel fails to match the alias file at mount time (leaving
FDEV(i).has_alias unset and allowing pinned files to allocate in that
range) and subsequently fails to reserve the device range when requested.

Enforce that if an alias filename is specified, it must match the device
name. Also allow specifying just '-c <device>@' as a shorthand so users
do not have to redundantly type the device basename twice.

Reported-by: Wenjie Qi <qiwenjie@xiaomi.com>
Fixes: 8cc4e257ec20 ("mkfs.f2fs: add device aliasing feature")
Signed-off-by: Daeho Jeong <daehojeong@google.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2 files changed