* when there is '/' at the end of path, the name will be just one '\0'
* eat all '/' at the end of name
---
direct/rtems/rtems.c | 59 +++++++++++++++++++++++++++++++++++--------------
1 files changed, 42 insertions(+), 17 deletions(-)
v2: it should ret = -1; not ret -1;
Hi Sebastien
please review this patch, if it's ok, I will commit it.
diff --git a/direct/rtems/rtems.c b/direct/rtems/rtems.c
index cec053b..d81c0d3 100644
--- a/direct/rtems/rtems.c
+++ b/direct/rtems/rtems.c
@@ -391,25 +391,37 @@ static int ycb_eval_path(const char *pathname, size_t
pathnamelen, int flags, rt
static int ycb_eval_path_for_make(const char *path,
rtems_filesystem_location_info_t *pathloc, const char **name)
{
char *s;
- char *path2;
- int r;
+ char *path1, *path2;
+ int r, i;
+
+ path1 = strdup(path);
+ if(path1 == NULL) {
+ errno = ENOMEM;
+ return -1;
+ }
+ i = strlen(path1) - 1;
+ while(path1[i] == '/') {
+ path1[i] = '\0';
+ i--;
+ }
- s = strrchr(path, '/');
+ s = strrchr(path1, '/');
if(s == NULL) {
*name = path;
return ycb_eval_path(".", strlen(path), 0, pathloc);
}
- *name = s + 1;
+ *name = path + (s - path1) + 1;
path2 = strdup(path);
if(path2 == NULL) {
errno = ENOMEM;
return -1;
}
- s = path2 + (s - path);
+ s = path2 + (s - path1);
*s = 0;
r = ycb_eval_path(path2, strlen(path2), 0, pathloc);
+ free(path1);
free(path2);
if(r == 0) {
@@ -462,9 +474,20 @@ static rtems_filesystem_node_types_t
ycb_node_type(rtems_filesystem_location_inf
static int ycb_mknod(const char *path, mode_t mode, dev_t dev,
rtems_filesystem_location_info_t *pathloc)
{
+ char *name, *s;
+ int ret = 0;
+
struct yaffs_obj *parent = pathloc->node_access;
struct yaffs_softc *sc = parent->my_dev->driver_context;
+ name = strdup(path);
+ if(name == NULL) {
+ errno = ENOMEM;
+ return -1;
+ }
+ s = strchr(name, '/');
+ *s = '\0';
+
if(parent->my_dev->read_only) {
errno = EROFS;
return -1;
@@ -472,38 +495,40 @@ static int ycb_mknod(const char *path, mode_t mode, dev_t
dev, rtems_filesystem_
ylock(sc);
- if(yaffs_find_by_name(parent, path)) {
+ if(yaffs_find_by_name(parent, name)) {
errno = EEXIST;
- yunlock(sc);
- return -1;
+ ret = -1;
+ goto free;
}
if(S_ISDIR(mode)) {
struct yaffs_obj *dir;
- dir = yaffs_create_dir(parent, path, mode, 0, 0);
+ dir = yaffs_create_dir(parent, name, mode, 0, 0);
if(dir == NULL) {
- yunlock(sc);
errno = ENOSPC; /* just assume no space */
- return -1;
+ ret = -1;
+ goto free;
}
} else if(S_ISREG(mode)) {
struct yaffs_obj *file;
- file = yaffs_create_file(parent, path, mode, 0, 0);
+ file = yaffs_create_file(parent, name, mode, 0, 0);
if(file == NULL) {
- yunlock(sc);
errno = ENOSPC; /* just assume no space */
- return -1;
+ ret = -1;
+ goto free;
}
} else {
- yunlock(sc);
printf("mknod of unsupported type\n");
errno = ENOSYS;
- return -1;
+ ret = -1;
+ goto free;
}
+free:
yunlock(sc);
- return 0;
+ free(name);
+ return ret;
}
static int ycb_chown(rtems_filesystem_location_info_t *pathloc, uid_t owner,
gid_t group)
--
1.7.0.4
_______________________________________________
http://lists.milkymist.org/listinfo.cgi/devel-milkymist.org
IRC: #milkymist@Freenode
Twitter: www.twitter.com/milkymistvj
Ideas? http://milkymist.uservoice.com