Message ID | 20240826064006.41623-4-michael.adler@siemens.com |
---|---|
State | Accepted |
Delegated to: | Stefano Babic |
Headers | show |
Series | Introduce FAT Filesystem Labeling | expand |
On 26.08.24 08:40, 'Michael Adler' via swupdate wrote: > It turns out that diskformat_fs_exists either returns 0 (false) or 1 > (true). Hence, we make this explicit by changing the return value to > bool. This eliminates the need to check for negative return values. > Also remove some trailing whitespace while we're at it. > > Signed-off-by: Michael Adler <michael.adler@siemens.com> > Signed-off-by: Christian Storm <christian.storm@siemens.com> > --- > fs/diskformat.c | 4 ++-- > handlers/diskformat_handler.c | 7 +------ > handlers/diskpart_handler.c | 11 ++--------- > include/fs_interface.h | 8 +++++--- > 4 files changed, 10 insertions(+), 20 deletions(-) > > diff --git a/fs/diskformat.c b/fs/diskformat.c > index ed1f9f08..86e8c59f 100644 > --- a/fs/diskformat.c > +++ b/fs/diskformat.c > @@ -74,9 +74,9 @@ char *diskformat_fs_detect(char *device) > return s; > } > > -int diskformat_fs_exists(char *device, char *fstype) > +bool diskformat_fs_exists(char *device, char *fstype) > { > - int ret = 0; > + bool ret = false; > char *filesystem = diskformat_fs_detect(device); > > if (filesystem) { > diff --git a/handlers/diskformat_handler.c b/handlers/diskformat_handler.c > index 0708a83a..d968394b 100644 > --- a/handlers/diskformat_handler.c > +++ b/handlers/diskformat_handler.c > @@ -39,12 +39,7 @@ static int diskformat(struct img_type *img, > ; /* Skip file system exists check */ > } else { > /* Check if file system exists */ > - ret = diskformat_fs_exists(img->device, fstype); > - > - if (ret < 0) > - return ret; > - > - if (ret) { > + if (diskformat_fs_exists(img->device, fstype)) { > TRACE("Found %s file system on %s, skip mkfs", > fstype, img->device); > return 0; > diff --git a/handlers/diskpart_handler.c b/handlers/diskpart_handler.c > index 0544eafc..e33a4517 100644 > --- a/handlers/diskpart_handler.c > +++ b/handlers/diskpart_handler.c > @@ -1176,15 +1176,8 @@ static int format_parts(struct hnd_priv priv, struct img_type *img, struct creat > char *device = fdisk_partname(path, partno); > > if (!createtable->parent && !part->force) { > - /* Check if file system exists */ > - ret = diskformat_fs_exists(device, part->fstype); > - > - if (ret < 0) { > - free(device); > - break; > - } > - > - if (ret) { > + /* Check if file system exists and if so, skip mkfs */ > + if (diskformat_fs_exists(device, part->fstype)) { > TRACE("Found %s file system on %s, skip mkfs", part->fstype, device); > ret = 0; > free(device); > diff --git a/include/fs_interface.h b/include/fs_interface.h > index cab3dec6..ccfea6bd 100644 > --- a/include/fs_interface.h > +++ b/include/fs_interface.h > @@ -6,8 +6,10 @@ > > #pragma once > > +#include <stdbool.h> > + > char *diskformat_fs_detect(char *device); > -int diskformat_fs_exists(char *device, char *fstype); > +bool diskformat_fs_exists(char *device, char *fstype); > > int diskformat_mkfs(char *device, char *fstype); > > @@ -15,11 +17,11 @@ int diskformat_mkfs(char *device, char *fstype); > extern int fat_mkfs(const char *device_name, const char *fstype); > #endif > > -#if defined (CONFIG_EXT_FILESYSTEM) > +#if defined (CONFIG_EXT_FILESYSTEM) > extern int ext_mkfs(const char *device_name, const char *fstype, unsigned long features, > const char *volume_label); > #endif > > -#if defined (CONFIG_BTRFS_FILESYSTEM) > +#if defined (CONFIG_BTRFS_FILESYSTEM) > extern int btrfs_mkfs(const char *device_name, const char *fstype); > #endif Reviewed-by: Stefano Babic <stefano.babic@swupdate.org>
diff --git a/fs/diskformat.c b/fs/diskformat.c index ed1f9f08..86e8c59f 100644 --- a/fs/diskformat.c +++ b/fs/diskformat.c @@ -74,9 +74,9 @@ char *diskformat_fs_detect(char *device) return s; } -int diskformat_fs_exists(char *device, char *fstype) +bool diskformat_fs_exists(char *device, char *fstype) { - int ret = 0; + bool ret = false; char *filesystem = diskformat_fs_detect(device); if (filesystem) { diff --git a/handlers/diskformat_handler.c b/handlers/diskformat_handler.c index 0708a83a..d968394b 100644 --- a/handlers/diskformat_handler.c +++ b/handlers/diskformat_handler.c @@ -39,12 +39,7 @@ static int diskformat(struct img_type *img, ; /* Skip file system exists check */ } else { /* Check if file system exists */ - ret = diskformat_fs_exists(img->device, fstype); - - if (ret < 0) - return ret; - - if (ret) { + if (diskformat_fs_exists(img->device, fstype)) { TRACE("Found %s file system on %s, skip mkfs", fstype, img->device); return 0; diff --git a/handlers/diskpart_handler.c b/handlers/diskpart_handler.c index 0544eafc..e33a4517 100644 --- a/handlers/diskpart_handler.c +++ b/handlers/diskpart_handler.c @@ -1176,15 +1176,8 @@ static int format_parts(struct hnd_priv priv, struct img_type *img, struct creat char *device = fdisk_partname(path, partno); if (!createtable->parent && !part->force) { - /* Check if file system exists */ - ret = diskformat_fs_exists(device, part->fstype); - - if (ret < 0) { - free(device); - break; - } - - if (ret) { + /* Check if file system exists and if so, skip mkfs */ + if (diskformat_fs_exists(device, part->fstype)) { TRACE("Found %s file system on %s, skip mkfs", part->fstype, device); ret = 0; free(device); diff --git a/include/fs_interface.h b/include/fs_interface.h index cab3dec6..ccfea6bd 100644 --- a/include/fs_interface.h +++ b/include/fs_interface.h @@ -6,8 +6,10 @@ #pragma once +#include <stdbool.h> + char *diskformat_fs_detect(char *device); -int diskformat_fs_exists(char *device, char *fstype); +bool diskformat_fs_exists(char *device, char *fstype); int diskformat_mkfs(char *device, char *fstype); @@ -15,11 +17,11 @@ int diskformat_mkfs(char *device, char *fstype); extern int fat_mkfs(const char *device_name, const char *fstype); #endif -#if defined (CONFIG_EXT_FILESYSTEM) +#if defined (CONFIG_EXT_FILESYSTEM) extern int ext_mkfs(const char *device_name, const char *fstype, unsigned long features, const char *volume_label); #endif -#if defined (CONFIG_BTRFS_FILESYSTEM) +#if defined (CONFIG_BTRFS_FILESYSTEM) extern int btrfs_mkfs(const char *device_name, const char *fstype); #endif