libfdisk: (sun) move driver from fdisk to library
... and also add fdisk_info_new_partition() Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
0d75581e44
commit
b4bfbaddfa
|
@ -17,8 +17,6 @@ fdisk_SOURCES = \
|
||||||
fdisks/fdiskmaclabel.h \
|
fdisks/fdiskmaclabel.h \
|
||||||
fdisks/fdisksgilabel.c \
|
fdisks/fdisksgilabel.c \
|
||||||
fdisks/fdisksgilabel.h \
|
fdisks/fdisksgilabel.h \
|
||||||
fdisks/fdisksunlabel.c \
|
|
||||||
fdisks/fdisksunlabel.h \
|
|
||||||
fdisks/partname.c \
|
fdisks/partname.c \
|
||||||
fdisks/common.h
|
fdisks/common.h
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
#include "strutils.h"
|
#include "strutils.h"
|
||||||
#include "closestream.h"
|
#include "closestream.h"
|
||||||
|
|
||||||
#include "fdisksunlabel.h"
|
#include "pt-sun.h" /* to toggle flags */
|
||||||
#include "fdisksgilabel.h"
|
#include "fdisksgilabel.h"
|
||||||
#include "fdiskmaclabel.h"
|
#include "fdiskmaclabel.h"
|
||||||
#include "fdiskdoslabel.h"
|
#include "fdiskdoslabel.h"
|
||||||
|
@ -683,18 +683,6 @@ static void verify(struct fdisk_context *cxt)
|
||||||
fdisk_verify_disklabel(cxt);
|
fdisk_verify_disklabel(cxt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_partition_size(struct fdisk_context *cxt,
|
|
||||||
int num, sector_t start, sector_t stop, int sysid)
|
|
||||||
{
|
|
||||||
char *str = size_to_human_string(SIZE_SUFFIX_3LETTER | SIZE_SUFFIX_SPACE,
|
|
||||||
(uint64_t)(stop - start + 1) * cxt->sector_size);
|
|
||||||
struct fdisk_parttype *t = fdisk_get_parttype_from_code(cxt, sysid);
|
|
||||||
|
|
||||||
printf(_("Partition %d of type %s and of size %s is set\n"),
|
|
||||||
num, t ? t->name : _("Unknown"), str);
|
|
||||||
free(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void new_partition(struct fdisk_context *cxt)
|
static void new_partition(struct fdisk_context *cxt)
|
||||||
{
|
{
|
||||||
assert(cxt);
|
assert(cxt);
|
||||||
|
|
|
@ -84,7 +84,6 @@ extern unsigned int read_int(struct fdisk_context *cxt,
|
||||||
unsigned int low, unsigned int dflt,
|
unsigned int low, unsigned int dflt,
|
||||||
unsigned int high, unsigned int base, char *mesg);
|
unsigned int high, unsigned int base, char *mesg);
|
||||||
extern void print_menu(struct fdisk_context *cxt, enum menutype menu);
|
extern void print_menu(struct fdisk_context *cxt, enum menutype menu);
|
||||||
extern void print_partition_size(struct fdisk_context *cxt, int num, sector_t start, sector_t stop, int sysid);
|
|
||||||
|
|
||||||
extern char *partition_type(struct fdisk_context *cxt, unsigned char type);
|
extern char *partition_type(struct fdisk_context *cxt, unsigned char type);
|
||||||
extern char read_chars(struct fdisk_context *cxt, char *mesg);
|
extern char read_chars(struct fdisk_context *cxt, char *mesg);
|
||||||
|
@ -94,9 +93,6 @@ extern unsigned int read_int_with_suffix(struct fdisk_context *cxt,
|
||||||
unsigned int low, unsigned int dflt, unsigned int high,
|
unsigned int low, unsigned int dflt, unsigned int high,
|
||||||
unsigned int base, char *mesg, int *is_suffix_used);
|
unsigned int base, char *mesg, int *is_suffix_used);
|
||||||
|
|
||||||
#define PLURAL 0
|
|
||||||
#define SINGULAR 1
|
|
||||||
|
|
||||||
extern sector_t get_nr_sects(struct partition *p);
|
extern sector_t get_nr_sects(struct partition *p);
|
||||||
|
|
||||||
extern int nowarn;
|
extern int nowarn;
|
||||||
|
|
|
@ -522,9 +522,10 @@ static void set_partition(struct fdisk_context *cxt,
|
||||||
set_start_sect(p, start - offset);
|
set_start_sect(p, start - offset);
|
||||||
set_nr_sects(p, stop - start + 1);
|
set_nr_sects(p, stop - start + 1);
|
||||||
|
|
||||||
if (!doext)
|
if (!doext) {
|
||||||
print_partition_size(cxt, i + 1, start, stop, sysid);
|
struct fdisk_parttype *t = fdisk_get_parttype_from_code(cxt, sysid);
|
||||||
|
fdisk_info_new_partition(cxt, i + 1, start, stop, t);
|
||||||
|
}
|
||||||
if (is_dos_compatible(cxt) && (start/(cxt->geom.sectors*cxt->geom.heads) > 1023))
|
if (is_dos_compatible(cxt) && (start/(cxt->geom.sectors*cxt->geom.heads) > 1023))
|
||||||
start = cxt->geom.heads*cxt->geom.sectors*1024 - 1;
|
start = cxt->geom.heads*cxt->geom.sectors*1024 - 1;
|
||||||
set_hsc(p->head, p->sector, p->cyl, start);
|
set_hsc(p->head, p->sector, p->cyl, start);
|
||||||
|
|
|
@ -629,8 +629,10 @@ static int sgi_set_partition(struct fdisk_context *cxt, size_t i,
|
||||||
|
|
||||||
if (sgi_gaps(cxt) < 0) /* rebuild freelist */
|
if (sgi_gaps(cxt) < 0) /* rebuild freelist */
|
||||||
printf(_("Partition overlap on the disk.\n"));
|
printf(_("Partition overlap on the disk.\n"));
|
||||||
if (length)
|
if (length) {
|
||||||
print_partition_size(cxt, i + 1, start, start + length, sys);
|
struct fdisk_parttype *t = fdisk_get_parttype_from_code(cxt, sys);
|
||||||
|
fdisk_info_new_partition(cxt, i + 1, start, start + length, t);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
#ifndef FDISK_SUN_LABEL_H
|
|
||||||
#define FDISK_SUN_LABEL_H
|
|
||||||
|
|
||||||
#include "pt-sun.h"
|
|
||||||
|
|
||||||
/* public SUN specific functions (TODO: move to libfdisk.h) */
|
|
||||||
extern void fdisk_sun_set_alt_cyl(struct fdisk_context *cxt);
|
|
||||||
extern void fdisk_sun_set_ncyl(struct fdisk_context *cxt, int cyl);
|
|
||||||
extern void fdisk_sun_set_xcyl(struct fdisk_context *cxt);
|
|
||||||
extern void fdisk_sun_set_ilfact(struct fdisk_context *cxt);
|
|
||||||
extern void fdisk_sun_set_rspeed(struct fdisk_context *cxt);
|
|
||||||
extern void fdisk_sun_set_pcylcount(struct fdisk_context *cxt);
|
|
||||||
|
|
||||||
#endif /* FDISK_SUN_LABEL_H */
|
|
|
@ -17,6 +17,8 @@ libfdisk_la_SOURCES = \
|
||||||
libfdisk/src/utils.c \
|
libfdisk/src/utils.c \
|
||||||
libfdisk/src/context.c \
|
libfdisk/src/context.c \
|
||||||
libfdisk/src/parttype.c \
|
libfdisk/src/parttype.c \
|
||||||
|
\
|
||||||
|
libfdisk/src/sun.c \
|
||||||
libfdisk/src/gpt.c
|
libfdisk/src/gpt.c
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -532,6 +532,21 @@ int fdisk_warnx(struct fdisk_context *cxt, const char *fmt, ...)
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int fdisk_info_new_partition(
|
||||||
|
struct fdisk_context *cxt,
|
||||||
|
int num, sector_t start, sector_t stop,
|
||||||
|
struct fdisk_parttype *t)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
char *str = size_to_human_string(SIZE_SUFFIX_3LETTER | SIZE_SUFFIX_SPACE,
|
||||||
|
(uint64_t)(stop - start + 1) * cxt->sector_size);
|
||||||
|
|
||||||
|
rc = fdisk_info(cxt, _("Partition %d of type %s and of size %s is set\n"),
|
||||||
|
num, t ? t->name : _("Unknown"), str);
|
||||||
|
free(str);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef TEST_PROGRAM
|
#ifdef TEST_PROGRAM
|
||||||
struct fdisk_label *fdisk_new_dos_label(struct fdisk_context *cxt) { return NULL; }
|
struct fdisk_label *fdisk_new_dos_label(struct fdisk_context *cxt) { return NULL; }
|
||||||
struct fdisk_label *fdisk_new_bsd_label(struct fdisk_context *cxt) { return NULL; }
|
struct fdisk_label *fdisk_new_bsd_label(struct fdisk_context *cxt) { return NULL; }
|
||||||
|
|
|
@ -327,13 +327,24 @@ extern int fdisk_probe_labels(struct fdisk_context *cxt);
|
||||||
extern void fdisk_deinit_label(struct fdisk_label *lb);
|
extern void fdisk_deinit_label(struct fdisk_label *lb);
|
||||||
|
|
||||||
|
|
||||||
/* gpt.c -- temporary bypass library API... */
|
|
||||||
extern void gpt_list_table(struct fdisk_context *cxt, int xtra);
|
|
||||||
|
|
||||||
/* ask.c */
|
/* ask.c */
|
||||||
extern int fdisk_ask_partnum(struct fdisk_context *cxt, size_t *partnum, int wantnew);
|
extern int fdisk_ask_partnum(struct fdisk_context *cxt, size_t *partnum, int wantnew);
|
||||||
|
|
||||||
extern struct tt *fdisk_ask_get_table(struct fdisk_ask *ask);
|
extern struct tt *fdisk_ask_get_table(struct fdisk_ask *ask);
|
||||||
extern int fdisk_print_table(struct fdisk_context *cxt, struct tt *tb);
|
extern int fdisk_print_table(struct fdisk_context *cxt, struct tt *tb);
|
||||||
|
|
||||||
|
extern int fdisk_info_new_partition(
|
||||||
|
struct fdisk_context *cxt,
|
||||||
|
int num, sector_t start, sector_t stop,
|
||||||
|
struct fdisk_parttype *t);
|
||||||
|
|
||||||
|
/* sun.h */
|
||||||
|
extern void fdisk_sun_set_alt_cyl(struct fdisk_context *cxt);
|
||||||
|
extern void fdisk_sun_set_ncyl(struct fdisk_context *cxt, int cyl);
|
||||||
|
extern void fdisk_sun_set_xcyl(struct fdisk_context *cxt);
|
||||||
|
extern void fdisk_sun_set_ilfact(struct fdisk_context *cxt);
|
||||||
|
extern void fdisk_sun_set_rspeed(struct fdisk_context *cxt);
|
||||||
|
extern void fdisk_sun_set_pcylcount(struct fdisk_context *cxt);
|
||||||
|
|
||||||
|
|
||||||
#endif /* _LIBFDISK_PRIVATE_H */
|
#endif /* _LIBFDISK_PRIVATE_H */
|
||||||
|
|
|
@ -88,7 +88,11 @@ extern int fdisk_context_switch_label(struct fdisk_context *cxt,
|
||||||
const char *name);
|
const char *name);
|
||||||
|
|
||||||
extern int fdisk_context_set_unit(struct fdisk_context *cxt, const char *str);
|
extern int fdisk_context_set_unit(struct fdisk_context *cxt, const char *str);
|
||||||
|
|
||||||
|
#define PLURAL 0
|
||||||
|
#define SINGULAR 1
|
||||||
extern const char *fdisk_context_get_unit(struct fdisk_context *cxt, int n);
|
extern const char *fdisk_context_get_unit(struct fdisk_context *cxt, int n);
|
||||||
|
|
||||||
extern unsigned int fdisk_context_get_units_per_sector(struct fdisk_context *cxt);
|
extern unsigned int fdisk_context_get_units_per_sector(struct fdisk_context *cxt);
|
||||||
|
|
||||||
extern int fdisk_context_enable_details(struct fdisk_context *cxt, int enable);
|
extern int fdisk_context_enable_details(struct fdisk_context *cxt, int enable);
|
||||||
|
|
|
@ -1,15 +1,11 @@
|
||||||
/*
|
/*
|
||||||
* fdisksunlabel.c
|
* Copyright (C) 2013 Karel Zak <kzak@redhat.com>
|
||||||
*
|
*
|
||||||
* I think this is mostly, or entirely, due to
|
* Based on original code from fdisk:
|
||||||
* Jakub Jelinek (jj@sunsite.mff.cuni.cz), July 1996
|
* Jakub Jelinek (jj@sunsite.mff.cuni.cz), July 1996
|
||||||
*
|
* Merged with fdisk for other architectures, aeb, June 1998.
|
||||||
* Merged with fdisk for other architectures, aeb, June 1998.
|
* Arnaldo Carvalho de Melo <acme@conectiva.com.br> Mar 1999, Internationalization
|
||||||
*
|
|
||||||
* Sat Mar 20 EST 1999 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
|
|
||||||
* Internationalization
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h> /* stderr */
|
#include <stdio.h> /* stderr */
|
||||||
#include <stdlib.h> /* qsort */
|
#include <stdlib.h> /* qsort */
|
||||||
#include <string.h> /* strstr */
|
#include <string.h> /* strstr */
|
||||||
|
@ -20,10 +16,9 @@
|
||||||
#include "blkdev.h"
|
#include "blkdev.h"
|
||||||
#include "bitops.h"
|
#include "bitops.h"
|
||||||
|
|
||||||
#include "common.h"
|
#include "fdiskP.h"
|
||||||
#include "fdisk.h"
|
#include "pt-sun.h"
|
||||||
#include "fdiskdoslabel.h"
|
#include "all-io.h"
|
||||||
#include "fdisksunlabel.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* in-memory fdisk SUN stuff
|
* in-memory fdisk SUN stuff
|
||||||
|
@ -77,6 +72,7 @@ static void set_sun_partition(struct fdisk_context *cxt, size_t i,
|
||||||
uint32_t start,uint32_t stop, uint16_t sysid)
|
uint32_t start,uint32_t stop, uint16_t sysid)
|
||||||
{
|
{
|
||||||
struct sun_disklabel *sunlabel = self_disklabel(cxt);
|
struct sun_disklabel *sunlabel = self_disklabel(cxt);
|
||||||
|
struct fdisk_parttype *t = fdisk_get_parttype_from_code(cxt, sysid);
|
||||||
|
|
||||||
sunlabel->vtoc.infos[i].id = cpu_to_be16(sysid);
|
sunlabel->vtoc.infos[i].id = cpu_to_be16(sysid);
|
||||||
sunlabel->vtoc.infos[i].flags = cpu_to_be16(0);
|
sunlabel->vtoc.infos[i].flags = cpu_to_be16(0);
|
||||||
|
@ -84,7 +80,8 @@ static void set_sun_partition(struct fdisk_context *cxt, size_t i,
|
||||||
cpu_to_be32(start / (cxt->geom.heads * cxt->geom.sectors));
|
cpu_to_be32(start / (cxt->geom.heads * cxt->geom.sectors));
|
||||||
sunlabel->partitions[i].num_sectors = cpu_to_be32(stop - start);
|
sunlabel->partitions[i].num_sectors = cpu_to_be32(stop - start);
|
||||||
fdisk_label_set_changed(cxt->label, 1);
|
fdisk_label_set_changed(cxt->label, 1);
|
||||||
print_partition_size(cxt, i + 1, start, stop, sysid);
|
|
||||||
|
fdisk_info_new_partition(cxt, i + 1, start, stop, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t count_used_partitions(struct fdisk_context *cxt)
|
static size_t count_used_partitions(struct fdisk_context *cxt)
|
||||||
|
@ -842,6 +839,7 @@ static int sun_write_disklabel(struct fdisk_context *cxt)
|
||||||
struct sun_disklabel *sunlabel;
|
struct sun_disklabel *sunlabel;
|
||||||
unsigned short *ush;
|
unsigned short *ush;
|
||||||
unsigned short csum = 0;
|
unsigned short csum = 0;
|
||||||
|
const size_t sz = sizeof(struct sun_disklabel);
|
||||||
|
|
||||||
assert(cxt);
|
assert(cxt);
|
||||||
assert(cxt->label);
|
assert(cxt->label);
|
||||||
|
@ -855,7 +853,7 @@ static int sun_write_disklabel(struct fdisk_context *cxt)
|
||||||
sunlabel->csum = csum;
|
sunlabel->csum = csum;
|
||||||
if (lseek(cxt->dev_fd, 0, SEEK_SET) < 0)
|
if (lseek(cxt->dev_fd, 0, SEEK_SET) < 0)
|
||||||
return -errno;
|
return -errno;
|
||||||
if (write(cxt->dev_fd, sunlabel, SECTOR_SIZE) != SECTOR_SIZE)
|
if (write_all(cxt->dev_fd, sunlabel, sz) != 0)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
Loading…
Reference in New Issue