/*
libparted
Copyright (C) 1998-2000, 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 "fat.h"
#include "traverse.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef DISCOVER_ONLY
#if 0
/* extremely ugly hack: stick everything that obviously isn't an unmovable file
* in here. Note: DAT is a bit dubious. Unfortunately, it's used by the
* registry, so it'll be all over the place :-(
*/
static char* movable_extensions[] = {
"",
"1ST",
"AVI",
"BAK", "BAT", "BMP",
"CFG", "COM", "CSS",
"DAT", "DLL", "DOC", "DRV",
"EXE",
"FAQ", "FLT", "FON",
"GID", "GIF",
"HLP", "HTT", "HTM",
"ICO", "INI",
"JPG",
"LNK", "LOG",
"KBD",
"ME", "MID", "MSG",
"OCX", "OLD",
"PIF", "PNG", "PRV",
"RTF",
"SCR", "SYS",
"TMP", "TTF", "TXT",
"URL",
"WAV",
"VBX", "VOC", "VXD",
};
static char*
get_extension (char* file_name)
{
char* ext;
if (!ext)
return "";
return "";
return ext + 1;
}
static int
is_movable_system_file (char* file_name)
{
int i;
for (i = 0; movable_extensions [i]; i++) {
return 1;
}
return 0;
}
#endif /* 0 */
/*
prints out the sequence of clusters for a given file chain, beginning
at start_cluster.
*/
#ifdef PED_VERBOSE
static void
{
int this_row;
this_row = 0;
if (++this_row == 7) {
putchar ('\n');
this_row = 0;
}
}
putchar ('\n');
}
#endif /* PED_VERBOSE */
static PedSector
{
result = a % b;
if (!result)
result = b;
return result;
}
/*
to "flag".
*/
static int
{
int last_cluster_usage;
if (ped_exception_throw (
_("Bad directory entry for %s: first cluster is the "
"end of file marker."),
return 0;
}
chain_length++;
if (!clst) {
_("Bad FAT: unterminated chain for %s. You "
"should run dosfsck or scandisk."),
return 0;
}
_("Bad FAT: cluster %d outside file system "
"in chain for %s. You should run dosfsck "
"or scandisk."),
(int) clst, chain_name);
return 0;
}
_("Bad FAT: cluster %d is cross-linked for "
"%s. You should run dosfsck or scandisk."),
(int) clst, chain_name);
return 0;
}
if (flag == FAT_FLAG_DIRECTORY)
}
if (size
&& chain_length
if (ped_exception_throw (
_("%s is %dk, but it has %d clusters (%dk)."),
(int) size / 2,
(int) chain_length,
return 0;
}
return 1;
}
/*
recursively traverses a directory, flagging all clusters in the process.
It frees the traverse_info structure before returning.
*/
static int
char* file_name_start;
break;
continue;
continue; /* skip . and .. entries */
512);
#ifdef PED_VERBOSE
#endif
#if 0
&& !is_movable_system_file (file_name)) {
_("The file %s is marked as a system file. "
"This means moving it could cause some "
"programs to stop working."),
switch (ex_status) {
case PED_EXCEPTION_CANCEL:
return 0;
case PED_EXCEPTION_UNHANDLED:
case PED_EXCEPTION_IGNORE:
}
}
#endif /* 0 */
if (fat_dir_entry_is_directory (this_entry)) {
return 0;
if (!subdir_trav_info)
return 0;
if (!flag_traverse_dir (subdir_trav_info))
return 0;
} else if (fat_dir_entry_is_file (this_entry)) {
return 0;
}
}
return 1;
}
static void
{
}
}
/*
fills in cluster_info. Each FAT entry (= cluster) is flagged as either
FAT_FLAG_FREE, FAT_FLAG_FILE or FAT_FLAG_DIRECTORY.
Also, the fraction of each cluster (x/64) is recorded
*/
int
/* set all clusters to unused as a default */
fs_info->total_dir_clusters = 0;
"\\");
if (!flag_traverse_dir (trav_info))
return 0;
FAT_FLAG_DIRECTORY, 0))
return 0;
} else {
if (!flag_traverse_dir (trav_info))
return 0;
}
return 1;
}
{
}
{
int fraction;
return 0;
if (fraction == 0)
fraction = 64;
}
{
return 0);
return flag;
/ fs_info->frag_sectors;
if (offset > last_frag_used)
return FAT_FLAG_FREE;
else
return flag;
}
int
{
case FAT_FLAG_FREE:
case FAT_FLAG_BAD:
return 0;
case FAT_FLAG_FILE:
case FAT_FLAG_DIRECTORY:
return 1;
}
return 0;
}
#endif /* !DISCOVER_ONLY */