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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [rc203soc/] [sw/] [uClinux/] [fs/] [ext2/] [symlink.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1628 jcastillo
/*
2
 *  linux/fs/ext2/symlink.c
3
 *
4
 * Copyright (C) 1992, 1993, 1994, 1995
5
 * Remy Card (card@masi.ibp.fr)
6
 * Laboratoire MASI - Institut Blaise Pascal
7
 * Universite Pierre et Marie Curie (Paris VI)
8
 *
9
 *  from
10
 *
11
 *  linux/fs/minix/symlink.c
12
 *
13
 *  Copyright (C) 1991, 1992  Linus Torvalds
14
 *
15
 *  ext2 symlink handling code
16
 */
17
 
18
#include <asm/segment.h>
19
 
20
#include <linux/errno.h>
21
#include <linux/fs.h>
22
#include <linux/ext2_fs.h>
23
#include <linux/sched.h>
24
#include <linux/stat.h>
25
 
26
static int ext2_readlink (struct inode *, char *, int);
27
static int ext2_follow_link (struct inode *, struct inode *, int, int,
28
                               struct inode **);
29
 
30
/*
31
 * symlinks can't do much...
32
 */
33
struct inode_operations ext2_symlink_inode_operations = {
34
        NULL,                   /* no file-operations */
35
        NULL,                   /* create */
36
        NULL,                   /* lookup */
37
        NULL,                   /* link */
38
        NULL,                   /* unlink */
39
        NULL,                   /* symlink */
40
        NULL,                   /* mkdir */
41
        NULL,                   /* rmdir */
42
        NULL,                   /* mknod */
43
        NULL,                   /* rename */
44
        ext2_readlink,          /* readlink */
45
        ext2_follow_link,       /* follow_link */
46
        NULL,                   /* readpage */
47
        NULL,                   /* writepage */
48
        NULL,                   /* bmap */
49
        NULL,                   /* truncate */
50
        NULL,                   /* permission */
51
        NULL                    /* smap */
52
};
53
 
54
static int ext2_follow_link(struct inode * dir, struct inode * inode,
55
                            int flag, int mode, struct inode ** res_inode)
56
{
57
        int error;
58
        struct buffer_head * bh = NULL;
59
        char * link;
60
 
61
        *res_inode = NULL;
62
        if (!dir) {
63
                dir = current->fs->root;
64
                dir->i_count++;
65
        }
66
        if (!inode) {
67
                iput (dir);
68
                return -ENOENT;
69
        }
70
        if (!S_ISLNK(inode->i_mode)) {
71
                iput (dir);
72
                *res_inode = inode;
73
                return 0;
74
        }
75
        if (current->link_count > 5) {
76
                iput (dir);
77
                iput (inode);
78
                return -ELOOP;
79
        }
80
        if (inode->i_blocks) {
81
                if (!(bh = ext2_bread (inode, 0, 0, &error))) {
82
                        iput (dir);
83
                        iput (inode);
84
                        return -EIO;
85
                }
86
                link = bh->b_data;
87
        } else
88
                link = (char *) inode->u.ext2_i.i_data;
89
        UPDATE_ATIME(inode);
90
        current->link_count++;
91
        error = open_namei (link, flag, mode, res_inode, dir);
92
        current->link_count--;
93
        iput (inode);
94
        if (bh)
95
                brelse (bh);
96
        return error;
97
}
98
 
99
static int ext2_readlink (struct inode * inode, char * buffer, int buflen)
100
{
101
        struct buffer_head * bh = NULL;
102
        char * link;
103
        int i, err;
104
        char c;
105
 
106
        if (!S_ISLNK(inode->i_mode)) {
107
                iput (inode);
108
                return -EINVAL;
109
        }
110
        if (buflen > inode->i_sb->s_blocksize - 1)
111
                buflen = inode->i_sb->s_blocksize - 1;
112
        if (inode->i_blocks) {
113
                bh = ext2_bread (inode, 0, 0, &err);
114
                if (!bh) {
115
                        iput (inode);
116
                        return 0;
117
                }
118
                link = bh->b_data;
119
        }
120
        else
121
                link = (char *) inode->u.ext2_i.i_data;
122
        i = 0;
123
        while (i < buflen && (c = link[i])) {
124
                i++;
125
                put_user (c, buffer++);
126
        }
127
        UPDATE_ATIME(inode);
128
        iput (inode);
129
        if (bh)
130
                brelse (bh);
131
        return i;
132
}

powered by: WebSVN 2.1.0

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