OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [fs/] [nfs/] [file.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1628 jcastillo
/*
2
 *  linux/fs/nfs/file.c
3
 *
4
 *  Copyright (C) 1992  Rick Sladkey
5
 *
6
 *  Changes Copyright (C) 1994 by Florian La Roche
7
 *   - Do not copy data too often around in the kernel.
8
 *   - In nfs_file_read the return value of kmalloc wasn't checked.
9
 *   - Put in a better version of read look-ahead buffering. Original idea
10
 *     and implementation by Wai S Kok elekokws@ee.nus.sg.
11
 *
12
 *  Expire cache on write to a file by Wai S Kok (Oct 1994).
13
 *
14
 *  Total rewrite of read side for new NFS buffer cache.. Linus.
15
 *
16
 *  nfs regular file handling functions
17
 */
18
 
19
#include <linux/sched.h>
20
#include <linux/kernel.h>
21
#include <linux/errno.h>
22
#include <linux/fcntl.h>
23
#include <linux/stat.h>
24
#include <linux/mm.h>
25
#include <linux/nfs_fs.h>
26
#include <linux/malloc.h>
27
#include <linux/pagemap.h>
28
 
29
#include <asm/segment.h>
30
#include <asm/system.h>
31
 
32
static int nfs_file_mmap(struct inode *, struct file *, struct vm_area_struct *);
33
static int nfs_file_read(struct inode *, struct file *, char *, int);
34
static int nfs_file_write(struct inode *, struct file *, const char *, int);
35
static int nfs_fsync(struct inode *, struct file *);
36
 
37
static struct file_operations nfs_file_operations = {
38
        NULL,                   /* lseek - default */
39
        nfs_file_read,          /* read */
40
        nfs_file_write,         /* write */
41
        NULL,                   /* readdir - bad */
42
        NULL,                   /* select - default */
43
        NULL,                   /* ioctl - default */
44
        nfs_file_mmap,          /* mmap */
45
        NULL,                   /* no special open is needed */
46
        NULL,                   /* release */
47
        nfs_fsync,              /* fsync */
48
};
49
 
50
struct inode_operations nfs_file_inode_operations = {
51
        &nfs_file_operations,   /* default file operations */
52
        NULL,                   /* create */
53
        NULL,                   /* lookup */
54
        NULL,                   /* link */
55
        NULL,                   /* unlink */
56
        NULL,                   /* symlink */
57
        NULL,                   /* mkdir */
58
        NULL,                   /* rmdir */
59
        NULL,                   /* mknod */
60
        NULL,                   /* rename */
61
        NULL,                   /* readlink */
62
        NULL,                   /* follow_link */
63
        nfs_readpage,           /* readpage */
64
        NULL,                   /* writepage */
65
        NULL,                   /* bmap */
66
        NULL                    /* truncate */
67
};
68
 
69
static inline void revalidate_inode(struct nfs_server * server, struct inode * inode)
70
{
71
        struct nfs_fattr fattr;
72
 
73
        if (jiffies - NFS_READTIME(inode) < NFS_ATTRTIMEO(inode))
74
                return;
75
 
76
        NFS_READTIME(inode) = jiffies;
77
        if (nfs_proc_getattr(server, NFS_FH(inode), &fattr) == 0) {
78
                nfs_refresh_inode(inode, &fattr);
79
                if (fattr.mtime.seconds == NFS_OLDMTIME(inode)) {
80
                        if ((NFS_ATTRTIMEO(inode) <<= 1) > server->acregmax)
81
                                NFS_ATTRTIMEO(inode) = server->acregmax;
82
                        return;
83
                }
84
                NFS_OLDMTIME(inode) = fattr.mtime.seconds;
85
        }
86
        invalidate_inode_pages(inode);
87
}
88
 
89
 
90
static int nfs_file_read(struct inode * inode, struct file * file,
91
        char * buf, int count)
92
{
93
        revalidate_inode(NFS_SERVER(inode), inode);
94
        return generic_file_read(inode, file, buf, count);
95
}
96
 
97
static int nfs_file_mmap(struct inode * inode, struct file * file, struct vm_area_struct * vma)
98
{
99
        revalidate_inode(NFS_SERVER(inode), inode);
100
        return generic_file_mmap(inode, file, vma);
101
}
102
 
103
static int nfs_fsync(struct inode *inode, struct file *file)
104
{
105
        return 0;
106
}
107
 
108
static int nfs_file_write(struct inode *inode, struct file *file, const char *buf,
109
                          int count)
110
{
111
        int result, written, wsize;
112
        struct nfs_fattr fattr;
113
        unsigned long pos;
114
 
115
        if (!inode) {
116
                printk("nfs_file_write: inode = NULL\n");
117
                return -EINVAL;
118
        }
119
        if (!S_ISREG(inode->i_mode)) {
120
                printk("nfs_file_write: write to non-file, mode %07o\n",
121
                        inode->i_mode);
122
                return -EINVAL;
123
        }
124
        if (count <= 0)
125
                return 0;
126
 
127
        pos = file->f_pos;
128
        if (file->f_flags & O_APPEND)
129
                pos = inode->i_size;
130
        wsize = NFS_SERVER(inode)->wsize;
131
        result = 0;
132
        written = 0;
133
        while (written < count) {
134
                int hunk = count - written;
135
                if (hunk >= wsize)
136
                        hunk = wsize;
137
                result = nfs_proc_write(inode,
138
                        pos, hunk, buf, &fattr);
139
                if (result < 0)
140
                        break;
141
                pos += hunk;
142
                buf += hunk;
143
                written += hunk;
144
                if (hunk < wsize)
145
                        break;
146
        }
147
        if (!written)
148
                return result;
149
        file->f_pos = pos;
150
        if (pos > inode->i_size)
151
                inode->i_size = pos;
152
        /* Avoid possible Solaris 2.5 nfsd bug */
153
        if (inode->i_ino == fattr.fileid)
154
                nfs_refresh_inode(inode, &fattr);
155
        return written;
156
}
157
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.