17 private const string NameField =
"_name";
21 public string Name => _name;
27 [SecuritySafeCritical]
41 [SecuritySafeCritical]
46 int errorMode = Win32Native.SetErrorMode(1);
49 if (!Win32Native.GetVolumeInformation(
Name, volumeName, 50, out
int _, out
int _, out
int _, stringBuilder, 50))
52 __Error.WinIODriveError(
Name, lastWin32Error);
57 Win32Native.SetErrorMode(errorMode);
68 [SecuritySafeCritical]
81 [SecuritySafeCritical]
84 int errorMode = Win32Native.SetErrorMode(1);
87 if (Win32Native.GetDiskFreeSpaceEx(
Name, out
long freeBytesForUser, out
long _, out
long _))
89 return freeBytesForUser;
91 __Error.WinIODriveError(
Name);
92 return freeBytesForUser;
96 Win32Native.SetErrorMode(errorMode);
108 [SecuritySafeCritical]
111 int errorMode = Win32Native.SetErrorMode(1);
114 if (Win32Native.GetDiskFreeSpaceEx(
Name, out
long _, out
long _, out
long freeBytes))
118 __Error.WinIODriveError(
Name);
123 Win32Native.SetErrorMode(errorMode);
135 [SecuritySafeCritical]
138 int errorMode = Win32Native.SetErrorMode(1);
141 if (Win32Native.GetDiskFreeSpaceEx(
Name, out
long _, out
long totalBytes, out
long _))
145 __Error.WinIODriveError(
Name);
150 Win32Native.SetErrorMode(errorMode);
167 [SecuritySafeCritical]
172 int errorMode = Win32Native.SetErrorMode(1);
175 if (!Win32Native.GetVolumeInformation(
Name, stringBuilder, 50, out
int _, out
int _, out
int _, fileSystemName, 50))
182 __Error.WinIODriveError(
Name, num);
187 Win32Native.SetErrorMode(errorMode);
191 [SecuritySafeCritical]
194 string path = _name +
".";
196 int errorMode = Win32Native.SetErrorMode(1);
199 if (!Win32Native.SetVolumeLabel(
Name, value))
202 if (lastWin32Error == 5)
206 __Error.WinIODriveError(
Name, lastWin32Error);
211 Win32Native.SetErrorMode(errorMode);
221 [SecuritySafeCritical]
224 if (driveName ==
null)
228 if (driveName.Length == 1)
230 _name = driveName +
":\\";
234 Path.CheckInvalidPathChars(driveName);
236 if (_name ==
null || _name.Length == 0 || _name.StartsWith(
"\\\\",
StringComparison.Ordinal))
241 if (_name.Length == 2 && _name[1] ==
':')
245 char c = driveName[0];
246 if ((c < 'A' || c >
'Z') && (c < 'a' || c >
'z'))
250 string path = _name +
".";
257 _name = (string)info.GetValue(
"_name", typeof(
string));
258 string path = _name +
".";
270 for (
int i = 0; i < logicalDrives.Length; i++)
272 array[i] =
new DriveInfo(logicalDrives[i]);
290 info.AddValue(
"_name", _name, typeof(
string));
Exposes instance methods for creating, moving, and enumerating through directories and subdirectories...
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
FileIOPermissionAccess
Specifies the type of file access requested.
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
override string ToString()
Returns a drive name as a string.
string VolumeLabel
Gets or sets the volume label of a drive.
static string GetPathRoot(string path)
Gets the root directory information of the specified path.
Describes the source and destination of a given serialized stream, and provides an additional caller-...
Provides information about, and means to manipulate, the current environment and platform....
static DriveInfo [] GetDrives()
Retrieves the drive names of all logical drives on a computer.
DriveType
Defines constants for drive types, including CDRom, Fixed, Network, NoRootDirectory,...
long TotalSize
Gets the total size of storage space on a drive, in bytes.
Exposes static methods for creating, moving, and enumerating through directories and subdirectories....
string Name
Gets the name of a drive, such as C:.
long TotalFreeSpace
Gets the total amount of free space available on a drive, in bytes.
Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks,...
Provides access to information on a drive.
bool IsReady
Gets a value that indicates whether a drive is ready.
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
long AvailableFreeSpace
Indicates the amount of available free space on a drive, in bytes.
The exception that is thrown when one of the arguments provided to a method is not valid.
void Demand()
Forces a T:System.Security.SecurityException at run time if all callers higher in the call stack have...
Allows an object to control its own serialization and deserialization.
static string [] GetLogicalDrives()
Retrieves the names of the logical drives on this computer in the form "<drive letter>:\".
Specifies that the class can be serialized.
string DriveFormat
Gets the name of the file system, such as NTFS or FAT32.
DirectoryInfo RootDirectory
Gets the root directory of a drive.
The exception that is thrown when the operating system denies access because of an I/O error or a spe...
Controls the ability to access files and folders. This class cannot be inherited.
static int GetLastWin32Error()
Returns the error code returned by the last unmanaged function that was called using platform invoke ...
void GetObjectData(SerializationInfo info, StreamingContext context)
Populates a T:System.Runtime.Serialization.SerializationInfo with the data needed to serialize the ta...
Performs operations on T:System.String instances that contain file or directory path information....
DriveInfo(string driveName)
Provides access to information on the specified drive.