Linux Audio

Check our new training course

Loading...
Note: File does not exist in v3.5.6.
 1/*
 2 * Copyright (C) 2017 Oracle.  All Rights Reserved.
 3 *
 4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
 5 *
 6 * This program is free software; you can redistribute it and/or
 7 * modify it under the terms of the GNU General Public License
 8 * as published by the Free Software Foundation; either version 2
 9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it would be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write the Free Software Foundation,
18 * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20#include "xfs.h"
21#include "xfs_fs.h"
22#include "xfs_shared.h"
23#include "xfs_format.h"
24#include "xfs_trans_resv.h"
25#include "xfs_mount.h"
26#include "xfs_defer.h"
27#include "xfs_btree.h"
28#include "xfs_bit.h"
29#include "xfs_log_format.h"
30#include "xfs_trans.h"
31#include "xfs_sb.h"
32#include "xfs_inode.h"
33#include "xfs_inode_fork.h"
34#include "xfs_symlink.h"
35#include "scrub/xfs_scrub.h"
36#include "scrub/scrub.h"
37#include "scrub/common.h"
38#include "scrub/trace.h"
39
40/* Set us up to scrub a symbolic link. */
41int
42xfs_scrub_setup_symlink(
43	struct xfs_scrub_context	*sc,
44	struct xfs_inode		*ip)
45{
46	/* Allocate the buffer without the inode lock held. */
47	sc->buf = kmem_zalloc_large(XFS_SYMLINK_MAXLEN + 1, KM_SLEEP);
48	if (!sc->buf)
49		return -ENOMEM;
50
51	return xfs_scrub_setup_inode_contents(sc, ip, 0);
52}
53
54/* Symbolic links. */
55
56int
57xfs_scrub_symlink(
58	struct xfs_scrub_context	*sc)
59{
60	struct xfs_inode		*ip = sc->ip;
61	struct xfs_ifork		*ifp;
62	loff_t				len;
63	int				error = 0;
64
65	if (!S_ISLNK(VFS_I(ip)->i_mode))
66		return -ENOENT;
67	ifp = XFS_IFORK_PTR(ip, XFS_DATA_FORK);
68	len = ip->i_d.di_size;
69
70	/* Plausible size? */
71	if (len > XFS_SYMLINK_MAXLEN || len <= 0) {
72		xfs_scrub_fblock_set_corrupt(sc, XFS_DATA_FORK, 0);
73		goto out;
74	}
75
76	/* Inline symlink? */
77	if (ifp->if_flags & XFS_IFINLINE) {
78		if (len > XFS_IFORK_DSIZE(ip) ||
79		    len > strnlen(ifp->if_u1.if_data, XFS_IFORK_DSIZE(ip)))
80			xfs_scrub_fblock_set_corrupt(sc, XFS_DATA_FORK, 0);
81		goto out;
82	}
83
84	/* Remote symlink; must read the contents. */
85	error = xfs_readlink_bmap_ilocked(sc->ip, sc->buf);
86	if (!xfs_scrub_fblock_process_error(sc, XFS_DATA_FORK, 0, &error))
87		goto out;
88	if (strnlen(sc->buf, XFS_SYMLINK_MAXLEN) < len)
89		xfs_scrub_fblock_set_corrupt(sc, XFS_DATA_FORK, 0);
90out:
91	return error;
92}