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

Subversion Repositories or1k

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1628 jcastillo
/*
2
 *  linux/fs/minix/file.c
3
 *
4
 *  Copyright (C) 1991, 1992 Linus Torvalds
5
 *
6
 *  minix regular file handling primitives
7
 */
8
 
9
#include <linux/sched.h>
10
#include <linux/minix_fs.h>
11
#include <linux/kernel.h>
12
#include <linux/errno.h>
13
#include <linux/fcntl.h>
14
#include <linux/stat.h>
15
#include <linux/locks.h>
16
#include <linux/mm.h>
17
#include <linux/pagemap.h>
18
 
19
#include <asm/segment.h>
20
#include <asm/system.h>
21
 
22
#define NBUF    32
23
 
24
#define MIN(a,b) (((a)<(b))?(a):(b))
25
#define MAX(a,b) (((a)>(b))?(a):(b))
26
 
27
#include <linux/fs.h>
28
#include <linux/minix_fs.h>
29
 
30
static int minix_file_write(struct inode *, struct file *, const char *, int);
31
 
32
/*
33
 * We have mostly NULL's here: the current defaults are ok for
34
 * the minix filesystem.
35
 */
36
static struct file_operations minix_file_operations = {
37
        NULL,                   /* lseek - default */
38
        generic_file_read,      /* read */
39
        minix_file_write,       /* write */
40
        NULL,                   /* readdir - bad */
41
        NULL,                   /* select - default */
42
        NULL,                   /* ioctl - default */
43
        generic_file_mmap,      /* mmap */
44
        NULL,                   /* no special open is needed */
45
        NULL,                   /* release */
46
        minix_sync_file         /* fsync */
47
};
48
 
49
struct inode_operations minix_file_inode_operations = {
50
        &minix_file_operations, /* default file operations */
51
        NULL,                   /* create */
52
        NULL,                   /* lookup */
53
        NULL,                   /* link */
54
        NULL,                   /* unlink */
55
        NULL,                   /* symlink */
56
        NULL,                   /* mkdir */
57
        NULL,                   /* rmdir */
58
        NULL,                   /* mknod */
59
        NULL,                   /* rename */
60
        NULL,                   /* readlink */
61
        NULL,                   /* follow_link */
62
        generic_readpage,       /* readpage */
63
        NULL,                   /* writepage */
64
        minix_bmap,             /* bmap */
65
        minix_truncate,         /* truncate */
66
        NULL                    /* permission */
67
};
68
 
69
static int minix_file_write(struct inode * inode, struct file * filp, const char * buf, int count)
70
{
71
        off_t pos;
72
        int written,c;
73
        struct buffer_head * bh;
74
        char * p;
75
 
76
        if (!inode) {
77
                printk("minix_file_write: inode = NULL\n");
78
                return -EINVAL;
79
        }
80
        if (!S_ISREG(inode->i_mode)) {
81
                printk("minix_file_write: mode = %07o\n",inode->i_mode);
82
                return -EINVAL;
83
        }
84
        if (filp->f_flags & O_APPEND)
85
                pos = inode->i_size;
86
        else
87
                pos = filp->f_pos;
88
        written = 0;
89
        while (written < count) {
90
                bh = minix_getblk(inode,pos/BLOCK_SIZE,1);
91
                if (!bh) {
92
                        if (!written)
93
                                written = -ENOSPC;
94
                        break;
95
                }
96
                c = BLOCK_SIZE - (pos % BLOCK_SIZE);
97
                if (c > count-written)
98
                        c = count-written;
99
                if (c != BLOCK_SIZE && !buffer_uptodate(bh)) {
100
                        ll_rw_block(READ, 1, &bh);
101
                        wait_on_buffer(bh);
102
                        if (!buffer_uptodate(bh)) {
103
                                brelse(bh);
104
                                if (!written)
105
                                        written = -EIO;
106
                                break;
107
                        }
108
                }
109
                p = (pos % BLOCK_SIZE) + bh->b_data;
110
                memcpy_fromfs(p,buf,c);
111
                update_vm_cache(inode, pos, p, c);
112
                mark_buffer_uptodate(bh, 1);
113
                mark_buffer_dirty(bh, 0);
114
                brelse(bh);
115
                pos += c;
116
                written += c;
117
                buf += c;
118
        }
119
        if (pos > inode->i_size)
120
                inode->i_size = pos;
121
        inode->i_mtime = inode->i_ctime = CURRENT_TIME;
122
        filp->f_pos = pos;
123
        inode->i_dirt = 1;
124
        return written;
125
}

powered by: WebSVN 2.1.0

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