The corresponding parameter values are modified by the C language for the corresponding node operation.
The process of implementing a Linux application access-to-use drive node is implemented on the basis of the corresponding kernel driver. Implementation process: Add the implementation file to use, add the compilation rule, compile the implementation
1. Add the implementation file to use
Choose the appropriate location to store the relevant source code, this time I stored in: Vendor\welcome directory, the new welcome.c
Tips: In the event of an undefined compilation, it is possible that there is no corresponding header file after the kernel upgrade, you can use the terminal man function name in Linux to see the function and the definition of the relevant header file, add can
#include <stdio.h>#include<stdlib.h>#include<fcntl.h>#include<unistd.h>//Drive node for kernel-generated nodes#defineDevice_name "/DEV/WELCOMF"intMain (intargcChar**argv) { intFD =-1; intval =0; FD=open (DEVICE_NAME,O_RDWR); if(FD = =-1) {printf ("Failed to open device%s.%m\n", device_name); return-1; } printf ("Read Original value: \ n"); Read (FD,&val,sizeof(Val)); printf ("val =%d.\n", Val); Val=2; printf ("Write value%d to%s.\n", Val,device_name); Write (FD,&val,sizeof(Val)); printf ("Read value again: \ n"); Read (FD,&val,sizeof(Val)); printf ("val =%d.\n", Val); return 0;}
2. Add Compilation rule Add Android.mk in this directory
local_path:=$ (call My-dir)
Include $ (clear_vars)
Local_module_tags:=optional
Local_module:=welcomebin
local_src_files:=$ (call All-subdir-c-files)
Include $ (build_executable)
3, compile and implement the direct compilation module MMM vendor/welcome
Then package the download, or directly use the production bin file with ADB push to the System/bin directory----If you cannot use the Attention node permissions issue
The bin file can be run through ADB into the appropriate directory. Can correctly output log and result is complete code
From Linux drivers to apk (2)