3
# dump_sys_state: dump some /sys and /proc files to a directory.
4
# $Id: dump_sys_state 8211 2010-03-02 14:55:22Z tzafrir $
6
# Written by Tzafrir Cohen <tzafrir.cohen@xorcom.com>
7
# Copyright (C) 2009, Xorcom
11
# This program is free software; you can redistribute it and/or modify
12
# it under the terms of the GNU General Public License as published by
13
# the Free Software Foundation; either version 2 of the License, or
14
# (at your option) any later version.
16
# This program is distributed in the hope that it will be useful,
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
# GNU General Public License for more details.
21
# You should have received a copy of the GNU General Public License
22
# along with this program; if not, write to the Free Software
23
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26
# The DAHDI-perl modules will use such a dump instead of the files from
27
# the real system if DAHDI_VIRT_TOP is set to the root.
29
# ./build_tools/dump_sys_state my_sys_state
32
# DAHDI_VIRT_TOP="$PWD/my_sys_state" dahdi_genconf
34
name=dahdi_sys_state_dump
37
echo "$0: dump system data for Dahdi-Perl"
38
echo "Usage: $0 [<name>]]"
40
echo "<name>: name of directory/tarball to create. Default: $name"
48
gzip -9 >$name.cpio.gz
59
# Give usage message on expected texts
61
help | -* ) usage; exit 1;;
64
if [ "$1" != '' ]; then
68
# funky permissions on procfs. Sadly rm -f does not kill them.
69
if [ -d "$name" ]; then
75
# delete a (potentially empty) list of files
77
xargs rm -f rm_files_non_existing_file
80
if [ -r /proc/bus/usb/devices ]; then
81
mkdir -p "$name/proc/bus/usb"
82
cp -a /proc/bus/usb/devices "$name/proc/bus/usb/"
85
if [ -d /proc/dahdi ]; then
86
mkdir -p "$name/proc/dahdi"
87
if find /proc/dahdi -type f >/dev/null; then
88
cp -a /proc/dahdi/* "$name/proc/dahdi/"
92
if [ -d /proc/xpp ]; then
93
mkdir -p "$name/proc/xpp"
94
if find /proc/xpp -type f >/dev/null; then
95
cp -a /proc/xpp/* "$name/proc/xpp/"
96
find "$name/proc/xpp" -type f -name command | rm_files
100
# FIXME: the following grab tons of files from sysfs. Any way to do with
102
pci_dev_pat='/sys/devices/pci*'
103
mkdir -p "$name/sys/devices"
104
cp -a $pci_dev_pat "$name/sys/devices/" 2>/dev/null
106
for bus in astribanks xpds pci pci_express usb; do
107
if [ -d /sys/bus/$bus ]; then
108
mkdir -p "$name/sys/bus/"
109
cp -a /sys/bus/$bus "$name/sys/bus/" 2>/dev/null
113
# Remove PCI devices of irelevan classes:
115
grep . "$name"/$pci_dev_pat/0*/class "$name"/$pci_dev_pat/0*/0*/class \
116
| perl -n -e '# Perl provides commented regexes:
117
next unless m{/class:( # The following is a list of device classes
118
# that can be safely removed:
119
0x060000 | # Host bridge
120
0x030000 | # VGA compatible controller
121
0x038000 | # Display controller
122
0x040300 | # Audio device
123
0x060401 | # PCI bridge
124
0x060100 | # ISA bridge
125
0x01018a | # IDE interface
126
0x01018f | # IDE interface
128
0x060700 | # CardBus bridge
129
0x0c0010 | # FireWire (IEEE 1394)
130
# The following are not to be removed:
131
#0x0c0300 | # USB Controller (UHCI?)
132
#0x060400 | # PCI bridge
133
#0x0c0320 | # USB Controller (EHCI?)
134
#0x020000 | # Ethernet controller
135
#0x0c0010 | # Network controller: (Wifi?)
137
# Leave out just the name of the node:
144
# FIXME: deleting those seems to remove common 'vendor' directories
145
# and mess things up. Skip it for now.
146
#rm -rf `irrelevant_devs`