diff --git a/src/gui/hdd_menu.cpp b/src/gui/hdd_menu.cpp index 79a68614e..beeeda119 100644 --- a/src/gui/hdd_menu.cpp +++ b/src/gui/hdd_menu.cpp @@ -494,17 +494,17 @@ _remount: if(!res) { snprintf(cmd, sizeof(cmd), "%s/movies", dst); - safe_mkdir((char *) cmd); + safe_mkdir(cmd); snprintf(cmd, sizeof(cmd), "%s/pictures", dst); - safe_mkdir((char *) cmd); + safe_mkdir(cmd); snprintf(cmd, sizeof(cmd), "%s/epg", dst); - safe_mkdir((char *) cmd); + safe_mkdir(cmd); snprintf(cmd, sizeof(cmd), "%s/music", dst); - safe_mkdir((char *) cmd); + safe_mkdir(cmd); snprintf(cmd, sizeof(cmd), "%s/logos", dst); - safe_mkdir((char *) cmd); + safe_mkdir(cmd); snprintf(cmd, sizeof(cmd), "%s/plugins", dst); - safe_mkdir((char *) cmd); + safe_mkdir(cmd); sync(); } _return: diff --git a/src/system/helpers.cpp b/src/system/helpers.cpp index 1c7542108..9b67a0f34 100644 --- a/src/system/helpers.cpp +++ b/src/system/helpers.cpp @@ -190,19 +190,28 @@ FILE* my_popen( pid_t& pid, const char *cmdstring, const char *type) return(fp); } -int safe_mkdir(char * path) +int safe_mkdir(const char * path) { struct statfs s; - int ret = 0; - if(!strncmp(path, "/hdd", 4)) { - ret = statfs("/hdd", &s); - if((ret != 0) || (s.f_type == 0x72b6)) - ret = -1; - else - mkdir(path, 0755); - } else - mkdir(path, 0755); - return ret; + size_t l = strlen(path); + char d[l + 3]; + strncpy(d, path, l); + + // skip trailing slashes + while (l > 0 && d[l - 1] == '/') + l--; + // find last slash + while (l > 0 && d[l - 1] != '/') + l--; + if (!l) + return -1; + // append a single dot + d[l++] = '.'; + d[l] = 0; + + if(statfs(d, &s) || (s.f_type == 0x72b6 /* jffs2 */)) + return -1; + return mkdir(path, 0755); } /* function used to check is this dir writable, i.e. not flash, for record etc */ diff --git a/src/system/helpers.h b/src/system/helpers.h index d9d4b6108..9639c39bf 100644 --- a/src/system/helpers.h +++ b/src/system/helpers.h @@ -30,7 +30,9 @@ int my_system(const char * cmd); int my_system(int argc, const char *arg, ...); /* argc is number of arguments including command */ FILE* my_popen( pid_t& pid, const char *cmdstring, const char *type); -int safe_mkdir(char * path); + +int safe_mkdir(const char * path); +inline int safe_mkdir(std::string path) { return safe_mkdir(path.c_str()); } off_t file_size(const char *filename); bool file_exists(const char *filename); void wakeup_hdd(const char *hdd_dir);