summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2007-07-05 18:01:47 +0200
committerSascha Hauer <sha@octopus.labnet.pengutronix.de>2007-07-05 18:01:47 +0200
commit46d7dcc9ad9ae61ccb8e9dbd1edf4b5df966e351 (patch)
tree038f8ee908c1aaa834a13fd4b0e351bdd4605ed9 /fs
parentf5b009b8278a7c4c73e225a3492b1a66e864b9f8 (diff)
downloadbarebox-46d7dcc9ad9ae61ccb8e9dbd1edf4b5df966e351.tar.gz
barebox-46d7dcc9ad9ae61ccb8e9dbd1edf4b5df966e351.tar.xz
svn_rev_364
- fix free corruption in open - simplify mount() - fix mem hole
Diffstat (limited to 'fs')
-rw-r--r--fs/fs.c71
1 files changed, 33 insertions, 38 deletions
diff --git a/fs/fs.c b/fs/fs.c
index 4f7ce230a9..f110d1c38c 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -236,6 +236,7 @@ int open(const char *pathname, int flags)
int exist;
struct stat s;
char *path;
+ char *freep;
exist = (stat(pathname, &s) == 0) ? 1 : 0;
@@ -256,6 +257,8 @@ int open(const char *pathname, int flags)
}
path = strdup(pathname);
+ freep = path;
+
dev = get_device_by_path(&path);
if (!dev)
goto out;
@@ -275,10 +278,11 @@ int open(const char *pathname, int flags)
if (errno)
goto out;
}
- errno = fsdrv->open(dev, f, pathname);
+ errno = fsdrv->open(dev, f, path);
if (errno)
goto out;
+
if (flags & O_TRUNC) {
errno = fsdrv->truncate(dev, f, 0);
if (errno)
@@ -288,11 +292,12 @@ int open(const char *pathname, int flags)
if (flags & O_APPEND)
f->pos = f->size;
+ free(freep);
return f->no;
out:
put_file(f);
- free(path);
+ free(freep);
return errno;
}
@@ -389,13 +394,13 @@ int close(int fd)
return errno;
}
-int mount(struct device_d *parent_device, char *fsname, char *path)
+int mount(const char *device, const char *fsname, const char *path)
{
struct driver_d *drv;
struct fs_driver_d *fs_drv;
struct mtab_entry *entry;
struct fs_device_d *fsdev;
- struct device_d *dev;
+ struct device_d *dev, *parent_device = 0;
int ret;
errno = 0;
@@ -424,45 +429,34 @@ int mount(struct device_d *parent_device, char *fsname, char *path)
fs_drv = drv->type_data;
- if (fs_drv->flags & FS_DRIVER_NO_DEV) {
- dev = xzalloc(sizeof(struct device_d));
- sprintf(dev->name, "%s", fsname);
- dev->type = DEVICE_TYPE_FS;
- if ((ret = register_device(dev))) {
- free(dev);
- errno = ret;
- goto out;
- }
- if (!dev->driver) {
- /* driver didn't accept the device. Bail out */
- free(dev);
- errno = -EINVAL;
- goto out;
- }
- } else {
+ if (!fs_drv->flags & FS_DRIVER_NO_DEV) {
+ parent_device = get_device_by_id(device + 5);
if (!parent_device) {
- printf("need device for driver %s\n", fsname);
+ printf("need a device for driver %s\n", fsname);
errno = -ENODEV;
goto out;
}
- fsdev = xzalloc(sizeof(struct fs_device_d));
- fsdev->parent = parent_device;
- sprintf(fsdev->dev.name, "%s", fsname);
- fsdev->dev.type = DEVICE_TYPE_FS;
- fsdev->dev.type_data = fsdev;
- if ((ret = register_device(&fsdev->dev))) {
- free(fsdev);
- errno = ret;
- goto out;
- }
- if (!fsdev->dev.driver) {
- /* driver didn't accept the device. Bail out */
- free(fsdev);
- errno = -EINVAL;
- goto out;
- }
- dev = &fsdev->dev;
}
+ fsdev = xzalloc(sizeof(struct fs_device_d));
+ fsdev->parent = parent_device;
+ sprintf(fsdev->dev.name, "%s", fsname);
+ fsdev->dev.type = DEVICE_TYPE_FS;
+ fsdev->dev.type_data = fsdev;
+
+ if ((ret = register_device(&fsdev->dev))) {
+ free(fsdev);
+ errno = ret;
+ goto out;
+ }
+
+ if (!fsdev->dev.driver) {
+ /* driver didn't accept the device. Bail out */
+ free(fsdev);
+ errno = -EINVAL;
+ goto out;
+ }
+
+ dev = &fsdev->dev;
/* add mtab entry */
entry = malloc(sizeof(struct mtab_entry));
@@ -509,6 +503,7 @@ int umount(const char *pathname)
last->next = entry->next;
unregister_device(entry->dev);
+ free(entry->dev->type_data);
free(entry);
return 0;