29 const std::string FatImageReader::TAG =
"FatImageReader";
32 : ibrcommon::IOException(create_message(errcode, operation, file)), _errorcode(errcode)
40 std::string FatImageReader::FatImageException::create_message(
int errcode,
const std::string &operation,
const ibrcommon::File &file)
43 ss << operation <<
" failed with " << errcode <<
" for " << file.
getPath();
64 if (file.
isRoot())
return true;
68 return d.dir_attr & DIR_ATTR_DIRECTORY;
77 if (file.
isRoot())
return 0;
81 return d.dir_file_size;
90 if (file.
isRoot())
return 0;
96 tm.tm_year = d.crttime.year - 1900;
97 tm.tm_mon = d.crttime.month - 1;
98 tm.tm_mday = d.crttime.day;
99 tm.tm_hour = d.crttime.hour;
100 tm.tm_min = d.crttime.min;
101 tm.tm_sec = d.crttime.sec / 2;
127 if (path.isRoot())
return;
130 byte* image_path =
const_cast<char *
>(_filename.getPath().c_str());
131 if ((ret = TFFS_mount(image_path, &htffs)) != TFFS_OK) {
132 throw FatImageException(ret,
"TFFS_mount", _filename);
136 FATFile parent = path.getParent();
139 const std::string dir_path = parent.getPath() + (parent.isRoot() ?
"" :
"/");
140 if ((ret = TFFS_opendir(htffs, const_cast<char *>(dir_path.c_str()), &hdir)) != TFFS_OK) {
148 ret = TFFS_readdir(hdir, &d);
149 if (ret == TFFS_OK) {
150 if (d.d_name == path.getBasename()) {
161 if ((ret = TFFS_closedir(hdir)) != TFFS_OK) {
167 if ((ret = TFFS_umount(htffs)) != TFFS_OK) {
168 throw FatImageException(ret,
"TFFS_umount", _filename);
190 byte* image_path =
const_cast<char *
>(_filename.getPath().c_str());
191 if ((ret = TFFS_mount(image_path, &htffs)) != TFFS_OK) {
196 const std::string dir_path = directory.getPath() + (directory.isRoot() ?
"" :
"/");
197 if ((ret = TFFS_opendir(htffs, const_cast<char *>(dir_path.c_str()), &hdir)) != TFFS_OK) {
204 if ((ret = TFFS_readdir(hdir, &dirent)) == TFFS_OK)
206 files.push_back(directory.get(dirent.d_name));
208 else if (ret == ERR_TFFS_LAST_DIRENTRY) {
217 if ((ret = TFFS_closedir(hdir)) != TFFS_OK) {
223 if ((ret = TFFS_umount(htffs)) != TFFS_OK) {
239 byte* path =
const_cast<char *
>(image.
getPath().c_str());
240 if ((ret = TFFS_mount(path, &_htffs)) != TFFS_OK)
247 byte* file =
const_cast<char*
>(p.c_str());
248 if ((ret = TFFS_fopen(_htffs, file,
"r", &_hfile)) != TFFS_OK)
271 if (( ret = TFFS_fread(_hfile, buf_size, (
unsigned char*) buff)) < 0)
273 if( ret == ERR_TFFS_FILE_EOF)
return 0;
276 std::stringstream ss;
277 ss <<
"TFFS_fread " << ret;
283 return (ret >= 0) ? (size_t)ret : 0;
291 if (TFFS_fclose(_hfile) != TFFS_OK) {
296 if (TFFS_umount(_htffs) != TFFS_OK) {