9
0
Fork 0

Create a unique cdev number for on demand devices

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 <jbe@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Juergen Beisert 2011-11-24 13:43:40 +01:00 committed by Sascha Hauer
parent 0c871d19dd
commit 3ca9f1812f
2 changed files with 15 additions and 0 deletions

View File

@ -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);

View File

@ -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);