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

23  #define MINIX2_SUPER_MAGIC2  0x2478 /* minix V2, имена 30 симв. */

24  #define MSDOS_SUPER_MAGIC    0x4d44

25  #define NCP_SUPER_MAGIC      0x564c

26  #define NFS_SUPER_MAGIC      0x6969

27  #define PROC_SUPER_MAGIC     0x9fa0

28  #define SMB_SUPER_MAGIC      0x517B

29  #define XENIX_SUPER_MAGIC    0x012FF7B4

30  #define SYSV4_SUPER_MAGIC    0x012FF7B5

31  #define SYSV2_SUPER_MAGIC    0x012FF7B6

32  #define COH_SUPER_MAGIC      0x012FF7B7

33  #define UFS_MAGIC            0x00011954

34  #define XFS_SUPER_MAGIC      0x58465342

35  #define _XIAFS_SUPER_MAGIC   0x012FD16D

36

37  void process(const char *filename);

38  void do_statfs(const struct mntent *fs);

39

40  int errors = 0;

41  char *myname;

42

    /* ...main() без изменений, process() почти идентична... */

85

86  /* type2str --- преобразование типа fs в строку из statfs(2) */

87

88  const char *type2str(long type)

89  {

90   static struct fsname {

91    long type;

92    const char *name;

93   } table[] = {

94    { AFFS_SUPER_MAGIC, "AFFS" },

95    { COH_SUPER_MAGIC, "COH" },

96    { EXT2_OLD_SUPER_MAGIC, "OLD EXT2" },

97    { EXT2_SUPER_MAGIС, "EXT2" },

98    { HPFS_SUPER_MAGIC, "HPFS" },

99    { ISOFS_SUPER_MAGIC, "ISOFS" },

100   { MINIX2_SUPER_MAGIC, "MINIX V2" },

101   { MINIX2_SUPER_MAGIC2, "MINIX V2 30 char" },

102   { MINIX_SUPER_MAGIC, "MINIX" },

103   { MINIX_SUPER_MAGIC2, "MINIX 30 char" },

104   { MSDOS_SUPER_MAGIC, "MSDOS" },

105   { NCP_SUPER_MAGIС, "NCP" },

106   { NFS_SUPER_MAGIC, "NFS" },

107   { PROC_SUPER_MAGIC, "PROC" },

108   { SMB_SUPER_MAGIC, "SMB" },

109   { SYSV2_SUPER_MAGIC, "SYSV2" },

110   { SYSV4_SUPER_MAGIC, "SYSV4" },

111   { UFS_MAGIC, "UFS" },

112   { XENIX_SUPER_MAGIC, "XENIX" },

113   { _XIAFS_SUPER_MAGIC, "XIAFS" },

114   { 0, NULL },

115  };

116  static char unknown[100];

117  int i;

118

119  for (i = 0; table[i].type != 0; i++)

120   if (table[i].type == type)

121    return table[i].name;

122

123  sprintf(unknown, "unknown type: %#x", type);

124  return unknown;

125 }

126

127 /* do_statfs --- Использовать statfs и вывести сведения */

128

129 void do_statfs(const struct mntent *fs)

130 {

131  struct statfs vfs;

132

133  if (fs->mnt_fsname[0] != '/') /* пропустить фиктивные файловые системы */

134   return;

135

136  if (statfs(fs->mnt_dir, &vfs) != 0) {

137   fprintf(stderr, "%s: %s: statfs failed: %s\n",

138    myname, fs->mnt_dir, strerror(errno));

139   errors++;

140   return;

141  }

142

143  printf("%s, mounted on %s:\n", fs->mnt_dir, fs->mnt_fsname);

144

145  printf("\tf_type: %s\n", type2str(vfs.f_type));

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

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

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

Стивен Прата

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