Subversion Repositories shark

Rev

Rev 3 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
 
1063 tullio 2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License as published by
5
 * the Free Software Foundation; either version 2 of the License, or
6
 * (at your option) any later version.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 * GNU General Public License for more details.
12
 *
13
 * You should have received a copy of the GNU General Public License
14
 * along with this program; if not, write to the Free Software
15
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 *
17
 */
18
 
2 pj 19
#include <fs/types.h>
20
#include <fs/errno.h>
21
#include <fs/task.h>
22
#include <fs/maccess.h>
23
#include <fs/fcntl.h>
24
 
25
#include "file.h"
26
#include "inode.h"
27
#include "dentry.h"
28
#include "fileop.h"
29
#include "dentryop.h"
30
#include "inodeop.h"
31
#include "fsconst.h"
32
#include "fs.h"
33
 
34
int k_ftruncate(int fd, __off_t len)
35
{
36
  struct inode *in;
37
  int res;
38
  __pid_t pid;
39
 
40
  call_to_fs();
41
 
42
  /* don't try to use a bad file descriptor */
43
  pid=__get_pid();
44
  if (check_fd(pid,fd)) {
45
    printk(KERN_INFO "k_ftruncate: using bad file descriptor");
46
    return_from_fs(-EBADF);
47
  }
48
 
49
  /* don't try to write a directory */
50
  if (file_ptr(pid,fd)->f_flag_isdir) return_from_fs(-EBADF);
51
 
52
  /* if in read only mode (errno OK?)*/
53
  if (*fildesfflags_ptr(pid,fd)&O_RDONLY)
54
    return_from_fs(-EPERM);
55
 
56
  /* acquire write lock on inode's file */
57
  in=file_ptr(pid,fd)->f_dentry->d_inode;
58
  __rwlock_wrlock(&in->i_lock);
59
 
60
  /*
61
  if (*fildesfflags_ptr(pid,fd)&O_APPEND)
62
    if (file_ptr(pid,fd)->f_pos!=
63
        file_ptr(pid,fd)->f_dentry->d_inode->i_st.st_size) {
64
      __off_t off;
65
      off=file_ptr(pid,fd)->f_op->lseek(file_ptr(pid,fd),0,SEEK_END);
66
      if (off!=file_ptr(pid,fd)->f_dentry->d_inode->i_st.st_size) {
67
        sz=-ESPIPE;
68
        goto SKIP;
69
      }
70
    }
71
    */
72
 
73
  /* truncate */
74
  res=in->i_op->truncate(in,len);
75
 
76
  /* release the lock */
77
  __rwlock_wrunlock(&in->i_lock);
78
 
79
  return_from_fs(res);
80
}