mail archive of the rauc mailing list
 help / color / mirror / Atom feed
From: Ladislav Michl <ladis@linux-mips.org>
To: Trent Piepho <tpiepho@impinj.com>
Cc: rauc@pengutronix.de, Enrico Jorns <ejo@pengutronix.de>,
	Jan Luebbe <jlu@pengutronix.de>
Subject: Re: [RAUC] Failed to mount seed slot
Date: Wed, 8 May 2019 07:44:11 +0200	[thread overview]
Message-ID: <20190508054411.GA11035@lenoch> (raw)
In-Reply-To: <1557251975.31309.83.camel@impinj.com>

On Tue, May 07, 2019 at 05:59:36PM +0000, Trent Piepho wrote:
> On Tue, 2019-05-07 at 17:49 +0200, Ladislav Michl wrote:
> > On Tue, May 07, 2019 at 09:31:28AM +0200, Ladislav Michl wrote:
> >  typedef struct {
> > -	gboolean is_device;  // vs being a loop mounted file
> > -	dev_t dev;  // the device, or for a file, the device the file is on
> > -	ino_t inode;  // inode of file for a non-device
> > +	gboolean is_device;	/* vs being a loop mounted file */
> > +	dev_t dev;		/* the device, or for a file, the device the file is on */
> > +	ino_t inode;		/* inode of file for a non-device */
> >  } MountableObj;
> 
> There would also need to be another bool to indicate if the device is a
>  block dev or char dev, since the major:minor could match between
> different device types.  That could be part of a union with inode since
> the two are mutually exclusive.

As those functions are close to each other I didn't bothered with creating
an union and simply used 1 and 2 for is_device :)
Also directory can be a bind mount, so added that as well, however it is not
yet tested.

---
 src/config_file.c | 60 ++++++++++++++++++++++++++---------------------
 1 file changed, 33 insertions(+), 27 deletions(-)

diff --git a/src/config_file.c b/src/config_file.c
index 875e0ee..d966533 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -494,38 +494,44 @@ free:
 	return res;
 }
 
-// Something that is, or can be, mounted onto a mount point
+/* Something that is, or can be, mounted onto a mount point */
 typedef struct {
-	gboolean is_device;  // vs being a loop mounted file
-	dev_t dev;  // the device, or for a file, the device the file is on
-	ino_t inode;  // inode of file for a non-device
+	dev_t dev;		/* the device, or for a file, the device the file is on */
+	ino_t inode;		/* inode of file for a non-device */
+	gchar is_device;	/* vs being a loop mounted file */
 } MountableObj;
 
-// Take a device (or file) path and normalize it
-static MountableObj *normalize_mountable_object(const gchar *devicepath)
+/* Take a device (or file) path or name and normalize it */
+static gboolean normalize_mountable_object(const gchar *name, MountableObj *obj)
 {
-	MountableObj *obj;
 	GStatBuf st;
 
-	if (g_stat(devicepath, &st) == -1) {
+	if (g_stat(name, &st) == -1) {
 		/* Virtual filesystems like devpts trigger case */
-		g_debug("Can't stat '%s', assuming unmountable: %s", devicepath, g_strerror(errno));
-		return NULL;
+		g_debug("Can't stat '%s', assuming unmountable: %s", name, g_strerror(errno));
+		return FALSE;
 	}
 
-	obj = g_new0(MountableObj, 1);
-	if (S_ISBLK(st.st_mode)) {
-		obj->is_device = TRUE;
+	switch (st.st_mode & S_IFMT) {
+	case S_IFCHR:
+		obj->is_device = 1;
 		obj->dev = st.st_rdev;
-	} else if (S_ISREG(st.st_mode)) {
-		obj->is_device = FALSE;
+		break;
+	case S_IFBLK:
+		obj->is_device = 2;
+		obj->dev = st.st_rdev;
+		break;
+	case S_IFDIR:
+	case S_IFREG:
+		obj->is_device = 0;
 		obj->dev = st.st_dev;
 		obj->inode = st.st_ino;
-	} else {
-		g_debug("Device '%s' is not something which is mountable", devicepath);
-		g_clear_pointer(&obj, g_free);
+		break;
+	default:
+		g_debug("Device '%s' is unmountable", name);
+		return FALSE;
 	}
-	return obj;
+	return TRUE;
 }
 
 /* Compare two MountableObj for equality */
@@ -546,24 +552,24 @@ RaucSlot *find_slot_by_device(GHashTable *slots, const gchar *device)
 {
 	GHashTableIter iter;
 	RaucSlot *slot;
-	g_autofree MountableObj *obj = NULL;
+	MountableObj obj;
+	gboolean normalized;
 
 	g_return_val_if_fail(slots, NULL);
 	g_return_val_if_fail(device, NULL);
 
-	obj = normalize_mountable_object(device);
+	normalized = normalize_mountable_object(device, &obj);
 
 	g_hash_table_iter_init(&iter, slots);
 	while (g_hash_table_iter_next(&iter, NULL, (gpointer*) &slot)) {
 		if (g_strcmp0(slot->device, device) == 0)
 			goto out;
 
-		// Path doesn't match, but maybe device is same?
-		if (obj) {
-			g_autofree MountableObj *slot_obj =
-				normalize_mountable_object(slot->device);
-
-			if (slot_obj && is_same_mountable_object(obj, slot_obj))
+		/* Path doesn't match, but maybe device is the same? */
+		if (normalized) {
+			MountableObj slot_obj;
+			if (normalize_mountable_object(slot->device, &slot_obj) &&
+			    is_same_mountable_object(&obj, &slot_obj))
 				goto out;
 		}
 	}
-- 
2.20.1

      parent reply	other threads:[~2019-05-08  5:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-06 17:44 Ladislav Michl
2019-05-07  7:31 ` Ladislav Michl
2019-05-07 15:49   ` Ladislav Michl
2019-05-07 17:59     ` Trent Piepho
2019-05-07 20:33       ` Ladislav Michl
2019-05-09 11:32         ` Ladislav Michl
2019-05-08  5:44       ` Ladislav Michl [this message]

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=20190508054411.GA11035@lenoch \
    --to=ladis@linux-mips.org \
    --cc=ejo@pengutronix.de \
    --cc=jlu@pengutronix.de \
    --cc=rauc@pengutronix.de \
    --cc=tpiepho@impinj.com \
    /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