00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00025 #include "plibc_private.h"
00026
00032 int statfs(const char *path, struct statfs *buf)
00033 {
00034 HINSTANCE h;
00035 FARPROC f;
00036 char tmp[MAX_PATH], resolved_path[MAX_PATH];
00037 int retval = 0;
00038
00039 errno = 0;
00040
00041 realpath(path, resolved_path);
00042 if(!resolved_path)
00043 retval = -1;
00044 else
00045 {
00046
00047 h = LoadLibraryA("kernel32.dll");
00048 if(h)
00049 f = GetProcAddress(h, "GetDiskFreeSpaceExA");
00050 else
00051 f = NULL;
00052 if(f)
00053 {
00054 ULARGE_INTEGER bytes_free, bytes_total, bytes_free2;
00055 if(!f(resolved_path, &bytes_free2, &bytes_total, &bytes_free))
00056 {
00057 errno = ENOENT;
00058 retval = -1;
00059 }
00060 else
00061 {
00062 buf->f_bsize = FAKED_BLOCK_SIZE;
00063 buf->f_bfree = (bytes_free.QuadPart) / FAKED_BLOCK_SIZE;
00064 buf->f_files = buf->f_blocks =
00065 (bytes_total.QuadPart) / FAKED_BLOCK_SIZE;
00066 buf->f_ffree = buf->f_bavail =
00067 (bytes_free2.QuadPart) / FAKED_BLOCK_SIZE;
00068 }
00069 }
00070 else
00071 {
00072 DWORD sectors_per_cluster, bytes_per_sector;
00073 if(h)
00074 FreeLibrary(h);
00075 if(!GetDiskFreeSpaceA(resolved_path, §ors_per_cluster,
00076 &bytes_per_sector, &buf->f_bavail,
00077 &buf->f_blocks))
00078 {
00079 errno = ENOENT;
00080 retval = -1;
00081 }
00082 else
00083 {
00084 buf->f_bsize = sectors_per_cluster * bytes_per_sector;
00085 buf->f_files = buf->f_blocks;
00086 buf->f_ffree = buf->f_bavail;
00087 buf->f_bfree = buf->f_bavail;
00088 }
00089 }
00090 if(h)
00091 FreeLibrary(h);
00092 }
00093
00094
00095 if(strspn(":", resolved_path) > 0)
00096 resolved_path[3] = '\0';
00097 if(GetVolumeInformation
00098 (resolved_path, NULL, 0, &buf->f_fsid, &buf->f_namelen, NULL, tmp,
00099 MAX_PATH))
00100 {
00101 if(strcasecmp("NTFS", tmp) == 0)
00102 {
00103 buf->f_type = NTFS_SUPER_MAGIC;
00104 }
00105 else
00106 {
00107 buf->f_type = MSDOS_SUPER_MAGIC;
00108 }
00109 }
00110 else
00111 {
00112 errno = ENOENT;
00113 retval = -1;
00114 }
00115 return retval;
00116 }
00117
00118