aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Innes2000-12-17 23:13:26 +0000
committerAndrew Innes2000-12-17 23:13:26 +0000
commit2254bcde534143e48b624128a43e86699342b61b (patch)
tree88970528f4f64437a3d10ea9fd96d75c87fba5de /src
parent605e284f5b430335402cad59b1d627e250408ba2 (diff)
downloademacs-2254bcde534143e48b624128a43e86699342b61b.tar.gz
emacs-2254bcde534143e48b624128a43e86699342b61b.zip
(Ffile_system_info): New function.
(syms_of_w32fns): Defsubr it.
Diffstat (limited to 'src')
-rw-r--r--src/w32fns.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/w32fns.c b/src/w32fns.c
index c11f66b8a03..c888dd36716 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -13184,6 +13184,101 @@ is set to off if the low bit of NEW-STATE is zero, otherwise on.")
13184 return Qnil; 13184 return Qnil;
13185} 13185}
13186 13186
13187DEFUN ("file-system-info", Ffile_system_info, Sfile_system_info, 1, 1, 0,
13188 "Return storage information about the file system FILENAME is on.\n\
13189Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total\n\
13190storage of the file system, FREE is the free storage, and AVAIL is the\n\
13191storage available to a non-superuser. All 3 numbers are in bytes.\n\
13192If the underlying system call fails, value is nil.")
13193 (filename)
13194 Lisp_Object filename;
13195{
13196 Lisp_Object encoded, value;
13197
13198 CHECK_STRING (filename, 0);
13199 filename = Fexpand_file_name (filename, Qnil);
13200 encoded = ENCODE_FILE (filename);
13201
13202 value = Qnil;
13203
13204 /* Determining the required information on Windows turns out, sadly,
13205 to be more involved than one would hope. The original Win32 api
13206 call for this will return bogus information on some systems, but we
13207 must dynamically probe for the replacement api, since that was
13208 added rather late on. */
13209 {
13210 HMODULE hKernel = GetModuleHandle ("kernel32");
13211 BOOL (*pfn_GetDiskFreeSpaceEx)
13212 (char *, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER)
13213 = (void *) GetProcAddress (hKernel, "GetDiskFreeSpaceEx");
13214
13215 /* On Windows, we may need to specify the root directory of the
13216 volume holding FILENAME. */
13217 char rootname[MAX_PATH];
13218 char *name = XSTRING (encoded)->data;
13219
13220 /* find the root name of the volume if given */
13221 if (isalpha (name[0]) && name[1] == ':')
13222 {
13223 rootname[0] = name[0];
13224 rootname[1] = name[1];
13225 rootname[2] = '\\';
13226 rootname[3] = 0;
13227 }
13228 else if (IS_DIRECTORY_SEP (name[0]) && IS_DIRECTORY_SEP (name[1]))
13229 {
13230 char *str = rootname;
13231 int slashes = 4;
13232 do
13233 {
13234 if (IS_DIRECTORY_SEP (*name) && --slashes == 0)
13235 break;
13236 *str++ = *name++;
13237 }
13238 while ( *name );
13239
13240 *str++ = '\\';
13241 *str = 0;
13242 }
13243
13244 if (pfn_GetDiskFreeSpaceEx)
13245 {
13246 LARGE_INTEGER availbytes;
13247 LARGE_INTEGER freebytes;
13248 LARGE_INTEGER totalbytes;
13249
13250 if (pfn_GetDiskFreeSpaceEx(rootname,
13251 &availbytes,
13252 &totalbytes,
13253 &freebytes))
13254 value = list3 (make_float ((double) totalbytes.QuadPart),
13255 make_float ((double) freebytes.QuadPart),
13256 make_float ((double) availbytes.QuadPart));
13257 }
13258 else
13259 {
13260 DWORD sectors_per_cluster;
13261 DWORD bytes_per_sector;
13262 DWORD free_clusters;
13263 DWORD total_clusters;
13264
13265 if (GetDiskFreeSpace(rootname,
13266 &sectors_per_cluster,
13267 &bytes_per_sector,
13268 &free_clusters,
13269 &total_clusters))
13270 value = list3 (make_float ((double) total_clusters
13271 * sectors_per_cluster * bytes_per_sector),
13272 make_float ((double) free_clusters
13273 * sectors_per_cluster * bytes_per_sector),
13274 make_float ((double) free_clusters
13275 * sectors_per_cluster * bytes_per_sector));
13276 }
13277 }
13278
13279 return value;
13280}
13281
13187syms_of_w32fns () 13282syms_of_w32fns ()
13188{ 13283{
13189 /* This is zero if not using MS-Windows. */ 13284 /* This is zero if not using MS-Windows. */
@@ -13643,6 +13738,8 @@ versions of Windows) characters.");
13643 defsubr (&Sw32_toggle_lock_key); 13738 defsubr (&Sw32_toggle_lock_key);
13644 defsubr (&Sw32_find_bdf_fonts); 13739 defsubr (&Sw32_find_bdf_fonts);
13645 13740
13741 defsubr (&Sfile_system_info);
13742
13646 /* Setting callback functions for fontset handler. */ 13743 /* Setting callback functions for fontset handler. */
13647 get_font_info_func = w32_get_font_info; 13744 get_font_info_func = w32_get_font_info;
13648 13745