fdisk / src / common.h

Milko Krachounov e91a781 c49ae77 
Milko Krachounov e91a781 

Milko Krachounov ff17591 

Milko Krachounov 3489d2e 

Milko Krachounov ff17591 

Milko Krachounov f5663ef 

Milko Krachounov ff17591 

Milko Krachounov 01e20a6 

Milko Krachounov e91a781 

Milko Krachounov c98e0f6 
Milko Krachounov e91a781 

Milko Krachounov ff17591 
Christian Brunel… 208b795 
Milko Krachounov ff17591 
Christian Brunel… 208b795 
Milko Krachounov ff17591 
Christian Brunel… 208b795 

Milko Krachounov ff17591 
Christian Brunel… 208b795 

Milko Krachounov e91a781 

Christian Brunel… 208b795 

Christian 64d428d 

Christian Brunel… 208b795 
Milko Krachounov 6d0e8de 

Milko Krachounov e0888e1 
Milko Krachounov ff17591 
Milko Krachounov e3a3fac 
Milko Krachounov e0888e1 

Milko Krachounov d85e297 

Milko Krachounov 3641027 
Christian eefc7cd 

Milko Krachounov 45c3a60 

Milko Krachounov 3641027 

Milko Krachounov aa259dd 

Milko Krachounov 3641027 
Milko Krachounov 6d0e8de 

Milko Krachounov e0888e1 

Milko Krachounov ff17591 
Christian eefc7cd 
Milko Krachounov 6d0e8de 

Christian eefc7cd 

Milko Krachounov 6d0e8de 
Christian eefc7cd 

Milko Krachounov 6d0e8de 
Milko Krachounov ff17591 
Milko Krachounov 45c3a60 
Christian eefc7cd 
Milko Krachounov ff17591 
Christian eefc7cd 
Milko Krachounov e0888e1 

Milko Krachounov 6d0e8de 
Milko Krachounov 45c3a60 
Milko Krachounov e0888e1 

Milko Krachounov 8d0a1a9 
Milko Krachounov 56ca13d 

Milko Krachounov 8d0a1a9 
Milko Krachounov aa259dd 
Milko Krachounov fc550a0 

Milko Krachounov c98e0f6 
Milko Krachounov ff17591 

Milko Krachounov 01e20a6 

Milko Krachounov ff17591 
Christian Brunel… 208b795 

Milko Krachounov 01e20a6 

Milko Krachounov 6d0e8de 

Milko Krachounov 7d386ad 

Milko Krachounov f5663ef 
Milko Krachounov 7d386ad 

Milko Krachounov 00f1987 

Milko Krachounov 8d0a1a9 24cd2aa 

Milko Krachounov 1894e1b 24cd2aa 
Milko Krachounov 1894e1b 
Milko Krachounov e91a781 
    GNU fdisk - a clone of Linux fdisk.

    Copyright (C) 2006
    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
    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, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA


#include <parted/parted.h>
#include "strlist.h"

typedef struct _UICalls UICalls;
struct _UICalls {
	/* The first parameter specifies the prompt text */
	/* All functions should return 1 on success, 0 otherwise */
	/* getstring: 	The second parameter is the string that is read. *
	 * There are two valid string lists, the second is localized     *
	 * The function *MUST* return the string from the non-localized  *
	 * list corresponding to the localized one.                      *
	 * The integer specified how to treat multiwords, TODO: explain  */
	int (*getstring)(const char* prompt, char** value, const StrList*,
	                 const StrList* loc, int multi_word);
	int (*getint)(const char* prompt, int* value);
	int (*getbool)(const char* prompt, int* value);
	int (*getdev)(const char* prompt, PedDevice** value);
	/* getpart, if the disk is NULL, it should be specified.
	            This won't actually be used */
	int (*getparttype) (const char* prompt, const PedDisk*,
	int (*getpart)(const char* prompt, PedDisk**, PedPartition** value);
	int (*getdisktype)(const char* prompt, PedDiskType** value);
	int (*getfstype)(const char* prompt, PedFileSystemType** value);
	int (*getpartpos)(const char* prompt, const void* context, 
	                   const char *possibilities);
	PedTimer* timer;
	int need_commit;

typedef enum _UIOpts UIOpts;
enum _UIOpts {
	/* Warn the user if the operation commits the data to the disk */
	UI_WARN_COMMIT = 1 << 0,
	/* Allow the user to adjust start/end on resize, etc */
	/* Allow the user to specify the partition type */
    /* Prefer the beginning to be snapped to the old begining
     * e.g. during resize */
    UI_SNAP_TO_START = 1 << 3,
	/* Option specific for each function */

typedef enum _AlignType AlignType;
enum _AlignType {
    /* ALIGNMENT_INVALID shouldn't be assigned to partition_align_type */

extern int compat_mode;
extern AlignType current_partition_align_type;

/* Christian <>
	 We use  this macro to know how  to align the partitions.  
	 In this way, We use  "ALIGNMENT_CYLINDER" when 
	 compat_mode is active. */
#define partition_align_type (compat_mode ? ALIGNMENT_CYLINDER : current_partition_align_type)

/* Structures used to specify partition position */
typedef struct _SectPos SectPos;
struct _SectPos {
	PedSector sector;
	PedGeometry *range;

typedef struct _PartPos PartPos;
struct _PartPos {
	SectPos start;
	SectPos end;

/* Specific for perform_resize: */
#define UI_NO_FS_RESIZE UI_FUNCTION_SPECIFIC_1	/* Will only change geometry */
/* Specific for perform_set: */
#define UI_FLAG_TOGGLE UI_FUNCTION_SPECIFIC_1	/* perform_set must toggle flags */
/* Specific for perform_mkfs */

extern int warn_fs_support(void);
#define XASSERT(_condition, _code)                                           \
do {                                                                         \
	if(!(_condition))                                                          \
		{                                                                        \
			ped_exception_throw(PED_EXCEPTION_ERROR,                               \
													PED_EXCEPTION_CANCEL,                              \
													"GNU Fdisk error: %s:%d assertion `%s' failed.",   \
													__FILE__, __LINE__, #_condition);                  \
			_code;                                                                 \
		}                                                                        \
} while(0)

/* Setting of UICalls */
extern void set_uicalls(UICalls *);

/* Lists. Should be initialized. */
extern StrList *disk_type_list;
extern StrList *fs_type_list;
//extern StrList *fs_type_resize;
extern StrList *fs_type_mkfs;
extern StrList *flag_name_list;

/* List init functions */
extern int init_flag_str();
extern int init_fs_type_str();
extern int init_disk_type_str();

/* We will also use this functions in cfdisk */
extern int _can_create_primary (const PedDisk*);
extern int _can_create_extended (const PedDisk*);
extern int _can_create_logical (const PedDisk*);

#define can_create_primary(disk) _can_create_primary(disk)
#define can_create_extended(disk) _can_create_extended(disk)
#define can_create_logical(disk) _can_create_logical(disk)

/* Main functions */

 * NOTE: resize, move and perhaps copy are dangerous.
 * Please, make your ui checks their status. If they FAIL and leave need_commit
 * to true, please reread the partition table from the device.
 * Sorry for the inconvinience. I might change this in the future so that it is
 * not needed
extern int perform_check (PedDisk*, PedPartition*);
extern int perform_mklabel (PedDevice*, PedDisk**, const PedDiskType*);

#if 0
extern int perform_mkfs (PedDisk*, PedPartition*,
                         const PedFileSystemType*, UIOpts);

/* NOTE: The PartPos structs *are* modified when calling these function */
extern int perform_mkpart (PedDisk* disk, PartPos *pos, 
													 PedPartitionType part_type, 
													 PedPartition **newpart, UIOpts opts);
#if 0
extern int perform_mkpartfs (PedDisk*, PartPos* pos,
                        PedPartitionType, const PedFileSystemType*,
                        PedPartition **newpart, UIOpts);

extern int perform_move (PedDisk * disk, PedPartition * part, PartPos * pos, UIOpts opts);
extern int perform_name (PedDisk*, PedPartition*, char*);
extern int perform_rescue (PedDisk*, PedSector start, PedSector end, UIOpts);
extern int perform_resize (PedDisk*, PedPartition*, PartPos* pos,
extern int perform_rm (PedDisk*, PedPartition*);
extern int perform_set_system (PedDisk*, PedPartition*, const PedFileSystemType*);
extern int perform_set (PedDisk*, PedPartition*, PedPartitionFlag, UIOpts);
extern int perform_commit (PedDisk*, UIOpts);
extern int perform_maximize (PedDisk*, PedPartition*);
extern int fix_partition_order (PedDisk*);
extern void check_partition_consistency (PedPartition *part);
extern void verify_partition_table (PedDisk *disk);

/* Additional functions */
extern char* partition_print_flags (PedPartition*);

extern PedConstraint*
constraint_from_start_end (PedDevice*, PedGeometry* range_start,
				PedGeometry* range_end);
extern PedConstraint*
constraint_intersect_and_destroy (PedConstraint* a, PedConstraint* b);
/* This function returns the closest possible start and end for a partition
   in the region first-last */
extern int fix_part_position(PedDevice *dev, PedSector *start, PedSector *end,
                             PedSector first, PedSector last);

/* This function converts none, cyl*, opt*, and min* to an AlignType */
extern AlignType string_to_align_type(const char *);

/* This function takes care of initializing the alignment flags
 * and should be called after a disk is created. Returns 1 on success */
extern int init_disk_flags(PedDisk *);

/* Choose the partition position */
extern int
query_part_position(const char* prompt, const void* context, PartPos* pos,
                    PedSector first, PedSector last, PedDevice *dev, 
                    PedConstraint *constraint, UIOpts *opts);

/* Functions used by fdisk at the moment */
/* TODO: Some of these do things close to the UICalls functions */
extern int get_device(const char* prompt, PedDevice**);
extern int get_disk (const char* prompt, PedDisk**);
extern int get_partition (const char* prompt, PedDisk*, PedPartition**);
extern int get_disk_type (const char* prompt, const PedDiskType**);
extern int (*get_part_type) (const char* prompt, const PedDisk*,
extern int get_fs_type (const char* prompt, const PedFileSystemType**,
                        int mkfs);
extern int get_part_flag (const char* prompt, PedPartition*, PedPartitionFlag*);

extern PedPartition* part_list_prev (PedPartition*, PedPartitionType skip);
extern PedPartition* part_list_next (PedPartition*, PedPartitionType skip);

extern PedPartition *disk_get_prev_nmd_partition(PedDisk *disk,
                                                 PedPartition *part);
/* Other cfdisk/fdisk common functions */
extern void print_partition_types();
extern int count_logical_partition(PedDisk *disk);