super.c (ea68a3e9d14e9e0bf017d178fb4bd53b6deb1482) | super.c (3acea5fc335420ba7ef53947cf2d98d07fac39f7) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * Copyright (C) 2017-2018 HUAWEI, Inc. 4 * https://www.huawei.com/ 5 * Copyright (C) 2021, Alibaba Cloud 6 */ 7#include <linux/module.h> 8#include <linux/statfs.h> --- 38 unchanged lines hidden (view full) --- 47 vaf.va = &args; 48 49 pr_info("(device %s): %pV", sb->s_id, &vaf); 50 va_end(args); 51} 52 53static int erofs_superblock_csum_verify(struct super_block *sb, void *sbdata) 54{ | 1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * Copyright (C) 2017-2018 HUAWEI, Inc. 4 * https://www.huawei.com/ 5 * Copyright (C) 2021, Alibaba Cloud 6 */ 7#include <linux/module.h> 8#include <linux/statfs.h> --- 38 unchanged lines hidden (view full) --- 47 vaf.va = &args; 48 49 pr_info("(device %s): %pV", sb->s_id, &vaf); 50 va_end(args); 51} 52 53static int erofs_superblock_csum_verify(struct super_block *sb, void *sbdata) 54{ |
55 size_t len = 1 << EROFS_SB(sb)->blkszbits; |
|
55 struct erofs_super_block *dsb; 56 u32 expected_crc, crc; 57 | 56 struct erofs_super_block *dsb; 57 u32 expected_crc, crc; 58 |
58 dsb = kmemdup(sbdata + EROFS_SUPER_OFFSET, 59 EROFS_BLKSIZ - EROFS_SUPER_OFFSET, GFP_KERNEL); | 59 if (len > EROFS_SUPER_OFFSET) 60 len -= EROFS_SUPER_OFFSET; 61 62 dsb = kmemdup(sbdata + EROFS_SUPER_OFFSET, len, GFP_KERNEL); |
60 if (!dsb) 61 return -ENOMEM; 62 63 expected_crc = le32_to_cpu(dsb->checksum); 64 dsb->checksum = 0; 65 /* to allow for x86 boot sectors and other oddities. */ | 63 if (!dsb) 64 return -ENOMEM; 65 66 expected_crc = le32_to_cpu(dsb->checksum); 67 dsb->checksum = 0; 68 /* to allow for x86 boot sectors and other oddities. */ |
66 crc = crc32c(~0, dsb, EROFS_BLKSIZ - EROFS_SUPER_OFFSET); | 69 crc = crc32c(~0, dsb, len); |
67 kfree(dsb); 68 69 if (crc != expected_crc) { 70 erofs_err(sb, "invalid checksum 0x%08x, 0x%08x expected", 71 crc, expected_crc); 72 return -EBADMSG; 73 } 74 return 0; --- 52 unchanged lines hidden (view full) --- 127/* read variable-sized metadata, offset will be aligned by 4-byte */ 128static void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf, 129 erofs_off_t *offset, int *lengthp) 130{ 131 u8 *buffer, *ptr; 132 int len, i, cnt; 133 134 *offset = round_up(*offset, 4); | 70 kfree(dsb); 71 72 if (crc != expected_crc) { 73 erofs_err(sb, "invalid checksum 0x%08x, 0x%08x expected", 74 crc, expected_crc); 75 return -EBADMSG; 76 } 77 return 0; --- 52 unchanged lines hidden (view full) --- 130/* read variable-sized metadata, offset will be aligned by 4-byte */ 131static void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf, 132 erofs_off_t *offset, int *lengthp) 133{ 134 u8 *buffer, *ptr; 135 int len, i, cnt; 136 137 *offset = round_up(*offset, 4); |
135 ptr = erofs_read_metabuf(buf, sb, erofs_blknr(*offset), EROFS_KMAP); | 138 ptr = erofs_read_metabuf(buf, sb, erofs_blknr(sb, *offset), EROFS_KMAP); |
136 if (IS_ERR(ptr)) 137 return ptr; 138 | 139 if (IS_ERR(ptr)) 140 return ptr; 141 |
139 len = le16_to_cpu(*(__le16 *)&ptr[erofs_blkoff(*offset)]); | 142 len = le16_to_cpu(*(__le16 *)&ptr[erofs_blkoff(sb, *offset)]); |
140 if (!len) 141 len = U16_MAX + 1; 142 buffer = kmalloc(len, GFP_KERNEL); 143 if (!buffer) 144 return ERR_PTR(-ENOMEM); 145 *offset += sizeof(__le16); 146 *lengthp = len; 147 148 for (i = 0; i < len; i += cnt) { | 143 if (!len) 144 len = U16_MAX + 1; 145 buffer = kmalloc(len, GFP_KERNEL); 146 if (!buffer) 147 return ERR_PTR(-ENOMEM); 148 *offset += sizeof(__le16); 149 *lengthp = len; 150 151 for (i = 0; i < len; i += cnt) { |
149 cnt = min(EROFS_BLKSIZ - (int)erofs_blkoff(*offset), len - i); 150 ptr = erofs_read_metabuf(buf, sb, erofs_blknr(*offset), | 152 cnt = min_t(int, sb->s_blocksize - erofs_blkoff(sb, *offset), 153 len - i); 154 ptr = erofs_read_metabuf(buf, sb, erofs_blknr(sb, *offset), |
151 EROFS_KMAP); 152 if (IS_ERR(ptr)) { 153 kfree(buffer); 154 return ptr; 155 } | 155 EROFS_KMAP); 156 if (IS_ERR(ptr)) { 157 kfree(buffer); 158 return ptr; 159 } |
156 memcpy(buffer + i, ptr + erofs_blkoff(*offset), cnt); | 160 memcpy(buffer + i, ptr + erofs_blkoff(sb, *offset), cnt); |
157 *offset += cnt; 158 } 159 return buffer; 160} 161 162static int erofs_load_compr_cfgs(struct super_block *sb, 163 struct erofs_super_block *dsb) 164{ --- 58 unchanged lines hidden (view full) --- 223 struct erofs_device_info *dif, erofs_off_t *pos) 224{ 225 struct erofs_sb_info *sbi = EROFS_SB(sb); 226 struct erofs_fscache *fscache; 227 struct erofs_deviceslot *dis; 228 struct block_device *bdev; 229 void *ptr; 230 | 161 *offset += cnt; 162 } 163 return buffer; 164} 165 166static int erofs_load_compr_cfgs(struct super_block *sb, 167 struct erofs_super_block *dsb) 168{ --- 58 unchanged lines hidden (view full) --- 227 struct erofs_device_info *dif, erofs_off_t *pos) 228{ 229 struct erofs_sb_info *sbi = EROFS_SB(sb); 230 struct erofs_fscache *fscache; 231 struct erofs_deviceslot *dis; 232 struct block_device *bdev; 233 void *ptr; 234 |
231 ptr = erofs_read_metabuf(buf, sb, erofs_blknr(*pos), EROFS_KMAP); | 235 ptr = erofs_read_metabuf(buf, sb, erofs_blknr(sb, *pos), EROFS_KMAP); |
232 if (IS_ERR(ptr)) 233 return PTR_ERR(ptr); | 236 if (IS_ERR(ptr)) 237 return PTR_ERR(ptr); |
234 dis = ptr + erofs_blkoff(*pos); | 238 dis = ptr + erofs_blkoff(sb, *pos); |
235 236 if (!dif->path) { 237 if (!dis->tag[0]) { 238 erofs_err(sb, "empty device tag @ pos %llu", *pos); 239 return -EINVAL; 240 } 241 dif->path = kmemdup_nul(dis->tag, sizeof(dis->tag), GFP_KERNEL); 242 if (!dif->path) --- 485 unchanged lines hidden (view full) --- 728 sbi->opt = ctx->opt; 729 sbi->devs = ctx->devs; 730 ctx->devs = NULL; 731 sbi->fsid = ctx->fsid; 732 ctx->fsid = NULL; 733 sbi->domain_id = ctx->domain_id; 734 ctx->domain_id = NULL; 735 | 239 240 if (!dif->path) { 241 if (!dis->tag[0]) { 242 erofs_err(sb, "empty device tag @ pos %llu", *pos); 243 return -EINVAL; 244 } 245 dif->path = kmemdup_nul(dis->tag, sizeof(dis->tag), GFP_KERNEL); 246 if (!dif->path) --- 485 unchanged lines hidden (view full) --- 732 sbi->opt = ctx->opt; 733 sbi->devs = ctx->devs; 734 ctx->devs = NULL; 735 sbi->fsid = ctx->fsid; 736 ctx->fsid = NULL; 737 sbi->domain_id = ctx->domain_id; 738 ctx->domain_id = NULL; 739 |
740 sbi->blkszbits = PAGE_SHIFT; |
|
736 if (erofs_is_fscache_mode(sb)) { 737 sb->s_blocksize = EROFS_BLKSIZ; 738 sb->s_blocksize_bits = LOG_BLOCK_SIZE; 739 740 err = erofs_fscache_register_fs(sb); 741 if (err) 742 return err; 743 --- 311 unchanged lines hidden (view full) --- 1055 struct super_block *sb = dentry->d_sb; 1056 struct erofs_sb_info *sbi = EROFS_SB(sb); 1057 u64 id = 0; 1058 1059 if (!erofs_is_fscache_mode(sb)) 1060 id = huge_encode_dev(sb->s_bdev->bd_dev); 1061 1062 buf->f_type = sb->s_magic; | 741 if (erofs_is_fscache_mode(sb)) { 742 sb->s_blocksize = EROFS_BLKSIZ; 743 sb->s_blocksize_bits = LOG_BLOCK_SIZE; 744 745 err = erofs_fscache_register_fs(sb); 746 if (err) 747 return err; 748 --- 311 unchanged lines hidden (view full) --- 1060 struct super_block *sb = dentry->d_sb; 1061 struct erofs_sb_info *sbi = EROFS_SB(sb); 1062 u64 id = 0; 1063 1064 if (!erofs_is_fscache_mode(sb)) 1065 id = huge_encode_dev(sb->s_bdev->bd_dev); 1066 1067 buf->f_type = sb->s_magic; |
1063 buf->f_bsize = EROFS_BLKSIZ; | 1068 buf->f_bsize = sb->s_blocksize; |
1064 buf->f_blocks = sbi->total_blocks; 1065 buf->f_bfree = buf->f_bavail = 0; 1066 1067 buf->f_files = ULLONG_MAX; 1068 buf->f_ffree = ULLONG_MAX - sbi->inos; 1069 1070 buf->f_namelen = EROFS_NAME_LEN; 1071 --- 56 unchanged lines hidden --- | 1069 buf->f_blocks = sbi->total_blocks; 1070 buf->f_bfree = buf->f_bavail = 0; 1071 1072 buf->f_files = ULLONG_MAX; 1073 buf->f_ffree = ULLONG_MAX - sbi->inos; 1074 1075 buf->f_namelen = EROFS_NAME_LEN; 1076 --- 56 unchanged lines hidden --- |