I have implemented a character device driver on CentOS 7. The driver is functioning normally when it is called from a C program, thusly...
char bytes[8];
int fd = open("/dev/fortuna", O_RDONLY);
if (fd < 0) {
perror("File open error: ");
return -1;
}
int in = read(fd, bytes, 8);
if (in < 0) {
perror("File read error: ");
}
close(fd);
The driver read function is invoked with count = 8 and the program completes with no errors. The driver function prototype is...
static ssize_t fortuna_read(struct file *filp, char *buff, size_t count, loff_t *offp);
However, if the read is invoked from a C++ stream, as follows...
char bytes[8];
std::ifstream in("/dev/fortuna");
if (in.good()) {
in.read(bytes, 8);
}
in.close();
The driver read function is invoked with count = 8191. If the driver is invoked from a Java FileReader, as follows...
File file = new File("/dev/fortuna");
file.setReadOnly();
FileReader reader = new FileReader(file);
char[] cbuf = new char[8];
int read = reader.read(cbuf);
reader.close();
The driver read function is invoked with count = 8192. The write functions behave similarly.
Google has failed me. Help?