/* df.c - Despliega estadisticas sobre el uso del disco Copyright (C) 1999-2002 Luis C. Castro Skertchly This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 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, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* Changes: 1.0 - First version 2.0 - Code changed to enable disks > 2 GB */ #define _CRT_SECURE_NO_DEPRECATE #define _WIN32_WINNT 0x0501 #define WIN32_LEAN_AND_MEAN #include #include #include #include "luislib.h" char sb[256]; int main(int argc, char **argv) { char szRootPathName[_MAX_PATH]; __int64 i64FreeBytesAvailable; __int64 i64TotalBytes; __int64 i64TotalFreeBytes; DWORD dwSectorsPerCluster; DWORD dwBytesPerSector; DWORD dwFreeClusters; DWORD dwClusters; char drive; char temp[32]; printf("df - Version 2.0\nCopyright (C) 2000-2007, Luis C. Castro Skertchly\n"); drive = 0; memset(sb, 0, sizeof(sb)); if (argv[1]) { if (!strcmp(argv[1], "/?") || !strcmp(argv[1], "--help")) { printf("Usage: df [drive | UNC path]\nNote: If using UNC path, it must include\n" "a trailing backslash, for example, \\\\SERVER\\Resource\\\n"); return 0; } strcpy(sb, argv[1]); } else { if (!GetCurrentDirectory(sizeof(sb), sb)) { PutError(argv[0], NULL); return 1; } } if (sb[1] == ':') { drive = toupper(sb[0]); szRootPathName[0] = drive; szRootPathName[1] = ':'; szRootPathName[2] = '\\'; szRootPathName[3] = 0; } else { int i, j; for(i = 0, j = 0; (j < 4) && sb[i]; i++) { szRootPathName[i] = sb[i]; if (sb[i] == '\\') j++; } szRootPathName[i] = 0; } if (!GetDiskFreeSpace(szRootPathName, &dwSectorsPerCluster, &dwBytesPerSector, &dwFreeClusters, &dwClusters)) { wsprintf(sb, "%s - %s", szRootPathName, "GetDiskSpace()"); PutError(sb, NULL); return 1; } if (!GetDiskFreeSpaceEx(szRootPathName, (PULARGE_INTEGER) &i64FreeBytesAvailable, (PULARGE_INTEGER) &i64TotalBytes, (PULARGE_INTEGER) &i64TotalFreeBytes)) { wsprintf(sb, "%s - %s", szRootPathName, "GetDiskSpaceEx()"); PutError(sb, NULL); return 1; } if (drive) { printf("Drive %c:\n", drive); } else { printf("UNC: %s\n", szRootPathName); } printf("%s Sectors per cluster\n", NumericFormat("###,###,###,###,###", dwSectorsPerCluster, temp)); printf("%s Bytes per sector\n", NumericFormat("###,###,###,###,###", dwBytesPerSector, temp)); printf("%s Clusters\n", NumericFormat("###,###,###,###,###", dwClusters, temp)); printf("%s Free Clusters\n", NumericFormat("###,###,###,###,###", dwFreeClusters, temp)); printf("%s KB total disk space\n", NumericFormatL("###,###,###,###,###", i64TotalBytes / 1024, temp)); printf("%s KB free\n", NumericFormatL("###,###,###,###,###", i64TotalFreeBytes / 1024, temp)); return 0; }