Release new version 0.17.1
[grml-hwinfo.git] / sysdump
1 #!/usr/bin/perl
2 #
3 #    sysdump - dump /sys to a textformat
4 #
5 #    Copyright 2005 David Schmitt <david@schmitt.edv-bus.at>
6 #
7 #    This program is free software; you can redistribute it and/or modify
8 #    it under the terms of the GNU General Public License as published by
9 #    the Free Software Foundation; either version 2 of the License, or
10 #    (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU General Public License for more details.
16 #
17 #    You should have received a copy of the GNU General Public License
18 #    along with this program; if not, write to the Free Software
19 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 #
21 #       Version 0.1: Initial prototype
22 #
23
24 use warnings;
25 use strict;
26
27 $| = 1;
28
29 #my $basedir = `systool -m`;
30 #chomp $basedir;
31 my $basedir = '/sys';
32
33 sub dump_dir($$)
34 {
35         my $level = shift;
36         my $dir = shift;
37
38         opendir(DIR, $dir) || die "can't opendir $dir: $!";
39         my @entries = grep { !/^\.\.?/ } readdir(DIR);
40         closedir(DIR);
41
42         #print " "x$level;
43         print $dir, ":\n";
44
45         foreach my $entry (sort @entries)
46         {
47                 dump_entry($level + 1, "$dir/$entry");
48         }
49 }
50
51 sub dump_link($$)
52 {
53         my $level = shift;
54         my $link = shift;
55
56         #print " "x$level;
57         print $link, " -> ", readlink($link), "\n";
58 }
59
60 sub dump_value($$)
61 {
62         my $level = shift;
63         my $file = shift;
64
65         # ignore list: files that we can't read or are known to cause problems
66         SWITCH: for ($file) {
67                 (
68                         /.*\/bind$/ ||
69                         /.*\/clear$/ ||
70                         /.*\/delete$/ ||
71                         /.*\/delete_device$/ ||
72                         /.*\/drivers_probe$/ ||
73                         /.*\/host_reset$/ ||
74                         /.*\/new_device$/ ||
75                         /.*\/new_id$/ ||
76                         /.*\/reconfig$/ ||
77                         /.*\/remove$/ ||
78                         /.*\/remove_id$/ ||
79                         /.*\/rescan$/ ||
80                         /.*\/reset$/ ||
81                         /.*\/scan$/ ||
82                         /\/sys\/class\/gpio\/export$/ ||
83                         /\/sys\/class\/gpio\/unexport$/ ||
84                         /\/sys\/devices\/platform\/i8042\/serio[0-9]+\/drvctl$/ ||
85                         /\/sys\/devices\/system\/clockevents\/clockevent[0-9]+\/unbind_device$/ ||
86                         /\/sys\/devices\/system\/clocksource\/clocksource[0-9]+\/unbind_clocksource$/ ||
87                         /\/sys\/devices\/system\/memory\/hard_offline_page$/ ||
88                         /\/sys\/devices\/system\/memory\/soft_offline_page$/ ||
89                         /\/sys\/devices\/system\/node\/node[0-9]\/compact$/ ||
90                         /\/sys\/devices\/virtual\/graphics\/fbcon\/rotate_all$/ ||
91                         /\/sys\/firmware\/efi\/vars\/del_var$/ ||
92                         /\/sys\/firmware\/efi\/vars\/new_var$/ ||
93                         /\/sys\/kernel\/debug\/.*/ ||
94                         /\/sys\/kernel\/security\/apparmor\/revision$/ ||
95                         /\/sys\/kernel\/tracing\/per_cpu\/cpu[0-9]+\/snapshot_raw$/ ||
96                         /\/sys\/kernel\/tracing\/per_cpu\/cpu[0-9]+\/trace_pipe.*/ ||
97                         /\/sys\/kernel\/tracing\/trace_pipe/ ||
98                         /\/sys\/module\/md_mod\/parameters\/new_array$/ ||
99                         /.*\/unbind$/
100                 ) && do {
101                         print "ignoring file $file\n";
102                         return 0;
103                 }
104         }
105
106         if (!open (FILE, "<$file")) {
107                 print STDERR "can't open $file: '$!'\n";
108                 return 0;
109         }
110
111         my $value;
112         {       local $/;
113                 $value = <FILE>;
114                 $value = defined($value)?$value:"undef";
115         }
116         chomp $value;
117         close FILE;
118
119         #print " "x$level;
120         print $file, " = '", $value, "'\n";
121 }
122
123 sub dump_entry($$)
124 {
125         my $level = shift;
126         my $file = shift;
127
128         return dump_link($level, $file) if -l $file;
129         return dump_dir($level, $file) if -d $file;
130         return dump_value($level, $file) if -r $file;
131 }
132
133 dump_dir(0, $basedir);
134