~ubuntu-branches/ubuntu/saucy/fuse-umfuse-ext2/saucy

« back to all changes in this revision

Viewing changes to fuse-ext2/op_readlink.c

  • Committer: Package Import Robot
  • Author(s): Ludovico Gardenghi, Filippo Giunchedi, Ludovico Gardenghi
  • Date: 2012-06-24 20:58:20 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20120624205820-d9avp9pa6zgiyac7
Tags: 0.4-1
[ Filippo Giunchedi ]
* Add DM-Upload-Allowed field

[ Ludovico Gardenghi ]
* New upstream release
  + Source code completely changed, now it's a fork of fuse-ext2 by
    Alper Akcan
  + Update copyright file accordingly
  + Resolve old codebase issues (Closes: #562177, #670622)
* Update to S-V 3.9.3
* Switch to machine-readable copyright file
* Update mail address for Ludovico Gardenghi
* Add compatibility symlinks (old version used fuseext2, this one uses
  fuse-ext2)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Copyright (c) 2008-2010 Alper Akcan <alper.akcan@gmail.com>
 
3
 * Copyright (c) 2009-2010 Renzo Davoli <renzo@cs.unibo.it>
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program (in the main directory of the fuse-ext2
 
17
 * distribution in the file COPYING); if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
 */
 
20
 
 
21
#include "fuse-ext2.h"
 
22
 
 
23
int op_readlink (const char *path, char *buf, size_t size)
 
24
{
 
25
        int rt;
 
26
        size_t s;
 
27
        errcode_t rc;
 
28
        ext2_ino_t ino;
 
29
        char *b = NULL;
 
30
        char *pathname;
 
31
        struct ext2_inode inode;
 
32
        ext2_filsys e2fs;
 
33
        FUSE_EXT2_LOCK;
 
34
        e2fs    = current_ext2fs();
 
35
        
 
36
        debugf("enter");
 
37
        debugf("path = %s", path);
 
38
 
 
39
        rt = do_readinode(e2fs, path, &ino, &inode);
 
40
        if (rt) {
 
41
                debugf("do_readinode(%s, &ino, &inode); failed", path);
 
42
                goto err;
 
43
        }
 
44
        
 
45
        if (!LINUX_S_ISLNK(inode.i_mode)) {
 
46
                debugf("%s is not a link", path);
 
47
                rt = -EINVAL;
 
48
                goto err;
 
49
        }
 
50
        
 
51
        if (ext2fs_inode_data_blocks(e2fs, &inode)) {
 
52
                rc = ext2fs_get_mem(EXT2_BLOCK_SIZE(e2fs->super), &b);
 
53
                if (rc) {
 
54
                        debugf("ext2fs_get_mem(EXT2_BLOCK_SIZE(e2fs->super), &b); failed");
 
55
                        rt = -ENOMEM;
 
56
                        goto err;
 
57
                }
 
58
                rc = io_channel_read_blk(e2fs->io, inode.i_block[0], 1, b);
 
59
                if (rc) {
 
60
                        ext2fs_free_mem(&b);
 
61
                        debugf("io_channel_read_blk(e2fs->io, inode.i_block[0], 1, b); failed");
 
62
                        rt = -EIO;
 
63
                        goto err;
 
64
                }
 
65
                pathname = b;
 
66
        } else {
 
67
                pathname = (char *) &(inode.i_block[0]);
 
68
        }
 
69
        
 
70
        debugf("pathname: %s", pathname);
 
71
        
 
72
        s = (size < strlen(pathname) + 1) ? size : strlen(pathname) + 1;
 
73
        snprintf(buf, s, "%s", pathname);
 
74
        
 
75
        if (b) {
 
76
                ext2fs_free_mem(&b);
 
77
        }
 
78
 
 
79
        debugf("leave");
 
80
        FUSE_EXT2_UNLOCK;
 
81
        return 0;
 
82
err:
 
83
        FUSE_EXT2_UNLOCK;
 
84
        return rt;
 
85
}