1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861
|
/*
libparted - a library for manipulating disk partitions
Copyright (C) 1999-2001, 2007-2010 Free Software Foundation, 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 3 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, see <http://www.gnu.org/licenses/>.
*/
/** \file filesys.c */
/**
* \addtogroup PedFileSystem
*
* \note File systems exist on a PedGeometry - NOT a PedPartition.
*
* @{
*/
#include <config.h>
#include <parted/parted.h>
#include <parted/debug.h>
#if ENABLE_NLS
# include <libintl.h>
# define _(String) dgettext (PACKAGE, String)
#else
# define _(String) (String)
#endif /* ENABLE_NLS */
#define BUFFER_SIZE 4096 /* in sectors */
static PedFileSystemType* fs_types = NULL;
static PedFileSystemAlias* fs_aliases = NULL;
void
ped_file_system_type_register (PedFileSystemType* fs_type)
{
PED_ASSERT (fs_type != NULL, return);
PED_ASSERT (fs_type->ops != NULL, return);
PED_ASSERT (fs_type->name != NULL, return);
fs_type->next = fs_types;
fs_types = fs_type;
}
void
ped_file_system_type_unregister (PedFileSystemType* fs_type)
{
PedFileSystemType* walk;
PedFileSystemType* last = NULL;
PED_ASSERT (fs_types != NULL, return);
PED_ASSERT (fs_type != NULL, return);
for (walk = fs_types; walk && walk != fs_type;
last = walk, walk = walk->next);
PED_ASSERT (walk != NULL, return);
if (last)
((struct _PedFileSystemType*) last)->next = fs_type->next;
else
fs_types = fs_type->next;
}
void
ped_file_system_alias_register (PedFileSystemType* fs_type, const char* alias,
int deprecated)
{
PedFileSystemAlias* fs_alias;
PED_ASSERT (fs_type != NULL, return);
PED_ASSERT (alias != NULL, return);
fs_alias = ped_malloc (sizeof *fs_alias);
if (!fs_alias)
return;
fs_alias->next = fs_aliases;
fs_alias->fs_type = fs_type;
fs_alias->alias = alias;
fs_alias->deprecated = deprecated;
fs_aliases = fs_alias;
}
void
ped_file_system_alias_unregister (PedFileSystemType* fs_type,
const char* alias)
{
PedFileSystemAlias* walk;
PedFileSystemAlias* last = NULL;
PED_ASSERT (fs_aliases != NULL, return);
PED_ASSERT (fs_type != NULL, return);
PED_ASSERT (alias != NULL, return);
for (walk = fs_aliases; walk; last = walk, walk = walk->next) {
if (walk->fs_type == fs_type && !strcmp (walk->alias, alias))
break;
}
PED_ASSERT (walk != NULL, return);
if (last)
last->next = walk->next;
else
fs_aliases = walk->next;
free (walk);
}
/**
* Get a PedFileSystemType by its @p name.
*
* @return @c NULL if none found.
*/
PedFileSystemType*
ped_file_system_type_get (const char* name)
{
PedFileSystemType* walk;
PedFileSystemAlias* alias_walk;
PED_ASSERT (name != NULL, return NULL);
for (walk = fs_types; walk != NULL; walk = walk->next) {
if (!strcasecmp (walk->name, name))
break;
}
if (walk != NULL)
return walk;
for (alias_walk = fs_aliases; alias_walk != NULL;
alias_walk = alias_walk->next) {
if (!strcasecmp (alias_walk->alias, name))
break;
}
if (alias_walk != NULL) {
if (alias_walk->deprecated)
PED_DEBUG (0, "File system alias %s is deprecated",
name);
return alias_walk->fs_type;
}
return NULL;
}
/**
* Get the next PedFileSystemType after @p fs_type.
*
* @return @c NULL if @p fs_type is the last item in the list.
*/
PedFileSystemType*
ped_file_system_type_get_next (const PedFileSystemType* fs_type)
{
if (fs_type)
return fs_type->next;
else
return fs_types;
}
/**
* Get the next PedFileSystemAlias after @p fs_alias.
*
* @return @c NULL if @p fs_alias is the last item in the list.
*/
PedFileSystemAlias*
ped_file_system_alias_get_next (const PedFileSystemAlias* fs_alias)
{
if (fs_alias)
return fs_alias->next;
else
return fs_aliases;
}
/**
* Attempt to find a file system and return the region it occupies.
*
* @param fs_type The file system type to probe for.
* @param geom The region to be searched.
*
* @return @p NULL if @p fs_type file system wasn't detected
*/
PedGeometry*
ped_file_system_probe_specific (
const PedFileSystemType* fs_type, PedGeometry* geom)
{
PedGeometry* result;
PED_ASSERT (fs_type != NULL, return NULL);
PED_ASSERT (fs_type->ops->probe != NULL, return NULL);
PED_ASSERT (geom != NULL, return NULL);
/* Fail all fs-specific probe-related tests when sector size
is not the default. */
if (geom->dev->sector_size != PED_SECTOR_SIZE_DEFAULT)
return 0;
if (!ped_device_open (geom->dev))
return 0;
result = fs_type->ops->probe (geom);
ped_device_close (geom->dev);
return result;
}
static int
_test_open (PedFileSystemType* fs_type, PedGeometry* geom)
{
PedFileSystem* fs;
ped_exception_fetch_all ();
fs = fs_type->ops->open (geom);
if (fs)
fs_type->ops->close (fs);
else
ped_exception_catch ();
ped_exception_leave_all ();
return fs != NULL;
}
static PedFileSystemType*
_probe_with_open (PedGeometry* geom, int detected_count,
PedFileSystemType* detected[])
{
int i;
PedFileSystemType* open_detected = NULL;
ped_device_open (geom->dev);
/* If one and only one file system that Parted is able to open
* can be successfully opened on this geometry, return it.
* If more than one can be, return NULL.
*/
for (i=0; i<detected_count; i++) {
if (!detected[i]->ops->open || !_test_open (detected [i], geom))
continue;
if (open_detected) {
ped_device_close (geom->dev);
return NULL;
} else {
open_detected = detected [i];
}
}
/* If no file system has been successfully opened, and
* if Parted has detected at most one unopenable file system,
* return it.
*/
if (!open_detected)
for (i=0; i<detected_count; i++) {
if (detected[i]->ops->open)
continue;
if (open_detected) {
ped_device_close (geom->dev);
return NULL;
} else {
open_detected = detected [i];
}
}
ped_device_close (geom->dev);
return open_detected;
}
static int
_geometry_error (const PedGeometry* a, const PedGeometry* b)
{
PedSector start_delta = a->start - b->start;
PedSector end_delta = a->end - b->end;
return abs (start_delta) + abs (end_delta);
}
static PedFileSystemType*
_best_match (const PedGeometry* geom, PedFileSystemType* detected [],
const int detected_error [], int detected_count)
{
int best_match = 0;
int i;
PedSector min_error;
min_error = PED_MAX (4096, geom->length / 100);
for (i = 1; i < detected_count; i++) {
if (detected_error [i] < detected_error [best_match])
best_match = i;
}
/* make sure the best match is significantly better than all the
* other matches
*/
for (i = 0; i < detected_count; i++) {
if (i == best_match)
continue;
if (abs (detected_error [best_match] - detected_error [i])
< min_error)
return NULL;
}
return detected [best_match];
}
/**
* Attempt to detect a file system in region \p geom.
* This function tries to be clever at dealing with ambiguous
* situations, such as when one file system was not completely erased before a
* new file system was created on top of it.
*
* \return a new PedFileSystem on success, \c NULL on failure
*/
PedFileSystemType*
ped_file_system_probe (PedGeometry* geom)
{
PedFileSystemType* detected[32];
int detected_error[32];
int detected_count = 0;
PedFileSystemType* walk = NULL;
PED_ASSERT (geom != NULL, return NULL);
if (!ped_device_open (geom->dev))
return NULL;
ped_exception_fetch_all ();
while ( (walk = ped_file_system_type_get_next (walk)) ) {
PedGeometry* probed;
probed = ped_file_system_probe_specific (walk, geom);
if (probed) {
detected [detected_count] = walk;
detected_error [detected_count]
= _geometry_error (geom, probed);
detected_count++;
ped_geometry_destroy (probed);
} else {
ped_exception_catch ();
}
}
ped_exception_leave_all ();
ped_device_close (geom->dev);
if (!detected_count)
return NULL;
walk = _best_match (geom, detected, detected_error, detected_count);
if (walk)
return walk;
return _probe_with_open (geom, detected_count, detected);
}
/**
* This function erases all file system signatures that indicate that a
* file system occupies a given region described by \p geom.
* After this operation ped_file_system_probe() won't detect any file system.
*
* \note ped_file_system_create() calls this before creating a new file system.
*
* \return \c 1 on success, \c 0 on failure
*/
int
ped_file_system_clobber (PedGeometry* geom)
{
PedFileSystemType* fs_type = NULL;
PED_ASSERT (geom != NULL, return 0);
if (!ped_device_open (geom->dev))
goto error;
ped_exception_fetch_all ();
while ((fs_type = ped_file_system_type_get_next (fs_type))) {
PedGeometry* probed;
if (!fs_type->ops->clobber)
continue;
probed = ped_file_system_probe_specific (fs_type, geom);
if (!probed) {
ped_exception_catch ();
continue;
}
ped_geometry_destroy (probed);
if (fs_type->ops->clobber && !fs_type->ops->clobber (geom)) {
ped_exception_leave_all ();
goto error_close_dev;
}
}
ped_device_close (geom->dev);
ped_exception_leave_all ();
return 1;
error_close_dev:
ped_device_close (geom->dev);
error:
return 0;
}
/* This function erases all signatures that indicate the presence of
* a file system in a particular region, without erasing any data
* contained inside the "exclude" region.
*/
static int
ped_file_system_clobber_exclude (PedGeometry* geom,
const PedGeometry* exclude)
{
PedGeometry* clobber_geom;
int status;
if (ped_geometry_test_sector_inside (exclude, geom->start))
return 1;
clobber_geom = ped_geometry_duplicate (geom);
if (ped_geometry_test_overlap (clobber_geom, exclude))
ped_geometry_set_end (clobber_geom, exclude->start - 1);
status = ped_file_system_clobber (clobber_geom);
ped_geometry_destroy (clobber_geom);
return status;
}
/**
* This function opens the file system stored on \p geom, if it
* can find one.
* It is often called in the following manner:
* \code
* fs = ped_file_system_open (&part.geom)
* \endcode
*
* \throws PED_EXCEPTION_ERROR if file system could not be detected
* \throws PED_EXCEPTION_ERROR if the file system is bigger than its volume
* \throws PED_EXCEPTION_NO_FEATURE if opening of a file system stored on
* \p geom is not implemented
*
* \return a PedFileSystem on success, \c NULL on failure.
*/
PedFileSystem*
ped_file_system_open (PedGeometry* geom)
{
PedFileSystemType* type;
PedFileSystem* fs;
PedGeometry* probed_geom;
PED_ASSERT (geom != NULL, return NULL);
if (!ped_device_open (geom->dev))
goto error;
type = ped_file_system_probe (geom);
if (!type) {
ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
_("Could not detect file system."));
goto error_close_dev;
}
probed_geom = ped_file_system_probe_specific (type, geom);
if (!probed_geom)
goto error_close_dev;
if (!ped_geometry_test_inside (geom, probed_geom)) {
if (ped_exception_throw (
PED_EXCEPTION_ERROR,
PED_EXCEPTION_IGNORE_CANCEL,
_("The file system is bigger than its volume!"))
!= PED_EXCEPTION_IGNORE)
goto error_destroy_probed_geom;
}
if (!type->ops->open) {
ped_exception_throw (PED_EXCEPTION_NO_FEATURE,
PED_EXCEPTION_CANCEL,
_("Support for opening %s file systems "
"is not implemented yet."),
type->name);
goto error_destroy_probed_geom;
}
fs = type->ops->open (probed_geom);
if (!fs)
goto error_destroy_probed_geom;
ped_geometry_destroy (probed_geom);
return fs;
error_destroy_probed_geom:
ped_geometry_destroy (probed_geom);
error_close_dev:
ped_device_close (geom->dev);
error:
return 0;
}
/**
* This function initializes a new file system of type \p type on
* a region described by \p geom, writing out appropriate metadata and
* signatures. If \p timer is non-NULL, it is used as the progress meter.
*
* \throws PED_EXCEPTION_NO_FEATURE if creating file system type \p type
* is not implemented yet
*
* \return a PedFileSystem on success, \c NULL on failure
*/
PedFileSystem*
ped_file_system_create (PedGeometry* geom, const PedFileSystemType* type,
PedTimer* timer)
{
PedFileSystem* fs;
PED_ASSERT (geom != NULL, return NULL);
PED_ASSERT (type != NULL, return NULL);
if (!type->ops->create) {
ped_exception_throw (PED_EXCEPTION_NO_FEATURE,
PED_EXCEPTION_CANCEL,
_("Support for creating %s file systems "
"is not implemented yet."),
type->name);
goto error;
}
if (!ped_device_open (geom->dev))
goto error;
if (!ped_file_system_clobber (geom))
goto error_close_dev;
fs = type->ops->create (geom, timer);
if (!fs)
goto error_close_dev;
return fs;
error_close_dev:
ped_device_close (geom->dev);
error:
return 0;
}
/**
* Close file system \p fs.
*
* \return \c 1 on success, \c 0 on failure
*/
int
ped_file_system_close (PedFileSystem* fs)
{
PedDevice* dev = fs->geom->dev;
PED_ASSERT (fs != NULL, goto error_close_dev);
if (!fs->type->ops->close (fs))
goto error_close_dev;
ped_device_close (dev);
return 1;
error_close_dev:
ped_device_close (dev);
return 0;
}
/**
* Check \p fs file system for errors.
*
* \throws PED_EXCEPTION_NO_FEATURE if checking file system \p fs is
* not implemented yet
*
* \return \c 0 on failure (i.e. unfixed errors)
*/
int
ped_file_system_check (PedFileSystem* fs, PedTimer* timer)
{
PED_ASSERT (fs != NULL, return 0);
if (!fs->type->ops->check) {
ped_exception_throw (PED_EXCEPTION_NO_FEATURE,
PED_EXCEPTION_CANCEL,
_("Support for checking %s file systems "
"is not implemented yet."),
fs->type->name);
return 0;
}
return fs->type->ops->check (fs, timer);
}
static int
_raw_copy (const PedGeometry* src, PedGeometry* dest, PedTimer* timer)
{
char* buf;
PedSector pos;
PED_ASSERT (src != NULL, goto error);
PED_ASSERT (dest != NULL, goto error);
PED_ASSERT (src->length <= dest->length, goto error);
buf = ped_malloc (BUFFER_SIZE * 512); /* FIXME */
if (!buf)
goto error;
if (!ped_device_open (src->dev))
goto error_free_buf;
if (!ped_device_open (dest->dev))
goto error_close_src;
for (pos = 0; pos + BUFFER_SIZE < src->length; pos += BUFFER_SIZE) {
ped_timer_update (timer, 1.0 * pos / src->length);
if (!ped_geometry_read (src, buf, pos, BUFFER_SIZE))
goto error_close_dest;
if (!ped_geometry_write (dest, buf, pos, BUFFER_SIZE))
goto error_close_dest;
}
if (pos < src->length) {
ped_timer_update (timer, 1.0 * pos / src->length);
if (!ped_geometry_read (src, buf, pos, src->length - pos))
goto error_close_dest;
if (!ped_geometry_write (dest, buf, pos, src->length - pos))
goto error_close_dest;
}
ped_timer_update (timer, 1.0);
ped_device_close (src->dev);
ped_device_close (dest->dev);
free (buf);
return 1;
error_close_dest:
ped_device_close (dest->dev);
error_close_src:
ped_device_close (src->dev);
error_free_buf:
free (buf);
error:
return 0;
}
static PedFileSystem*
_raw_copy_and_resize (const PedFileSystem* fs, PedGeometry* geom,
PedTimer* timer)
{
PedFileSystem* new_fs;
PedTimer* sub_timer = NULL;
ped_timer_reset (timer);
ped_timer_set_state_name (timer, _("raw block copying"));
sub_timer = ped_timer_new_nested (timer, 0.95);
if (!_raw_copy (fs->geom, geom, sub_timer))
goto error;
ped_timer_destroy_nested (sub_timer);
new_fs = ped_file_system_open (geom);
if (!new_fs)
goto error;
ped_timer_set_state_name (timer, _("growing file system"));
sub_timer = ped_timer_new_nested (timer, 0.05);
if (!ped_file_system_resize (new_fs, geom, sub_timer))
goto error_close_new_fs;
ped_timer_destroy_nested (sub_timer);
return new_fs;
error_close_new_fs:
ped_file_system_close (new_fs);
error:
ped_timer_destroy_nested (sub_timer);
return NULL;
}
/**
* Create a new file system (of the same type) on \p geom, and
* copy the contents of \p fs into the new filesystem.
* If \p timer is non-NULL, it is used as the progress meter.
*
* \throws PED_EXCEPTION_ERROR when trying to copy onto an overlapping partition
* \throws PED_EXCEPTION_NO_FEATURE if copying of file system \p fs
* is not implemented yet
*
* \return a new PedFileSystem on success, \c NULL on failure
*/
PedFileSystem*
ped_file_system_copy (PedFileSystem* fs, PedGeometry* geom, PedTimer* timer)
{
PedFileSystem* new_fs;
PED_ASSERT (fs != NULL, return 0);
PED_ASSERT (geom != NULL, return 0);
if (!ped_device_open (geom->dev))
goto error;
if (ped_geometry_test_overlap (fs->geom, geom)) {
ped_exception_throw (
PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
_("Can't copy onto an overlapping partition."));
goto error_close_dev;
}
if (!fs->checked && fs->type->ops->check) {
if (!ped_file_system_check (fs, timer))
goto error_close_dev;
}
if (!ped_file_system_clobber_exclude (geom, fs->geom))
goto error_close_dev;
if (!fs->type->ops->copy) {
if (fs->type->ops->resize) {
if (fs->geom->length <= geom->length)
return _raw_copy_and_resize (
fs, (PedGeometry*) geom,
timer);
ped_exception_throw (
PED_EXCEPTION_NO_FEATURE,
PED_EXCEPTION_CANCEL,
_("Direct support for copying file systems is "
"not yet implemented for %s. However, "
"support for resizing is implemented. "
"Therefore, the file system can be copied if "
"the new partition is at least as big as the "
"old one. So, either shrink the partition "
"you are trying to copy, or copy to a bigger "
"partition."),
fs->type->name);
goto error_close_dev;
} else {
ped_exception_throw (
PED_EXCEPTION_NO_FEATURE,
PED_EXCEPTION_CANCEL,
_("Support for copying %s file systems is not "
"implemented yet."),
fs->type->name);
goto error_close_dev;
}
}
new_fs = fs->type->ops->copy (fs, geom, timer);
if (!new_fs)
goto error_close_dev;
return new_fs;
error_close_dev:
ped_device_close (geom->dev);
error:
return NULL;;
}
/**
* Resize \p fs to new geometry \p geom.
*
* \p geom should satisfy the ped_file_system_get_resize_constraint().
* (This isn't asserted, so it's not a bug not to... just it's likely
* to fail ;) If \p timer is non-NULL, it is used as the progress meter.
*
* \throws PED_EXCEPTION_NO_FEATURE if resizing of file system \p fs
* is not implemented yet
*
* \return \c 0 on failure
*/
int
ped_file_system_resize (PedFileSystem* fs, PedGeometry* geom, PedTimer* timer)
{
PED_ASSERT (fs != NULL, return 0);
PED_ASSERT (geom != NULL, return 0);
if (!fs->type->ops->resize) {
ped_exception_throw (PED_EXCEPTION_NO_FEATURE,
PED_EXCEPTION_CANCEL,
_("Support for resizing %s file systems "
"is not implemented yet."),
fs->type->name);
return 0;
}
if (!fs->checked && fs->type->ops->check) {
if (!ped_file_system_check (fs, timer))
return 0;
}
if (!ped_file_system_clobber_exclude (geom, fs->geom))
return 0;
return fs->type->ops->resize (fs, geom, timer);
}
/**
* This function returns a constraint on the region that all file systems
* of a particular type \p fs_type created on device \p dev with
* ped_file_system_create() must satisfy. For example, FAT16 file systems must
* be at least 32 megabytes.
*
* \return \c NULL on failure
*/
PedConstraint*
ped_file_system_get_create_constraint (const PedFileSystemType* fs_type,
const PedDevice* dev)
{
PED_ASSERT (fs_type != NULL, return NULL);
PED_ASSERT (dev != NULL, return NULL);
if (!fs_type->ops->get_create_constraint)
return NULL;
return fs_type->ops->get_create_constraint (dev);
}
/**
* Return a constraint, that represents all of the possible ways the
* file system \p fs can be resized with ped_file_system_resize().
* This takes into account the amount of used space on
* the filesystem \p fs and the capabilities of the resize algorithm.
* Hints:
* -# if constraint->start_align->grain_size == 0, or
* constraint->start_geom->length == 1, then the start can not be moved
* -# constraint->min_size is the minimum size you can resize the partition
* to. You might want to tell the user this ;-).
*
* \return a PedConstraint on success, \c NULL on failure
*/
PedConstraint*
ped_file_system_get_resize_constraint (const PedFileSystem* fs)
{
PED_ASSERT (fs != NULL, return 0);
if (!fs->type->ops->get_resize_constraint)
return NULL;
return fs->type->ops->get_resize_constraint (fs);
}
/**
* Get the constraint on copying \p fs with ped_file_system_copy()
* to somewhere on \p dev.
*
* \return a PedConstraint on success, \c NULL on failure
*/
PedConstraint*
ped_file_system_get_copy_constraint (const PedFileSystem* fs,
const PedDevice* dev)
{
PedGeometry full_dev;
PED_ASSERT (fs != NULL, return NULL);
PED_ASSERT (dev != NULL, return NULL);
if (fs->type->ops->get_copy_constraint)
return fs->type->ops->get_copy_constraint (fs, dev);
if (fs->type->ops->resize) {
if (!ped_geometry_init (&full_dev, dev, 0, dev->length - 1))
return NULL;
return ped_constraint_new (
ped_alignment_any, ped_alignment_any,
&full_dev, &full_dev,
fs->geom->length, dev->length);
}
return NULL;
}
/** @} */
|