/*
libparted
Copyright (C) 1998-2001, 2007, 2009-2010 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/>.
*/
#include <config.h>
#include <string.h>
#include "fat.h"
#ifndef DISCOVER_ONLY
static int
{
return 0);
switch (flag) {
case FAT_FLAG_FREE:
return 0;
case FAT_FLAG_DIRECTORY:
return 1;
case FAT_FLAG_FILE:
case FAT_FLAG_BAD:
return 0;
}
return 0;
}
static int
{
return 1;
}
return 0; /* all done! */
}
static int
{
int status;
FatFragment i;
if (status)
return 1;
/* something bad happened, so read fragments one by one. (The error may
have occurred on an unused fragment: who cares) */
for (i = 0; i < length; i++) {
if (ctx->buffer_map [i]) {
ctx->buffer_offset + i))
return 0;
}
}
return 1;
}
static int
{
for (frag = 0;
frag++) {
}
}
return 0;
return 1;
}
/*****************************************************************************
* here starts the write code. All assumes that ctx->buffer_map [first] and
* ctx->buffer_map [last] are occupied by fragments that need to be duplicated.
*****************************************************************************/
/* finds the first fragment that is not going to get overwritten (that needs to
get read in) */
static FatFragment
{
int old;
continue;
new++;
return new;
}
return -1;
}
/* finds the last fragment that is not going to get overwritten (that needs to
get read in) */
static FatFragment
{
int old;
continue;
new--;
return new;
}
return -1;
}
/* "underlay" refers to the "static" fragments, that remain unchanged.
* when writing large chunks at a time, we don't want to clobber these,
* so we read them in, and write them back again. MUCH quicker that way.
*/
static int
{
if (first_underlay == -1)
return 1;
* new_fs_info->frag_size,
return 0;
return 1;
}
/* quick_group_write() makes no attempt to recover from errors - just
* does things fast. If there is an error, slow_group_write() is
* called.
* Note: we do syncing writes, to make sure there isn't any
* error writing out. It's rather difficult recovering from errors
* further on.
*/
static int
{
int active_length;
int i;
int offset;
goto error;
continue;
}
goto error;
return 1;
return 0;
}
/* Writes fragments out, one at a time, avoiding errors on redundant writes
* on damaged parts of the disk we already know about. If there's an error
* on one of the required fragments, it gets marked as bad, and a replacement
* is found.
*/
static int
{
int i;
continue;
ctx->buffer_map [i])) {
ctx->buffer_map [i]);
(new_fs_info->fat);
if (ctx->buffer_map [i] == 0)
return 0;
}
}
return 1;
}
static int
{
int i;
continue;
}
return 1;
}
static int
{
return 0;
}
return 0;
return 1;
}
/* assumes fragment size and new_fs's cluster size are equal */
static int
{
int group_start;
FatFragment i;
group_start = -1;
for (i = 0; i < ctx->buffer_frags; i++) {
continue;
ctx->frags_duped++;
if (!new_cluster)
return 0;
if (group_start == -1)
group_start = group_end = i;
return 0);
group_end = i;
} else {
/* ran out of room in the buffer, so write this group,
* and start a new one...
*/
return 0;
group_start = group_end = i;
}
}
return 0;
return 1;
}
/* default all fragments to unmoved
*/
static void
{
FatFragment i;
for (i = 0; i < old_fs_info->frag_count; i++)
}
static FatFragment
{
FatFragment i;
total = 0;
for (i = 0; i < fs_info->frag_count; i++) {
if (needs_duplicating (ctx, i))
total++;
}
return total;
}
/* duplicates unreachable file clusters, and all directory clusters
*/
int
{
init_remap (ctx);
ctx->buffer_offset = 0;
ctx->frags_duped = 0;
while (search_next_fragment (ctx)) {
if (!fetch_fragments (ctx))
return 0;
if (!write_fragments (ctx))
return 0;
}
return 1;
}
#endif /* !DISCOVER_ONLY */