2017-06-08 8 views
0

st_blksize戻り値のビット数またはバイト数は?私はこれらの行を使用して、私のマシンでブロックサイズを見つけようとしている

struct stat fi; 
stat("/tmp, &fi); 
BLOCK_SIZE = fi.st_blksize; 

んBLOCK_SIZEはバイトまたは単一のブロックでビットの数の数を表しますか?

ドキュメントは言う:

"blksize_t st_blocksizeは;/*ファイルシステムのブロックサイズI/O * /" が

+1

それはだ - :Linuxのmanページのサンプルコードhereを参照してください。 –

答えて

6

あなたがthis POSIX <sys/stat.h> referenceを読めば、あなたはstat構造のst_blocksメンバーの

ユニットはPOSIX.1-2008内で定義されていないでしょう。いくつかの実装では、512バイトです。ファイルシステムごとに異なる場合があります。そこst_blocksst_blksizeの値の間に相関関係はありません、とf_bsize<sys/statvfs.h>から構造体のメンバ。だから、

標準化ユニットは、それはそれはビットでだとは考えにくいのですst_blksizeのためにそこにいなかった。取得するには現在のオペレーティングシステムと実際に使用されているファイルシステムを調べなければならない実際のユニット

Linux stat manual pageには明示的には記載されていませんが、the example単位はバイトであると言います。

0

ブロックサイズは通常、バイト単位でとstatの場合に与えられていることです。ビットでそれを与えることはあまり意味がありません。

1

Bytesです。ないビットで、バイト単位で

printf("Preferred I/O block size: %ld bytes\n", (long) sb.st_blksize);

The following program calls stat() and displays selected fields in 
    the returned stat structure. 

    #include <sys/types.h> 
    #include <sys/stat.h> 
    #include <time.h> 
    #include <stdio.h> 
    #include <stdlib.h> 
    #include <sys/sysmacros.h> 

    int 
    main(int argc, char *argv[]) 
    { 
     struct stat sb; 

     if (argc != 2) { 
      fprintf(stderr, "Usage: %s <pathname>\n", argv[0]); 
      exit(EXIT_FAILURE); 
     } 

     if (stat(argv[1], &sb) == -1) { 
      perror("stat"); 
      exit(EXIT_FAILURE); 
     } 

     printf("ID of containing device: [%lx,%lx]\n", 
      (long) major(sb.st_dev), (long) minor(sb.st_dev)); 

     printf("File type: "); 

     switch (sb.st_mode & S_IFMT) { 
     case S_IFBLK: printf("block device\n");   break; 
     case S_IFCHR: printf("character device\n");  break; 
     case S_IFDIR: printf("directory\n");    break; 
     case S_IFIFO: printf("FIFO/pipe\n");    break; 
     case S_IFLNK: printf("symlink\n");     break; 
     case S_IFREG: printf("regular file\n");   break; 
     case S_IFSOCK: printf("socket\n");     break; 
     default:  printf("unknown?\n");    break; 
     } 

     printf("I-node number:   %ld\n", (long) sb.st_ino); 

     printf("Mode:      %lo (octal)\n", 
       (unsigned long) sb.st_mode); 

     printf("Link count:    %ld\n", (long) sb.st_nlink); 
     printf("Ownership:    UID=%ld GID=%ld\n", 
       (long) sb.st_uid, (long) sb.st_gid); 

     printf("Preferred I/O block size: %ld bytes\n", 
       (long) sb.st_blksize); 
     printf("File size:    %lld bytes\n", 
       (long long) sb.st_size); 
     printf("Blocks allocated:   %lld\n", 
       (long long) sb.st_blocks); 

     printf("Last status change:  %s", ctime(&sb.st_ctime)); 
     printf("Last file access:   %s", ctime(&sb.st_atime)); 
     printf("Last file modification: %s", ctime(&sb.st_mtime)); 

     exit(EXIT_SUCCESS); 
    } 
関連する問題