minix/lib/posix/_truncate.c
Ben Gras 50b06261b6 Implementation of truncate(), ftruncate() and the F_FREESP fcntl().
Implemented by changing write_map to accept a WMAP_FREE flag. In that
case, it doesn't update the datablock (creating indirect zones as
necessary) pointer, but it frees the datablock if present. Also it
frees the single and double indirect blocks if unused.

This makes the implementation of truncate_inode() simpler.
truncate_inode() now accepts a truncation length which makes
implementing truncate() and ftruncate() simple.

This also allowed implementing the F_FREESP fcntl().
2006-01-11 17:14:51 +00:00

24 lines
443 B
C
Executable file

#include <lib.h>
#include <string.h>
#define truncate _truncate
#define ftruncate _ftruncate
#include <unistd.h>
PUBLIC int truncate(const char *_path, off_t _length)
{
message m;
m.m2_p1 = (char *) _path;
m.m2_i1 = strlen(_path)+1;
m.m2_l1 = _length;
return(_syscall(FS, TRUNCATE, &m));
}
PUBLIC int ftruncate(int _fd, off_t _length)
{
message m;
m.m2_l1 = _length;
m.m2_i1 = _fd;
return(_syscall(FS, FTRUNCATE, &m));
}