source: rtems/cpukit/libblock/src/blkdev-blkstats.c @ 24d0ee57

5
Last change on this file since 24d0ee57 was 24d0ee57, checked in by Chris Johns <chrisj@…>, on 05/20/16 at 08:39:50

cpukit, testsuite: Add rtems_printf and rtems_printer support.

This change adds rtems_printf and related functions and wraps the
RTEMS print plugin support into a user API. All references to the
plugin are removed and replaced with the rtems_printer interface.

Printk and related functions are made to return a valid number of
characters formatted and output.

The function attribute to check printf functions has been added
to rtems_printf and printk. No changes to remove warrnings are part
of this patch set.

The testsuite has been moved over to the rtems_printer. The testsuite
has a mix of rtems_printer access and direct print control via the
tmacros.h header file. The support for begink/endk has been removed
as it served no purpose and only confused the code base. The testsuite
has not been refactored to use rtems_printf. This is future work.

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/**
2 * @file
3 *
4 * @brief Block Device Statistics Command
5 * @ingroup rtems_blkdev Block Device Management
6 */
7
8/*
9 * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
10 *
11 *  embedded brains GmbH
12 *  Obere Lagerstr. 30
13 *  82178 Puchheim
14 *  Germany
15 *  <rtems@embedded-brains.de>
16 *
17 * The license and distribution terms for this file may be
18 * found in the file LICENSE in this distribution or at
19 * http://www.rtems.org/license/LICENSE.
20 */
21
22#if HAVE_CONFIG_H
23  #include "config.h"
24#endif
25
26#include <rtems/blkdev.h>
27
28#include <sys/stat.h>
29#include <fcntl.h>
30#include <unistd.h>
31#include <errno.h>
32#include <string.h>
33
34void rtems_blkstats(const rtems_printer* printer, const char *device, bool reset)
35{
36  int fd = open(device, O_RDONLY);
37
38  if (fd >= 0) {
39    struct stat st;
40    int rv;
41
42    rv = fstat(fd, &st);
43    if (rv == 0) {
44      if (S_ISBLK(st.st_mode)) {
45        if (reset) {
46          rv = rtems_disk_fd_reset_device_stats(fd);
47          if (rv != 0) {
48            rtems_printf(printer, "error: reset stats: %s\n", strerror(errno));
49          }
50        } else {
51          uint32_t media_block_size = 0;
52          uint32_t media_block_count = 0;
53          uint32_t block_size = 0;
54          rtems_blkdev_stats stats;
55
56          rtems_disk_fd_get_media_block_size(fd, &media_block_size);
57          rtems_disk_fd_get_block_count(fd, &media_block_count);
58          rtems_disk_fd_get_block_size(fd, &block_size);
59
60          rv = rtems_disk_fd_get_device_stats(fd, &stats);
61          if (rv == 0) {
62            rtems_blkdev_print_stats(
63              &stats,
64              media_block_size,
65              media_block_count,
66              block_size,
67              printer
68            );
69          } else {
70            rtems_printf(printer, "error: get stats: %s\n", strerror(errno));
71          }
72        }
73      } else {
74        rtems_printf(printer, "error: not a block device\n");
75      }
76    } else {
77      rtems_printf(printer, "error: get file stats: %s\n", strerror(errno));
78    }
79
80    rv = close(fd);
81    if (rv != 0) {
82      rtems_printf(printer, "error: close device: %s\n", strerror(errno));
83    }
84  } else {
85    rtems_printf(printer, "error: open device: %s\n", strerror(errno));
86  }
87}
Note: See TracBrowser for help on using the repository browser.