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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [fs/] [sysv/] [symlink.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/sysv/symlink.c
3
 *
4
 *  minix/symlink.c
5
 *  Copyright (C) 1991, 1992  Linus Torvalds
6
 *
7
 *  coh/symlink.c
8
 *  Copyright (C) 1993  Pascal Haible, Bruno Haible
9
 *
10
 *  sysv/symlink.c
11
 *  Copyright (C) 1993  Bruno Haible
12
 *
13
 *  SystemV/Coherent symlink handling code
14
 */
15
 
16
#include <linux/errno.h>
17
#include <linux/sched.h>
18
#include <linux/sysv_fs.h>
19
#include <linux/stat.h>
20
 
21
#include <asm/segment.h>
22
 
23
static int sysv_readlink(struct inode *, char *, int);
24
static int sysv_follow_link(struct inode *, struct inode *, int, int, struct inode **);
25
 
26
/*
27
 * symlinks can't do much...
28
 */
29
struct inode_operations sysv_symlink_inode_operations = {
30
        NULL,                   /* no file-operations */
31
        NULL,                   /* create */
32
        NULL,                   /* lookup */
33
        NULL,                   /* link */
34
        NULL,                   /* unlink */
35
        NULL,                   /* symlink */
36
        NULL,                   /* mkdir */
37
        NULL,                   /* rmdir */
38
        NULL,                   /* mknod */
39
        NULL,                   /* rename */
40
        sysv_readlink,          /* readlink */
41
        sysv_follow_link,       /* follow_link */
42
        NULL,                   /* readpage */
43
        NULL,                   /* writepage */
44
        NULL,                   /* bmap */
45
        NULL,                   /* truncate */
46
        NULL                    /* permission */
47
};
48
 
49
static int sysv_follow_link(struct inode * dir, struct inode * inode,
50
        int flag, int mode, struct inode ** res_inode)
51
{
52
        int error;
53
        struct buffer_head * bh;
54
 
55
        *res_inode = NULL;
56
        if (!dir) {
57
                dir = current->fs->root;
58
                dir->i_count++;
59
        }
60
        if (!inode) {
61
                iput(dir);
62
                return -ENOENT;
63
        }
64
        if (!S_ISLNK(inode->i_mode)) {
65
                iput(dir);
66
                *res_inode = inode;
67
                return 0;
68
        }
69
        if (current->link_count > 5) {
70
                iput(inode);
71
                iput(dir);
72
                return -ELOOP;
73
        }
74
        if (!(bh = sysv_file_bread(inode, 0, 0))) { /* is reading 1 block enough ?? */
75
                iput(inode);
76
                iput(dir);
77
                return -EIO;
78
        }
79
        iput(inode);
80
        current->link_count++;
81
        error = open_namei(bh->b_data,flag,mode,res_inode,dir);
82
        current->link_count--;
83
        brelse(bh);
84
        return error;
85
}
86
 
87
static int sysv_readlink(struct inode * inode, char * buffer, int buflen)
88
{
89
        struct buffer_head * bh;
90
        char * bh_data;
91
        int i;
92
        char c;
93
 
94
        if (!S_ISLNK(inode->i_mode)) {
95
                iput(inode);
96
                return -EINVAL;
97
        }
98
        if (buflen > inode->i_sb->sv_block_size_1)
99
                buflen = inode->i_sb->sv_block_size_1;
100
        bh = sysv_file_bread(inode, 0, 0);
101
        iput(inode);
102
        if (!bh)
103
                return 0;
104
        bh_data = bh->b_data;
105
        i = 0;
106
        while (i<buflen && (c = bh_data[i])) {
107
                i++;
108
                put_user(c,buffer++);
109
        }
110
        brelse(bh);
111
        return i;
112
}

powered by: WebSVN 2.1.0

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