Не правильно отображается количество свободных кластеров на диске
GetDiskFreeSpace - определить день недели и количество свободных кластеров на диске. Не могу разобраться, по диску "D" показывает всё правильно, а по "C" разбежка может достигать от 1 до 3 ГБ. Код к первому заданию. И может подскажете количество свободных кластеров - это количество вообще свободного места на диске или что-то другое? Вроде бы стоит размер одного кластера 4096 и можно чтобы два ответа как-то были друг от друга ?
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp5
{
public partial class Form1 : Form
{
[DllImport("kernel32.dll")]
public static extern void GetSystemTime(ref SYSTEMTIME lpSystemTime);
[DllImport("kernel32.dll")]
public static extern bool GetDiskFreeSpace(string lpRootPathName, out uint lpSectorsPerCluster, out uint lpBytesPerSector, out uint lpNumberOfFreeClusters, out uint lpTotalNumberOfClusters);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
// Get current day of the week
SYSTEMTIME systemTime = new SYSTEMTIME();
GetSystemTime(ref systemTime);
DayOfWeek dayOfWeek = (DayOfWeek)systemTime.wDayOfWeek;
// Display the result
textBox1.Text = "Сегодня " + dayOfWeek.ToString();
// Get information about the free space on the C drive
uint sectorsPerCluster, bytesPerSector, numberOfFreeClusters, totalNumberOfClusters;
if (GetDiskFreeSpace("C:\\", out sectorsPerCluster, out bytesPerSector, out numberOfFreeClusters, out totalNumberOfClusters))
{
// Calculate the free space in megabytes
ulong freeSpaceInMB = numberOfFreeClusters * (ulong)sectorsPerCluster * (ulong)bytesPerSector / (1024 * 1024);
// Display the result
textBox1.AppendText(Environment.NewLine + " На диске свободно " + freeSpaceInMB + " МБ");
}
}
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEMTIME
{
public ushort wYear;
public ushort wMonth;
public ushort wDayOfWeek;
public ushort wDay;
public ushort wHour;
public ushort wMinute;
public ushort wSecond;
public ushort wMilliseconds;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
