From f9a070f8270d0cd8fd0fd097a8dd4e3c6863fb41 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Fri, 10 May 2024 15:36:03 +0100 Subject: [PATCH] daemon: Move gdisk function to a new file After subsequent commits, this will be the only remaining use of gdisk, so put it in its own file now. (cherry picked from commit d5c6e15180dc23f8b1e46c24b0e9f18c4695708a) (cherry picked from commit d400b0637e2f59deab9f5e00c8366a28e4c52dfa) --- daemon/Makefile.am | 1 + daemon/gdisk.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++ daemon/parted.c | 22 --------------------- 3 files changed, 49 insertions(+), 22 deletions(-) create mode 100644 daemon/gdisk.c diff --git a/daemon/Makefile.am b/daemon/Makefile.am index b30153bab..7109e1145 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -130,6 +130,7 @@ guestfsd_SOURCES = \ fs-min-size.c \ fsck.c \ fstrim.c \ + gdisk.c \ glob.c \ grep.c \ grub.c \ diff --git a/daemon/gdisk.c b/daemon/gdisk.c new file mode 100644 index 000000000..0bf3b282a --- /dev/null +++ b/daemon/gdisk.c @@ -0,0 +1,48 @@ +/* libguestfs - the guestfsd daemon + * Copyright (C) 2009-2024 Red Hat 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include + +#include +#include + +#include "daemon.h" +#include "actions.h" +#include "optgroups.h" + +int +optgroup_gdisk_available (void) +{ + return prog_exists ("sgdisk"); +} + +int +do_part_expand_gpt(const char *device) +{ + CLEANUP_FREE char *err = NULL; + + int r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR, + "sgdisk", "-e", device, NULL); + + if (r == -1) { + reply_with_error ("%s -e %s: %s", "sgdisk", device, err); + return -1; + } + + return 0; +} diff --git a/daemon/parted.c b/daemon/parted.c index d0f2ce03b..9af5556c9 100644 --- a/daemon/parted.c +++ b/daemon/parted.c @@ -456,12 +456,6 @@ do_part_set_mbr_id (const char *device, int partnum, int idbyte) return 0; } -int -optgroup_gdisk_available (void) -{ - return prog_exists ("sgdisk"); -} - int do_part_set_gpt_type (const char *device, int partnum, const char *guid) { @@ -662,19 +656,3 @@ do_part_set_disk_guid_random (const char *device) return 0; } - -int -do_part_expand_gpt(const char *device) -{ - CLEANUP_FREE char *err = NULL; - - int r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR, - "sgdisk", "-e", device, NULL); - - if (r == -1) { - reply_with_error ("%s -e %s: %s", "sgdisk", device, err); - return -1; - } - - return 0; -}