Skip to content

Dfs fixbug #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/dfs/filesystems/elmfat/dfs_elm.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ int dfs_elm_mount(struct dfs_filesystem *fs, unsigned long rwflag, const void *d
if (fat == RT_NULL)
{
disk[index] = RT_NULL;
return -1;
return -DFS_STATUS_ENOMEM;
}

/* mount fatfs, always 0 logic driver */
Expand Down Expand Up @@ -141,7 +141,7 @@ int dfs_elm_mount(struct dfs_filesystem *fs, unsigned long rwflag, const void *d
/* mount succeed! */
fs->data = fat;
rt_free(dir);
return 0;
return DFS_STATUS_OK;
}

__err:
Expand Down
20 changes: 13 additions & 7 deletions components/dfs/src/dfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ void fd_put(struct dfs_fd *fd)
dfs_unlock();
};

/**
/**
* @ingroup Fd
*
* This function will return whether this file has been opend.
*
*
* @param pathname the file path name.
*
* @return 0 on file has been open successfully, -1 on open failed.
Expand Down Expand Up @@ -220,7 +220,7 @@ int fd_is_open(const char *pathname)
/* get file path name under mounted file system */
if (fs->path[0] == '/' && fs->path[1] == '\0')
mountpath = fullpath;
else
else
mountpath = fullpath + strlen(fs->path);

dfs_lock();
Expand Down Expand Up @@ -271,7 +271,7 @@ const char *dfs_subdir(const char *directory, const char *filename)
return dir;
}

/**
/**
* this function will normalize a path according to specified parent directory
* and file name.
*
Expand Down Expand Up @@ -304,18 +304,24 @@ char *dfs_normalize_path(const char *directory, const char *filename)
{
fullpath = rt_malloc(strlen(directory) + strlen(filename) + 2);

if (fullpath == RT_NULL)
return RT_NULL;

/* join path and file name */
rt_snprintf(fullpath, strlen(directory) + strlen(filename) + 2,
rt_snprintf(fullpath, strlen(directory) + strlen(filename) + 2,
"%s/%s", directory, filename);
}
else
{
fullpath = rt_strdup(filename); /* copy string */

if (fullpath == RT_NULL)
return RT_NULL;
}

src = fullpath;
dst = fullpath;

dst0 = dst;
while (1)
{
Expand Down Expand Up @@ -374,7 +380,7 @@ char *dfs_normalize_path(const char *directory, const char *filename)
dst --;
if (dst < dst0)
{
rt_free(fullpath);
rt_free(fullpath);
return RT_NULL;
}
while (dst0 < dst && dst[-1] != '/')
Expand Down
59 changes: 30 additions & 29 deletions components/dfs/src/dfs_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,39 @@
int dfs_register(const struct dfs_filesystem_operation *ops)
{
int index, result;
int free_index;

result = 0;
free_index = DFS_FILESYSTEM_TYPES_MAX;

/* lock filesystem */
dfs_lock();

/* check if this filesystem was already registered */
for (index = 0; index < DFS_FILESYSTEM_TYPES_MAX; index++)
{
if (filesystem_operation_table[index] != RT_NULL &&
strcmp(filesystem_operation_table[index]->name, ops->name) == 0)
if (filesystem_operation_table[index] == RT_NULL)
{
/* find out an empty filesystem type entry */
if (free_index == DFS_FILESYSTEM_TYPES_MAX)
free_index = index;
}
else if (strcmp(filesystem_operation_table[index]->name, ops->name) == 0)
{
result = -1;
goto err;
}
}

/* find out an empty filesystem type entry */
for (index = 0;
index < DFS_FILESYSTEM_TYPES_MAX && filesystem_operation_table[index] != RT_NULL;
index ++)
;

/* filesystem type table full */
if (index == DFS_FILESYSTEM_TYPES_MAX)
if (free_index == DFS_FILESYSTEM_TYPES_MAX)
{
result = -1;
goto err;
}

/* save the filesystem's operations */
filesystem_operation_table[index] = ops;
filesystem_operation_table[free_index] = ops;

err:
dfs_unlock();
Expand Down Expand Up @@ -94,12 +95,10 @@ struct dfs_filesystem *dfs_filesystem_lookup(const char *path)
{
if (filesystem_table[index].path == RT_NULL)
continue;
else
{
fspath = strlen(filesystem_table[index].path);
if (fspath < prefixlen)
continue;
}

fspath = strlen(filesystem_table[index].path);
if (fspath < prefixlen)
continue;

if ((filesystem_table[index].ops != RT_NULL) &&
(strncmp(filesystem_table[index].path, path, fspath) == 0))
Expand Down Expand Up @@ -217,7 +216,7 @@ int dfs_mount(const char *device_name,
struct dfs_filesystem *fs;
char *fullpath=RT_NULL;
rt_device_t dev_id;
int index;
int index, free_index;

/* open specific device */
if (device_name != RT_NULL)
Expand All @@ -241,20 +240,22 @@ int dfs_mount(const char *device_name,
dfs_lock();
for (index = 0; index < DFS_FILESYSTEM_TYPES_MAX; index++)
{
if (filesystem_operation_table[index] == RT_NULL)
continue;

if (strcmp(filesystem_operation_table[index]->name, filesystemtype) == 0)
break;
}
dfs_unlock();

/* can't find filesystem */
if (index == DFS_FILESYSTEM_TYPES_MAX)
{
rt_set_errno(-DFS_STATUS_ENODEV);
dfs_unlock();

return -1;
}
ops = filesystem_operation_table[index];
dfs_unlock();

/* make full path for special file */
fullpath = dfs_normalize_path(RT_NULL, path);
Expand All @@ -280,33 +281,33 @@ int dfs_mount(const char *device_name,
dfs_file_close(&fd);
}

free_index = DFS_FILESYSTEMS_MAX;
/* check whether the file system mounted or not */
dfs_lock();
for (index = 0; index < DFS_FILESYSTEMS_MAX; index ++)
{
if (filesystem_table[index].ops != RT_NULL &&
strcmp(filesystem_table[index].path, path) == 0)
if (filesystem_table[index].ops == RT_NULL)
{
/* find out an empty filesystem table entry */
if (free_index == DFS_FILESYSTEMS_MAX)
free_index = index;
}
else if (strcmp(filesystem_table[index].path, path) == 0)
{
rt_set_errno(-DFS_STATUS_EINVAL);
goto err1;
}
}

/* find out an empty filesystem table entry */
for (index = 0;
index < DFS_FILESYSTEMS_MAX && filesystem_table[index].ops != RT_NULL;
index ++)
;

/* can't find en empty filesystem table entry */
if (index == DFS_FILESYSTEMS_MAX)
if (free_index == DFS_FILESYSTEMS_MAX)
{
rt_set_errno(-DFS_STATUS_ENOSPC);
goto err1;
}

/* register file system */
fs = &(filesystem_table[index]);
fs = &(filesystem_table[free_index]);
fs->path = fullpath;
fs->ops = ops;
fs->dev_id = dev_id;
Expand Down