minix/servers/pfs/link.c

50 lines
1.5 KiB
C
Raw Normal View History

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;
off_t start;
pino_t inumb;
2012-02-13 16:28:04 +01:00
inumb = (pino_t) fs_m_in->REQ_INODE_NR;
2009-12-20 21:41:50 +01:00
if( (rip = find_inode(inumb)) == NULL) return(EINVAL);
2009-12-20 21:41:50 +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);
}