Читаем Linux программирование в примерах полностью

fsblkcnt_t f_blocks

Общее число блоков (в единицах f_bsize) в файловой системе.

fsblkcnt_t f_bfree

Общее число свободных блоков в файловой системе.

fsblkcnt_t f_bavail

Число блоков, которые действительно могут использоваться. Некоторые файловые системы резервируют часть блоков файловой системы для использования суперпользователем при заполнении файловой системы. Современные системы резервируют около 5 процентов, хотя это число может быть изменено администратором. (См. tune2fs(8) на системе GNU/Linux и tunefs(8) на системах Unix.)

fsfilcnt_t f_files

Общее число индексов («порядковых номеров файлов» на языке POSIX) в файловой системе. Это число обычно инициализируется и делается постоянным при создании файловой системы.

fsfilcnt_t f_ffree

Общее число свободных узлов.

fsfilcnt_t f_favail

Число индексов, которые действительно могут быть использованы. Некоторая часть индексов резервируются для суперпользователя, точно так же, как для блоков.

unsigned long int f_fsid

ID файловой системы. POSIX не определяет, что оно представляет, и это под Linux не используется.

unsigned long int f_flag

Флаги, дающие информацию о файловой системе. POSIX определяет два флага: ST_RDONLY для файловых систем только для чтения (таких, как CD-ROM) и ST_NOSUID, который запрещает использование битов setuid и setgid в исполняемых файлах. Системы GNU/Linux предусматривают дополнительные флаги: они перечислены в табл. 8.2.

Таблица 8.2. Значения GLIBC для f_flag

ФлагPOSIXЗначение
ST_MANDLOCKОсуществляет принудительное блокирование (см. раздел 14.2).
ST_NOATIMEНе обновлять при каждом доступе время доступа
ST_NODEVЗапрещает доступ через файлы устройств
ST_NODIRATIMEНе обновлять поле времени доступе каталогов
ST_NOEXECЗапрещает исполнение двоичных файлов
ST_NOSUIDФайловая система запрещает использование битов setuid и setgid.
ST_RDONLYФайловая система только для чтения.
ST_SYNCHRONOUSЛюбая запись осуществляется синхронно (см. раздел 4.6.3).

unsigned long int f_namemax

Максимальная длина имени файла. Это относится к каждому отдельному компоненту в имени пути; другими словами, максимальная длина для элемента каталога

Типы fsblkcnt_t и fsfilcnt_t определены в . Они обычно являются unsigned long, но на современных системах они могут быть даже 64-разрядными, поскольку диски стали очень большими. Следующая программа, ch08-statvfs.c, показывает, как использовать statvfs():

1  /* ch08-statvfs.с --- демонстрация statvfs */

2

3  /* ЗАМЕЧАНИЕ: специфично для GNU/Linux! */

4

5  #include

6  #include

7  #include /* для getmntent(), et al. */

8  #include /* для getopt() */

9  #include

10 #include

11

12 void process(const char *filename);

13 void do_statvfs(const struct mntent *fs);

14

15 int errors = 0;

16 char *myname;

17

18 /* main --- обработка опций */

19

20 int main(int argc, char **argv)

21 {

22  int c;

23  char *file = "/etc/mtab"; /* файл для чтения по умолчанию */

24

25  myname = argv[0];

26  while ((c = getopt(argc, argv, "f:")) != -1) {

27   switch (c) {

28   case 'f':

29    file = optarg;

30    break;

31   default:

32    fprintf(stderr, "usage: %s [-f fstab-file]\n", argv[0]);

33    exit(1);

34   }

35  }

36

37  process(file);

38  return (errors != 0);

39 }

40

41 /* process --- чтение структур struct mntent из файла */

42

43 void process(const char *filename)

44 {

45  FILE* fp;

46  struct mntent *fs;

47

Перейти на страницу:

Похожие книги

C++ Primer Plus
C++ Primer Plus

C++ Primer Plus is a carefully crafted, complete tutorial on one of the most significant and widely used programming languages today. An accessible and easy-to-use self-study guide, this book is appropriate for both serious students of programming as well as developers already proficient in other languages.The sixth edition of C++ Primer Plus has been updated and expanded to cover the latest developments in C++, including a detailed look at the new C++11 standard.Author and educator Stephen Prata has created an introduction to C++ that is instructive, clear, and insightful. Fundamental programming concepts are explained along with details of the C++ language. Many short, practical examples illustrate just one or two concepts at a time, encouraging readers to master new topics by immediately putting them to use.Review questions and programming exercises at the end of each chapter help readers zero in on the most critical information and digest the most difficult concepts.In C++ Primer Plus, you'll find depth, breadth, and a variety of teaching techniques and tools to enhance your learning:• A new detailed chapter on the changes and additional capabilities introduced in the C++11 standard• Complete, integrated discussion of both basic C language and additional C++ features• Clear guidance about when and why to use a feature• Hands-on learning with concise and simple examples that develop your understanding a concept or two at a time• Hundreds of practical sample programs• Review questions and programming exercises at the end of each chapter to test your understanding• Coverage of generic C++ gives you the greatest possible flexibility• Teaches the ISO standard, including discussions of templates, the Standard Template Library, the string class, exceptions, RTTI, and namespaces

Стивен Прата

Программирование, программы, базы данных