filesys.c revision 7e7bd3dccbfe8f79e25e5c1554b5bc3a9aaca321
/*
libparted - a library for manipulating disk partitions
Copyright (C) 1999, 2000, 2001, 2007 Free Software Foundation, Inc.
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>
#if ENABLE_NLS
# include <libintl.h>
#else
#endif /* ENABLE_NLS */
void
{
/* pretend that "next" isn't part of the struct :-) */
}
void
{
if (last)
else
}
/**
* Get a PedFileSystemType by its @p name.
*
* @return @c NULL if none found.
*/
ped_file_system_type_get (const char* name)
{
break;
}
return walk;
}
/**
* Get the next PedFileSystemType after @p fs_type.
*
* @return @c NULL if @p fs_type is the last item in the list.
*/
{
if (fs_type)
else
return fs_types;
}
/**
* 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
*/
{
return 0;
return result;
}
static int
{
if (fs)
else
}
static PedFileSystemType*
{
int i;
/* 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++) {
continue;
if (open_detected) {
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++) {
continue;
if (open_detected) {
return NULL;
} else {
open_detected = detected [i];
}
}
return open_detected;
}
static int
{
}
static PedFileSystemType*
const int detected_error [], int detected_count)
{
int best_match = 0;
int i;
for (i = 1; i < detected_count; i++) {
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;
< 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
*/
{
int detected_error[32];
int detected_count = 0;
return NULL;
if (probed) {
} else {
}
}
if (!detected_count)
return NULL;
if (walk)
return walk;
}
/**
* 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
{
goto error;
continue;
if (!probed) {
continue;
}
goto error_close_dev;
}
}
return 1;
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
const PedGeometry* exclude)
{
int status;
return 1;
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.
*/
{
goto error;
if (!type) {
_("Could not detect file system."));
goto error_close_dev;
}
if (!probed_geom)
goto error_close_dev;
if (ped_exception_throw (
_("The file system is bigger than its volume!"))
}
_("Support for opening %s file systems "
"is not implemented yet."),
}
if (!fs)
return fs;
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
*/
{
_("Support for creating %s file systems "
"is not implemented yet."),
goto error;
}
goto error;
if (!ped_file_system_clobber (geom))
goto error_close_dev;
if (!fs)
goto error_close_dev;
return fs;
return 0;
}
/**
* Close file system \p fs.
*
* \return \c 1 on success, \c 0 on failure
*/
int
{
goto error_close_dev;
return 1;
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
{
_("Support for checking %s file systems "
"is not implemented yet."),
return 0;
}
}
static int
{
char* buf;
if (!buf)
goto error;
goto error_free_buf;
goto error_close_src;
goto error_close_dest;
goto error_close_dest;
}
goto error_close_dest;
goto error_close_dest;
}
return 1;
return 0;
}
static PedFileSystem*
{
goto error;
if (!new_fs)
goto error;
goto error_close_new_fs;
return new_fs;
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
*/
{
goto error;
_("Can't copy onto an overlapping partition."));
goto error_close_dev;
}
goto error_close_dev;
}
goto error_close_dev;
return _raw_copy_and_resize (
timer);
_("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."),
goto error_close_dev;
} else {
_("Support for copying %s file systems is not "
"implemented yet."),
goto error_close_dev;
}
}
if (!new_fs)
goto error_close_dev;
return new_fs;
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
{
_("Support for resizing %s file systems "
"is not implemented yet."),
return 0;
}
return 0;
}
return 0;
}
/**
* 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
*/
{
return NULL;
}
/**
* 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
*/
{
return NULL;
}
/**
* 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
*/
{
return NULL;
return ped_constraint_new (
}
return NULL;
}
/** @} */