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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [fs/] [xiafs/] [symlink.c] - Blame information for rev 1628

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

Line No. Rev Author Line
1 1628 jcastillo
/*
2
 *  linux/fs/xiafs/symlink.c
3
 *
4
 *  Copyright (C) Q. Frank Xia, 1993.
5
 *
6
 *  Based on Linus' minix/symlink.c
7
 *  Copyright (C) Linus Torvalds, 1991, 1992.
8
 *
9
 *  This software may be redistributed per Linux Copyright.
10
 */
11
 
12
#include <linux/errno.h>
13
#include <linux/sched.h>
14
#include <linux/fs.h>
15
#include <linux/xia_fs.h>
16
#include <linux/stat.h>
17
 
18
#include <asm/segment.h>
19
 
20
static int
21
xiafs_readlink(struct inode *, char *, int);
22
 
23
static int
24
xiafs_follow_link(struct inode *, struct inode *, int, int, struct inode **);
25
 
26
/*
27
 * symlinks can't do much...
28
 */
29
struct inode_operations xiafs_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
        xiafs_readlink,         /* readlink */
41
        xiafs_follow_link,      /* follow_link */
42
        NULL,                   /* readpage */
43
        NULL,                   /* writepage */
44
        NULL,                   /* bmap */
45
        NULL,                   /* truncate */
46
        NULL                    /* permission */
47
};
48
 
49
static int xiafs_readlink(struct inode * inode, char * buffer, int buflen)
50
{
51
    struct buffer_head * bh;
52
    int i;
53
    char c;
54
 
55
    if (!S_ISLNK(inode->i_mode)) {
56
        iput(inode);
57
        return -EINVAL;
58
    }
59
    if (buflen > BLOCK_SIZE)
60
        buflen = BLOCK_SIZE;
61
    bh = xiafs_bread(inode, 0, 0);
62
    if (!IS_RDONLY (inode)) {
63
        inode->i_atime=CURRENT_TIME;
64
        inode->i_dirt=1;
65
    }
66
    iput(inode);
67
    if (!bh)
68
        return 0;
69
    for (i=0; i < buflen && (c=bh->b_data[i]); i++)
70
      put_user(c, buffer++);
71
    if (i < buflen-1)
72
      put_user('\0', buffer);
73
    brelse(bh);
74
    return i;
75
}
76
 
77
static int xiafs_follow_link(struct inode * dir, struct inode * inode,
78
        int flag, int mode, struct inode ** res_inode)
79
{
80
    int error;
81
    struct buffer_head * bh;
82
 
83
    *res_inode = NULL;
84
    if (!dir) {
85
        dir = current->fs->root;
86
        dir->i_count++;
87
    }
88
    if (!inode) {
89
        iput(dir);
90
        return -ENOENT;
91
    }
92
    if (!S_ISLNK(inode->i_mode)) {
93
        iput(dir);
94
        *res_inode = inode;
95
        return 0;
96
    }
97
    if (!IS_RDONLY (inode)) {
98
        inode->i_atime=CURRENT_TIME;
99
        inode->i_dirt=1;
100
    }
101
    if (current->link_count > 5) {
102
        iput(inode);
103
        iput(dir);
104
        return -ELOOP;
105
    }
106
    if (!(bh = xiafs_bread(inode, 0, 0))) {
107
        iput(inode);
108
        iput(dir);
109
        return -EIO;
110
    }
111
    iput(inode);
112
    current->link_count++;
113
    error = open_namei(bh->b_data,flag,mode,res_inode,dir);
114
    current->link_count--;
115
    brelse(bh);
116
    return error;
117
}
118
 
119
 
120
 

powered by: WebSVN 2.1.0

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