2 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
3 * Copyright (c) 2012-2013 Red Hat, Inc.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it would 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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 * Each contiguous block has a header, so it is not just a simple pathlen
30 int buflen
= XFS_SYMLINK_BUF_SPACE(mp
, mp
->m_sb
.sb_blocksize
);
32 return (pathlen
+ buflen
- 1) / buflen
;
43 struct xfs_dsymlink_hdr
*dsl
= bp
->b_addr
;
45 if (!xfs_sb_version_hascrc(&mp
->m_sb
))
48 dsl
->sl_magic
= cpu_to_be32(XFS_SYMLINK_MAGIC
);
49 dsl
->sl_offset
= cpu_to_be32(offset
);
50 dsl
->sl_bytes
= cpu_to_be32(size
);
51 uuid_copy(&dsl
->sl_uuid
, &mp
->m_sb
.sb_uuid
);
52 dsl
->sl_owner
= cpu_to_be64(ino
);
53 dsl
->sl_blkno
= cpu_to_be64(bp
->b_bn
);
54 bp
->b_ops
= &xfs_symlink_buf_ops
;
56 return sizeof(struct xfs_dsymlink_hdr
);
60 * Checking of the symlink header is split into two parts. the verifier does
61 * CRC, location and bounds checking, the unpacking function checks the path
62 * parameters and owner.
72 struct xfs_dsymlink_hdr
*dsl
= bp
->b_addr
;
74 if (offset
!= be32_to_cpu(dsl
->sl_offset
))
76 if (size
!= be32_to_cpu(dsl
->sl_bytes
))
78 if (ino
!= be64_to_cpu(dsl
->sl_owner
))
89 struct xfs_mount
*mp
= bp
->b_target
->bt_mount
;
90 struct xfs_dsymlink_hdr
*dsl
= bp
->b_addr
;
92 if (!xfs_sb_version_hascrc(&mp
->m_sb
))
94 if (dsl
->sl_magic
!= cpu_to_be32(XFS_SYMLINK_MAGIC
))
96 if (!uuid_equal(&dsl
->sl_uuid
, &mp
->m_sb
.sb_uuid
))
98 if (bp
->b_bn
!= be64_to_cpu(dsl
->sl_blkno
))
100 if (be32_to_cpu(dsl
->sl_offset
) +
101 be32_to_cpu(dsl
->sl_bytes
) >= MAXPATHLEN
)
103 if (dsl
->sl_owner
== 0)
110 xfs_symlink_read_verify(
113 struct xfs_mount
*mp
= bp
->b_target
->bt_mount
;
115 /* no verification of non-crc buffers */
116 if (!xfs_sb_version_hascrc(&mp
->m_sb
))
119 if (!xfs_verify_cksum(bp
->b_addr
, BBTOB(bp
->b_length
),
120 offsetof(struct xfs_dsymlink_hdr
, sl_crc
)) ||
121 !xfs_symlink_verify(bp
)) {
122 XFS_CORRUPTION_ERROR(__func__
, XFS_ERRLEVEL_LOW
, mp
, bp
->b_addr
);
123 xfs_buf_ioerror(bp
, EFSCORRUPTED
);
128 xfs_symlink_write_verify(
131 struct xfs_mount
*mp
= bp
->b_target
->bt_mount
;
132 struct xfs_buf_log_item
*bip
= bp
->b_fspriv
;
134 /* no verification of non-crc buffers */
135 if (!xfs_sb_version_hascrc(&mp
->m_sb
))
138 if (!xfs_symlink_verify(bp
)) {
139 XFS_CORRUPTION_ERROR(__func__
, XFS_ERRLEVEL_LOW
, mp
, bp
->b_addr
);
140 xfs_buf_ioerror(bp
, EFSCORRUPTED
);
145 struct xfs_dsymlink_hdr
*dsl
= bp
->b_addr
;
146 dsl
->sl_lsn
= cpu_to_be64(bip
->bli_item
.li_lsn
);
148 xfs_update_cksum(bp
->b_addr
, BBTOB(bp
->b_length
),
149 offsetof(struct xfs_dsymlink_hdr
, sl_crc
));
152 const struct xfs_buf_ops xfs_symlink_buf_ops
= {
153 .verify_read
= xfs_symlink_read_verify
,
154 .verify_write
= xfs_symlink_write_verify
,
158 xfs_symlink_local_to_remote(
159 struct xfs_trans
*tp
,
161 struct xfs_inode
*ip
,
162 struct xfs_ifork
*ifp
)
164 struct xfs_mount
*mp
= ip
->i_mount
;
167 if (!xfs_sb_version_hascrc(&mp
->m_sb
)) {
169 memcpy(bp
->b_addr
, ifp
->if_u1
.if_data
, ifp
->if_bytes
);
174 * As this symlink fits in an inode literal area, it must also fit in
175 * the smallest buffer the filesystem supports.
177 ASSERT(BBTOB(bp
->b_length
) >=
178 ifp
->if_bytes
+ sizeof(struct xfs_dsymlink_hdr
));
180 bp
->b_ops
= &xfs_symlink_buf_ops
;
183 buf
+= xfs_symlink_hdr_set(mp
, ip
->i_ino
, 0, ifp
->if_bytes
, bp
);
184 memcpy(buf
, ifp
->if_u1
.if_data
, ifp
->if_bytes
);