1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <unistd.h>
5 #include <signal.h>
6 #include <sys/types.h>
7 #include <errno.h>
8 #include <sys/time.h>
9 #include <sdklog.h>
10 #include "CameraFileCfg.h"
11 #include "StorageManager.h"
12 #include "mount.h"
13
14 void AutoMountCallback(NetlinkEvent * evt, void *usrdata);
15 /**************************************
16 Function:
17 Description:
18 ***************************************/
mount(void * usrdata)19 mount::mount(void *usrdata)
20 {
21 NetlinkManager *nm;
22 AutEvent *pevent = AutEvent::Instance();
23
24 if (!(nm = NetlinkManager::Instance())) {
25 ALOGV("Unable to create NetlinkManager");
26 //printf("can't get the netlinkManager's instance\n");
27 };
28
29 pevent->setEventCb(AutoMountCallback, (void *) usrdata);
30 if (nm->start()) {
31 ALOGV("Unable to start NetlinkManager (%s)");
32 }
33 }
34
35
36 /**************************************
37 Function:
38 Description:
39 ***************************************/
AutoMountCallback(NetlinkEvent * evt,void * usrdata)40 void AutoMountCallback(NetlinkEvent * evt, void *usrdata)
41 {
42 ALOGV("event act=%d %s ", evt->getAction(), evt->getSubsystem());
43
44 int action = evt->getAction();
45 const char *devtype = evt->findParam("DEVTYPE");
46
47
48 if (action == NetlinkEvent::NlActionAdd) {
49 int major = atoi(evt->findParam("MAJOR"));
50 int minor = atoi(evt->findParam("MINOR"));
51 char nodepath[255];
52
53 if (!strcmp(devtype, "disk")) {
54
55 //enhanceUsbStability(evt);
56
57 ALOGW("line=%d,devtype=%s", __LINE__, devtype);
58 //handleDiskAdded(dp, evt);
59 char bufname[512];
60 memset(bufname, 0, 512);
61 char tmpbuf[256];
62 char real_path[256];
63 config_get_curfiledir(0, bufname);
64 int len = strlen(bufname);
65 const char *tmp = evt->findParam("NPARTS");
66
67
68 if (tmp) {
69 int npart = atoi(tmp);
70 if (npart == 0) {
71 const char *devname = evt->findParam("DEVNAME");
72 ALOGW("devname=%s", devname);
73
74
75 char buf[256];
76 if (strstr(devname, "sd")) {
77
78 system("mkdir -p /mnt/usb");
79 sprintf(buf,
80 "mount -t vfat /dev/%s /mnt/usb -o defaults,noatime,async,iocharset=cp936",
81 devname);
82 }
83 else if (strstr(devname, "mmcblk1"))
84 sprintf(buf,
85 "mount -t vfat /dev/%s /mnt/sdcard/mmcblk1p1 -o defaults,noatime,async,iocharset=cp936",
86 devname);
87 else
88 sprintf(buf, "echo mount fail > /dev/ttyS0");
89
90 system("mkdir -p /mnt/sdcard/mmcblk1p1");
91 system(buf);
92 }
93 }
94 else {
95 SLOGW("Kernel block uevent missing 'NPARTS'");
96 //mDiskNumParts = 1;
97 }
98 strcpy(tmpbuf, bufname);
99 for (int i = 0; i < len; i++) {
100 if (tmpbuf[len - 1 - i] == '/') {
101 tmpbuf[len - 1 - i] = 0;
102 }
103 else {
104 break;
105 }
106 }
107
108 int rmret = readlink(tmpbuf, real_path, sizeof(real_path));
109 if (rmret < 0) {
110 ALOGV("mount path not a symlink %s err=%d", tmpbuf, errno);
111
112 strcpy(real_path, tmpbuf);
113 }
114 else {
115 ALOGV("mount real path is %s \r\n", real_path);
116 }
117 for (int i = 0; i < 6; i++) {
118 if (isMounted(real_path))
119 break;
120
121 sleep(1);
122 }
123
124 /*
125 if (g_recordstatus == 0) {
126 pdvr1->startRecord();
127 g_recordstatus = 1;
128 }
129 else
130 ALOGE("record status error g_recordstatus=%d", g_recordstatus);
131 */
132
133 }
134
135 }
136 else if (action == NetlinkEvent::NlActionRemove) {
137 if (!strcmp(devtype, "disk")) {
138
139 /*
140 if (g_recordstatus == 1) {
141 pdvr1->storage_state=0;//tmp
142 pdvr1->stopRecord();
143 g_recordstatus = 0;
144 ALOGE("sdcard has remove,stopRecord now,g_recordstatus=%d", g_recordstatus);
145
146 }
147 */
148
149 }
150 }
151
152 }
153
154 /**************************************
155 Function:
156 Description:
157 ***************************************/
~mount()158 mount::~mount()
159 {
160
161 }
162
163