This commit is contained in:
Kevin Lange 2013-03-15 00:52:09 -07:00
parent 8dd2686b40
commit eb92cccecd
4 changed files with 37 additions and 24 deletions

View File

@ -15,7 +15,7 @@ uint32_t read_null(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buf
return 0;
}
memset(buffer, 0x00, 1);
return 1;
return 0;
}
uint32_t write_null(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer) {

View File

@ -51,7 +51,7 @@ fs_node_t * serial_device_create(int device) {
strcpy(fnode->name, "serial");
fnode->uid = 0;
fnode->gid = 0;
fnode->flags = 0;
fnode->flags = FS_CHARDEVICE;
fnode->read = read_serial;
fnode->write = write_serial;
fnode->open = open_serial;

View File

@ -135,14 +135,8 @@ int waitpid(int pid, int *status, int options) {
// --- I/O ---
/*
* isatty -- returns 1 if connected to a terminal device,
* returns 0 if not. Since we're hooked up to a
* serial port, we'll say yes and return a 1.
*/
int isatty(int fd) {
fprintf(stderr, "[debug] pid %d: isatty(%d);\n", getpid(), fd);
/* XXX: Do the right thing */
return (fd < 3);
}

View File

@ -7,6 +7,7 @@
* things like that.
*/
#include <stdio.h>
#include <sys/stat.h>
#define CHUNK_SIZE 4096
@ -24,23 +25,41 @@ int main(int argc, char ** argv) {
}
}
size_t length;
struct stat _stat;
fstat(fileno(fd), &_stat);
fseek(fd, 0, SEEK_END);
length = ftell(fd);
fseek(fd, 0, SEEK_SET);
if (S_ISCHR(_stat.st_mode)) {
/* character devices should be read byte by byte until we get a 0 respones */
char buf[CHUNK_SIZE];
while (length > CHUNK_SIZE) {
fread( buf, 1, CHUNK_SIZE, fd);
fwrite(buf, 1, CHUNK_SIZE, stdout);
fflush(stdout);
length -= CHUNK_SIZE;
}
if (length > 0) {
fread( buf, 1, length, fd);
fwrite(buf, 1, length, stdout);
fflush(stdout);
while (1) {
char buf[2];
size_t read = fread(buf, 1, 1, fd);
if (!read) {
break;
}
fwrite(buf, 1, read, stdout);
fflush(stdout);
}
} else {
size_t length;
fseek(fd, 0, SEEK_END);
length = ftell(fd);
fseek(fd, 0, SEEK_SET);
char buf[CHUNK_SIZE];
while (length > CHUNK_SIZE) {
fread( buf, 1, CHUNK_SIZE, fd);
fwrite(buf, 1, CHUNK_SIZE, stdout);
fflush(stdout);
length -= CHUNK_SIZE;
}
if (length > 0) {
fread( buf, 1, length, fd);
fwrite(buf, 1, length, stdout);
fflush(stdout);
}
}
fclose(fd);