즉 : 포맷되지 않은 드라이브 크기를 확인하려면 어떻게해야합니까? 포맷되지 않은 드라이브 ... 형식이 지정되지 않은 드라이브 만 고려하십시오.드라이브의 공간/크기를 프로그래밍 방식으로 어떻게 결정합니까? LInux와 Windows 모두에서
4
A
답변
3
전체 드라이브의 크기를 원한다면 Linux에서 /sys/block/sda/size
을 읽으십시오.
파티션의 크기를 확인하려면 /sys/block/sda/sda1/size
을 읽으십시오.
sda
, sda1
을 장치/파티션 이름으로 바꿉니다.
또는 원시 장치 파일을 열 수있는 경우 BLKGETSIZE
ioctl
을 사용할 수 있습니다.
2
windows ... DeviceIoControl()을 사용할 수 있습니다. 리눅스 프로그래밍
#include <windows.h>
#include <winioctl.h>
#include <stdio.h>
BOOL GetDriveGeometry(DISK_GEOMETRY *pdg)
{
HANDLE hDevice; // handle to the drive to be examined
BOOL bResult; // results flag
DWORD junk; // discard results
hDevice = CreateFile(TEXT("\\\\.\\PhysicalDrive0"), // drive
0, // no access to the drive
FILE_SHARE_READ | // share mode
FILE_SHARE_WRITE,
NULL, // default security attributes
OPEN_EXISTING, // disposition
0, // file attributes
NULL); // do not copy file attributes
if (hDevice == INVALID_HANDLE_VALUE) // cannot open the drive
{
return (FALSE);
}
bResult = DeviceIoControl(hDevice, // device to be queried
IOCTL_DISK_GET_DRIVE_GEOMETRY, // operation to perform
NULL, 0, // no input buffer
pdg, sizeof(*pdg), // output buffer
&junk, // # bytes returned
(LPOVERLAPPED) NULL); // synchronous I/O
CloseHandle(hDevice);
return (bResult);
}
int main(int argc, char *argv[])
{
DISK_GEOMETRY pdg; // disk drive geometry structure
BOOL bResult; // generic results flag
ULONGLONG DiskSize; // size of the drive, in bytes
bResult = GetDriveGeometry (&pdg);
if (bResult)
{
printf("Cylinders = %I64d\n", pdg.Cylinders);
printf("Tracks/cylinder = %ld\n", (ULONG) pdg.TracksPerCylinder);
printf("Sectors/track = %ld\n", (ULONG) pdg.SectorsPerTrack);
printf("Bytes/sector = %ld\n", (ULONG) pdg.BytesPerSector);
DiskSize = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder *
(ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;
printf("Disk size = %I64d (Bytes) = %I64d (Gb)\n", DiskSize,
DiskSize/(1024 * 1024 * 1024));
}
else
{
printf ("GetDriveGeometry failed. Error %ld.\n", GetLastError());
}
return ((int)bResult);
}
0
는 : 다양한 경고가 고정으로
이 기본적으로 http://www.linuxproblem.org/art_20.html에서 코드#include <fcntl.h>
#include <linux/fs.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <unistd.h>
int main(int argc, char **argv)
{
int fd;
unsigned long long numblocks=0;
fd = open(argv[1], O_RDONLY);
ioctl(fd, BLKGETSIZE64, &numblocks);
close(fd);
printf("Number of bytes: %llu, this makes %.3f GB\n",
numblocks,
(double)numblocks/(1024 * 1024 * 1024));
}
, BLKGETSIZE64
를 사용하도록.
관련 문제
- 1. 특정 드라이브의 유형을 어떻게 결정합니까?
- 2. 프로그래밍 방식으로 바탕 화면의 크기를 어떻게 결정합니까?
- 3. Windows DPI 설정을 프로그래밍 방식으로 결정합니까?
- 4. Windows 컴퓨터가 도메인의 구성원인지 여부를 프로그래밍 방식으로 어떻게 결정합니까?
- 5. SharePoint 목록의 크기는 어떻게 결정합니까? 프로그래밍 방식으로
- 6. 프로그래밍 방식으로 실패한 URLLoader를 어떻게 결정합니까?
- 7. Linux와 Windows 링커의 차이점
- 8. ehcache가 실행 중인지 어떻게 프로그램 방식으로 결정합니까?
- 9. GPU의 메모리 버스 너비와 클럭 속도를 프로그래밍 방식으로 어떻게 결정합니까?
- 10. 프로그래밍 방식으로 WPF 차트의 Y 축 섹션 너비를 어떻게 결정합니까?
- 11. HTML 개체가 수신 대기하는 이벤트를 프로그래밍 방식으로 어떻게 결정합니까?
- 12. Groove 작업 영역의 크기를 프로그래밍 방식으로 결정합니까?
- 13. 함수의 평가가 할당되었는지 프로그래밍 방식으로 결정합니까?
- 14. Django : 프로그래밍 방식으로 관리 페이지 경로를 결정합니까?
- 15. 프로그래밍 방식으로 Qt 스타일 시트 옵션을 결정합니까?
- 16. Windows 컴퓨터의 ID는 어떻게 결정합니까?
- 17. SuSE Linux에서 SATA 드라이브의 플러그를 프로그래밍 방식으로 감지하는 방법은 무엇입니까?
- 18. Win32에서 광학 드라이브의 기능을 프로그래밍 방식으로 결정하는 방법
- 19. 프로그래밍 방식으로 Windows 서비스 설치
- 20. 프로그래밍 방식으로 Windows 잠금 해제
- 21. 종속성 워커는 Linux와 동일합니까?
- 22. javac.exe는 프로그래밍 방식으로 어떻게 찾습니까?
- 23. .NET에서 "네트워크 위치"를 어떻게 결정합니까?
- 24. USB 포트의 속도는 어떻게 결정합니까?
- 25. Windows 스왑 공간 사용을 프로그래밍 방식으로 실시간으로 모니터링하는 방법은 무엇입니까?
- 26. Windows Mobile에서 프로그램 인터럽트를 어떻게 결정합니까?
- 27. 프로그래밍 방식으로 Windows XP 유휴 시간 재설정
- 28. 프로그래밍 방식으로 Windows 탐색기의 모양을 변경합니까?
- 29. 명령 줄에서 AIR 응용 프로그램을 시작했는지 프로그래밍 방식으로 결정합니까?
- 30. 프로그래밍 방식으로 Windows 시스템 시간을 변경하는 방법?
또는'/ proc/partitions'를 스캔하십시오. :) – ephemient