Advertisement
Guest User

sector

a guest
Dec 6th, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.44 KB | None | 0 0
  1. #include <windows.h>
  2.  
  3. #include <stdio.h>
  4.  
  5. int main(void){
  6.     char const * fname = "test.txt";
  7.     int err = 0;
  8.     HANDLE file = CreateFile(fname,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
  9.     if(file==INVALID_HANDLE_VALUE){
  10.         fprintf(stderr,"Open of \"%s\" failed.\n",fname);
  11.         return 1;
  12.     }
  13.     FILE_STORAGE_INFO fsi;
  14.     if(GetFileInformationByHandleEx(
  15.         file,
  16.         FileStorageInfo,
  17.         &fsi,
  18.         sizeof(fsi) == 0))
  19.     {
  20.         fputs("GetFileInformationByHandleEx failed.\n",stderr);
  21.         err = 1;
  22.         goto quick_err;
  23.     }
  24.    
  25.     printf("fsi.LogicalBytesPerSector: %lu\n"
  26.            "fsi.PhysicalBytesPerSectorForAtomicity: %lu\n"
  27.            "fsi.PhysicalBytesPerSectorForPerformance: %lu\n"
  28.            "fsi.FileSystemEffectivePhysicalBytesPerSectorForAtomicity: %lu\n"
  29.            "fsi.Flags: %lu\n"
  30.            "fsi.ByteOffsetForSectorAlignment: %lu\n"
  31.            "fsi.ByteOffsetForPartitionAlignment: %lu\n",
  32.         fsi.LogicalBytesPerSector,
  33.         fsi.PhysicalBytesPerSectorForAtomicity,
  34.         fsi.PhysicalBytesPerSectorForPerformance,
  35.         fsi.FileSystemEffectivePhysicalBytesPerSectorForAtomicity,
  36.         fsi.Flags,
  37.         fsi.ByteOffsetForSectorAlignment,
  38.         fsi.ByteOffsetForPartitionAlignment);
  39.     long spc;
  40.     long bps;//
  41.     long nfc;
  42.     long tnc;
  43.     if(GetDiskFreeSpaceW(NULL,&spc,&bps,&nfc,&tnc)==0){
  44.         fputs("GetFreeSpaceW failed.\n",stderr);
  45.         err = 1;
  46.         goto quick_err;
  47.     }
  48.     printf("spc: %ld\nbps: %ld\nnfc: %ld\ntnc: %ld\n",spc,bps,nfc,tnc);
  49. quick_err:
  50.     CloseHandle(file);
  51.     return err;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement