From 378c18e5f024ac5a8aef4cb40d7c9aa9633d144c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 16:30:35 +0200 Subject: Adding upstream version 2.38.1. Signed-off-by: Daniel Baumann --- disk-utils/sfdisk.c | 2476 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 2476 insertions(+) create mode 100644 disk-utils/sfdisk.c (limited to 'disk-utils/sfdisk.c') diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c new file mode 100644 index 0000000..38c7b17 --- /dev/null +++ b/disk-utils/sfdisk.c @@ -0,0 +1,2476 @@ +/* + * Copyright (C) 1995 Andries E. Brouwer (aeb@cwi.nl) + * Copyright (C) 2014 Karel Zak + * + * 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 1 + * or (at your option) any later version. + * + * A.V. Le Blanc (LeBlanc@mcc.ac.uk) wrote Linux fdisk 1992-1994, + * patched by various people (faith@cs.unc.edu, martin@cs.unc.edu, + * leisner@sdsp.mc.xerox.com, esr@snark.thyrsus.com, aeb@cwi.nl) + * 1993-1995, with version numbers (as far as I have seen) 0.93 - 2.0e. + * This program had (head,sector,cylinder) as basic unit, and was + * (therefore) broken in several ways for the use on larger disks - + * for example, my last patch (from 2.0d to 2.0e) was required + * to allow a partition to cross cylinder 8064, and to write an + * extended partition past the 4GB mark. + * + * Karel Zak wrote new sfdisk based on libfdisk from util-linux + * in 2014. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef HAVE_LIBREADLINE +# define _FUNCTION_DEF +# include +#endif +#include +#include + +#include "c.h" +#include "xalloc.h" +#include "nls.h" +#include "debug.h" +#include "strutils.h" +#include "closestream.h" +#include "colors.h" +#include "blkdev.h" +#include "all-io.h" +#include "rpmatch.h" +#include "optutils.h" +#include "ttyutils.h" + +#include "libfdisk.h" +#include "fdisk-list.h" + +/* + * sfdisk debug stuff (see fdisk.h and include/debug.h) + */ +static UL_DEBUG_DEFINE_MASK(sfdisk); +UL_DEBUG_DEFINE_MASKNAMES(sfdisk) = UL_DEBUG_EMPTY_MASKNAMES; + +#define SFDISKPROG_DEBUG_INIT (1 << 1) +#define SFDISKPROG_DEBUG_PARSE (1 << 2) +#define SFDISKPROG_DEBUG_MISC (1 << 3) +#define SFDISKPROG_DEBUG_ASK (1 << 4) +#define SFDISKPROG_DEBUG_ALL 0xFFFF + +#define DBG(m, x) __UL_DBG(sfdisk, SFDISKPROG_DEBUG_, m, x) +#define ON_DBG(m, x) __UL_DBG_CALL(sfdisk, SFDISKPROG_DEBUG_, m, x) + +enum { + ACT_FDISK = 1, + ACT_ACTIVATE, + ACT_CHANGE_ID, + ACT_DUMP, + ACT_LIST, + ACT_LIST_FREE, + ACT_LIST_TYPES, + ACT_REORDER, + ACT_RELOCATE, + ACT_SHOW_SIZE, + ACT_SHOW_GEOM, + ACT_VERIFY, + ACT_PARTTYPE, + ACT_PARTUUID, + ACT_PARTLABEL, + ACT_PARTATTRS, + ACT_DISKID, + ACT_DELETE, + ACT_BACKUP_SECTORS, +}; + +struct sfdisk { + int act; /* ACT_* */ + int partno; /* -N , default -1 */ + int wipemode; /* remove foreign signatures from disk */ + int pwipemode; /* remove foreign signatures from partitions */ + const char *lockmode; /* as specified by --lock */ + const char *label; /* --label