Skip to content

Commit ffd608f

Browse files
committed
Initial commit
0 parents  commit ffd608f

23 files changed

+2722
-0
lines changed

Makefile.am

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SUBDIRS = src
2+

bootstrap

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
autoreconf -vif

configure.ac

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
AC_INIT([checkdisks], [0.0.1], [@t-nelson on GitHub])
2+
AC_CONFIG_HEADERS([config.h])
3+
AM_INIT_AUTOMAKE([foreign])
4+
5+
# Work around stupid autoconf default cflags. pt 1
6+
SAVE_CFLAGS="x${CFLAGS}"
7+
8+
AC_PROG_CC
9+
AC_PROG_RANLIB
10+
11+
AM_PROG_CC_C_O
12+
13+
# Work around stupid autoconf default cflags. pt 2
14+
if test "$SAVE_CFLAGS" = "x"; then
15+
CFLAGS=""
16+
fi
17+
18+
AC_ARG_ENABLE([debug],
19+
[AC_HELP_STRING([--disable-debug],
20+
[Disable debugging facilities])],
21+
[use_debug=$enableval],
22+
[use_debug=yes])
23+
24+
if test x$use_debug = xyes; then
25+
DBG_CFLAGS="-g -Wall -Werror"
26+
else
27+
RLS_CFLAGS=-O2
28+
RLS_CPPFLAGS=-DNDEBUG
29+
fi
30+
31+
AC_CONFIG_FILES([Makefile]
32+
[src/Makefile]
33+
)
34+
35+
AM_CPPFLAGS=-D_GNU_SOURCE
36+
37+
AC_SUBST(DBG_CFLAGS)
38+
AC_SUBST(RLS_CFLAGS)
39+
AC_SUBST(RLS_CPPFLAGS)
40+
AC_SUBST(AM_CPPFLAGS)
41+
42+
AC_CHECK_LIB([pci], [main],, AC_MSG_ERROR([Missing a required library!]))
43+
AC_CHECK_LIB([m], [main],, AC_MSG_ERROR([Missing a required library!]))
44+
45+
PKG_CHECK_MODULES([DBUS], [dbus-1])
46+
47+
AC_OUTPUT

src/Makefile.am

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
SUBDIRS = .
2+
3+
bin_PROGRAMS = checkdisks
4+
5+
checkdisks_SHORTNAME = .cd
6+
7+
MOSTLYCLEANFILES = .cd-*.o
8+
9+
checkdisks_CPPFLAGS = $(AM_CPPFLAGS) $(RLS_CPPFLAGS)
10+
checkdisks_CFLAGS = $(RLS_CFLAGS) $(DBG_CFLAGS) $(DBUS_CFLAGS)
11+
checkdisks_LDADD = $(DBUS_LIBS)
12+
13+
checkdisks_SOURCES= \
14+
blk_dev_info.c \
15+
info_manager.c \
16+
main.c \
17+
output_fmt.c \
18+
pci_slot.c \
19+
scsi_host.c \
20+
scsi_target.c \
21+
sysfs_scan.c \
22+
udisks2.c \
23+
utils.c
24+

src/blk_dev_info.c

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
#include "blk_dev_info.h"
3+
4+
#include <stdio.h>
5+
#include <string.h>
6+
7+
struct blk_dev_info*
8+
blk_dev_info_create(
9+
)
10+
{
11+
struct blk_dev_info* bdi;
12+
13+
if (NULL != (bdi = calloc(1, sizeof(struct blk_dev_info))))
14+
blk_dev_info_init(bdi);
15+
16+
return bdi;
17+
}
18+
19+
void
20+
blk_dev_info_destroy(
21+
struct blk_dev_info* bdi
22+
)
23+
{
24+
blk_dev_info_cleanup(bdi);
25+
free(bdi);
26+
}
27+
28+
void
29+
blk_dev_info_init(
30+
struct blk_dev_info* bdi
31+
)
32+
{
33+
static const struct blk_dev_info template = BLK_DEV_INFO_STATIC_INIT;
34+
35+
memcpy(bdi, &template, sizeof(struct blk_dev_info));
36+
}
37+
38+
void
39+
blk_dev_info_cleanup(
40+
struct blk_dev_info* bdi
41+
)
42+
{
43+
if (bdi)
44+
{
45+
free(bdi->model);
46+
free(bdi->serial);
47+
}
48+
}
49+
50+
void
51+
blk_dev_info_dump(
52+
const struct blk_dev_info* bdi
53+
, int indent
54+
)
55+
{
56+
printf( "%*.*sModel: %s\n", indent, indent, "", bdi->model);
57+
printf( "%*.*sSerial: %s\n", indent, indent, "", bdi->serial);
58+
printf( "%*.*sSize: %lu\n", indent, indent, "", bdi->size_byt);
59+
printf( "%*.*sPwr. on Sec: %ld\n", indent, indent, "", bdi->smt_pwr_on_sec);
60+
printf( "%*.*sTemp: %f\n", indent, indent, "", bdi->smt_temp_kel);
61+
printf( "%*.*sBad Sect.: %ld\n", indent, indent, "", bdi->smt_bad_sect);
62+
}
63+

src/blk_dev_info.h

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
#ifndef BLK_DEV_INFO_H__
3+
#define BKL_DEV_INFO_H__
4+
5+
#include <stdlib.h>
6+
#include <stdint.h>
7+
8+
#define BLK_DEV_INFO_UNSET_STRING (NULL)
9+
#define BLK_DEV_INFO_UNSET_U64 (UINT64_MAX)
10+
#define BLK_DEV_INFO_UNSET_I64 (-1)
11+
#define BLK_DEV_INFO_UNSET_DBL (-1.0)
12+
13+
struct blk_dev_info
14+
{
15+
char* model;
16+
char* serial;
17+
uint64_t size_byt;
18+
int64_t smt_pwr_on_sec;
19+
double smt_temp_kel;
20+
int64_t smt_bad_sect;
21+
};
22+
23+
#define BLK_DEV_INFO_STATIC_INIT { \
24+
BLK_DEV_INFO_UNSET_STRING \
25+
, BLK_DEV_INFO_UNSET_STRING \
26+
, BLK_DEV_INFO_UNSET_U64 \
27+
, BLK_DEV_INFO_UNSET_I64 \
28+
, BLK_DEV_INFO_UNSET_DBL \
29+
, BLK_DEV_INFO_UNSET_I64 \
30+
}
31+
struct blk_dev_info*
32+
blk_dev_info_create(
33+
);
34+
void
35+
blk_dev_info_destroy(
36+
struct blk_dev_info* bdi
37+
);
38+
39+
/* blk_dev_info_init is called automatically by blk_dev_info_create */
40+
void
41+
blk_dev_info_init(
42+
struct blk_dev_info* bdi
43+
);
44+
/* blk_dev_info_cleanup is called automatically by blk_dev_info_destroy */
45+
void
46+
blk_dev_info_cleanup(
47+
struct blk_dev_info* bdi
48+
);
49+
50+
void
51+
blk_dev_info_dump(
52+
const struct blk_dev_info* bdi
53+
, int indent
54+
);
55+
56+
#endif /* BLK_DEV_INFO_H__ */
57+

0 commit comments

Comments
 (0)