1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
|
/*
libparted - a library for manipulating disk partitions
Copyright (C) 1999-2001, 2007-2014, 2019-2023 Free Software Foundation,
Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include "configmake.h"
#include <parted/parted.h>
#include <parted/debug.h>
#include "architecture.h"
#if ENABLE_NLS
# include <locale.h>
# include <libintl.h>
# define _(String) dgettext (PACKAGE, String)
#else
# define _(String) (String)
#endif /* ENABLE_NLS */
/* ped_malloc() debugging. Stick the address and size of memory blocks that
* weren't free()d in here, and an exception will be thrown when it is
* allocated. That way, you can find out what, exactly, the allocated thing
* is, and where it is created.
*/
typedef struct
{
void* pointer;
size_t size;
} pointer_size_type;
/* IMHO, none of the DEBUG-related code below is useful, and the
ped_malloc memset code is actually quite harmful: it masked at
least two nasty bugs that were fixed in June of 2007. */
#undef DEBUG
#ifdef DEBUG
static pointer_size_type dodgy_malloc_list[] = {
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0}
};
static int dodgy_memory_active[100];
#endif /* DEBUG */
extern void ped_disk_aix_init ();
extern void ped_disk_bsd_init ();
extern void ped_disk_dvh_init ();
extern void ped_disk_gpt_init ();
extern void ped_disk_loop_init ();
extern void ped_disk_mac_init ();
extern void ped_disk_msdos_init ();
extern void ped_disk_pc98_init ();
extern void ped_disk_sun_init ();
extern void ped_disk_amiga_init ();
extern void ped_disk_dasd_init ();
extern void ped_disk_atari_init ();
static void
init_disk_types ()
{
/* Note that probing is done in the reverse order of init */
ped_disk_loop_init (); /* must be last in the probe list */
#if defined __s390__ || defined __s390x__
ped_disk_dasd_init();
#endif
ped_disk_atari_init (); /* easy false positives, so probe others first */
ped_disk_sun_init ();
#ifdef ENABLE_PC98
ped_disk_pc98_init ();
#endif
ped_disk_msdos_init ();
ped_disk_mac_init ();
ped_disk_gpt_init ();
ped_disk_dvh_init ();
ped_disk_bsd_init ();
ped_disk_amiga_init ();
ped_disk_aix_init ();
}
extern void ped_file_system_amiga_init (void);
extern void ped_file_system_xfs_init (void);
extern void ped_file_system_ufs_init (void);
extern void ped_file_system_reiserfs_init (void);
extern void ped_file_system_ntfs_init (void);
extern void ped_file_system_linux_swap_init (void);
extern void ped_file_system_jfs_init (void);
extern void ped_file_system_hfs_init (void);
extern void ped_file_system_fat_init (void);
extern void ped_file_system_f2fs_init (void);
extern void ped_file_system_ext2_init (void);
extern void ped_file_system_nilfs2_init (void);
extern void ped_file_system_btrfs_init (void);
extern void ped_file_system_udf_init (void);
extern void ped_file_system_zfs_init (void);
static void
init_file_system_types ()
{
ped_file_system_amiga_init ();
ped_file_system_xfs_init ();
ped_file_system_ufs_init ();
ped_file_system_reiserfs_init ();
ped_file_system_ntfs_init ();
ped_file_system_linux_swap_init ();
ped_file_system_jfs_init ();
ped_file_system_hfs_init ();
ped_file_system_fat_init ();
ped_file_system_f2fs_init ();
ped_file_system_ext2_init ();
ped_file_system_nilfs2_init ();
ped_file_system_btrfs_init ();
ped_file_system_udf_init ();
ped_file_system_zfs_init ();
}
extern void ped_disk_aix_done ();
extern void ped_disk_bsd_done ();
extern void ped_disk_dvh_done ();
extern void ped_disk_gpt_done ();
extern void ped_disk_loop_done ();
extern void ped_disk_mac_done ();
extern void ped_disk_msdos_done ();
extern void ped_disk_pc98_done ();
extern void ped_disk_sun_done ();
extern void ped_disk_amiga_done ();
extern void ped_disk_dasd_done ();
extern void ped_disk_atari_done ();
static void
done_disk_types ()
{
#if defined __s390__ || __s390x__
ped_disk_dasd_done ();
#endif
ped_disk_sun_done ();
#ifdef ENABLE_PC98
ped_disk_pc98_done ();
#endif
ped_disk_msdos_done ();
ped_disk_mac_done ();
ped_disk_loop_done ();
ped_disk_gpt_done ();
ped_disk_dvh_done ();
ped_disk_bsd_done ();
ped_disk_amiga_done ();
ped_disk_aix_done ();
ped_disk_atari_done ();
}
static void _init() __attribute__ ((constructor));
static void
_init()
{
#ifdef ENABLE_NLS
bindtextdomain (PACKAGE, LOCALEDIR);
#endif
init_disk_types ();
init_file_system_types ();
ped_set_architecture ();
#ifdef DEBUG
memset (dodgy_memory_active, 0, sizeof (dodgy_memory_active));
#endif
}
extern void ped_file_system_nilfs2_done (void);
extern void ped_file_system_ext2_done (void);
extern void ped_file_system_fat_done (void);
extern void ped_file_system_f2fs_done (void);
extern void ped_file_system_hfs_done (void);
extern void ped_file_system_jfs_done (void);
extern void ped_file_system_linux_swap_done (void);
extern void ped_file_system_ntfs_done (void);
extern void ped_file_system_reiserfs_done (void);
extern void ped_file_system_ufs_done (void);
extern void ped_file_system_xfs_done (void);
extern void ped_file_system_amiga_done (void);
extern void ped_file_system_btrfs_done (void);
extern void ped_file_system_udf_done (void);
extern void ped_file_system_zfs_done (void);
static void
done_file_system_types ()
{
ped_file_system_zfs_done ();
ped_file_system_nilfs2_done ();
ped_file_system_ext2_done ();
ped_file_system_f2fs_done ();
ped_file_system_fat_done ();
ped_file_system_hfs_done ();
ped_file_system_jfs_done ();
ped_file_system_linux_swap_done ();
ped_file_system_ntfs_done ();
ped_file_system_reiserfs_done ();
ped_file_system_ufs_done ();
ped_file_system_xfs_done ();
ped_file_system_amiga_done ();
ped_file_system_btrfs_done ();
ped_file_system_udf_done ();
}
static void _done() __attribute__ ((destructor));
static void
_done()
{
ped_device_free_all ();
done_disk_types ();
done_file_system_types ();
}
const char*
ped_get_version ()
{
return VERSION;
}
void*
ped_malloc (size_t size)
{
void* mem;
mem = (void*) malloc (size);
if (!mem) {
ped_exception_throw (PED_EXCEPTION_FATAL, PED_EXCEPTION_CANCEL,
_("Out of memory."));
return NULL;
}
return mem;
}
void* ped_calloc (size_t size)
{
void* buf = ped_malloc (size);
memset (buf, 0, size);
return buf;
}
|