@@ -65,8 +65,23 @@ bool ndb_file::is_regular_file() const
65
65
return false ;
66
66
}
67
67
68
+ bool ndb_file::check_is_regular_file () const
69
+ {
70
+ #if defined(VM_TRACE) || !defined(NDEBUG) || defined(ERROR_INSERT)
71
+ if (!is_open ()) return true ;
72
+ struct stat sb;
73
+ if (fstat (m_handle, &sb) == -1 ) return true ;
74
+ if ((sb.st_mode & S_IFMT) == S_IFREG) return true ;
75
+ fprintf (stderr," FATAL ERROR: %s: %u: Handle is not a regular file: fd=%d file type=%o\n " ,__func__,__LINE__,m_handle,sb.st_mode &S_IFMT);
76
+ return false ;
77
+ #else
78
+ return true ;
79
+ #endif
80
+ }
81
+
68
82
int ndb_file::write_forward (const void * buf, ndb_file::size_t count)
69
83
{
84
+ require (check_is_regular_file ());
70
85
require (check_block_size_and_alignment (buf, count, get_pos ()));
71
86
int ret;
72
87
do {
@@ -83,6 +98,7 @@ int ndb_file::write_forward(const void* buf, ndb_file::size_t count)
83
98
int ndb_file::write_pos (const void * buf, ndb_file::size_t count,
84
99
ndb_off_t offset)
85
100
{
101
+ require (check_is_regular_file ());
86
102
require (check_block_size_and_alignment (buf, count, offset));
87
103
int ret;
88
104
do {
@@ -98,6 +114,7 @@ int ndb_file::write_pos(const void* buf, ndb_file::size_t count,
98
114
99
115
int ndb_file::read_forward (void * buf, ndb_file::size_t count) const
100
116
{
117
+ require (check_is_regular_file ());
101
118
require (check_block_size_and_alignment (buf, count, 1 ));
102
119
int ret;
103
120
do {
@@ -107,6 +124,7 @@ int ndb_file::read_forward(void* buf, ndb_file::size_t count) const
107
124
}
108
125
int ndb_file::read_backward (void * buf, ndb_file::size_t count) const
109
126
{
127
+ require (check_is_regular_file ());
110
128
require (check_block_size_and_alignment (buf, count, 1 ));
111
129
// Current pos must be within file.
112
130
// Current pos - count must be within file.
@@ -146,6 +164,7 @@ int ndb_file::read_backward(void* buf, ndb_file::size_t count) const
146
164
int ndb_file::read_pos (void * buf, ndb_file::size_t count,
147
165
ndb_off_t offset) const
148
166
{
167
+ require (check_is_regular_file ());
149
168
require (check_block_size_and_alignment (buf, count, offset));
150
169
int ret;
151
170
do {
0 commit comments