@@ -113,9 +113,12 @@ void calculate_pfs_getdirentries(OrbisInternals::DirentCombination* spec, const
113113 spec->expected_errno = 0 ;
114114
115115 spec->expected_lseek = calculate_lseek (size, 0 , offset, 0 );
116- if (spec->expected_lseek < 0 ) spec->expected_errno = EINVAL ;
116+ if (spec->expected_lseek < 0 ) {
117+ spec->expected_errno = EINVAL ;
118+ }
119+ spec->expected_end_position = spec->expected_lseek >= 0 ? spec->expected_lseek : previous_basep;
117120
118- if (count = = 0 ) {
121+ if (count < = 0 ) {
119122 spec->expected_result = einval_int;
120123 spec->expected_errno = EINVAL ;
121124 return ;
@@ -126,8 +129,6 @@ void calculate_pfs_getdirentries(OrbisInternals::DirentCombination* spec, const
126129 s64 file_offset_down = ALDN (offset, 512 );
127130 s64 directory_size = ALUP (size, 0x10000 );
128131
129- offset = spec->expected_errno == EINVAL ? previous_basep : spec->expected_lseek ;
130-
131132 // within the same sector, no 512b alignment inbetween
132133 if (apparent_end_down <= file_offset_down) {
133134 spec->expected_result = s64 (einval_int);
@@ -136,8 +137,8 @@ void calculate_pfs_getdirentries(OrbisInternals::DirentCombination* spec, const
136137 return ;
137138 }
138139
139- spec->expected_basep = spec->expected_lseek >= 0 ? spec->expected_lseek : previous_basep;
140140 previous_basep = spec->expected_basep ;
141+ spec->expected_basep = spec->expected_lseek >= 0 ? spec->expected_lseek : previous_basep;
141142
142143 if (offset >= size) {
143144 spec->expected_result = 0 ;
@@ -194,9 +195,13 @@ void calculate_normal_getdirentries(OrbisInternals::DirentCombination* spec, con
194195 spec->expected_errno = 0 ;
195196
196197 spec->expected_lseek = calculate_lseek (size, 0 , offset, 0 );
197- if (spec->expected_lseek < 0 ) spec->expected_errno = EINVAL ;
198+ if (spec->expected_lseek < 0 ) {
199+ spec->expected_errno = EINVAL ;
200+ }
201+
202+ spec->expected_end_position = spec->expected_lseek >= 0 ? spec->expected_lseek : 0 ;
198203
199- if (count == 0 ) {
204+ if (count < 0 ) {
200205 spec->expected_result = einval_int;
201206 spec->expected_errno = EINVAL ;
202207 return ;
@@ -207,26 +212,27 @@ void calculate_normal_getdirentries(OrbisInternals::DirentCombination* spec, con
207212
208213 // within the same sector, no 512b alignment inbetween
209214 if (apparent_end_down <= ALDN (offset, 512 )) {
210- spec->expected_result = s64 (einval_int);
211- spec->expected_end_position = offset;
212- spec->expected_errno = EINVAL ;
215+ spec->expected_result = s64 (einval_int);
216+ // spec->expected_end_position = offset;
217+ spec->expected_errno = EINVAL ;
213218 return ;
214219 }
215220
216- spec->expected_basep = spec->expected_lseek >= 0 ? spec->expected_lseek : previous_basep;
217221 previous_basep = spec->expected_basep ;
222+ spec->expected_basep = spec->expected_lseek >= 0 ? spec->expected_lseek : previous_basep;
218223
219224 if (offset >= size) {
220225 // spec->expected_basep = offset;
221- spec->expected_result = 0 ;
222- spec->expected_end_position = offset;
223- spec->expected_errno = 0 ;
226+ spec->expected_result = 0 ;
227+ // spec->expected_end_position = offset;
228+ spec->expected_errno = 0 ;
224229 return ;
225230 }
226231 // we can now assume that offset always includes some data
227232 s64 allowed_count = std::min (apparent_end_down - offset, count);
233+ allowed_count = std::min (allowed_count, size - offset);
228234 spec->expected_result = allowed_count;
229- spec->expected_end_position = static_cast <s64>(offset + allowed_count);
235+ spec->expected_end_position = static_cast <s64>(spec-> expected_basep + allowed_count);
230236}
231237
232238s64 calculate_lseek (s64 directory_size, s64 file_offset, s64 offset, int whence) {
0 commit comments