]> git.proxmox.com Git - ceph.git/blame_incremental - ceph/src/ceph-clsinfo
import ceph quincy 17.2.1
[ceph.git] / ceph / src / ceph-clsinfo
... / ...
CommitLineData
1#!/bin/sh
2
3
4show_name=0
5show_ver=0
6show_arch=0
7show_default=1
8fname=""
9
10usage="usage: $0 [option]... <cls_filename>\n"
11usage=$usage"options:\n"
12usage=$usage"\t-n, --name\n"
13usage=$usage"\t-v, --ver\n"
14usage=$usage"\t-a, --arch\n"
15
16usage_exit() {
17 printf "$usage"
18 exit 1
19}
20
21err_exit() {
22 echo "Error: $*"
23 exit 1
24}
25
26while [ $# -ge 1 ]; do
27case $1 in
28 -n | --name )
29 show_name=1
30 show_default=0
31 ;;
32 -v | --ver )
33 show_ver=1
34 show_default=0
35 ;;
36 -a | --arch )
37 show_arch=1
38 show_default=0
39 ;;
40 * )
41 [ -n "$fname" ] && usage_exit
42 fname=$1
43 ;;
44
45esac
46shift
47done
48
49[ -z "$fname" ] && usage_exit
50
51if [ $show_default -eq 1 ]; then
52 show_name=1
53 show_ver=1
54 show_arch=1
55fi
56
57[ -e "$fname" ] || err_exit "File not found: ${fname}"
58
59if [ $show_name -eq 1 ]; then
60 raw_name=`nm $fname | grep __cls_name__`
61 name=`echo $raw_name | sed 's/.*cls_name__//g'`
62 [ -z "$name" ] && err_exit "Could not detect class name"
63 s=$name
64 c=" "
65fi
66
67if [ $show_ver -eq 1 ]; then
68 raw_ver=`nm $fname | grep __cls_ver__`
69 ver=`echo $raw_ver | sed 's/.*cls_ver__//g; s/_/./g'`
70 [ -z "$ver" ] && err_exit "Could not detect class version"
71 s=$s$c$ver
72 c=" "
73fi
74
75if [ $show_arch -eq 1 ]; then
76 raw_arch=`readelf -h $fname | grep Machine`
77 arch=""
78 [ `echo $raw_arch | grep -c 386` -gt 0 ] && arch="i386"
79 [ `echo $raw_arch | grep -c 86-64` -gt 0 ] && arch="x86-64"
80 [ -z "$arch" ] && err_exit "unknown file architecture"
81 s=$s$c$arch
82 c=" "
83fi
84
85echo $s