|
发表于 2022-6-18 19:40:05
|
显示全部楼层
#include <stdio.h>+ Y6 Q. z8 l, a6 D' ^
#include <unistd.h>$ J* s2 K' c/ Q. \1 f# t
#include <fcntl.h>
5 f5 z' A3 g0 J#include <errno.h>3 C3 l' s/ \9 b1 [
#include <sys/ioctl.h>
$ a( I9 s& D- {$ {- B7 x
5 O( z, Z5 u/ p2 H Z* n0 Z#define IOCMD_LOCK 0xC0204D011 ~% l- \7 w, T, Y% M
#define IOCMD_UNLOCK 0xC0204D02
0 K' W- X, T5 Y5 Q$ y6 g! a; z& }+ @0 g! T# o
void usage(const char* app); B8 _8 o4 L4 R; {9 ]
{
+ z/ }4 M- ~. A( S* D. A% e0 m1 E printf("%s -l <mtd name> ... lock mtd\n", app);
$ \+ ^9 q# J/ E. T$ P: I' N6 _ printf("%s -u <mtd name> ... unlock mtd\n", app);
. G0 C# {/ f4 s/ t4 [$ y}" g3 \- e2 h- X$ I/ l9 u5 U I+ @4 g
) L) L6 t" u9 r- I- g( k1 |5 G1 Z- o
int main(int argc, char* argv[])& J( ~0 ~ E" W7 Q7 {
{
- I: X9 ~# d8 \7 t* C const char* file = "/proc/wap_proc/mtd_protect";6 o# Q, {9 u! N: h2 x# R
int fd, r;8 n; S$ D \# @" T
unsigned long cmd = IOCMD_UNLOCK;
' O4 z5 ]* ^5 f" c$ u
. d; w7 m: B( E+ o6 ^$ o5 u( | if(argc < 3) ~* f; S! m' `! T
{: j* [. z, l5 H
usage(argv[0]);9 T& C3 M; m! |6 c7 E. f& y% N
return 1;; @' C9 f1 l- W& x* B# X; ~& j
}7 n/ w9 @, ~- j# ~2 m" }
if('-' == argv[1][0])
; U# V) a/ Z4 F! u( l7 i8 e {: [, G. c/ U9 D4 t! V |7 [
if('l' == argv[1][1])
5 y. r7 P* Z) g7 H( c cmd = IOCMD_LOCK;- |& D" `2 R; N. I
else if('u' != argv[1][1])
* u! C( p/ P. I ]0 A$ b4 B9 D {usage(argv[0]); return 1;}
5 ?8 [+ {! b) D8 B3 D0 ]. L) p4 t8 z- x }
" B6 D! U9 L+ T& C5 f, { else0 Y9 }3 I: E% y N, \
{
# `+ O, {' C! b+ M/ n% i usage(argv[0]);: c3 z' G) e) m: b
return 1;
6 J& e( i1 K H1 g5 q, K+ w }
0 `6 c& F7 s/ n2 | fd = open(file, O_RDWR);& T* M, b. r- l
if(fd < 0)
/ U& c7 y$ _8 n- j( g- G* t @4 |& g {% K2 _2 p. R6 j/ a n- l
printf("Can not open: %s\n", file);2 I4 u; y- ^0 i* k9 _
return 1;
* R" N% X9 w6 [' ]& B }
# w) C4 N/ l8 n. s$ D r = ioctl(fd, cmd, argv[2]);1 @! c! {" ~2 ?& J
close(fd);2 |$ U" \2 k$ b4 S9 W6 @' W8 A& m: q
printf("%s '%s' %s. errno:%u\n", " \' v. }( x6 K' P
(IOCMD_UNLOCK == cmd ? "Unlock" : "Lock"),
2 @. j& `4 G1 A4 U# | argv[2], (r < 0 ? "failed" : "success"), errno);
1 L4 X9 C: l( D; E& v8 ` return 0;
, x0 a4 F7 }# c* H) V0 E \}$ ?" y& q2 v! v; n9 M
g* @2 Z: e7 ^ ~
: N3 R2 n) ~! P E: @' l
2 a' ~& o! T) }5 q: J" X
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
×
|