blob: e86c3b04245326f155da9d503c4591ef226325d3
1 | #define LOG_TAG "BLOB_FILE" |
2 | |
3 | #include <stdio.h> |
4 | #include <unistd.h> |
5 | #include <string.h> |
6 | #include <sys/stat.h> |
7 | #include <fcntl.h> |
8 | #include <errno.h> |
9 | #include "tvconfig/tvconfig.h" |
10 | #include "CBlobDeviceFile.h" |
11 | #include "CTvLog.h" |
12 | |
13 | CBlobDeviceFile::CBlobDeviceFile() |
14 | { |
15 | m_dev_total_size = 4 * 1024; |
16 | m_dev_fd = -1; |
17 | mDataBuf = new unsigned char[m_dev_total_size]; |
18 | |
19 | const char *device_path = config_get_str(CFG_SECTION_SETTING, "device_path", "/param/default_data"); |
20 | const char *device_size = config_get_str(CFG_SECTION_SETTING, "device_size", "0x1000"); |
21 | strcpy(m_dev_path, device_path); |
22 | } |
23 | |
24 | CBlobDeviceFile::~CBlobDeviceFile() |
25 | { |
26 | if (mDataBuf != NULL) { |
27 | delete mDataBuf; |
28 | mDataBuf = NULL; |
29 | } |
30 | CloseDevice(); |
31 | } |
32 | |
33 | int CBlobDeviceFile::WriteBytes(int offset, int size, unsigned char *buf) |
34 | { |
35 | |
36 | lseek(m_dev_fd, offset, SEEK_SET); |
37 | write(m_dev_fd, buf, size); |
38 | //not need |
39 | //fsync(device_fd); |
40 | return 0; |
41 | } |
42 | int CBlobDeviceFile::ReadBytes(int offset, int size, unsigned char *buf) |
43 | { |
44 | lseek(m_dev_fd, offset, SEEK_SET); |
45 | read(m_dev_fd, buf, size); |
46 | return 0; |
47 | } |
48 | int CBlobDeviceFile::EraseAllData() |
49 | { |
50 | return 0; |
51 | } |
52 | int CBlobDeviceFile::InitCheck() |
53 | { |
54 | return 0; |
55 | } |
56 | |
57 | int CBlobDeviceFile::OpenDevice() |
58 | { |
59 | if (strlen(m_dev_path) <= 0) return -1; |
60 | |
61 | m_dev_fd = open(m_dev_path, O_RDWR | O_SYNC | O_CREAT, S_IRUSR | S_IWUSR); |
62 | |
63 | if (m_dev_fd < 0) { |
64 | LOGE("%s, Open device file \"%s\" error: %s.\n", "TV", m_dev_path, strerror(errno)); |
65 | return -1; |
66 | } |
67 | |
68 | return 0; |
69 | } |
70 | |
71 | int CBlobDeviceFile::CloseDevice() |
72 | { |
73 | if (m_dev_fd >= 0) { |
74 | close(m_dev_fd); |
75 | m_dev_fd = -1; |
76 | } |
77 | return 0; |
78 | } |
79 |