{"id":286,"date":"2013-06-07T09:22:52","date_gmt":"2013-06-07T09:22:52","guid":{"rendered":"http:\/\/www.selinuxplus.com\/?p=286"},"modified":"2013-06-07T09:23:31","modified_gmt":"2013-06-07T09:23:31","slug":"linux-kernel%e5%ae%9a%e5%88%b6%ef%bc%88%e4%ba%94%ef%bc%89","status":"publish","type":"post","link":"http:\/\/www.selinuxplus.com\/?p=286","title":{"rendered":"linux kernel\u5b9a\u5236\uff08\u4e94\uff09"},"content":{"rendered":"<p>5 \u83b7\u5f97\u9a71\u52a8\u6a21\u5757\u7684\u811a\u672c<br \/>\n\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u51fa\u5904<a href=\"http:\/\/www.selinuxplus.com\/?p=286\" title=\"selinuxplus.com\" target=\"_blank\">[By SELinux+]<\/a><\/p>\n<pre class=\"lang:default decode:true \" >#!\/bin\/sh\r\n#auth qfong.com\r\n#site: www.selinuxplus.com www.qfong.com\r\n\r\nexport black='\\033[0m'\r\nexport boldblack='\\033[1;0m'\r\nexport red='\\033[31m'\r\nexport boldred='\\033[1;31m'\r\nexport green='\\033[32m'\r\nexport boldgreen='\\033[1;32m'\r\nexport yellow='\\033[33m'\r\nexport boldyellow='\\033[1;33m'\r\nexport blue='\\033[34m'\r\nexport boldblue='\\033[1;34m'\r\nexport magenta='\\033[35m'\r\nexport boldmagenta='\\033[1;35m'\r\nexport cyan='\\033[36m'\r\nexport boldcyan='\\033[1;36m'\r\nexport white='\\033[37m'\r\nexport boldwhite='\\033[1;37m'\r\n\r\n\r\ncecho ()\r\n\r\n\r\n{\r\nlocal default_msg=\"No message passed.\"\r\n\r\nmessage=${1:-$default_msg}\t# Defaults to default message.\r\n\r\n\r\ncolor=${2:-black}\t\t# Defaults to black, if not specified.\r\n\r\ncase $color in\r\n\tblack)\r\n\t\t printf \"$black\" ;;\r\n\tboldblack)\r\n\t\t printf \"$boldblack\" ;;\r\n\tred)\r\n\t\t printf \"$red\" ;;\r\n\tboldred)\r\n\t\t printf \"$boldred\" ;;\r\n\tyellow)\r\n\t\t printf \"$yellow\" ;;\r\n\tboldyellow)\r\n\t\t printf \"$boldyellow\" ;;\r\n\tblue)\r\n\t\t printf \"$blue\" ;;\r\n\tboldblue)\r\n\t\t printf \"$boldblue\" ;;\r\n\tmagenta)\r\n\t\t printf \"$magenta\" ;;\r\n\tboldmagenta)\r\n\t\t printf \"$boldmagenta\" ;;\r\n\tcyan)\r\n\t\t printf \"$cyan\" ;;\r\n\tboldcyan)\r\n\t\t printf \"$boldcyan\" ;;\r\n\twhite)\r\n\t\t printf \"$white\" ;;\r\n\tboldwhite)\r\n\t\t printf \"$boldwhite\" ;;\r\nesac\r\n  printf \"%s\"  \"$message\"\r\n  tput sgr0\t\t\t# Reset to normal.\r\n  printf \"$black\"\r\n\r\nreturn\r\n}\r\ncechon ()\r\n\r\n\r\n{\r\nlocal default_msg=\"No message passed.\"\r\n\r\nmessage=${1:-$default_msg}\t# Defaults to default message.\r\n\r\n\r\ncolor=${2:-black}\t\t# Defaults to black, if not specified.\r\n\r\ncase $color in\r\n\tblack)\r\n\t\t printf \"$black\" ;;\r\n\tboldblack)\r\n\t\t printf \"$boldblack\" ;;\r\n\tred)\r\n\t\t printf \"$red\" ;;\r\n\tboldred)\r\n\t\t printf \"$boldred\" ;;\r\n\tyellow)\r\n\t\t printf \"$yellow\" ;;\r\n\tboldyellow)\r\n\t\t printf \"$boldyellow\" ;;\r\n\tblue)\r\n\t\t printf \"$blue\" ;;\r\n\tboldblue)\r\n\t\t printf \"$boldblue\" ;;\r\n\tmagenta)\r\n\t\t printf \"$magenta\" ;;\r\n\tboldmagenta)\r\n\t\t printf \"$boldmagenta\" ;;\r\n\tcyan)\r\n\t\t printf \"$cyan\" ;;\r\n\tboldcyan)\r\n\t\t printf \"$boldcyan\" ;;\r\n\twhite)\r\n\t\t printf \"$white\" ;;\r\n\tboldwhite)\r\n\t\t printf \"$boldwhite\" ;;\r\nesac\r\n  printf \"%s\\n\"  \"$message\"\r\n  tput sgr0\t\t\t# Reset to normal.\r\n  printf \"$black\"\r\n\r\nreturn\r\n}\r\n\r\n\r\ndriver()\r\n{\r\nif [ $# != \"2\" ]; then\r\n        echo \r\n        cechon \"Script to display the drivers and modules for a specified sysfs class device\" \"boldblue\"\r\n        cechon \"Usage: $0 &lt;CLASS_NAME&gt;\" \"boldred\"\r\n        echo \"example usage:\"\r\n        cecho  \"     $0 d \" \"blue\"\r\n\tcechon \"sha\" \"boldmagenta\"\r\n        echo \"Will show all drivers and modules for the sda block device.\"\r\n        cechon \"==============================================================\" \"white\"\r\n        exit 1\r\nfi \r\n\r\n\r\n##\r\n## for \" find \/sys\/class -name sda \"\r\n##\r\nDEV=$2\r\nif test -e \"$2\";then\r\n\tDEVPATH=$2\r\nelse\r\n\t#find sysfs device directory for device\r\n\tDEVPATH=$(find \/sys\/class -name \"$2\" |head -1 )\r\n\ttest -z \"$DEVPATH\" &amp;&amp; DEVPATH=$(find \/sys\/block -name \"$2\" |head -1 )\r\n\ttest -z \"$DEVPATH\" &amp;&amp; DEVPATH=$(find \/sys\/bus -name \"$2\" |head -1 )\r\n\tif ! test -e \"$DEVPATH\";then\r\n\t\tcechon \"No Device Found !!!\" \"red\"\r\n\t\texit 1\r\n\tfi\r\nfi\r\ncechon \"==============================================================\" \"white\"\r\n        cechon \"\tGet Driver Tools ... \" \"boldred\"\r\ncechon \"==============================================================\" \"white\"\r\nprintf \"Looking at sysfs devices:\"\r\ncechon \"$DEVPATH\" \"boldmagenta\"\r\nif test -L \"$DEVPATH\" ;then\r\n\t# resolve class device link to device directory\r\n\tEDVPATH=$(readlink -f $DEVPATH)\r\n\tprintf \"Resolve link to:\"\r\n\tcechon \"$DEVPATH\" \"boldmagenta\"\r\nfi\r\n\r\nif test -d \"$DEVPATH\";then\r\n\t#resolve old-style \"device\" loink to the parent device\r\n\tPARENT=$DEVPATH\r\n\twhile test \"$PARENT\" != \"\/\";do\r\n\t\tif test -L \"$PARENT\/device\"; then\r\n\t\t\tDEVPATH=$(readlink -f $PARENT\/device)\r\n\t\t\tprintf \"follow 'device' link to parent ::\"\r\n\t\t\tcechon \"$DEVPATH\" \"boldmagenta\"\t\r\n\t\t\tbreak\t\r\n\t\tfi\r\n\t\tPARENT=$(dirname $PARENT)\r\n\tdone\r\nfi\r\n\tcechon \"##############################################################\" \"white\"\r\nwhile test \"$DEVPATH\" != \"\/\" ;do\r\n\tDRIVERPATH=\r\n\tDRIVER=\r\n\tMOUDLEPATH=\r\n\tMODULE=\r\n\tif test -e $DEVPATH\/driver ;then\r\n\r\n\t\tDRIVERPATH=$(readlink -f $DEVPATH\/driver)\r\n\t\tDRIVER=$(basename $DRIVERPATH)\t\r\n\t\tprintf \"Found driver:\"\r\n\t\tcechon \"$DRIVER\" \"boldmagenta\"\t\r\n\t\tif test -e $DRIVERPATH\/module; then\r\n\t\t\tMODULEPATH=$(readlink -f $DRIVERPATH\/module)\r\n\t\t\tMODULE=$(basename $MODULEPATH)\r\n\t\t\tprintf \"Found module:\"\r\n\t\t\tcechon \"$MODULE\" \"boldmagenta\"\t\r\n\t\tfi\r\n\t\tcechon \"--------------------------------------------------------------\" \"white\"\r\n\t\t\r\n\tfi\r\n\tDEVPATH=$(dirname $DEVPATH)\r\ndone\r\n}\r\nmodules(){\r\nfor i in `find \/sys\/ -name modalias -exec cat {} \\;`;\r\ndo\r\n \/sbin\/modprobe --config \/dev\/null --show-depends $i ;\r\ndone | rev |cut -f 1 -d '\/' |rev |sort -u   &gt;\/tmp\/list_modules  \r\n\r\n\r\nclear \r\nclear \r\nclear\r\ncechon \"==============================================================\" \"white\"\r\n        cechon \"\tGet Modules Tools ... \" \"boldred\"\r\ncechon \"==============================================================\" \"white\"\r\ncat \/tmp\/list_modules\r\nrm \/tmp\/list_modules\r\n}\r\nusages(){\r\n        cechon \"Usage: $0 &lt;FILES&gt; \" \"boldred\"\r\n        echo \"example usage:\"\r\n        cecho  \"     $0 \" \"blue\"\r\n\tcechon \"d|m\" \"boldmagenta\"\r\n        cechon \"==============================================================\" \"white\"\r\n}\r\n\r\nINP=$1\r\nINF=${1:-usage}\r\nif [[ $1 == \"d\" ]];then\r\n\r\ndriver $@\r\nelif [[ $1 == \"m\" ]];then\r\nmodules\r\nelif [[ $1 == \"usages\" ]];then\r\nusages\r\nelse\r\nusages\r\nfi\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>5 \u83b7\u5f97\u9a71\u52a8\u6a21\u5757\u7684\u811a\u672c \u8f6c\u8f7d\u8bf7\u6ce8\u660e\u51fa\u5904[By SE&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[45,5],"tags":[48,37,38],"_links":{"self":[{"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=\/wp\/v2\/posts\/286"}],"collection":[{"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=286"}],"version-history":[{"count":2,"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=\/wp\/v2\/posts\/286\/revisions"}],"predecessor-version":[{"id":288,"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=\/wp\/v2\/posts\/286\/revisions\/288"}],"wp:attachment":[{"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=286"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}