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 d5c6e15180)
(cherry picked from commit d400b0637e)
This commit is contained in:
Richard W.M. Jones
2024-05-10 15:36:03 +01:00
parent f2bfa98f05
commit f9a070f827
3 changed files with 49 additions and 22 deletions

View File

@@ -130,6 +130,7 @@ guestfsd_SOURCES = \
fs-min-size.c \
fsck.c \
fstrim.c \
gdisk.c \
glob.c \
grep.c \
grub.c \

48
daemon/gdisk.c Normal file
View File

@@ -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 <config.h>
#include <stdio.h>
#include <stdlib.h>
#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;
}

View File

@@ -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;
}