1010#include "fd-util.h"
1111#include "log.h"
1212#include "sd-device.h"
13- #include "stdio-util.h" /* xsprintf() */
1413#include "string-util.h"
1514
1615/* Returns the size in bytes of the block device at dev_path.
@@ -124,8 +123,8 @@ int dm_clone_create_device(
124123 const char * dest_dev ,
125124 const char * metadata_dev ) {
126125
126+ _cleanup_free_ char * target_params = NULL ;
127127 uint64_t src_dev_size_sectors , src_dev_size ;
128- char target_params [256 ];
129128 int r ;
130129
131130 assert (name );
@@ -137,13 +136,18 @@ int dm_clone_create_device(
137136 if (r < 0 )
138137 return r ;
139138
140- src_dev_size_sectors = src_dev_size / 512 ;
139+ /* According to the Linux kernel sysfs ABI, the size of a block device reported in
140+ * /sys/block/<disk>/size is always expressed in units of 512-byte sectors, regardless
141+ * of the physical block size of the device. */
142+ const uint64_t SECTOR_SIZE = 512 ;
143+ src_dev_size_sectors = src_dev_size / SECTOR_SIZE ;
141144
142145 /* dm-clone target params: <metadata_dev> <dest_dev> <source_dev> <region_size> <hydration_threshold> [options]
143146 * 8 = region size in sectors (4KB regions with 512-byte sectors)
144147 * 1 = hydration threshold (regions to hydrate per batch)
145148 * no_hydration = don't start automatic background hydration */
146- xsprintf (target_params , "%s %s %s 8 1 no_hydration" , metadata_dev , dest_dev , source_dev );
149+ if (asprintf (& target_params , "%s %s %s 8 1 no_hydration" , metadata_dev , dest_dev , source_dev ) < 0 )
150+ return log_oom ();
147151
148152 r = dm_clone_create (name );
149153 if (r < 0 )
0 commit comments