From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from metis.ext.pengutronix.de ([2001:6f8:1178:4:290:27ff:fe1d:cc33]) by casper.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1RTYey-0005hc-RW for barebox@lists.infradead.org; Thu, 24 Nov 2011 12:44:14 +0000 Received: from dude.hi.pengutronix.de ([2001:6f8:1178:2:21e:67ff:fe11:9c5c]) by metis.ext.pengutronix.de with esmtp (Exim 4.72) (envelope-from ) id 1RTYej-0006pQ-9C for barebox@lists.infradead.org; Thu, 24 Nov 2011 13:43:57 +0100 Received: from jbe by dude.hi.pengutronix.de with local (Exim 4.77) (envelope-from ) id 1RTYei-0002LS-6r for barebox@lists.infradead.org; Thu, 24 Nov 2011 13:43:56 +0100 From: Juergen Beisert Date: Thu, 24 Nov 2011 13:43:40 +0100 Message-Id: <1322138631-8963-3-git-send-email-jbe@pengutronix.de> In-Reply-To: <1322138631-8963-1-git-send-email-jbe@pengutronix.de> References: <1322138631-8963-1-git-send-email-jbe@pengutronix.de> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: barebox-bounces@lists.infradead.org Errors-To: barebox-bounces+u.kleine-koenig=pengutronix.de@lists.infradead.org Subject: [PATCH 02/13] Create a unique cdev number for on demand devices To: barebox@lists.infradead.org For disk like devices attached to MCI, ATA or USB it depends on the order they will be recognized. So an unique number for all disk like devices is required. Signed-off-by: Juergen Beisert --- fs/devfs-core.c | 14 ++++++++++++++ include/driver.h | 1 + 2 files changed, 15 insertions(+), 0 deletions(-) diff --git a/fs/devfs-core.c b/fs/devfs-core.c index 519e18e..9bc3126 100644 --- a/fs/devfs-core.c +++ b/fs/devfs-core.c @@ -40,6 +40,20 @@ struct cdev *cdev_by_name(const char *filename) return NULL; } +int cdev_find_free_index(const char *basename) +{ + int i; + char fname[100]; + + for (i = 0; i < 1000; i++) { + snprintf(fname, sizeof(fname), "%s%d", basename, i); + if (cdev_by_name(fname) == NULL) + return i; + } + + return -EBUSY; /* all indexes are used */ +} + struct cdev *cdev_open(const char *name, unsigned long flags) { struct cdev *cdev = cdev_by_name(name); diff --git a/include/driver.h b/include/driver.h index 80de0c8..fe9d37a 100644 --- a/include/driver.h +++ b/include/driver.h @@ -394,6 +394,7 @@ struct cdev { int devfs_create(struct cdev *); int devfs_remove(struct cdev *); +int cdev_find_free_index(const char *); struct cdev *cdev_by_name(const char *filename); struct cdev *cdev_open(const char *name, unsigned long flags); void cdev_close(struct cdev *cdev); -- 1.7.7.1 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox