Skip to content

Commit

Permalink
Added I/O sync through ioctl for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
wavesoft committed Jan 11, 2012
1 parent 96f1e6f commit c1de3c8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
15 changes: 13 additions & 2 deletions includes/disk.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,17 @@ namespace fpio {
} bControlIn;
};

class disk: public errorbase {

//
// Disk I/O Class
//
// This class provides the required I/O interface with the floppy disk
// file or block device. It provides a memory-mapped structure with
// real-time communication with the other end.
//
class disk:
public errorbase
{
public:

// Constructor/Destructor
Expand All @@ -95,7 +105,8 @@ namespace fpio {

private:

int fd; // File descriptor
int fd; // File descriptor
bool useDevice; // Use device I/O (ioctl when needed) instead of file I/O

};

Expand Down
14 changes: 14 additions & 0 deletions src/disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
#include <errno.h>
#include <string.h>

#if defined __linux__
#include <linux/fd.h>
#endif

#include "../includes/disk.h"

using namespace fpio;
Expand All @@ -44,6 +48,7 @@ disk::disk(const char * file, int flags) {
this->useExceptions=true;
this->clear();
this->fd=0;
this->useDevice=false;

// Prepare the open flags
int oflags = O_RDWR | O_SYNC;
Expand All @@ -59,6 +64,9 @@ disk::disk(const char * file, int flags) {
oflags |= O_DIRECT; // Non-posix
#endif

// Enable device access
this->useDevice=true;

}

// Open the file
Expand Down Expand Up @@ -114,6 +122,12 @@ void disk::reset() {
void disk::sync() {
if (!this->ready()) return;
msync(this->map, SZ_FLOPPY, MS_SYNC | MS_INVALIDATE);
#if defined __linux__
if (this->useDevice) {
ioctl(this->fd, FDFLUSH, 0);
}
#endif

};

bool disk::ready() {
Expand Down

0 comments on commit c1de3c8

Please sign in to comment.