📄 chkdsk.c
字号:
}
else
gl.n_free_clusters += 1;
}
return (TRUE);
}
/* int add_cluster_to_lost_list(pdrive, cluster)
*
* This routine is called by check_lost_clusters. It takes a cluster known
* to be lost and adds the chain which it heads to the lost chain list. If a
* chain head in the lost chain list is a member of the chain headed by
* cluster, it is replaced. With cluster.
*/
short add_cluster_to_lost_list(DDRIVE *pdr , CLTYPE cluster) /*__fn__*/
{
CLTYPE first_cluster_in_chain;
short i;
short found;
/* Save the top of the chain */
first_cluster_in_chain = cluster;
tm_printf_2("lost cluster %ld\n", (long) cluster);
found = FALSE;
while (cluster)
{
/* See if this cluster is the head of another lost chain
If so replace the head of that chain with the head of
the chain we are traversing */
if (!found)
{
for (i = 0; i < (short)gl.n_lost_chains; i++)
{
if (gl.lost_chain_list[i] == cluster)
{
gl.lost_chain_list[i] = first_cluster_in_chain;
found = TRUE;
break;
}
}
}
/* Now mark the cluster used. - we do this so we don't re-process
any of the clusters in this chain */
if ((gl.cl_start <= cluster) && (cluster < gl.cl_end))
{
set_bit(gl.bm_used, cluster - gl.cl_start);
}
cluster = pc_clnext(pdr, cluster);
}
/* If we didn't attach the chain to a list we already had we will
add it to the end */
if (!found)
gl.lost_chain_list[gl.n_lost_chains++] = first_cluster_in_chain;
if (gl.n_lost_chains >= NLOST_ALLOWED)
{
tm_printf("Too Many Lost Chains\n");
return(FALSE);
}
return(TRUE);
}
/* count_lost_clusters(DDRIVE *pdr)
*
* This routine scans the lost chain list and tallies the total number of
* clusters that were found.
*/
dword count_lost_clusters(DDRIVE *pdr) /*__fn__*/
{
short i;
CLTYPE cluster;
CLTYPE save_cluster;
int n_lost_this;
gl.n_lost_clusters = 0;
for (i = 0; i < (short)gl.n_lost_chains; i++)
{
n_lost_this = 0;
save_cluster = cluster = gl.lost_chain_list[i];
while (cluster)
{
n_lost_this++;
gl.n_lost_clusters++;
cluster = pc_clnext(pdr, cluster);
}
tm_printf_3("CL: %ld LOST: %ld\n", (dword)save_cluster, (dword) n_lost_this);
}
return(gl.n_lost_clusters);
}
/************************************************************************
* *
* Crossed chain fns *
* *
************************************************************************/
/* scan_crossed_files()
*
* This routine scans all files and subdirectories in the whole filesystem.
* For each cluster it looks to see if it is in the crossed file list that
* we generated earlier. If the cluster is found the file or subdirectory
* is added to the list of crossed files at that cluster.
*/
short scan_crossed_files(char *dir_name) /*__fn__*/
{
DROBJ *directory;
DROBJ *entry;
char ldir_name[EMAXPATH];
/* Find the directory for scanning the dir for files */
directory = pc_fndnode(dir_name);
if (!directory)
{
tm_printf_2("Failed Scanning Directory %s\n", dir_name);
return(FALSE);
}
if (gl.be_verbose)
{
tm_printf_2("%s\n",dir_name);
}
if (!pc_isroot(directory))
gl.n_user_directories += 1;
/* See if this directory is crossed with another */
if (!process_crossed_file(directory, dir_name))
{
pc_freeobj(directory);
tm_printf_2("Failed Scanning Directory %s\n", dir_name);
return(FALSE);
}
/* Scan through the directory looking for all files */
entry = pc_get_inode(0,directory, (PFBYTE)"*", (PFBYTE)"*",TRUE);
if (entry)
{
do
{
if (!(entry->finode->fattribute & (AVOLUME | ADIRENT) ))
{
pc_mfile((byte *)gl.gl_file_name, (byte *)entry->finode->fname, (byte *)entry->finode->fext);
pc_mpath((byte *)gl.gl_file_path, (byte *)dir_name, (byte *)gl.gl_file_name);
if (gl.be_verbose)
{
tm_printf_2(" %s\n", gl.gl_file_path);
}
/* See if this file is crossed with another */
if (!process_crossed_file(entry, gl.gl_file_path))
{
pc_freeobj(entry);
pc_freeobj(directory);
tm_printf_2("Failed Scanning File %s\n", gl.gl_file_path);
return(FALSE);
}
}
} while (pc_get_inode(entry , directory, (PFBYTE)"*", (PFBYTE)"*",TRUE));
pc_freeobj(entry);
}
pc_freeobj(directory);
/* Now we call scan_crossed_files() for each subdirectory */
/* Find the directory for scanning the dir for files */
directory = pc_fndnode(dir_name);
if (!directory)
{
tm_printf_2("Failed Scanning Directory %s\n", dir_name);
return(FALSE);
}
/* Scan through the directory looking for all files */
entry = pc_get_inode(0,directory, (PFBYTE)"*", (PFBYTE)"*",TRUE);
if (entry)
{
do
{
/* Scan it if it is a directory and not "." or ".." */
if (entry->finode->fattribute & ADIRENT)
{
if ( !pc_isdot(entry->finode->fname, entry->finode->fext) &&
!pc_isdotdot(entry->finode->fname, entry->finode->fext) )
{
pc_mfile((byte *)gl.gl_file_name, (byte *)entry->finode->fname, (byte *)entry->finode->fext);
pc_mpath((byte *)ldir_name, (byte *)dir_name, (byte *)gl.gl_file_name);
if (!scan_crossed_files(ldir_name))
{
pc_freeobj(directory);
pc_freeobj(entry);
return(FALSE);
}
}
}
} while (pc_get_inode(entry , directory, (PFBYTE)"*", (PFBYTE)"*",TRUE));
pc_freeobj(entry);
}
pc_freeobj(directory);
return (TRUE);
}
/* Given the file or directory at pobj see if any of its clusters are
crossed with another file or directory. */
short process_crossed_file(DROBJ *pobj, char *filename) /*__fn__*/
{
CLTYPE cluster;
short i;
CROSSED_FILE *pcross;
if (pc_isroot(pobj))
return(TRUE);
cluster = pc_finode_cluster(pobj->pdrive, pobj->finode);
while (cluster)
{
for (i = 0; i < (short)gl.n_crossed_points; i++)
{
/* If this cluster intersects with another chain. */
if (gl.crossed_points[i].cluster == cluster)
{
pcross = gl.crossed_points[i].plist;
while (pcross)
{
/* If already in the list for this cluster continue
processing the next cluster. */
if (tc_strcmp(pcross->file_name, filename) == 0)
break;
pcross = pcross->pnext;
}
if (!pcross)
{
/* Add this file/dir name to the list of files crossed
at this point */
if (!gl.crossed_file_freelist)
{
tm_printf("Too many crossed Files\n"); return(FALSE);
}
else
{
/* Add the file to the beginning of the list of files
crossed at this cluster */
pcross = gl.crossed_file_freelist;
gl.crossed_file_freelist = pcross->pnext;
pcross->pnext = gl.crossed_points[i].plist;
gl.crossed_points[i].plist = pcross;
tc_strcpy(pcross->file_name, filename);
}
}
}
}
cluster = pc_clnext(pobj->pdrive, cluster);
}
return(TRUE);
}
/* add_cluster_to_crossed(cluster)
*
* This routine is called by process_used_map if it detects a crossed
* chain (by finding a cluster that is already marked in the used map)
* It scans the list of crossed clusters. If cluster is not already in
* the list it is added. If we exceed the predefined value NCROSSED_ALLOWED
* it returns FALSE.
*/
short add_cluster_to_crossed(CLTYPE cluster) /*__fn__*/
{
short i;
if (gl.n_crossed_points >= NCROSSED_ALLOWED)
{
tm_printf("Too many crossed chains\n");
return(FALSE);
}
for (i = 0; i < (short) gl.n_crossed_points; i++)
{
if (gl.crossed_points[i].cluster == cluster)
return(TRUE);
}
gl.crossed_points[gl.n_crossed_points].cluster = cluster;
gl.n_crossed_points += 1;
return(TRUE);
}
/************************************************************************
* *
* Utility Functions *
* *
************************************************************************/
/* chain_size (CLTYPE cluster)
*
* Calculate (return) a chain's size in bytes
*
* Called by: build_chk_file
*/
CLTYPE chain_size(CLTYPE cluster) /*__fn__*/
{
CLTYPE n_clusters;
n_clusters = 0;
while (cluster)
{
n_clusters += 1;
cluster = pc_clnext(gl.drive_structure, cluster);
}
n_clusters *= (CLTYPE) gl.drive_structure->secpalloc;
n_clusters *= (CLTYPE) 512;
return(n_clusters);
}
/* clr_bit (byte *bitmap, dword index)
*
* Clear the bit at bitmap[index]
*/
void clr_bit(byte *bitmap, dword index)
{
bitmap[(dword) (index >> 3)] &= ~(1 << (index & 0x7));
}
/* get_bit (byte *bitmap, dword index)
*
* Return the bit at bitmap[index] (assuming bitmap is a bit array)
*/
byte get_bit(byte *bitmap, dword index)
{
return ((byte)(bitmap[(dword) (index >> 3)] & (1 << (index & 0x7))));
}
/* set_bit (byte *bitmap, dword index)
*
* Set the bit at bitmap[index] to 1
*/
void set_bit(byte *bitmap, dword index)
{
bitmap[(dword) (index >> 3)] |= (1 << (index & 0x7));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -