kern
diff src/bdev.c @ 91:f83f50c17c3b
continuing with the fs
added strtol and strstr to klibc
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 09 Dec 2011 15:29:54 +0200 |
parents | 7ff2b4971216 |
children | 083849df660b |
line diff
1.1 --- a/src/bdev.c Fri Dec 09 13:44:15 2011 +0200 1.2 +++ b/src/bdev.c Fri Dec 09 15:29:54 2011 +0200 1.3 @@ -1,11 +1,13 @@ 1.4 #include <stdlib.h> 1.5 +#include <string.h> 1.6 #include <assert.h> 1.7 #include "bdev.h" 1.8 #include "ata.h" 1.9 #include "part.h" 1.10 1.11 -#define MINOR_DISK(x) (((x) >> 4) & 0xf) 1.12 -#define MINOR_PART(x) ((x) & 0xf) 1.13 +#define MKMINOR(disk, part) ((((disk) & 0xf) << 4) | ((part) & 0xf)) 1.14 +#define MINOR_DISK(x) (((x) >> 4) & 0xf) 1.15 +#define MINOR_PART(x) ((x) & 0xf) 1.16 1.17 struct block_device *blk_open(dev_t dev) 1.18 { 1.19 @@ -84,3 +86,35 @@ 1.20 } 1.21 return 0; 1.22 } 1.23 + 1.24 +dev_t bdev_by_name(const char *name) 1.25 +{ 1.26 + int minor; 1.27 + int atadev, part = 0; 1.28 + 1.29 + char *tmp = strrchr(name, '/'); 1.30 + if(tmp) { 1.31 + name = tmp + 1; 1.32 + } 1.33 + 1.34 + if(strstr(name, "ata") != name) { 1.35 + return 0; 1.36 + } 1.37 + name += 3; 1.38 + 1.39 + atadev = strtol(name, &tmp, 10); 1.40 + if(tmp == name) { 1.41 + return 0; 1.42 + } 1.43 + name = tmp; 1.44 + 1.45 + if(*name++ == 'p') { 1.46 + part = strtol(name, &tmp, 10) + 1; 1.47 + if(tmp == name) { 1.48 + return 0; 1.49 + } 1.50 + } 1.51 + 1.52 + minor = MKMINOR(atadev, part); 1.53 + return DEVNO(0, minor); 1.54 +}