Linux下侦测 USB Disk 插拔(2)


            // USB 设备的插入时,会出现以 add@/devices/ 开头,含 usb 的字符串
            if( 0 == memcmp( caKernelMsgBuff,
                             "add@",
                             4 )
                &&
                NULL != strstr( caKernelMsgBuff,
                                "usb" ) )
            {
                printf( "Add USB Device\n" );
                break;
            }


            // USB 设备的拔除时,会出现以 remove@/devices/ 开头,含 usb 的字符串
            if( 0 == memcmp( caKernelMsgBuff,
                             "remove@",
                             7 )
                &&
                NULL != strstr( caKernelMsgBuff,
                                "usb" ) )
            {
                printf( "Remove USB Device\n" );
                break;
            }
        }


        // 等一秒钟,让设备加载完毕
        sleep(1);


    }while( 0 );


    // 如果 创建套接字成功 的话,则
    if ( -1 != sfd )
    {
        // 关闭套接字
        close( sfd );
        sfd = -1;
    }


    return iResult;
}


int main(int argc, char* argv[])
{
    printf( "monitoring_usb_device return %d\n",
            monitoring_usb_device() );


    return 0;
 
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/22635.html