2009-12-20 21:41:50 +01:00
|
|
|
#include "fs.h"
|
|
|
|
#include "buf.h"
|
|
|
|
#include "inode.h"
|
|
|
|
#include <minix/vfsif.h>
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* fs_ftrunc *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int fs_ftrunc(message *fs_m_in, message *fs_m_out)
|
2009-12-20 21:41:50 +01:00
|
|
|
{
|
|
|
|
struct inode *rip;
|
2012-08-25 19:42:05 +02:00
|
|
|
off_t start;
|
2013-03-07 15:46:21 +01:00
|
|
|
pino_t inumb;
|
2012-02-13 16:28:04 +01:00
|
|
|
|
2013-03-07 15:46:21 +01:00
|
|
|
inumb = (pino_t) fs_m_in->REQ_INODE_NR;
|
2009-12-20 21:41:50 +01:00
|
|
|
|
2010-05-10 15:26:00 +02:00
|
|
|
if( (rip = find_inode(inumb)) == NULL) return(EINVAL);
|
2009-12-20 21:41:50 +01:00
|
|
|
|
2014-02-24 17:28:29 +01:00
|
|
|
start = fs_m_in->REQ_TRC_START;
|
2009-12-20 21:41:50 +01:00
|
|
|
|
|
|
|
return truncate_inode(rip, start);
|
|
|
|
}
|
2012-02-13 16:28:04 +01:00
|
|
|
|
2009-12-20 21:41:50 +01:00
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* truncate_inode *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int truncate_inode(rip, newsize)
|
2009-12-20 21:41:50 +01:00
|
|
|
register struct inode *rip; /* pointer to inode to be truncated */
|
|
|
|
off_t newsize; /* inode must become this size */
|
|
|
|
{
|
|
|
|
/* Set inode to a certain size, freeing any zones no longer referenced
|
|
|
|
* and updating the size in the inode. If the inode is extended, the
|
|
|
|
* extra space is a hole that reads as zeroes.
|
|
|
|
*
|
|
|
|
* Nothing special has to happen to file pointers if inode is opened in
|
2012-02-13 16:28:04 +01:00
|
|
|
* O_APPEND mode, as this is different per fd and is checked when
|
2009-12-20 21:41:50 +01:00
|
|
|
* writing is done.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Pipes can shrink, so adjust size to make sure all zones are removed. */
|
|
|
|
if(newsize != 0) return(EINVAL); /* Only truncate pipes to 0. */
|
|
|
|
rip->i_size = newsize;
|
2012-02-13 16:28:04 +01:00
|
|
|
|
2009-12-20 21:41:50 +01:00
|
|
|
/* Next correct the inode size. */
|
|
|
|
wipe_inode(rip); /* Pipes can only be truncated to 0. */
|
|
|
|
|
|
|
|
return(OK);
|
|
|
|
}
|