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().
45 lines
829 B
C
Executable file
45 lines
829 B
C
Executable file
#include <lib.h>
|
|
#define fcntl _fcntl
|
|
#include <fcntl.h>
|
|
#include <stdarg.h>
|
|
|
|
#if _ANSI
|
|
PUBLIC int fcntl(int fd, int cmd, ...)
|
|
#else
|
|
PUBLIC int fcntl(fd, cmd)
|
|
int fd;
|
|
int cmd;
|
|
#endif
|
|
{
|
|
va_list argp;
|
|
message m;
|
|
|
|
va_start(argp, cmd);
|
|
|
|
/* Set up for the sensible case where there is no variable parameter. This
|
|
* covers F_GETFD, F_GETFL and invalid commands.
|
|
*/
|
|
m.m1_i3 = 0;
|
|
m.m1_p1 = NIL_PTR;
|
|
|
|
/* Adjust for the stupid cases. */
|
|
switch(cmd) {
|
|
case F_DUPFD:
|
|
case F_SETFD:
|
|
case F_SETFL:
|
|
m.m1_i3 = va_arg(argp, int);
|
|
break;
|
|
case F_GETLK:
|
|
case F_SETLK:
|
|
case F_SETLKW:
|
|
case F_FREESP:
|
|
m.m1_p1 = (char *) va_arg(argp, struct flock *);
|
|
break;
|
|
}
|
|
|
|
/* Clean up and make the system call. */
|
|
va_end(argp);
|
|
m.m1_i1 = fd;
|
|
m.m1_i2 = cmd;
|
|
return(_syscall(FS, FCNTL, &m));
|
|
}
|