VFS/PFS: remove remnants of file position in pipes
This commit is contained in:
parent
306f3ccd6f
commit
b180f32ab3
2 changed files with 32 additions and 51 deletions
|
@ -1,7 +1,8 @@
|
||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
#include "buf.h"
|
#include "buf.h"
|
||||||
#include <minix/com.h>
|
|
||||||
#include "inode.h"
|
#include "inode.h"
|
||||||
|
#include <minix/com.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
/*===========================================================================*
|
/*===========================================================================*
|
||||||
|
@ -53,10 +54,10 @@ int fs_readwrite(message *fs_m_in, message *fs_m_out)
|
||||||
return(EFBIG);
|
return(EFBIG);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
position = bp->b_bytes;
|
position = 0;
|
||||||
if (nrbytes > rip->i_size - position) {
|
if (nrbytes > rip->i_size) {
|
||||||
/* There aren't that many bytes to read */
|
/* There aren't that many bytes to read */
|
||||||
nrbytes = rip->i_size - position;
|
nrbytes = rip->i_size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,25 +76,18 @@ int fs_readwrite(message *fs_m_in, message *fs_m_out)
|
||||||
cum_io += nrbytes;
|
cum_io += nrbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
fs_m_out->RES_SEEK_POS_LO = position; /* It might change later and the VFS
|
|
||||||
has to know this value */
|
|
||||||
|
|
||||||
/* On write, update file size and access time. */
|
/* On write, update file size and access time. */
|
||||||
if (rw_flag == WRITING) {
|
if (rw_flag == WRITING) {
|
||||||
if (position > f_size) rip->i_size = position;
|
rip->i_size = position;
|
||||||
} else {
|
} else {
|
||||||
if(position >= rip->i_size) {
|
memmove(bp->b_data, bp->b_data+nrbytes, rip->i_size - nrbytes);
|
||||||
/* All data in the pipe is read, so reset pipe pointers */
|
rip->i_size -= nrbytes;
|
||||||
rip->i_size = 0; /* no data left */
|
|
||||||
position = 0; /* reset reader(s) */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rw_flag == READING)
|
|
||||||
bp->b_bytes = position;
|
|
||||||
if (rw_flag == READING) rip->i_update |= ATIME;
|
if (rw_flag == READING) rip->i_update |= ATIME;
|
||||||
if (rw_flag == WRITING) rip->i_update |= CTIME | MTIME;
|
if (rw_flag == WRITING) rip->i_update |= CTIME | MTIME;
|
||||||
fs_m_out->RES_NBYTES = (size_t) cum_io;
|
fs_m_out->RES_NBYTES = (size_t) cum_io;
|
||||||
|
fs_m_out->RES_SEEK_POS_LO = rip->i_size;
|
||||||
|
|
||||||
put_inode(rip);
|
put_inode(rip);
|
||||||
put_block(rip->i_dev, rip->i_num);
|
put_block(rip->i_dev, rip->i_num);
|
||||||
|
|
|
@ -297,46 +297,33 @@ size_t req_size;
|
||||||
r = req_readwrite(vp->v_mapfs_e, vp->v_mapinode_nr, position, rw_flag, usr_e,
|
r = req_readwrite(vp->v_mapfs_e, vp->v_mapinode_nr, position, rw_flag, usr_e,
|
||||||
buf, size, &new_pos, &cum_io_incr);
|
buf, size, &new_pos, &cum_io_incr);
|
||||||
|
|
||||||
if (r >= 0) {
|
if (r != OK) {
|
||||||
if (ex64hi(new_pos))
|
return(r);
|
||||||
panic("rw_pipe: bad new pos");
|
|
||||||
|
|
||||||
cum_io += cum_io_incr;
|
|
||||||
buf += cum_io_incr;
|
|
||||||
req_size -= cum_io_incr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* On write, update file size and access time. */
|
if (ex64hi(new_pos))
|
||||||
if (rw_flag == WRITING) {
|
panic("rw_pipe: bad new pos");
|
||||||
if (cmp64ul(new_pos, vp->v_size) > 0) {
|
|
||||||
if (ex64hi(new_pos) != 0) {
|
cum_io += cum_io_incr;
|
||||||
panic("read_write: file size too big for v_size");
|
buf += cum_io_incr;
|
||||||
}
|
req_size -= cum_io_incr;
|
||||||
vp->v_size = ex64lo(new_pos);
|
|
||||||
}
|
vp->v_size = ex64lo(new_pos);
|
||||||
} else {
|
|
||||||
if (cmp64ul(new_pos, vp->v_size) >= 0) {
|
if (partial_pipe) {
|
||||||
/* Pipe emtpy; reset size */
|
/* partial write on pipe with */
|
||||||
vp->v_size = 0;
|
/* O_NONBLOCK, return write count */
|
||||||
|
if (!(oflags & O_NONBLOCK)) {
|
||||||
|
/* partial write on pipe with req_size > PIPE_SIZE,
|
||||||
|
* non-atomic
|
||||||
|
*/
|
||||||
|
fp->fp_cum_io_partial = cum_io;
|
||||||
|
pipe_suspend(f, buf, req_size);
|
||||||
|
return(SUSPEND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r == OK) {
|
fp->fp_cum_io_partial = 0;
|
||||||
if (partial_pipe) {
|
|
||||||
/* partial write on pipe with */
|
|
||||||
/* O_NONBLOCK, return write count */
|
|
||||||
if (!(oflags & O_NONBLOCK)) {
|
|
||||||
/* partial write on pipe with req_size > PIPE_SIZE,
|
|
||||||
* non-atomic
|
|
||||||
*/
|
|
||||||
fp->fp_cum_io_partial = cum_io;
|
|
||||||
pipe_suspend(f, buf, req_size);
|
|
||||||
return(SUSPEND);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fp->fp_cum_io_partial = 0;
|
|
||||||
return(cum_io);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(r);
|
return(cum_io);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue