本文整理汇总了C++中self_disklabel函数的典型用法代码示例。如果您正苦于以下问题:C++ self_disklabel函数的具体用法?C++ self_disklabel怎么用?C++ self_disklabel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了self_disklabel函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: sun_toggle_partition_flag
static int sun_toggle_partition_flag(struct fdisk_context *cxt, size_t i, unsigned long flag)
{
struct sun_disklabel *sunlabel;
struct sun_info *p;
assert(cxt);
assert(cxt->label);
assert(fdisk_is_label(cxt, SUN));
if (i >= cxt->label->nparts_max)
return -EINVAL;
sunlabel = self_disklabel(cxt);
p = &sunlabel->vtoc.infos[i];
switch (flag) {
case SUN_FLAG_UNMNT:
p->flags ^= cpu_to_be16(SUN_FLAG_UNMNT);
fdisk_label_set_changed(cxt->label, 1);
break;
case SUN_FLAG_RONLY:
p->flags ^= cpu_to_be16(SUN_FLAG_RONLY);
fdisk_label_set_changed(cxt->label, 1);
break;
default:
return 1;
}
return 0;
}
开发者ID:ArakniD,项目名称:util-linux,代码行数:30,代码来源:sun.c
示例2: fdisk_sgi_set_bootfile
int fdisk_sgi_set_bootfile(struct fdisk_context *cxt)
{
int rc = 0;
size_t sz;
char *name = NULL;
struct sgi_disklabel *sgilabel = self_disklabel(cxt);
fdisk_info(cxt, _("The current boot file is: %s"), sgilabel->boot_file);
rc = fdisk_ask_string(cxt, _("Enter of the new boot file"), &name);
if (rc == 0)
rc = sgi_check_bootfile(cxt, name);
if (rc) {
if (rc == 1)
fdisk_info(cxt, _("Boot file unchanged"));
goto done;
}
memset(sgilabel->boot_file, 0, sizeof(sgilabel->boot_file));
sz = strlen(name);
assert(sz <= sizeof(sgilabel->boot_file)); /* see sgi_check_bootfile() */
memcpy(sgilabel->boot_file, name, sz);
fdisk_sinfo(cxt, FDISK_INFO_SUCCESS,
_("Bootfile is changed to \"%s\"."), name);
done:
free(name);
return rc;
}
开发者ID:TacheR,项目名称:util-linux,代码行数:31,代码来源:sgi.c
示例3: sgi_set_partition
static int sgi_set_partition(struct fdisk_context *cxt, size_t i,
unsigned int start, unsigned int length, int sys)
{
struct sgi_disklabel *sgilabel;
assert(cxt);
assert(cxt->label);
assert(fdisk_is_disklabel(cxt, SGI));
sgilabel = self_disklabel(cxt);
sgilabel->partitions[i].type = cpu_to_be32(sys);
sgilabel->partitions[i].num_blocks = cpu_to_be32(length);
sgilabel->partitions[i].first_block = cpu_to_be32(start);
fdisk_label_set_changed(cxt->label, 1);
if (sgi_gaps(cxt) < 0) /* rebuild freelist */
fdisk_warnx(cxt, _("Partition overlap on the disk."));
if (length) {
struct fdisk_parttype *t = fdisk_get_parttype_from_code(cxt, sys);
fdisk_info_new_partition(cxt, i + 1, start, start + length, t);
}
return 0;
}
开发者ID:TacheR,项目名称:util-linux,代码行数:25,代码来源:sgi.c
示例4: sun_delete_partition
static int sun_delete_partition(struct fdisk_context *cxt,
size_t partnum)
{
struct sun_disklabel *sunlabel;
struct sun_partition *part;
struct sun_info *info;
unsigned int nsec;
assert(cxt);
assert(cxt->label);
assert(fdisk_is_label(cxt, SUN));
sunlabel = self_disklabel(cxt);
part = &sunlabel->partitions[partnum];
info = &sunlabel->vtoc.infos[partnum];
if (partnum == 2 &&
be16_to_cpu(info->id) == SUN_TAG_WHOLEDISK &&
!part->start_cylinder &&
(nsec = be32_to_cpu(part->num_sectors))
== cxt->geom.heads * cxt->geom.sectors * cxt->geom.cylinders)
fdisk_info(cxt, _("If you want to maintain SunOS/Solaris compatibility, "
"consider leaving this "
"partition as Whole disk (5), starting at 0, with %u "
"sectors"), nsec);
info->id = cpu_to_be16(SUN_TAG_UNASSIGNED);
part->num_sectors = 0;
cxt->label->nparts_cur = count_used_partitions(cxt);
fdisk_label_set_changed(cxt->label, 1);
return 0;
}
开发者ID:ArakniD,项目名称:util-linux,代码行数:31,代码来源:sun.c
示例5: sgi_check_bootfile
static int sgi_check_bootfile(struct fdisk_context *cxt, const char *name)
{
size_t sz;
struct sgi_disklabel *sgilabel = self_disklabel(cxt);
sz = strlen(name);
if (sz < 3) {
/* "/a\n" is minimum */
fdisk_warnx(cxt, _("Invalid Bootfile! "
"The bootfile must be an absolute non-zero pathname,"
"e.g. \"/unix\" or \"/unix.save\"."));
return -EINVAL;
} else if (sz > sizeof(sgilabel->boot_file)) {
fdisk_warnx(cxt, _("Name of Bootfile too long: %zu bytes maximum."),
sizeof(sgilabel->boot_file));
return -EINVAL;
} else if (*name != '/') {
fdisk_warnx(cxt, _("Bootfile must have a fully qualified pathname."));
return -EINVAL;
}
if (strncmp(name, (char *) sgilabel->boot_file,
sizeof(sgilabel->boot_file))) {
fdisk_warnx(cxt, _("Be aware, that the bootfile is not checked "
"for existence. SGI's default is \"/unix\" and for "
"backup \"/unix.save\"."));
/* filename is correct and did change */
return 0;
}
return 1; /* filename did not change */
}
开发者ID:TacheR,项目名称:util-linux,代码行数:35,代码来源:sgi.c
示例6: sgi_toggle_partition_flag
static int sgi_toggle_partition_flag(struct fdisk_context *cxt, size_t i, unsigned long flag)
{
struct sgi_disklabel *sgilabel;
assert(cxt);
assert(cxt->label);
assert(fdisk_is_disklabel(cxt, SGI));
if (i >= cxt->label->nparts_max)
return -EINVAL;
sgilabel = self_disklabel(cxt);
switch (flag) {
case SGI_FLAG_BOOT:
sgilabel->root_part_num =
be16_to_cpu(sgilabel->root_part_num) == i ?
0 : cpu_to_be16(i);
fdisk_label_set_changed(cxt->label, 1);
break;
case SGI_FLAG_SWAP:
sgilabel->swap_part_num =
be16_to_cpu(sgilabel->swap_part_num) == i ?
0 : cpu_to_be16(i);
fdisk_label_set_changed(cxt->label, 1);
break;
default:
return 1;
}
return 0;
}
开发者ID:TacheR,项目名称:util-linux,代码行数:31,代码来源:sgi.c
示例7: sun_list_disklabel
static int sun_list_disklabel(struct fdisk_context *cxt)
{
struct sun_disklabel *sunlabel;
assert(cxt);
assert(cxt->label);
assert(fdisk_is_label(cxt, SUN));
sunlabel = self_disklabel(cxt);
if (fdisk_is_details(cxt)) {
fdisk_info(cxt,
_("Label geometry: %d rpm, %d alternate and %d physical cylinders,\n"
" %d extra sects/cyl, interleave %d:1"),
be16_to_cpu(sunlabel->rpm),
be16_to_cpu(sunlabel->acyl),
be16_to_cpu(sunlabel->pcyl),
be16_to_cpu(sunlabel->apc),
be16_to_cpu(sunlabel->intrlv));
fdisk_info(cxt, _("Label ID: %s"), sunlabel->label_id);
fdisk_info(cxt, _("Volume ID: %s"),
*sunlabel->vtoc.volume_id ? sunlabel->vtoc.volume_id : _("<none>"));
}
return 0;
}
开发者ID:ArakniD,项目名称:util-linux,代码行数:26,代码来源:sun.c
示例8: sun_write_disklabel
static int sun_write_disklabel(struct fdisk_context *cxt)
{
struct sun_disklabel *sunlabel;
unsigned short *ush;
unsigned short csum = 0;
const size_t sz = sizeof(struct sun_disklabel);
assert(cxt);
assert(cxt->label);
assert(fdisk_is_label(cxt, SUN));
sunlabel = self_disklabel(cxt);
/* Maybe geometry has been modified */
sunlabel->nhead = cpu_to_be16(cxt->geom.heads);
sunlabel->nsect = cpu_to_be16(cxt->geom.sectors);
if (cxt->geom.cylinders != be16_to_cpu(sunlabel->ncyl)) {
int a = cpu_to_be16(cxt->geom.cylinders);
int b = be16_to_cpu(sunlabel->acyl);
sunlabel->ncyl = a - b;
}
ush = (unsigned short *) sunlabel;
while(ush < (unsigned short *)(&sunlabel->csum))
csum ^= *ush++;
sunlabel->csum = csum;
if (lseek(cxt->dev_fd, 0, SEEK_SET) < 0)
return -errno;
if (write_all(cxt->dev_fd, sunlabel, sz) != 0)
return -errno;
return 0;
}
开发者ID:ArakniD,项目名称:util-linux,代码行数:35,代码来源:sun.c
示例9: fdisk_bsd_edit_disklabel
int fdisk_bsd_edit_disklabel(struct fdisk_context *cxt)
{
struct bsd_disklabel *d = self_disklabel(cxt);
uintmax_t res;
#if defined (__alpha__) || defined (__ia64__)
if (fdisk_ask_number(cxt, DEFAULT_SECTOR_SIZE, d->d_secsize,
UINT32_MAX, _("bytes/sector"), &res) == 0)
d->d_secsize = res;
d->d_nsectors = ask_uint32(cxt, d->d_nsectors, _("sectors/track"));
d->d_ntracks = ask_uint32(cxt, d->d_ntracks, _("tracks/cylinder"));
d->d_ncylinders = ask_uint32(cxt, d->d_ncylinders ,_("cylinders"));
#endif
if (fdisk_ask_number(cxt, 1, d->d_nsectors * d->d_ntracks,
d->d_nsectors * d->d_ntracks,
_("sectors/cylinder"), &res) == 0)
d->d_secpercyl = res;
d->d_rpm = ask_uint16(cxt, d->d_rpm, _("rpm"));
d->d_interleave = ask_uint16(cxt, d->d_interleave, _("interleave"));
d->d_trackskew = ask_uint16(cxt, d->d_trackskew, _("trackskew"));
d->d_cylskew = ask_uint16(cxt, d->d_cylskew, _("cylinderskew"));
d->d_headswitch = ask_uint32(cxt, d->d_headswitch, _("headswitch"));
d->d_trkseek = ask_uint32(cxt, d->d_trkseek, _("track-to-track seek"));
d->d_secperunit = d->d_secpercyl * d->d_ncylinders;
return 0;
}
开发者ID:Berrrry,项目名称:util-linux,代码行数:30,代码来源:bsd.c
示例10: bsd_write_disklabel
static int bsd_write_disklabel(struct fdisk_context *cxt)
{
off_t offset = 0;
struct fdisk_bsd_label *l = self_label(cxt);
struct bsd_disklabel *d = self_disklabel(cxt);
if (l->dos_part)
offset = dos_partition_get_start(l->dos_part) * cxt->sector_size;
d->d_checksum = 0;
d->d_checksum = bsd_dkcksum(d);
/* Update label within boot block. */
memmove(&l->bsdbuffer[BSD_LABELSECTOR * DEFAULT_SECTOR_SIZE
+ BSD_LABELOFFSET], d, sizeof(*d));
#if defined (__alpha__) && BSD_LABELSECTOR == 0
/* Write the checksum to the end of the first sector. */
alpha_bootblock_checksum(l->bsdbuffer);
#endif
if (lseek(cxt->dev_fd, offset, SEEK_SET) == -1) {
fdisk_warn(cxt, _("seek on %s failed"), cxt->dev_path);
return -errno;
}
if (write_all(cxt->dev_fd, l->bsdbuffer, sizeof(l->bsdbuffer))) {
fdisk_warn(cxt, _("cannot write %s"), cxt->dev_path);
return -errno;
}
sync_disks(cxt);
fdisk_sinfo(cxt, FDISK_INFO_SUCCESS,
_("Disklabel written to %s."), cxt->dev_path);
return 0;
}
开发者ID:Berrrry,项目名称:util-linux,代码行数:35,代码来源:bsd.c
示例11: bsd_partition_is_used
static int bsd_partition_is_used(
struct fdisk_context *cxt,
size_t partnum)
{
struct bsd_disklabel *d = self_disklabel(cxt);
if (partnum >= BSD_MAXPARTITIONS)
return 0;
return d->d_partitions[partnum].p_size ? 1 : 0;
}
开发者ID:Berrrry,项目名称:util-linux,代码行数:11,代码来源:bsd.c
示例12: fdisk_sgi_create_info
int fdisk_sgi_create_info(struct fdisk_context *cxt)
{
struct sgi_disklabel *sgilabel = self_disklabel(cxt);
/* I keep SGI's habit to write the sgilabel to the second block */
sgilabel->volume[0].block_num = cpu_to_be32(2);
sgilabel->volume[0].num_bytes = cpu_to_be32(sizeof(struct sgi_info));
strncpy((char *) sgilabel->volume[0].name, "sgilabel", 8);
fdisk_info(cxt, _("SGI info created on second sector"));
return 0;
}
开发者ID:TacheR,项目名称:util-linux,代码行数:12,代码来源:sgi.c
示例13: sun_set_parttype
static int sun_set_parttype(
struct fdisk_context *cxt,
size_t i,
struct fdisk_parttype *t)
{
struct sun_disklabel *sunlabel;
struct sun_partition *part;
struct sun_info *info;
assert(cxt);
assert(cxt->label);
assert(fdisk_is_disklabel(cxt, SUN));
sunlabel = self_disklabel(cxt);
if (i >= cxt->label->nparts_max || !t || t->type > UINT16_MAX)
return -EINVAL;
if (i == 2 && t->type != SUN_TAG_WHOLEDISK)
fdisk_info(cxt, _("Consider leaving partition 3 as Whole disk (5),\n"
"as SunOS/Solaris expects it and even Linux likes it.\n"));
part = &sunlabel->partitions[i];
info = &sunlabel->vtoc.infos[i];
if (t->type == SUN_TAG_LINUX_SWAP && !part->start_cylinder) {
int yes, rc;
rc = fdisk_ask_yesno(cxt,
_("It is highly recommended that the partition at offset 0\n"
"is UFS, EXT2FS filesystem or SunOS swap. Putting Linux swap\n"
"there may destroy your partition table and bootblock.\n"
"Are you sure you want to tag the partition as Linux swap?"), &yes);
if (rc)
return rc;
if (!yes)
return 1;
}
switch (t->type) {
case SUN_TAG_SWAP:
case SUN_TAG_LINUX_SWAP:
/* swaps are not mountable by default */
info->flags |= cpu_to_be16(SUN_FLAG_UNMNT);
break;
default:
/* assume other types are mountable;
user can change it anyway */
info->flags &= ~cpu_to_be16(SUN_FLAG_UNMNT);
break;
}
info->id = cpu_to_be16(t->type);
return 0;
}
开发者ID:Kynde,项目名称:util-linux,代码行数:53,代码来源:sun.c
示例14: count_used_partitions
static size_t count_used_partitions(struct fdisk_context *cxt)
{
struct sun_disklabel *sunlabel = self_disklabel(cxt);
size_t ct = 0, i;
assert(sunlabel);
for (i = 0; i < cxt->label->nparts_max; i++) {
if (sunlabel->partitions[i].num_sectors)
ct++;
}
return ct;
}
开发者ID:ArakniD,项目名称:util-linux,代码行数:13,代码来源:sun.c
示例15: sgi_set_partition
static int sgi_set_partition(struct fdisk_context *cxt,
size_t i,
struct fdisk_partition *pa)
{
struct sgi_disklabel *sgilabel;
if (i >= cxt->label->nparts_max)
return -EINVAL;
sgilabel = self_disklabel(cxt);
if (pa->type) {
struct fdisk_parttype *t = pa->type;
if (sgi_get_num_sectors(cxt, i) == 0) /* caught already before, ... */ {
fdisk_warnx(cxt, _("Sorry, only for non-empty partitions you can change the tag."));
return -EINVAL;
}
if ((i == 10 && t->code != SGI_TYPE_ENTIRE_DISK)
|| (i == 8 && t->code != 0))
fdisk_info(cxt, _("Consider leaving partition 9 as volume header (0), "
"and partition 11 as entire volume (6), "
"as IRIX expects it."));
if (cxt->script == NULL
&& ((t->code != SGI_TYPE_ENTIRE_DISK) && (t->code != SGI_TYPE_VOLHDR))
&& (sgi_get_start_sector(cxt, i) < 1)) {
int yes = 0;
fdisk_ask_yesno(cxt,
_("It is highly recommended that the partition at offset 0 "
"is of type \"SGI volhdr\", the IRIX system will rely on it to "
"retrieve from its directory standalone tools like sash and fx. "
"Only the \"SGI volume\" entire disk section may violate this. "
"Are you sure about tagging this partition differently?"), &yes);
if (!yes)
return 1;
}
sgilabel->partitions[i].type = cpu_to_be32(t->code);
}
if (fdisk_partition_has_start(pa))
sgilabel->partitions[i].first_block = cpu_to_be32(pa->start);
if (fdisk_partition_has_size(pa))
sgilabel->partitions[i].num_blocks = cpu_to_be32(pa->size);
fdisk_label_set_changed(cxt->label, 1);
return 0;
}
开发者ID:Distrotech,项目名称:util-linux,代码行数:50,代码来源:sgi.c
示例16: fdisk_sun_set_pcylcount
/**
* fdisk_sun_set_pcylcount
* @cxt: context
*
* Sets number of physical cylinders. This function uses libfdisk Ask API for
* dialog with user.
*
* Returns: 0 on success, <0 on error.
*/
int fdisk_sun_set_pcylcount(struct fdisk_context *cxt)
{
struct sun_disklabel *sunlabel = self_disklabel(cxt);
uintmax_t res;
int rc = fdisk_ask_number(cxt, 0, /* low */
be16_to_cpu(sunlabel->pcyl), /* default */
USHRT_MAX, /* high */
_("Number of physical cylinders"), /* query */
&res); /* result */
if (!rc)
return rc;
sunlabel->pcyl = cpu_to_be16(res);
return 0;
}
开发者ID:ArakniD,项目名称:util-linux,代码行数:23,代码来源:sun.c
示例17: fdisk_sun_set_ilfact
/**
* fdisk_sun_set_ilfact:
* @cxt: context
*
* Sets interleave factor. This function uses libfdisk Ask API for dialog with
* user.
*
* Returns: 0 on success, <0 on error.
*/
int fdisk_sun_set_ilfact(struct fdisk_context *cxt)
{
struct sun_disklabel *sunlabel = self_disklabel(cxt);
uintmax_t res;
int rc = fdisk_ask_number(cxt, 1, /* low */
be16_to_cpu(sunlabel->intrlv), /* default */
32, /* high */
_("Interleave factor"), /* query */
&res); /* result */
if (rc)
return rc;
sunlabel->intrlv = cpu_to_be16(res);
return 0;
}
开发者ID:ArakniD,项目名称:util-linux,代码行数:23,代码来源:sun.c
示例18: fdisk_sun_set_rspeed
/**
* fdisk_sun_set_rspeed
* @cxt: context
*
* Sets rotation speed. This function uses libfdisk Ask API for dialog with
* user.
*
* Returns: 0 on success, <0 on error.
*/
int fdisk_sun_set_rspeed(struct fdisk_context *cxt)
{
struct sun_disklabel *sunlabel = self_disklabel(cxt);
uintmax_t res;
int rc = fdisk_ask_number(cxt, 1, /* low */
be16_to_cpu(sunlabel->rpm), /* default */
USHRT_MAX, /* high */
_("Rotation speed (rpm)"), /* query */
&res); /* result */
if (rc)
return rc;
sunlabel->rpm = cpu_to_be16(res);
return 0;
}
开发者ID:ArakniD,项目名称:util-linux,代码行数:23,代码来源:sun.c
示例19: bsd_readlabel
/*
* Read a bsd_disklabel from sector 0 or from the starting sector of p.
* If it has the right magic, return 0.
*/
static int bsd_readlabel(struct fdisk_context *cxt)
{
struct fdisk_bsd_label *l;
struct bsd_disklabel *d;
int t;
off_t offset = 0;
l = self_label(cxt);
d = self_disklabel(cxt);
if (l->dos_part)
/* BSD is nested within DOS partition, get the begin of the
* partition. Note that DOS uses native sector size. */
offset = dos_partition_get_start(l->dos_part) * cxt->sector_size;
if (lseek(cxt->dev_fd, offset, SEEK_SET) == -1)
return -1;
if (read_all(cxt->dev_fd, l->bsdbuffer, sizeof(l->bsdbuffer)) < 0)
return errno ? -errno : -1;
/* The offset to begin of the disk label. Note that BSD uses
* 512-byte (default) sectors. */
memmove(d, &l->bsdbuffer[BSD_LABELSECTOR * DEFAULT_SECTOR_SIZE
+ BSD_LABELOFFSET], sizeof(*d));
if (d->d_magic != BSD_DISKMAGIC || d->d_magic2 != BSD_DISKMAGIC) {
DBG(LABEL, ul_debug("not found magic"));
return -1;
}
for (t = d->d_npartitions; t < BSD_MAXPARTITIONS; t++) {
d->d_partitions[t].p_size = 0;
d->d_partitions[t].p_offset = 0;
d->d_partitions[t].p_fstype = BSD_FS_UNUSED;
}
if (d->d_npartitions > BSD_MAXPARTITIONS)
fdisk_warnx(cxt, ("Too many partitions (%d, maximum is %d)."),
d->d_npartitions, BSD_MAXPARTITIONS);
/* let's follow in-PT geometry */
cxt->geom.sectors = d->d_nsectors;
cxt->geom.heads = d->d_ntracks;
cxt->geom.cylinders = d->d_ncylinders;
cxt->label->nparts_cur = d->d_npartitions;
cxt->label->nparts_max = BSD_MAXPARTITIONS;
DBG(LABEL, ul_debug("read BSD label"));
return 0;
}
开发者ID:Berrrry,项目名称:util-linux,代码行数:54,代码来源:bsd.c
示例20: fdisk_sun_set_xcyl
/**
* fdisk_sun_set_xcyl:
* @cxt: context
*
* Sets number of extra sectors per cylinder. This function uses libfdisk Ask API
* for dialog with user.
*
* Returns: 0 on success, <0 on error.
*/
int fdisk_sun_set_xcyl(struct fdisk_context *cxt)
{
struct sun_disklabel *sunlabel = self_disklabel(cxt);
uintmax_t res;
int rc = fdisk_ask_number(cxt, 0, /* low */
be16_to_cpu(sunlabel->apc), /* default */
cxt->geom.sectors, /* high */
_("Extra sectors per cylinder"), /* query */
&res); /* result */
if (rc)
return rc;
sunlabel->apc = cpu_to_be16(res);
return 0;
}
开发者ID:ArakniD,项目名称:util-linux,代码行数:23,代码来源:sun.c
注:本文中的self_disklabel函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论