|
|
@@ -66,23 +66,27 @@ static mnt_info_t* get_info(fs_handle_t *h, char *dev)
|
|
|
}
|
|
|
static int dfs_mounts(const char *dev, const char *path, const char *fs_type)
|
|
|
{
|
|
|
- int r,err;
|
|
|
- char *p=NULL,tmp;
|
|
|
+ char *p=(char*)path;
|
|
|
+ int r=0,len=strlen(path);
|
|
|
|
|
|
- p = strchr(path, '/');
|
|
|
+ if(len>1) {
|
|
|
+ p = strchr(path+1, '/');
|
|
|
+ }
|
|
|
while(p) {
|
|
|
- tmp = *p;
|
|
|
- *p = 0;
|
|
|
+ if(p>path) *p = 0;
|
|
|
r = dfs_mount(dev, path, fs_type, 0, 0);
|
|
|
LOGD("___ %s mount %s!\n", path, r?"failed":"ok");
|
|
|
- *p = tmp;
|
|
|
+ if(p>path) *p = '/';
|
|
|
|
|
|
p = strchr(p+1, '/');
|
|
|
+ if(r) break;
|
|
|
}
|
|
|
+ return r;
|
|
|
}
|
|
|
static int do_mount(fs_handle_t *h, char *dev, int flag)
|
|
|
{
|
|
|
int r=0;
|
|
|
+ rt_err_t err=0;
|
|
|
mnt_info_t *info=NULL;
|
|
|
rt_device_t devid=NULL;
|
|
|
|
|
|
@@ -106,13 +110,11 @@ static int do_mount(fs_handle_t *h, char *dev, int flag)
|
|
|
if(flag) {
|
|
|
r = dfs_mounts(info->dev, info->mpath, info->ftype);
|
|
|
if (r) {
|
|
|
- if(rt_get_errno()==EPERM) {
|
|
|
- r = dfs_mkfs(info->dev, info->ftype);
|
|
|
+ r = dfs_mkfs(info->dev, info->ftype);
|
|
|
+ if(r==0) {
|
|
|
+ r = dfs_mounts(info->dev, info->mpath, info->ftype);
|
|
|
if(r==0) {
|
|
|
- r = dfs_mounts(info->dev, info->mpath, info->ftype);
|
|
|
- if(r==0) {
|
|
|
- h->mounted[info->id] = 1;
|
|
|
- }
|
|
|
+ h->mounted[info->id] = 1;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -157,6 +159,33 @@ int fs_test(void)
|
|
|
}
|
|
|
|
|
|
|
|
|
+int fs_mkdir(char *path)
|
|
|
+{
|
|
|
+ char tmp[256];
|
|
|
+ char *p = NULL;
|
|
|
+ size_t len;
|
|
|
+ mode_t mode=0755;
|
|
|
+
|
|
|
+ snprintf(tmp, sizeof(tmp),"%s",path);
|
|
|
+ len = strlen(tmp);
|
|
|
+ if(tmp[len - 1] == '/')
|
|
|
+ tmp[len - 1] = 0;
|
|
|
+
|
|
|
+ for(p = tmp + 1; *p; p++) {
|
|
|
+ if(*p == '/') {
|
|
|
+ *p = 0;
|
|
|
+ if(access(tmp, F_OK)==-1) {
|
|
|
+ if (mkdir(tmp, mode) == -1) {
|
|
|
+ if (errno != EEXIST) return -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ *p = '/';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return mkdir(tmp, mode);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
|
|
|
int fs_length(char* path)
|
|
|
{
|
|
|
@@ -175,23 +204,28 @@ int fs_length(char* path)
|
|
|
|
|
|
int fs_exist(char* path)
|
|
|
{
|
|
|
- int r;
|
|
|
- struct stat st;
|
|
|
-
|
|
|
- r = stat(path, &st);
|
|
|
- if (r) {
|
|
|
- return 0;
|
|
|
+ int r=0;
|
|
|
+ if(access(path, F_OK)!=-1) {
|
|
|
+ r = 1;
|
|
|
}
|
|
|
|
|
|
- return 1;
|
|
|
+ return r;
|
|
|
}
|
|
|
|
|
|
|
|
|
int fs_save(char *path, void *buf, int len)
|
|
|
{
|
|
|
int r;
|
|
|
- FILE *fp=fopen(path, "w");;
|
|
|
+ FILE *fp=NULL;
|
|
|
+ char *p=strrchr(path, '/');
|
|
|
+
|
|
|
+ if(p) {
|
|
|
+ *p = 0;
|
|
|
+ r = fs_mkdir(path);
|
|
|
+ *p = '/';
|
|
|
+ }
|
|
|
|
|
|
+ fp = fopen(path, "w");
|
|
|
if(!fp) {
|
|
|
LOGE("file_save, fopen %s failed\n", path);
|
|
|
return -1;
|