![]() |
udefrag.dll Architecture - Reference Manual - Guides |
|
00001 /* 00002 * UltraDefrag - powerful defragmentation tool for Windows NT. 00003 * Copyright (c) 2007-2010 by Dmitri Arkhangelski (dmitriar@gmail.com). 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00027 #include "../../include/ntndk.h" 00028 00029 #include "../../include/udefrag.h" 00030 #include "../zenwinx/zenwinx.h" 00031 00032 volume_info v[MAX_DOS_DRIVES + 1]; 00033 00034 int internal_validate_volume(unsigned char letter,int skip_removable, 00035 int *is_removable,char *fsname,LARGE_INTEGER *ptotal,LARGE_INTEGER *pfree); 00036 00062 int __stdcall udefrag_get_avail_volumes(volume_info **vol_info,int skip_removable) 00063 { 00064 ULONG i, index; 00065 char letter; 00066 00067 /* get full list of volumes */ 00068 *vol_info = v; 00069 /* set error mode to ignore missing removable drives */ 00070 if(winx_set_system_error_mode(INTERNAL_SEM_FAILCRITICALERRORS) < 0) 00071 return (-1); 00072 index = 0; 00073 for(i = 0; i < MAX_DOS_DRIVES; i++){ 00074 letter = 'A' + (char)i; 00075 if(internal_validate_volume(letter, skip_removable, 00076 &(v[index].is_removable), v[index].fsname, 00077 &(v[index].total_space), &(v[index].free_space)) < 0) continue; 00078 v[index].letter = letter; 00079 index ++; 00080 } 00081 v[index].letter = 0; 00082 /* try to restore error mode to default state */ 00083 winx_set_system_error_mode(1); /* equal to SetErrorMode(0) */ 00084 return 0; 00085 } 00086 00097 int __stdcall udefrag_validate_volume(unsigned char letter,int skip_removable) 00098 { 00099 int is_removable; 00100 int error_code; 00101 /* 00102 * The following parameters are required 00103 * to exclude missing floppies. 00104 */ 00105 char fsname[MAXFSNAME]; 00106 LARGE_INTEGER total, free; 00107 00108 /* set error mode to ignore missing removable drives */ 00109 if(winx_set_system_error_mode(INTERNAL_SEM_FAILCRITICALERRORS) < 0) 00110 return (-1); 00111 error_code = internal_validate_volume(letter,skip_removable,&is_removable, 00112 fsname,&total,&free); 00113 if(error_code < 0) return error_code; 00114 /* try to restore error mode to default state */ 00115 winx_set_system_error_mode(1); /* equal to SetErrorMode(0) */ 00116 return 0; 00117 } 00118 00142 int internal_validate_volume(unsigned char letter,int skip_removable, 00143 int *is_removable,char *fsname,LARGE_INTEGER *ptotal,LARGE_INTEGER *pfree) 00144 { 00145 int type; 00146 00147 *is_removable = FALSE; 00148 type = winx_get_drive_type(letter); 00149 if(type < 0) return (-1); 00150 if(type == DRIVE_CDROM){ 00151 DebugPrint("Volume %c: is on cdrom drive.",letter); 00152 return UDEFRAG_CDROM; 00153 } 00154 if(type == DRIVE_REMOTE){ 00155 DebugPrint("Volume %c: is on remote drive.",letter); 00156 return UDEFRAG_REMOTE; 00157 } 00158 if(type == DRIVE_ASSIGNED_BY_SUBST_COMMAND){ 00159 DebugPrint("It seems that %c: volume letter is assigned by \'subst\' command.",letter); 00160 return UDEFRAG_ASSIGNED_BY_SUBST; 00161 } 00162 if(type == DRIVE_REMOVABLE){ 00163 *is_removable = TRUE; 00164 if(skip_removable){ 00165 DebugPrint("Volume %c: is on removable media.",letter); 00166 return UDEFRAG_REMOVABLE; 00167 } 00168 } 00169 /* get volume information */ 00170 if(ptotal && pfree){ 00171 if(winx_get_volume_size(letter,ptotal,pfree) < 0) 00172 return (-1); 00173 } 00174 if(fsname){ 00175 if(winx_get_filesystem_name(letter,fsname,MAXFSNAME) < 0) 00176 return (-1); 00177 } 00178 return 0; 00179 } 00180