summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <[email protected]>2022-11-16 07:45:33 +0100
committerChristophe Grenier <[email protected]>2022-11-16 07:45:33 +0100
commit1c09ffcb6f0a3c0defb6ef9e0e576d06fcf2031a (patch)
tree20910c7ea3a3ea882f6cb8217fd5d50990b7e71f
parent1c05a14387cb9790cc51959664b50142d6045f37 (diff)
new constant SINGLE_PARTITION_TYPE to improve code testing
-rw-r--r--src/addpart.c41
-rw-r--r--src/autoset.c18
-rw-r--r--src/partgptro.c3
-rw-r--r--src/partgptw.c3
-rw-r--r--src/parthumax.c3
-rw-r--r--src/parthumax.h13
-rw-r--r--src/parti386.h2
-rw-r--r--src/partsun.h12
-rw-r--r--src/partxbox.c3
-rw-r--r--src/partxbox.h12
-rw-r--r--src/sun.c4
11 files changed, 98 insertions, 16 deletions
diff --git a/src/addpart.c b/src/addpart.c
index 0db0e3c5..9f297c3a 100644
--- a/src/addpart.c
+++ b/src/addpart.c
@@ -25,6 +25,7 @@
#endif
#include <stdio.h>
+#include <assert.h>
#include "types.h"
#include "common.h"
#include "parti386.h"
@@ -35,28 +36,52 @@
#include "partxbox.h"
#include "addpart.h"
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_GPT)
extern const arch_fnct_t arch_gpt;
-extern const arch_fnct_t arch_i386;
+#endif
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_HUMAX)
extern const arch_fnct_t arch_humax;
+#endif
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_I386)
+extern const arch_fnct_t arch_i386;
+#endif
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_MAC)
extern const arch_fnct_t arch_mac;
+#endif
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_SUN)
extern const arch_fnct_t arch_sun;
+#endif
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_XBOX)
extern const arch_fnct_t arch_xbox;
+#endif
list_part_t *add_partition_cli(disk_t *disk, list_part_t *list_part, char **current_cmd)
{
- if(*current_cmd==NULL)
- return list_part;
+ assert(current_cmd!=NULL);
+ /*@ assert valid_read_string(*current_cmd); */
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_GPT)
if(disk->arch==&arch_gpt)
return add_partition_gpt_cli(disk, list_part, current_cmd);
- else if(disk->arch==&arch_i386)
+#endif
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_I386)
+ if(disk->arch==&arch_i386)
return add_partition_i386_cli(disk, list_part, current_cmd);
- else if(disk->arch==&arch_humax)
+#endif
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_HUMAX)
+ if(disk->arch==&arch_humax)
return add_partition_humax_cli(disk, list_part, current_cmd);
- else if(disk->arch==&arch_mac)
+#endif
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_MAC)
+ if(disk->arch==&arch_mac)
return add_partition_mac_cli(disk, list_part, current_cmd);
- else if(disk->arch==&arch_sun)
+#endif
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_SUN)
+ if(disk->arch==&arch_sun)
return add_partition_sun_cli(disk, list_part, current_cmd);
- else if(disk->arch==&arch_xbox)
+#endif
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_XBOX)
+ if(disk->arch==&arch_xbox)
return add_partition_xbox_cli(disk, list_part, current_cmd);
+#endif
return list_part;
}
diff --git a/src/autoset.c b/src/autoset.c
index 08a255ce..bc44fd2f 100644
--- a/src/autoset.c
+++ b/src/autoset.c
@@ -27,18 +27,30 @@
#include "common.h"
#include "autoset.h"
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_GPT)
extern const arch_fnct_t arch_gpt;
+#endif
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_HUMAX)
extern const arch_fnct_t arch_humax;
+#endif
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_MAC)
extern const arch_fnct_t arch_mac;
+#endif
void autoset_unit(disk_t *disk)
{
if(disk==NULL)
return ;
if(
- disk->arch==&arch_mac ||
- disk->arch==&arch_gpt ||
- disk->arch==&arch_humax ||
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_GPT)
+ disk->arch==&arch_gpt ||
+#endif
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_HUMAX)
+ disk->arch==&arch_humax ||
+#endif
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_MAC)
+ disk->arch==&arch_mac ||
+#endif
(disk->geom.heads_per_cylinder==1 && disk->geom.sectors_per_head==1))
disk->unit=UNIT_SECTOR;
else
diff --git a/src/partgptro.c b/src/partgptro.c
index 1a1753df..75f4f99f 100644
--- a/src/partgptro.c
+++ b/src/partgptro.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_I386)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -35,4 +36,4 @@ int write_part_gpt(disk_t *disk_car, const list_part_t *list_part, const int ro,
return -1;
return 0;
}
-
+#endif
diff --git a/src/partgptw.c b/src/partgptw.c
index 0621e1b7..0e57eb4d 100644
--- a/src/partgptw.c
+++ b/src/partgptw.c
@@ -20,7 +20,7 @@
*/
-
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_GPT)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -310,3 +310,4 @@ int write_part_gpt(disk_t *disk_car, const list_part_t *list_part, const int ro,
disk_car->sync(disk_car);
return 0;
}
+#endif
diff --git a/src/parthumax.c b/src/parthumax.c
index 1088a826..58109915 100644
--- a/src/parthumax.c
+++ b/src/parthumax.c
@@ -20,7 +20,7 @@
*/
-
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_HUMAX)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -362,3 +362,4 @@ static const char *get_partition_typename_humax(const partition_t *partition)
{
return "Partition";
}
+#endif
diff --git a/src/parthumax.h b/src/parthumax.h
index 2787e529..6022655b 100644
--- a/src/parthumax.h
+++ b/src/parthumax.h
@@ -24,9 +24,20 @@
#ifdef __cplusplus
extern "C" {
#endif
-
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_HUMAX)
+/*@
+ @ requires valid_disk(disk_car);
+ @ requires \valid_read(disk_car);
+ @ requires valid_list_part(list_part);
+ @ requires \valid(current_cmd);
+ @ requires separation: \separated(disk_car, list_part, current_cmd, *current_cmd);
+ @ requires valid_read_string(*current_cmd);
+ @*/
+// ensures valid_list_part(\result);
+// ensures valid_read_string(*current_cmd);
list_part_t *add_partition_humax_cli(const disk_t *disk_car,list_part_t *list_part, char **current_cmd);
+#endif
#ifdef __cplusplus
} /* closing brace for extern "C" */
#endif
diff --git a/src/parti386.h b/src/parti386.h
index f8cb990c..2a63833c 100644
--- a/src/parti386.h
+++ b/src/parti386.h
@@ -21,6 +21,7 @@
*/
#ifndef _PARTI386_H
#define _PARTI386_H
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_I386)
#ifdef __cplusplus
extern "C" {
#endif
@@ -56,3 +57,4 @@ int recover_i386_logical(disk_t *disk, const unsigned char *buffer, partition_t
} /* closing brace for extern "C" */
#endif
#endif
+#endif
diff --git a/src/partsun.h b/src/partsun.h
index c649d0f5..ff53034c 100644
--- a/src/partsun.h
+++ b/src/partsun.h
@@ -24,9 +24,21 @@
#ifdef __cplusplus
extern "C" {
#endif
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_SUN)
+/*@
+ @ requires valid_disk(disk_car);
+ @ requires \valid_read(disk_car);
+ @ requires valid_list_part(list_part);
+ @ requires \valid(current_cmd);
+ @ requires separation: \separated(disk_car, list_part, current_cmd, *current_cmd);
+ @ requires valid_read_string(*current_cmd);
+ @*/
+// ensures valid_list_part(\result);
+// ensures valid_read_string(*current_cmd);
list_part_t *add_partition_sun_cli(const disk_t *disk_car,list_part_t *list_part, char **current_cmd);
+#endif
#ifdef __cplusplus
} /* closing brace for extern "C" */
#endif
diff --git a/src/partxbox.c b/src/partxbox.c
index a28d391a..6a2a33e8 100644
--- a/src/partxbox.c
+++ b/src/partxbox.c
@@ -20,7 +20,7 @@
*/
-
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_XBOX)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -389,3 +389,4 @@ static const char *get_partition_typename_xbox(const partition_t *partition)
{
return get_partition_typename_xbox_aux(partition->part_type_xbox);
}
+#endif
diff --git a/src/partxbox.h b/src/partxbox.h
index f8972e32..3620a7e0 100644
--- a/src/partxbox.h
+++ b/src/partxbox.h
@@ -25,6 +25,7 @@
#ifdef __cplusplus
extern "C" {
#endif
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_XBOX)
struct xbox_partition
{
@@ -33,8 +34,19 @@ struct xbox_partition
uint32_t bootnbr;
} __attribute__ ((gcc_struct, __packed__));
+/*@
+ @ requires valid_disk(disk_car);
+ @ requires \valid_read(disk_car);
+ @ requires valid_list_part(list_part);
+ @ requires \valid(current_cmd);
+ @ requires separation: \separated(disk_car, list_part, current_cmd, *current_cmd);
+ @ requires valid_read_string(*current_cmd);
+ @*/
+// ensures valid_list_part(\result);
+// ensures valid_read_string(*current_cmd);
list_part_t *add_partition_xbox_cli(const disk_t *disk_car,list_part_t *list_part, char **current_cmd);
+#endif
#ifdef __cplusplus
} /* closing brace for extern "C" */
#endif
diff --git a/src/sun.c b/src/sun.c
index 88e1b48e..20680f5d 100644
--- a/src/sun.c
+++ b/src/sun.c
@@ -39,7 +39,9 @@
#include "log_part.h"
#define SUN_LABEL_MAGIC 0xDABE
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_SUN)
extern const arch_fnct_t arch_sun;
+#endif
static void set_sun_info_i386(partition_t *partition);
static int test_sun_i386(const disk_t *disk_car, const sun_partition_i386 *sunlabel, const partition_t *partition, const int verbose);
@@ -73,6 +75,7 @@ static int test_sun_i386(const disk_t *disk_car, const sun_partition_i386 *sunla
offset2cylinder(disk_car,partition->part_offset),
offset2head(disk_car,partition->part_offset),
offset2sector(disk_car,partition->part_offset));
+#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_SUN)
{
int i;
partition_t *new_partition=partition_new(NULL);
@@ -93,6 +96,7 @@ static int test_sun_i386(const disk_t *disk_car, const sun_partition_i386 *sunla
}
free(new_partition);
}
+#endif
return 0;
}