From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 03/12] fs: Store mtab entries in list
Date: Wed, 15 Feb 2012 09:22:36 +0100 [thread overview]
Message-ID: <1329294165-12089-4-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1329294165-12089-1-git-send-email-s.hauer@pengutronix.de>
To make the code a bit easier to read. Also, do not allow
to umount / when something else is mounted.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/mount.c | 17 +++++-------
fs/fs.c | 78 +++++++++++++++++++++++-------------------------------
include/fs.h | 6 +++-
3 files changed, 44 insertions(+), 57 deletions(-)
diff --git a/commands/mount.c b/commands/mount.c
index 7cefdbe..926cd3f 100644
--- a/commands/mount.c
+++ b/commands/mount.c
@@ -33,18 +33,15 @@
static int do_mount(struct command *cmdtp, int argc, char *argv[])
{
int ret = 0;
- struct mtab_entry *entry = NULL;
+ struct mtab_entry *entry;
if (argc == 1) {
- do {
- entry = mtab_next_entry(entry);
- if (entry) {
- printf("%s on %s type %s\n",
- entry->parent_device ? dev_name(entry->parent_device) : "none",
- entry->path,
- entry->dev->name);
- }
- } while (entry);
+ for_each_mtab_entry(entry) {
+ printf("%s on %s type %s\n",
+ entry->parent_device ? dev_name(entry->parent_device) : "none",
+ entry->path,
+ entry->dev->name);
+ }
return 0;
}
diff --git a/fs/fs.c b/fs/fs.c
index 13df71c..3dfbaaa 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -167,11 +167,12 @@ char *normalise_path(const char *pathname)
}
EXPORT_SYMBOL(normalise_path);
-static struct mtab_entry *mtab;
+LIST_HEAD(mtab_list);
+static struct mtab_entry *mtab_root;
struct mtab_entry *get_mtab_entry_by_path(const char *_path)
{
- struct mtab_entry *match = NULL, *e = mtab;
+ struct mtab_entry *e = NULL;
char *path, *tok;
if (*_path != '/')
@@ -183,24 +184,15 @@ struct mtab_entry *get_mtab_entry_by_path(const char *_path)
if (tok)
*tok = 0;
- while (e) {
- if (!strcmp(path, e->path)) {
- match = e;
- break;
- }
- e = e->next;
+ for_each_mtab_entry(e) {
+ if (!strcmp(path, e->path))
+ goto found;
}
-
+ e = mtab_root;
+found:
free(path);
- return match ? match : mtab;
-}
-
-struct mtab_entry *mtab_next_entry(struct mtab_entry *e)
-{
- if (!e)
- return mtab;
- return e->next;
+ return e;
}
const char *fsdev_get_mountpoint(struct fs_device_d *fsdev)
@@ -248,7 +240,7 @@ static struct device_d *get_fs_device_by_path(char **path)
e = get_mtab_entry_by_path(*path);
if (!e)
return NULL;
- if (e != mtab)
+ if (e != mtab_root)
*path += strlen(e->path);
dev = e->dev;
@@ -751,11 +743,6 @@ int mount(const char *device, const char *fsname, const char *_path)
debug("mount: %s on %s type %s\n", device, path, fsname);
- if (get_mtab_entry_by_path(path) != mtab) {
- errno = -EBUSY;
- goto out;
- }
-
if (strchr(path + 1, '/')) {
printf("mounting allowed on first directory level only\n");
errno = -EBUSY;
@@ -774,7 +761,7 @@ int mount(const char *device, const char *fsname, const char *_path)
goto out;
}
- if (mtab) {
+ if (mtab_root) {
if (path_check_prereq(path, S_IFDIR))
goto out;
} else {
@@ -825,16 +812,12 @@ int mount(const char *device, const char *fsname, const char *_path)
safe_strncpy(entry->path, path, PATH_MAX);
entry->dev = dev;
entry->parent_device = parent_device;
- entry->next = NULL;
-
- if (!mtab)
- mtab = entry;
- else {
- struct mtab_entry *e = mtab;
- while (e->next)
- e = e->next;
- e->next = entry;
- }
+
+ list_add_tail(&entry->list, &mtab_list);
+
+ if (!mtab_root)
+ mtab_root = entry;
+
errno = 0;
free(path);
@@ -854,27 +837,32 @@ EXPORT_SYMBOL(mount);
int umount(const char *pathname)
{
- struct mtab_entry *entry = mtab;
- struct mtab_entry *last = mtab;
+ struct mtab_entry *entry = NULL, *e;
char *p = normalise_path(pathname);
struct fs_device_d *fsdev;
- while(entry && strcmp(p, entry->path)) {
- last = entry;
- entry = entry->next;
+ for_each_mtab_entry(e) {
+ if (!strcmp(p, e->path)) {
+ entry = e;
+ break;
+ }
}
free(p);
+ if (e == mtab_root && !list_is_singular(&mtab_list)) {
+ errno = -EBUSY;
+ return errno;
+ }
+
if (!entry) {
errno = -EFAULT;
return errno;
}
- if (entry == mtab)
- mtab = mtab->next;
- else
- last->next = entry->next;
+ list_del(&entry->list);
+ if (entry == mtab_root)
+ mtab_root = NULL;
unregister_device(entry->dev);
fsdev = entry->dev->type_data;
@@ -951,11 +939,11 @@ int stat(const char *filename, struct stat *s)
goto out;
}
- if (e != mtab && strcmp(f, e->path)) {
+ if (e != mtab_root && strcmp(f, e->path)) {
f += strlen(e->path);
dev = e->dev;
} else
- dev = mtab->dev;
+ dev = mtab_root->dev;
fsdrv = (struct fs_driver_d *)dev->driver->type_data;
diff --git a/include/fs.h b/include/fs.h
index 97d5995..dd10677 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -78,11 +78,14 @@ struct fs_driver_d {
struct mtab_entry {
char path[PATH_MAX];
- struct mtab_entry *next;
struct device_d *dev;
struct device_d *parent_device;
+ struct list_head list;
};
+extern struct list_head mtab_list;
+#define for_each_mtab_entry(e) list_for_each_entry(e, &mtab_list, list)
+
struct fs_device_d {
char *backingstore; /* the device we are associated with */
struct device_d dev; /* our own device */
@@ -148,7 +151,6 @@ char *mkmodestr(unsigned long mode, char *str);
* directly in / and of course the root directory itself
*/
struct mtab_entry *get_mtab_entry_by_path(const char *path);
-struct mtab_entry *mtab_next_entry(struct mtab_entry *entry);
const char *fsdev_get_mountpoint(struct fs_device_d *fsdev);
/*
--
1.7.9
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2012-02-15 8:23 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-15 8:22 cleanup filesystem core Sascha Hauer
2012-02-15 8:22 ` [PATCH 01/12] add list_is_singular Sascha Hauer
2012-02-15 8:22 ` [PATCH 02/12] dos partitions: Do not register as fixed partitions Sascha Hauer
2012-02-15 8:22 ` Sascha Hauer [this message]
2012-02-15 8:22 ` [PATCH 04/12] fs: make locally used function get_mtab_entry_by_path static Sascha Hauer
2012-02-15 8:22 ` [PATCH 05/12] fs: Store mtab path in allocated string Sascha Hauer
2012-02-15 8:22 ` [PATCH 06/12] fs: remove unused function fsdev_get_mountpoint Sascha Hauer
2012-02-15 8:22 ` [PATCH 07/12] fs: simplify get_mtab_entry_by_path Sascha Hauer
2012-02-15 8:22 ` [PATCH 08/12] fs: remove only once used variable Sascha Hauer
2012-02-15 8:22 ` [PATCH 09/12] fs: remove fs devices list Sascha Hauer
2012-02-15 8:22 ` [PATCH 10/12] fs: put fs devices on its own bus Sascha Hauer
2012-02-15 8:22 ` [PATCH 11/12] fs: allow to mount on subdirectories Sascha Hauer
2012-02-15 8:22 ` [PATCH 12/12] devices: unregister children when unregistering a device Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1329294165-12089-4-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox