diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2025-04-13 08:33:40 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2025-04-21 18:46:30 -0400 |
commit | fee67d807bc36ff2cacb77286156798fd70e3f0c (patch) | |
tree | 3c05bd1237a6cdd731e651f8a9635b880e7bdfa7 | |
parent | 8fae948d60dbdc53278013c8103651578aee8c12 (diff) |
linux shim: implement BLK_OPEN_CREAT
this allows O_CREAT to be passed through, for the new image creation
tool.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r-- | c_src/cmd_device.c | 2 | ||||
-rw-r--r-- | c_src/cmd_format.c | 2 | ||||
-rw-r--r-- | c_src/tools-util.c | 4 | ||||
-rw-r--r-- | c_src/tools-util.h | 2 | ||||
-rw-r--r-- | include/linux/blk_types.h | 1 | ||||
-rw-r--r-- | linux/blkdev.c | 5 |
6 files changed, 10 insertions, 6 deletions
diff --git a/c_src/cmd_device.c b/c_src/cmd_device.c index 40ac87c7..96c25310 100644 --- a/c_src/cmd_device.c +++ b/c_src/cmd_device.c @@ -104,7 +104,7 @@ static int cmd_device_add(int argc, char *argv[]) struct bchfs_handle fs = bcache_fs_open(fs_path); - int ret = open_for_format(&dev_opts, force); + int ret = open_for_format(&dev_opts, 0, force); if (ret) die("Error opening %s: %s", dev_opts.path, strerror(-ret)); diff --git a/c_src/cmd_format.c b/c_src/cmd_format.c index 6534469f..ac48454f 100644 --- a/c_src/cmd_format.c +++ b/c_src/cmd_format.c @@ -275,7 +275,7 @@ int cmd_format(int argc, char *argv[]) } darray_for_each(devices, dev) { - int ret = open_for_format(dev, force); + int ret = open_for_format(dev, 0, force); if (ret) die("Error opening %s: %s", dev->path, strerror(-ret)); } diff --git a/c_src/tools-util.c b/c_src/tools-util.c index 496c875c..ea12946c 100644 --- a/c_src/tools-util.c +++ b/c_src/tools-util.c @@ -183,7 +183,7 @@ unsigned get_blocksize(int fd) } /* Open a block device, do magic blkid stuff to probe for existing filesystems: */ -int open_for_format(struct dev_opts *dev, bool force) +int open_for_format(struct dev_opts *dev, blk_mode_t mode, bool force) { int blkid_version_code = blkid_get_library_version(NULL, NULL); if (blkid_version_code < 2401) { @@ -208,7 +208,7 @@ int open_for_format(struct dev_opts *dev, bool force) size_t fs_type_len, fs_label_len; dev->file = bdev_file_open_by_path(dev->path, - BLK_OPEN_READ|BLK_OPEN_WRITE|BLK_OPEN_EXCL|BLK_OPEN_BUFFERED, + BLK_OPEN_READ|BLK_OPEN_WRITE|BLK_OPEN_EXCL|BLK_OPEN_BUFFERED|mode, dev, NULL); int ret = PTR_ERR_OR_ZERO(dev->file); if (ret < 0) diff --git a/c_src/tools-util.h b/c_src/tools-util.h index d3d6b14b..27652b62 100644 --- a/c_src/tools-util.h +++ b/c_src/tools-util.h @@ -98,7 +98,7 @@ ssize_t read_string_list_or_die(const char *, const char * const[], u64 get_size(int); unsigned get_blocksize(int); struct dev_opts; -int open_for_format(struct dev_opts *, bool); +int open_for_format(struct dev_opts *, blk_mode_t, bool); bool ask_yn(void); diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index e3c3a9b4..ee27b615 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -33,6 +33,7 @@ typedef unsigned int __bitwise blk_mode_t; #define BLK_OPEN_WRITE_IOCTL ((__force blk_mode_t)(1 << 4)) #define BLK_OPEN_BUFFERED ((__force blk_mode_t)(1 << 5)) +#define BLK_OPEN_CREAT ((__force blk_mode_t)(1 << 6)) struct inode { unsigned long i_ino; diff --git a/linux/blkdev.c b/linux/blkdev.c index d073ed6a..3569594f 100644 --- a/linux/blkdev.c +++ b/linux/blkdev.c @@ -190,7 +190,10 @@ struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode, if (mode & BLK_OPEN_EXCL) flags |= O_EXCL; - fd = open(path, flags); + if (mode & BLK_OPEN_CREAT) + flags |= O_CREAT; + + fd = open(path, flags, 0600); if (fd < 0) return ERR_PTR(-errno); |