diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 32070c03a..aa2fdbdad 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,24 @@ +2004-04-09 Corinna Vinschen + + * fhandler.h (class fhandler_dev_raw): Move status bits into protected + bitfield struct type status_flags. Drop unused has_written bit. + Add accessor methods. + (fhandler_dev_raw::clear): Remove. + (fhandler_dev_raw::reset_devbuf): Remove. + * fhandler_floppy.cc (fhandler_dev_floppy::lseek): Use accessor method + for is_writing. + * fhandler_raw.cc: Use status accessor methods throughout. + (fhandler_dev_raw::clear): Remove. + (fhandler_dev_raw::fhandler_dev_raw): Drop clear call. + (fhandler_dev_raw::~fhandler_dev_raw): Ditto. + * fhandler_tape.cc: Use mtinfo::status accessor methods throughout. + (mtinfo_drive::close): Fix conditional to enable BSD semantics + correctly. + (mtinfo_drive::get_status): Rename from mtinfo_drive::status. + * mtinfo.h (class mtinfo_drive): Move status bits into private bitfield + struct type status_flags. Add accessor methods. + Rename status method to get_status. + 2004-04-09 Corinna Vinschen * path.cc (fsinfo): Global storage for file system information. diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index b889c8450..c3922b5a2 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -497,13 +497,27 @@ class fhandler_dev_raw: public fhandler_base size_t devbufsiz; size_t devbufstart; size_t devbufend; - int eom_detected : 1; - int eof_detected : 1; - int lastblk_to_read : 1; - int is_writing : 1; - int has_written : 1; + struct status_flags + { + unsigned eom_detected : 1; + unsigned eof_detected : 1; + unsigned lastblk_to_read : 1; + unsigned is_writing : 1; + public: + status_flags () : + eom_detected (0), eof_detected (0), lastblk_to_read (0), is_writing (0) + {} + } status; + + void eom_detected (bool b) { status.eom_detected = b; } + bool eom_detected () { return status.eom_detected; } + void eof_detected (bool b) { status.eof_detected = b; } + bool eof_detected () { return status.eof_detected; } + void lastblk_to_read (bool b) { status.lastblk_to_read = b; } + bool lastblk_to_read () { return status.lastblk_to_read; } + void is_writing (bool b) { status.is_writing = b; } + bool is_writing () { return status.is_writing; } - virtual void clear (void); virtual BOOL write_file (const void *buf, DWORD to_write, DWORD *written, int *err); virtual BOOL read_file (void *buf, DWORD to_read, DWORD *read, int *err); @@ -516,13 +530,6 @@ class fhandler_dev_raw: public fhandler_base fhandler_dev_raw (); - inline void reset_devbuf (void) - { - devbufstart = devbufend = 0; - eom_detected = eof_detected = 0; - lastblk_to_read = is_writing = has_written = 0; - } - public: ~fhandler_dev_raw (void); diff --git a/winsup/cygwin/fhandler_floppy.cc b/winsup/cygwin/fhandler_floppy.cc index 5d715adc7..2d17d99e6 100644 --- a/winsup/cygwin/fhandler_floppy.cc +++ b/winsup/cygwin/fhandler_floppy.cc @@ -144,7 +144,7 @@ fhandler_dev_floppy::lseek (_off64_t offset, int whence) return -1; } current_position = low + ((_off64_t) high << 32); - if (is_writing) + if (is_writing ()) current_position += devbufend - devbufstart; else current_position -= devbufend - devbufstart; diff --git a/winsup/cygwin/fhandler_raw.cc b/winsup/cygwin/fhandler_raw.cc index c54ca5c53..ca012aa6a 100644 --- a/winsup/cygwin/fhandler_raw.cc +++ b/winsup/cygwin/fhandler_raw.cc @@ -27,18 +27,6 @@ /**********************************************************************/ /* fhandler_dev_raw */ -void -fhandler_dev_raw::clear (void) -{ - devbuf = NULL; - devbufsiz = 0; - devbufstart = 0; - devbufend = 0; - eom_detected = 0; - eof_detected = 0; - lastblk_to_read = 0; -} - int fhandler_dev_raw::is_eom (int win_error) { @@ -88,7 +76,7 @@ fhandler_dev_raw::writebuf (void) DWORD written; int ret = 0; - if (is_writing && devbuf && devbufend) + if (is_writing () && devbuf && devbufend) { DWORD to_write; int ret = 0; @@ -97,19 +85,16 @@ fhandler_dev_raw::writebuf (void) to_write = ((devbufend - 1) / 512 + 1) * 512; if (!write_file (devbuf, to_write, &written, &ret) && is_eom (ret)) - eom_detected = 1; - if (written) - has_written = 1; + eom_detected (true); devbufstart = devbufend = 0; } - is_writing = 0; + is_writing (false); return ret; } fhandler_dev_raw::fhandler_dev_raw () - : fhandler_base () + : fhandler_base (), status () { - clear (); set_need_fork_fixup (); } @@ -117,7 +102,6 @@ fhandler_dev_raw::~fhandler_dev_raw (void) { if (devbufsiz > 1L) delete [] devbuf; - clear (); } int __stdcall @@ -226,15 +210,15 @@ fhandler_dev_raw::raw_read (void *ptr, size_t& ulen) } /* Checking a previous end of file */ - if (eof_detected && !lastblk_to_read) + if (eof_detected () && !lastblk_to_read ()) { - eof_detected = 0; + eof_detected (false); ulen = 0; return; } /* Checking a previous end of media */ - if (eom_detected && !lastblk_to_read) + if (eom_detected () && !lastblk_to_read ()) { set_errno (ENOSPC); goto err; @@ -256,9 +240,9 @@ fhandler_dev_raw::raw_read (void *ptr, size_t& ulen) bytes_read += bytes_to_read; devbufstart += bytes_to_read; - if (lastblk_to_read) + if (lastblk_to_read ()) { - lastblk_to_read = 0; + lastblk_to_read (false); break; } } @@ -286,9 +270,9 @@ fhandler_dev_raw::raw_read (void *ptr, size_t& ulen) } if (is_eof (ret)) - eof_detected = 1; + eof_detected (true); else - eom_detected = 1; + eom_detected (true); if (!read2) { @@ -300,7 +284,7 @@ fhandler_dev_raw::raw_read (void *ptr, size_t& ulen) } break; } - lastblk_to_read = 1; + lastblk_to_read (true); } if (!read2) break; @@ -328,9 +312,9 @@ fhandler_dev_raw::raw_read (void *ptr, size_t& ulen) if (bytes_read) { if (is_eof (ret)) - eof_detected = 1; + eof_detected (true); else - eom_detected = 1; + eom_detected (true); } else if (is_eom (ret)) { @@ -359,15 +343,15 @@ fhandler_dev_raw::raw_write (const void *ptr, size_t len) int ret; /* Checking a previous end of media on tape */ - if (eom_detected) + if (eom_detected ()) { set_errno (ENOSPC); return -1; } - if (!is_writing) + if (!is_writing ()) devbufstart = devbufend = 0; - is_writing = 1; + is_writing (true); if (devbuf) { @@ -397,8 +381,6 @@ fhandler_dev_raw::raw_write (const void *ptr, size_t len) ret = 0; write_file (tgt, bytes_to_write, &written, &ret); - if (written) - has_written = 1; if (ret) { @@ -408,7 +390,7 @@ fhandler_dev_raw::raw_write (const void *ptr, size_t len) return -1; } - eom_detected = 1; + eom_detected (true); if (!written && !bytes_written) { @@ -441,21 +423,18 @@ fhandler_dev_raw::raw_write (const void *ptr, size_t len) { if (!write_file (p, len, &bytes_written, &ret)) { - if (bytes_written) - has_written = 1; if (!is_eom (ret)) { __seterrno (); return -1; } - eom_detected = 1; + eom_detected (true); if (!bytes_written) { set_errno (ENOSPC); return -1; } } - has_written = 1; } return bytes_written; } @@ -474,9 +453,9 @@ fhandler_dev_raw::dup (fhandler_base *child) fhc->devbuf = new char [devbufsiz]; fhc->devbufstart = 0; fhc->devbufend = 0; - fhc->eom_detected = eom_detected; - fhc->eof_detected = eof_detected; - fhc->lastblk_to_read = 0; + fhc->eom_detected (eom_detected ()); + fhc->eof_detected (eof_detected ()); + fhc->lastblk_to_read (false); } return ret; } @@ -486,7 +465,7 @@ fhandler_dev_raw::fixup_after_fork (HANDLE) { devbufstart = 0; devbufend = 0; - lastblk_to_read = 0; + lastblk_to_read (false); } void @@ -496,7 +475,7 @@ fhandler_dev_raw::fixup_after_exec () devbuf = new char [devbufsiz]; devbufstart = 0; devbufend = 0; - lastblk_to_read = 0; + lastblk_to_read (false); } int diff --git a/winsup/cygwin/fhandler_tape.cc b/winsup/cygwin/fhandler_tape.cc index e3c0fdc4c..caebaed89 100644 --- a/winsup/cygwin/fhandler_tape.cc +++ b/winsup/cygwin/fhandler_tape.cc @@ -80,12 +80,12 @@ mtinfo_drive::initialize (int num, bool first_time) lock = unlocked; if (first_time) { - buffer_writes = true; - two_fm = false; - fast_eom = false; - auto_lock = false; - sysv = false; - nowait = false; + buffer_writes (true); + two_fm (false); + fast_eom (false); + auto_lock (false); + sysv (false); + nowait (false); } for (int i = 0; i < MAX_PARTITION_NUM; ++i) part (i)->initialize (); @@ -139,17 +139,17 @@ mtinfo_drive::close (HANDLE mt, bool rewind) { /* if last operation was writing, write a filemark */ debug_printf ("writing filemark"); - write_marks (mt, TAPE_FILEMARKS, two_fm ? 2 : 1); - if (two_fm && !lasterr && !rewind) /* Backspace over the 2nd filemark. */ + write_marks (mt, TAPE_FILEMARKS, two_fm () ? 2 : 1); + if (two_fm () && !lasterr && !rewind) /* Backspace over 2nd filemark. */ { set_pos (mt, TAPE_SPACE_FILEMARKS, -1, false); if (!lasterr) part (partition)->fblock = 0; /* That's obvious, isn't it? */ } } - else if (dirty == has_read && sysv && !rewind) + else if (dirty == has_read && !rewind) { - if (sysv) + if (sysv ()) { /* Under SYSV semantics, the tape is moved past the next file mark after read. */ @@ -172,7 +172,7 @@ mtinfo_drive::close (HANDLE mt, bool rewind) debug_printf ("rewinding"); set_pos (mt, TAPE_REWIND, 0, false); } - if (auto_lock && lock == auto_locked) + if (auto_lock () && lock == auto_locked) prepare (mt, TAPE_UNLOCK); dirty = clean; return error ("close"); @@ -223,7 +223,7 @@ mtinfo_drive::read (HANDLE mt, void *ptr, size_t &ulen) goto out; } part (partition)->smark = false; - if (auto_lock && lock < auto_locked) + if (auto_lock () && lock < auto_locked) prepare (mt, TAPE_LOCK, true); ret = ReadFile (mt, ptr, ulen, &bytes_read, 0); lasterr = ret ? 0 : GetLastError (); @@ -287,7 +287,7 @@ mtinfo_drive::write (HANDLE mt, const void *ptr, size_t &len) } dirty = clean; part (partition)->smark = false; - if (auto_lock && lock < auto_locked) + if (auto_lock () && lock < auto_locked) prepare (mt, TAPE_LOCK, true); ret = WriteFile (mt, ptr, len, &bytes_written, 0); lasterr = ret ? 0: GetLastError (); @@ -372,7 +372,7 @@ mtinfo_drive::set_pos (HANDLE mt, int mode, long count, case TAPE_ABSOLUTE_BLOCK: case TAPE_LOGICAL_BLOCK: case TAPE_REWIND: - dont_wait = nowait ? TRUE : FALSE; + dont_wait = nowait () ? TRUE : FALSE; break; } if (mode == TAPE_SPACE_FILEMARKS) @@ -629,7 +629,7 @@ mtinfo_drive::erase (HANDLE mt, int mode) mode = TAPE_ERASE_SHORT; break; } - TAPE_FUNC (EraseTape (mt, mode, nowait ? TRUE : FALSE)); + TAPE_FUNC (EraseTape (mt, mode, nowait () ? TRUE : FALSE)); part (partition)->initialize (0); return error ("erase"); } @@ -641,7 +641,7 @@ mtinfo_drive::prepare (HANDLE mt, int action, bool is_auto) dirty = clean; if (action == TAPE_UNLOAD || action == TAPE_LOAD || action == TAPE_TENSION) - dont_wait = nowait ? TRUE : FALSE; + dont_wait = nowait () ? TRUE : FALSE; TAPE_FUNC (PrepareTape (mt, action, dont_wait)); /* Reset buffer after all successful preparations but lock and unlock. */ switch (action) @@ -696,7 +696,7 @@ mtinfo_drive::set_blocksize (HANDLE mt, long count) } int -mtinfo_drive::status (HANDLE mt, struct mtget *get) +mtinfo_drive::get_status (HANDLE mt, struct mtget *get) { int notape = 0; DWORD tstat; @@ -778,7 +778,7 @@ mtinfo_drive::status (HANDLE mt, struct mtget *get) if (notape) get->mt_gstat |= GMT_DR_OPEN (-1); - if (buffer_writes) + if (buffer_writes ()) get->mt_gstat |= GMT_IM_REP_EN (-1); /* TODO: Async writes */ else if (tstat == ERROR_DEVICE_REQUIRES_CLEANING) @@ -793,15 +793,15 @@ mtinfo_drive::status (HANDLE mt, struct mtget *get) get->mt_gstat |= GMT_HW_ECC (-1); if (dp ()->Compression) get->mt_gstat |= GMT_HW_COMP (-1); - if (two_fm) + if (two_fm ()) get->mt_gstat |= GMT_TWO_FM (-1); - if (fast_eom) + if (fast_eom ()) get->mt_gstat |= GMT_FAST_MTEOM (-1); - if (auto_lock) + if (auto_lock ()) get->mt_gstat |= GMT_AUTO_LOCK (-1); - if (sysv) + if (sysv ()) get->mt_gstat |= GMT_SYSV (-1); - if (nowait) + if (nowait ()) get->mt_gstat |= GMT_NOWAIT (-1); get->mt_erreg = 0; /* FIXME: No softerr counting */ @@ -837,16 +837,16 @@ mtinfo_drive::set_options (HANDLE mt, long options) case 0: if (options == 0 || options == 1) { - buffer_writes = (options == 1); + buffer_writes ((options == 1)); } break; case MT_ST_BOOLEANS: - buffer_writes = !!(options & MT_ST_BUFFER_WRITES); - two_fm = !!(options & MT_ST_TWO_FM); - fast_eom = !!(options & MT_ST_FAST_MTEOM); - auto_lock = !!(options & MT_ST_AUTO_LOCK); - sysv = !!(options & MT_ST_SYSV); - nowait = !!(options & MT_ST_NOWAIT); + buffer_writes (!!(options & MT_ST_BUFFER_WRITES)); + two_fm (!!(options & MT_ST_TWO_FM)); + fast_eom (!!(options & MT_ST_FAST_MTEOM)); + auto_lock (!!(options & MT_ST_AUTO_LOCK)); + sysv (!!(options & MT_ST_SYSV)); + nowait (!!(options & MT_ST_NOWAIT)); if (get_feature (TAPE_DRIVE_SET_ECC)) sdp.ECC = !!(options & MT_ST_ECC); if (get_feature (TAPE_DRIVE_SET_PADDING)) @@ -861,17 +861,17 @@ mtinfo_drive::set_options (HANDLE mt, long options) case MT_ST_CLEARBOOLEANS: set = (what == MT_ST_SETBOOLEANS); if (options & MT_ST_BUFFER_WRITES) - buffer_writes = set; + buffer_writes (set); if (options & MT_ST_TWO_FM) - two_fm = set; + two_fm (set); if (options & MT_ST_FAST_MTEOM) - fast_eom = set; + fast_eom (set); if (options & MT_ST_AUTO_LOCK) - auto_lock = set; + auto_lock (set); if (options & MT_ST_SYSV) - sysv = set; + sysv (set); if (options & MT_ST_NOWAIT) - nowait = set; + nowait (set); if (options & MT_ST_ECC) sdp.ECC = set; if (options & MT_ST_PADDING) @@ -974,7 +974,7 @@ mtinfo_drive::ioctl (HANDLE mt, unsigned int cmd, void *buf) set_pos (mt, TAPE_SPACE_FILEMARKS, op->mt_count, true); break; case MTEOM: - if (fast_eom && get_feature (TAPE_DRIVE_END_OF_DATA)) + if (fast_eom () && get_feature (TAPE_DRIVE_END_OF_DATA)) set_pos (mt, TAPE_SPACE_END_OF_DATA, 0, false); else set_pos (mt, TAPE_SPACE_FILEMARKS, 32767, false); @@ -1062,7 +1062,7 @@ mtinfo_drive::ioctl (HANDLE mt, unsigned int cmd, void *buf) { if (__check_null_invalid_struct (buf, sizeof (struct mtget))) return ERROR_NOACCESS; - status (mt, (struct mtget *) buf); + get_status (mt, (struct mtget *) buf); } else if (cmd == MTIOCPOS) { @@ -1169,7 +1169,7 @@ fhandler_dev_tape::open (int flags, mode_t) /* The O_TEXT flag is used to indicate write-through (non buffered writes) to the underlying fhandler_dev_raw::open call. */ flags &= ~O_TEXT; - if (!mt->drive (driveno ())->buffered_writes ()) + if (!mt->drive (driveno ())->buffer_writes ()) flags |= O_TEXT; ret = fhandler_dev_raw::open (flags); if (ret) @@ -1213,9 +1213,9 @@ fhandler_dev_tape::raw_read (void *ptr, size_t &ulen) size_t bytes_read = 0; int ret = 0; - if (lastblk_to_read) + if (lastblk_to_read ()) { - lastblk_to_read = 0; + lastblk_to_read (false); ulen = 0; return; } @@ -1265,7 +1265,7 @@ fhandler_dev_tape::raw_read (void *ptr, size_t &ulen) else { len = 0; if (bytes_read) - lastblk_to_read = 1; + lastblk_to_read (true); } } if (!ret && len > 0) @@ -1283,7 +1283,7 @@ fhandler_dev_tape::raw_read (void *ptr, size_t &ulen) memcpy (buf, devbuf, len); } else if (bytes_read) - lastblk_to_read = 1; + lastblk_to_read (true); } } if (ret) diff --git a/winsup/cygwin/mtinfo.h b/winsup/cygwin/mtinfo.h index 31260d17f..d6a9c505b 100644 --- a/winsup/cygwin/mtinfo.h +++ b/winsup/cygwin/mtinfo.h @@ -67,12 +67,15 @@ class mtinfo_drive lock_state lock; TAPE_GET_DRIVE_PARAMETERS _dp; TAPE_GET_MEDIA_PARAMETERS _mp; - bool buffer_writes; - bool two_fm; - bool fast_eom; - bool auto_lock; - bool sysv; - bool nowait; + struct status_flags + { + unsigned buffer_writes : 1; + unsigned two_fm : 1; + unsigned fast_eom : 1; + unsigned auto_lock : 1; + unsigned sysv : 1; + unsigned nowait : 1; + } status; mtinfo_part _part[MAX_PARTITION_NUM]; inline int error (const char *str) @@ -96,7 +99,7 @@ class mtinfo_drive int prepare (HANDLE mt, int action, bool is_auto = false); int set_compression (HANDLE mt, long count); int set_blocksize (HANDLE mt, long count); - int status (HANDLE mt, struct mtget *get); + int get_status (HANDLE mt, struct mtget *get); int set_options (HANDLE mt, long options); public: @@ -110,7 +113,18 @@ public: int ioctl (HANDLE mt, unsigned int cmd, void *buf); int set_pos (HANDLE mt, int mode, long count, bool sfm_func); - inline bool buffered_writes (void) { return buffer_writes; } + void buffer_writes (bool b) { status.buffer_writes = b; } + bool buffer_writes () { return status.buffer_writes; } + void two_fm (bool b) { status.two_fm = b; } + bool two_fm () { return status.two_fm; } + void fast_eom (bool b) { status.fast_eom = b; } + bool fast_eom () { return status.fast_eom; } + void auto_lock (bool b) { status.auto_lock = b; } + bool auto_lock () { return status.auto_lock; } + void sysv (bool b) { status.sysv = b; } + bool sysv () { return status.sysv; } + void nowait (bool b) { status.nowait = b; } + bool nowait () { return status.nowait; } PTAPE_GET_DRIVE_PARAMETERS dp (void) { return &_dp; } PTAPE_GET_MEDIA_PARAMETERS mp (void) { return &_mp; } mtinfo_part *part (int num) { return &_part[num]; }