geom.c revision 7e7bd3dccbfe8f79e25e5c1554b5bc3a9aaca321
/*
libparted - a library for manipulating disk partitions
Copyright (C) 1999, 2000, 2005, 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 geom.c */
/**
* \addtogroup PedGeometry
*
* \brief PedGeometry represents a continuous region on a device. All addressing
* through a PedGeometry object is in terms of the start of the continuous
* region.
*
* The following conditions are always true on a PedGeometry object manipulated
* with the GNU Parted API:
*
* - <tt>start + length - 1 == end</tt>
* - <tt>length > 0</tt>
* - <tt>start >= 0</tt>
* - <tt>end < dev->length</tt>
*
* @{
*/
#include <config.h>
#if ENABLE_NLS
# include <libintl.h>
#else
#endif /* ENABLE_NLS */
/**
* Initialize the previously allocated PedGeometry \p geom.
*/
int
{
}
/**
* Create a new PedGeometry object on \p disk, starting at \p start with a
* size of \p length sectors.
*
* \return NULL on failure.
*/
{
if (!geom)
goto error;
goto error_free_geom;
return geom;
return NULL;
}
/**
* Duplicate a PedGeometry object.
*
* This function constructs a PedGeometry object that is an identical but
* independent copy of \p geom. Both the input, \p geom, and the output
* should be destroyed with ped_geometry_destroy() when they are no
* longer needed.
*
* \return NULL on failure.
*/
{
}
/**
* Return a PedGeometry object that refers to the intersection of
* \p a and \p b.
*
* This function constructs a PedGeometry object that describes the
* region that is common to both a and b. If there is no such common
* region, it returns NULL. (This situation is not treated as an
* error by much of GNU Parted.)
*/
{
return NULL;
return NULL;
}
/**
* Destroy a PedGeometry object.
*/
void
{
}
/**
* Assign a new \p start, \p end (implicitly) and \p length to \p geom.
*
* \p geom->end is calculated from \p start and \p length.
*/
int
{
if (length < 1) {
_("Can't have the end before the start!"));
return 0;
}
_("Can't have a partition outside the disk!"));
return 0;
}
return 1;
}
/**
* Assign a new start to \p geom without changing \p geom->end.
*
* \p geom->length is updated accordingly.
*/
int
{
}
/**
* Assign a new end to \p geom without changing \p geom->start.
*
* \p geom->length is updated accordingly.
*/
int
{
}
/**
* Test if \p a overlaps with \p b.
*
* That is, they lie on the same physical device, and they share
* the same physical region at least partially.
*
* \return 1 if \p a and \p b overlap.
*/
int
{
PED_ASSERT (a != NULL, return 0);
PED_ASSERT (b != NULL, return 0);
return 0;
else
}
/**
* Tests if \p b lies completely within \p a. That is, they lie on the same
* physical device, and all of the \p b's region is contained inside
* \p a's.
*
* \return 1 if the region \p b describes is contained entirely inside \p a
*/
int
{
PED_ASSERT (a != NULL, return 0);
PED_ASSERT (b != NULL, return 0);
return 0;
}
/**
* Tests if \a a and \p b refer to the same physical region.
*
* \return 1 if \p a and \p b describe the same regions
*
*/
int
{
PED_ASSERT (a != NULL, return 0);
PED_ASSERT (b != NULL, return 0);
}
/**
* Tests if \p sector is inside \p geom.
*
* \return 1 if sector lies within the \p region that \p geom describes
*/
int
{
}
/**
* Reads data from the region represented by \p geom. \p offset is the
* location from within the region, not from the start of the disk.
* \p count sectors are read into \p buffer.
* This is essentially equivalent to:
* \code
* ped_device_read (geom->disk->dev, buffer, geom->start + offset, count)
* \endcode
*
* \throws PED_EXCEPTION_ERROR when attempting to read sectors outside of
* partition
*
* \return 0 on failure
*/
int
{
PED_ASSERT (offset >= 0, return 0);
PED_ASSERT (count >= 0, return 0);
return 0;
return 0;
return 1;
}
/**
* Flushes the cache on \p geom.
*
* This function flushes all write-behind caches that might be holding
* writes made by ped_geometry_write() to \p geom. It is slow, because
* it guarantees cache coherency among all relevant caches.
*
* \return 0 on failure
*/
int
{
}
/**
* Flushes the cache on \p geom.
*
* This function flushes all write-behind caches that might be holding writes
* made by ped_geometry_write() to \p geom. It does NOT ensure cache coherency
* with other caches that cache data in the region described by \p geom.
* If you need cache coherency, use ped_geometry_sync() instead.
*
* \return 0 on failure
*/
int
{
}
/**
* Writes data into the region represented by \p geom. \p offset is the
* location from within the region, not from the start of the disk.
* \p count sectors are written.
*
* \return 0 on failure
*/
int
{
int exception_status;
PED_ASSERT (offset >= 0, return 0);
PED_ASSERT (count >= 0, return 0);
_("Attempt to write sectors %ld-%ld outside of "
"partition on %s."),
return exception_status == PED_EXCEPTION_IGNORE;
}
return 0;
return 1;
}
/**
* Checks for physical disk errors. \todo use ped_device_check()
*
* Checks a region for physical defects on \p geom. \p buffer is used
* for temporary storage for ped_geometry_check(), and has an undefined
* value. \p buffer is \p buffer_size sectors long.
* The region checked starts at \p offset sectors inside the
* region represented by \p geom, and is \p count sectors long.
* \p granularity specificies how sectors should be grouped
* together. The first bad sector to be returned will always be in
* the form:
* <tt>offset + n * granularity</tt>
*
* \return the first bad sector, or 0 if there were no physical errors
*/
{
PedSector i;
goto found_error;
}
return 0;
return i;
}
}
goto retry; /* weird: failure on group read, but not individually */
}
/**
* This function takes a \p sector inside the region described by src, and
* returns that sector's address inside dst. This means that
*
* \code
* ped_geometry_read (dst, buf, ped_geometry_map(dst, src, sector), 1)
* \endcode
*
* does the same thing as
*
* \code
* ped_geometry_read (src, buf, sector, 1)
* \endcode
*
* Clearly, this will only work if \p src and \p dst overlap.
*
* \return -1 if \p sector is not within \p dst's space,
* or \p sector's address inside \p dst
*
*/
{
return -1;
return -1;
return -1;
return result;
}
/** @} */