Merge remote-tracking branch 'uncool/cst-next'

This need buildfixes and some functional updates...


Origin commit data
------------------
Branch: ni/coolstream
Commit: eeee5bacab
Author: Stefan Seyfried <seife@tuxbox-git.slipkontur.de>
Date: 2015-12-13 (Sun, 13 Dec 2015)



------------------
This commit was generated by Migit
This commit is contained in:
Stefan Seyfried
2015-12-13 17:41:55 +01:00
320 changed files with 21291 additions and 13199 deletions

View File

@@ -40,19 +40,21 @@
#include <fcntl.h>
#include <dirent.h>
#include <stdarg.h>
#include <algorithm>
#include <mntent.h>
#include <linux/hdreg.h>
#include <linux/fs.h>
#include "debug.h"
#include <system/helpers.h>
#include <gui/update_ext.h>
using namespace std;
void mySleep(int sec) {
int mySleep(int sec) {
struct timeval timeout;
timeout.tv_sec = sec;
timeout.tv_usec = 0;
select(0,0,0,0, &timeout);
return select(0,0,0,0, &timeout);
}
off_t file_size(const char *filename)
@@ -217,7 +219,7 @@ FILE* my_popen( pid_t& pid, const char *cmdstring, const char *type)
}
return(fp);
}
#if 0
int mkdirhier(const char *pathname, mode_t mode)
{
int res = -1;
@@ -238,7 +240,7 @@ int mkdirhier(const char *pathname, mode_t mode)
res = 0;
return res;
}
# endif
int safe_mkdir(const char * path)
{
@@ -281,6 +283,8 @@ int check_dir(const char * dir, bool allow_tmp)
default:
ret = 0; // ok
}
if(ret == -1)
printf("Wrong Filessystem Type: 0x%x\n",s.f_type);
}
return ret;
}
@@ -340,7 +344,7 @@ std::string find_executable(const char *name)
if (tmpPath)
path = strdupa(tmpPath);
else
path = strdupa("/bin:/usr/bin:/sbin:/usr/sbin");
path = strdupa("/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin");
if (name[0] == '/') { /* full path given */
if (!access(name, X_OK) && !stat(name, &s) && S_ISREG(s.st_mode))
return std::string(name);
@@ -423,8 +427,9 @@ std::string getNowTimeStr(const char* format)
{
char tmpStr[256];
struct timeval tv;
struct tm t;
gettimeofday(&tv, NULL);
strftime(tmpStr, sizeof(tmpStr), format, localtime(&tv.tv_sec));
strftime(tmpStr, sizeof(tmpStr), format, localtime_r(&tv.tv_sec, &t));
return (std::string)tmpStr;
}
@@ -587,11 +592,9 @@ bool CFileHelpers::copyDir(const char *Src, const char *Dst, bool backupMode)
}
else {
// directory
if (createDir(Dst, FileInfo.st_mode & 0x0FFF) == false) {
if (errno != EEXIST) {
closedir(Directory);
return false;
}
if (!createDir(Dst, FileInfo.st_mode & 0x0FFF)) {
closedir(Directory);
return false;
}
}
@@ -637,32 +640,34 @@ bool CFileHelpers::copyDir(const char *Src, const char *Dst, bool backupMode)
return true;
}
bool CFileHelpers::createDir(const char *Dir, mode_t mode)
// returns: true - success.
// false - errno is set
bool CFileHelpers::createDir(string& Dir, mode_t mode)
{
char dirPath[PATH_MAX];
DIR *dir;
if ((dir = opendir(Dir)) != NULL) {
closedir(dir);
errno = EEXIST;
return false;
}
int ret = -1;
while (ret == -1) {
strcpy(dirPath, Dir);
ret = mkdir(dirPath, mode);
if ((errno == ENOENT) && (ret == -1)) {
char * pos = strrchr(dirPath,'/');
if (pos != NULL) {
pos[0] = '\0';
createDir(dirPath, mode);
int res = 0;
for(string::iterator iter = Dir.begin() ; iter != Dir.end();) {
string::iterator newIter = find(iter, Dir.end(), '/' );
string newPath = string( Dir.begin(), newIter );
if(!newPath.empty() && !file_exists(newPath.c_str())) {
res = mkdir( newPath.c_str(), mode);
if (res == -1) {
if (errno == EEXIST) {
res = 0;
} else {
// We can assume that if an error
// occured, following will fail too,
// so break here.
dprintf(DEBUG_NORMAL, "[CFileHelpers %s] creating directory %s: %s\n", __func__, newPath.c_str(), strerror(errno));
break;
}
}
}
else
return !ret || (errno == EEXIST);
iter = newIter;
if(newIter != Dir.end())
++ iter;
}
errno = 0;
return true;
return (res == 0 ? true : false);
}
bool CFileHelpers::removeDir(const char *Dir)
@@ -692,6 +697,41 @@ bool CFileHelpers::removeDir(const char *Dir)
return true;
}
u_int64_t CFileHelpers::getDirSize(const char *dirname)
{
DIR *dir;
char fullDirName[500];
struct dirent *dirPnt;
struct stat cur_file;
uint64_t total_size = 0;
//open current dir
sprintf(fullDirName, "%s/", dirname);
if((dir = opendir(fullDirName)) == NULL) {
fprintf(stderr, "Couldn't open %s\n", fullDirName);
return 0;
}
//go through the directory
while( (dirPnt = readdir(dir)) != NULL ) {
if(strcmp((*dirPnt).d_name, "..") == 0 || strcmp((*dirPnt).d_name, ".") == 0)
continue;
//create current filepath
sprintf(fullDirName, "%s/%s", dirname, (*dirPnt).d_name);
if(stat(fullDirName, &cur_file) == -1)
continue;
if(cur_file.st_mode & S_IFREG) //file...
total_size += cur_file.st_size;
else if(cur_file.st_mode & S_IFDIR) //dir...
total_size += getDirSize(fullDirName);
}
closedir(dir);
return total_size;
}
static int hdd_open_dev(const char * fname)
{
FILE * fp;
@@ -831,3 +871,21 @@ std::string to_string(unsigned long long i)
return s.str();
}
std::string getJFFS2MountPoint(int mtdPos)
{
FILE* fd = fopen("/proc/mounts", "r");
if (!fd) return "";
int iBlock;
char lineRead[1024], sMount[512], sFs[512];
memset(lineRead, '\0', sizeof(lineRead));
while (fgets(lineRead, sizeof(lineRead)-1, fd)) {
sscanf(lineRead, "/dev/mtdblock%d %511s %511s", &iBlock, sMount, sFs);
if ((iBlock == mtdPos) && (strstr(sMount, "/") != NULL) && (strstr(sFs, "jffs2") != NULL)) {
fclose(fd);
return sMount;
}
memset(lineRead, '\0', sizeof(lineRead));
}
fclose(fd);
return "";
}