mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-29 13:48:21 +00:00
devman and vfs: check if a function is not implemented before calling
This commit is contained in:
@@ -31,6 +31,10 @@ int devman_write(int *error, int dev, void* buff, size_t count, size_t offset){
|
||||
if(major(dev) > highestmajor)
|
||||
return ENODEV;
|
||||
|
||||
|
||||
if(!majorcalls[major(dev)]->write)
|
||||
return ENOTTY;
|
||||
|
||||
return majorcalls[major(dev)]->write(error, minor(dev), buff, count, offset);
|
||||
|
||||
|
||||
@@ -40,6 +44,9 @@ int devman_read(int *error, int dev, void* buff, size_t count, size_t offset){
|
||||
|
||||
if(major(dev) > highestmajor)
|
||||
return ENODEV;
|
||||
|
||||
if(!majorcalls[major(dev)]->read)
|
||||
return ENOTTY;
|
||||
|
||||
|
||||
return majorcalls[major(dev)]->read(error, minor(dev), buff, count, offset);
|
||||
@@ -51,6 +58,9 @@ int devman_isatty(int dev){
|
||||
|
||||
if(major(dev) > highestmajor)
|
||||
return ENOTTY;
|
||||
|
||||
if(!majorcalls[major(dev)]->isatty)
|
||||
return ENOTTY;
|
||||
|
||||
return majorcalls[major(dev)]->isatty(minor(dev));
|
||||
|
||||
@@ -61,6 +71,10 @@ int devman_isseekable(int dev, size_t* max){
|
||||
if(major(dev) > highestmajor)
|
||||
return ENOTTY;
|
||||
|
||||
if(!majorcalls[major(dev)]->isseekable)
|
||||
return 0;
|
||||
|
||||
|
||||
return majorcalls[major(dev)]->isseekable(minor(dev), max);
|
||||
|
||||
}
|
||||
|
||||
+1
-10
@@ -127,7 +127,6 @@ int keyboard_getnew(){
|
||||
|
||||
}
|
||||
|
||||
static int write(int *error, int minor, void* buff, size_t count){*error = EINVAL; return -1;}
|
||||
static int read(int *error, int minor, void* buff, size_t count, size_t offset){
|
||||
count /= sizeof(kbpacket_t);
|
||||
if(count == 0){
|
||||
@@ -146,16 +145,8 @@ static int read(int *error, int minor, void* buff, size_t count, size_t offset){
|
||||
|
||||
}
|
||||
|
||||
static int isatty(){
|
||||
return ENOTTY;
|
||||
}
|
||||
|
||||
static int seekable(){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static devcalls calls = {
|
||||
read, write, isatty, seekable
|
||||
read
|
||||
};
|
||||
|
||||
void keyboard_init(){
|
||||
|
||||
@@ -13,17 +13,13 @@ static int write(int* error, int minor, void* buff, size_t count, size_t offset)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int isatty(int minor){
|
||||
return ENOTTY;
|
||||
}
|
||||
|
||||
static int isseekable(int minor, size_t* max){
|
||||
*max = ~(size_t)0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static devcalls calls = {
|
||||
read, write, isatty, isseekable
|
||||
read, write, NULL, isseekable
|
||||
};
|
||||
|
||||
void fulldev_init(){
|
||||
|
||||
@@ -12,17 +12,13 @@ static int write(int* error, int minor, void* buff, size_t count, size_t offset)
|
||||
return count;
|
||||
}
|
||||
|
||||
static int isatty(int minor){
|
||||
return ENOTTY;
|
||||
}
|
||||
|
||||
static int isseekable(int minor, size_t* max){
|
||||
*max = ~(size_t)0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static devcalls calls = {
|
||||
read, write, isatty, isseekable
|
||||
read, write, NULL, isseekable
|
||||
};
|
||||
|
||||
void nulldev_init(){
|
||||
|
||||
@@ -13,17 +13,13 @@ static int write(int* error, int minor, void* buff, size_t count, size_t offset)
|
||||
return count;
|
||||
}
|
||||
|
||||
static int isatty(int minor){
|
||||
return ENOTTY;
|
||||
}
|
||||
|
||||
static int isseekable(int minor, size_t* max){
|
||||
*max = ~(size_t)0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static devcalls calls = {
|
||||
read, write, isatty, isseekable
|
||||
read, write, NULL, isseekable
|
||||
};
|
||||
|
||||
void zerodev_init(){
|
||||
|
||||
Reference in New Issue
Block a user