00001 00017 #include <errno.h> 00018 #include <fcntl.h> 00019 #include <unistd.h> 00020 00021 #include "fsd_device.h" 00022 #include "fsd_debug.h" 00023 #include "fsd_defines.h" 00024 #include <stdio.h> 00025 #include <string.h> 00026 #include <stdlib.h> 00027 00028 00039 int fsd_chardevice_open() { 00040 return open(FSC_DEVICE_LOCATION, O_RDWR); 00041 } 00042 00043 00053 int fsd_chardevice_close(int fsc_device) { 00054 return close(fsc_device); 00055 } 00056 00057 00067 int fsd_chardevice_read(int fsc_device, char * buffer) { 00068 int result; 00069 if (!fsc_device) { 00070 return EFSC_DEVICE_NOT_OPEN; 00071 } 00072 00073 result = read(fsc_device, buffer, MAX_MESSAGE_LENGTH); 00074 switch (result) { 00075 case -EINVAL: 00076 PDEBUG("Fatal error: MAX_MESSAGE_LENGTH = (%d) is shorter than availible data from FSC device.\n", MAX_MESSAGE_LENGTH); 00077 break; 00078 case -EFAULT: 00079 PDEBUG("Fatal error: Data transfer from FSC device in kernel to FSD in user space failed.\n"); 00080 break; 00081 } 00082 00083 return result; 00084 } 00085 00086 00099 int fsd_chardevice_write(int fsc_device, const char* data, int count) { 00100 int result; 00101 if (!fsc_device) { 00102 return EFSC_DEVICE_NOT_OPEN; 00103 } 00104 00105 result = write(fsc_device, data, count); 00106 switch (result) { 00107 case -EINVAL: 00108 PDEBUG("Fatal error: number of chars in the message = (%d) is greater than FSC device input buffer size.\n", count); 00109 break; 00110 case -EFAULT: 00111 PDEBUG("Fatal error: Data transfer FSD in user space to FSC device in kernel failed.\n"); 00112 break; 00113 } 00114 return result; 00115 } 00116 00117