Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'erofs-for-6.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs

Pull erofs updates from Gao Xiang:
"In this cycle, sub-page block support for uncompressed files is
available. It's mainly used to enable original signing ('golden')
4k-block images on arm64 with 16/64k pages. In addition, end users
could also use this feature to build a manifest to directly refer to
golden tar data.

Besides, long xattr name prefix support is also introduced in this
cycle to avoid too many xattrs with the same prefix (e.g. overlayfs
xattrs). It's useful for erofs + overlayfs combination (like Composefs
model): the image size is reduced by ~14% and runtime performance is
also slightly improved.

Others are random fixes and cleanups as usual.

Summary:

- Add sub-page block size support for uncompressed files

- Support flattened block device for multi-blob images to be attached
into virtual machines (including cloud servers) and bare metals

- Support long xattr name prefixes to optimize images with common
xattr namespaces (e.g. files with overlayfs xattrs) use cases

- Various minor cleanups & fixes"

* tag 'erofs-for-6.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs:
erofs: cleanup i_format-related stuffs
erofs: sunset erofs_dbg()
erofs: fix potential overflow calculating xattr_isize
erofs: get rid of z_erofs_fill_inode()
erofs: enable long extended attribute name prefixes
erofs: handle long xattr name prefixes properly
erofs: add helpers to load long xattr name prefixes
erofs: introduce on-disk format for long xattr name prefixes
erofs: move packed inode out of the compression part
erofs: keep meta inode into erofs_buf
erofs: initialize packed inode after root inode is assigned
erofs: stop parsing non-compact HEAD index if clusterofs is invalid
erofs: don't warn ztailpacking feature anymore
erofs: simplify erofs_xattr_generic_get()
erofs: rename init_inode_xattrs with erofs_ prefix
erofs: move several xattr helpers into xattr.c
erofs: tidy up EROFS on-disk naming
erofs: support flattened block device for multi-blob images
erofs: set block size to the on-disk block size
erofs: avoid hardcoded blocksize for subpage block support

+539 -458
+2 -2
Documentation/filesystems/erofs.rst
··· 40 40 - Support multiple devices to refer to external blobs, which can be used 41 41 for container images; 42 42 43 - - 4KiB block size and 32-bit block addresses for each device, therefore 44 - 16TiB address space at most for now; 43 + - 32-bit block addresses for each device, therefore 16TiB address space at 44 + most with 4KiB block size for now; 45 45 46 46 - Two inode layouts for different requirements: 47 47
+47 -34
fs/erofs/data.c
··· 27 27 buf->page = NULL; 28 28 } 29 29 30 - void *erofs_bread(struct erofs_buf *buf, struct inode *inode, 31 - erofs_blk_t blkaddr, enum erofs_kmap_type type) 30 + /* 31 + * Derive the block size from inode->i_blkbits to make compatible with 32 + * anonymous inode in fscache mode. 33 + */ 34 + void *erofs_bread(struct erofs_buf *buf, erofs_blk_t blkaddr, 35 + enum erofs_kmap_type type) 32 36 { 33 - struct address_space *const mapping = inode->i_mapping; 34 - erofs_off_t offset = blknr_to_addr(blkaddr); 37 + struct inode *inode = buf->inode; 38 + erofs_off_t offset = (erofs_off_t)blkaddr << inode->i_blkbits; 35 39 pgoff_t index = offset >> PAGE_SHIFT; 36 40 struct page *page = buf->page; 37 41 struct folio *folio; ··· 45 41 erofs_put_metabuf(buf); 46 42 47 43 nofs_flag = memalloc_nofs_save(); 48 - folio = read_cache_folio(mapping, index, NULL, NULL); 44 + folio = read_cache_folio(inode->i_mapping, index, NULL, NULL); 49 45 memalloc_nofs_restore(nofs_flag); 50 46 if (IS_ERR(folio)) 51 47 return folio; ··· 67 63 return buf->base + (offset & ~PAGE_MASK); 68 64 } 69 65 66 + void erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb) 67 + { 68 + if (erofs_is_fscache_mode(sb)) 69 + buf->inode = EROFS_SB(sb)->s_fscache->inode; 70 + else 71 + buf->inode = sb->s_bdev->bd_inode; 72 + } 73 + 70 74 void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb, 71 75 erofs_blk_t blkaddr, enum erofs_kmap_type type) 72 76 { 73 - if (erofs_is_fscache_mode(sb)) 74 - return erofs_bread(buf, EROFS_SB(sb)->s_fscache->inode, 75 - blkaddr, type); 76 - 77 - return erofs_bread(buf, sb->s_bdev->bd_inode, blkaddr, type); 77 + erofs_init_metabuf(buf, sb); 78 + return erofs_bread(buf, blkaddr, type); 78 79 } 79 80 80 81 static int erofs_map_blocks_flatmode(struct inode *inode, ··· 88 79 erofs_blk_t nblocks, lastblk; 89 80 u64 offset = map->m_la; 90 81 struct erofs_inode *vi = EROFS_I(inode); 82 + struct super_block *sb = inode->i_sb; 91 83 bool tailendpacking = (vi->datalayout == EROFS_INODE_FLAT_INLINE); 92 84 93 - nblocks = DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ); 85 + nblocks = erofs_iblks(inode); 94 86 lastblk = nblocks - tailendpacking; 95 87 96 88 /* there is no hole in flatmode */ 97 89 map->m_flags = EROFS_MAP_MAPPED; 98 - if (offset < blknr_to_addr(lastblk)) { 99 - map->m_pa = blknr_to_addr(vi->raw_blkaddr) + map->m_la; 100 - map->m_plen = blknr_to_addr(lastblk) - offset; 90 + if (offset < erofs_pos(sb, lastblk)) { 91 + map->m_pa = erofs_pos(sb, vi->raw_blkaddr) + map->m_la; 92 + map->m_plen = erofs_pos(sb, lastblk) - offset; 101 93 } else if (tailendpacking) { 102 94 map->m_pa = erofs_iloc(inode) + vi->inode_isize + 103 - vi->xattr_isize + erofs_blkoff(offset); 95 + vi->xattr_isize + erofs_blkoff(sb, offset); 104 96 map->m_plen = inode->i_size - offset; 105 97 106 98 /* inline data should be located in the same meta block */ 107 - if (erofs_blkoff(map->m_pa) + map->m_plen > EROFS_BLKSIZ) { 108 - erofs_err(inode->i_sb, 109 - "inline data cross block boundary @ nid %llu", 99 + if (erofs_blkoff(sb, map->m_pa) + map->m_plen > sb->s_blocksize) { 100 + erofs_err(sb, "inline data cross block boundary @ nid %llu", 110 101 vi->nid); 111 102 DBG_BUGON(1); 112 103 return -EFSCORRUPTED; 113 104 } 114 105 map->m_flags |= EROFS_MAP_META; 115 106 } else { 116 - erofs_err(inode->i_sb, 117 - "internal error @ nid: %llu (size %llu), m_la 0x%llx", 107 + erofs_err(sb, "internal error @ nid: %llu (size %llu), m_la 0x%llx", 118 108 vi->nid, inode->i_size, map->m_la); 119 109 DBG_BUGON(1); 120 110 return -EIO; ··· 156 148 pos = ALIGN(erofs_iloc(inode) + vi->inode_isize + 157 149 vi->xattr_isize, unit) + unit * chunknr; 158 150 159 - kaddr = erofs_read_metabuf(&buf, sb, erofs_blknr(pos), EROFS_KMAP); 151 + kaddr = erofs_read_metabuf(&buf, sb, erofs_blknr(sb, pos), EROFS_KMAP); 160 152 if (IS_ERR(kaddr)) { 161 153 err = PTR_ERR(kaddr); 162 154 goto out; 163 155 } 164 156 map->m_la = chunknr << vi->chunkbits; 165 157 map->m_plen = min_t(erofs_off_t, 1UL << vi->chunkbits, 166 - roundup(inode->i_size - map->m_la, EROFS_BLKSIZ)); 158 + round_up(inode->i_size - map->m_la, sb->s_blocksize)); 167 159 168 160 /* handle block map */ 169 161 if (!(vi->chunkformat & EROFS_CHUNK_FORMAT_INDEXES)) { 170 - __le32 *blkaddr = kaddr + erofs_blkoff(pos); 162 + __le32 *blkaddr = kaddr + erofs_blkoff(sb, pos); 171 163 172 164 if (le32_to_cpu(*blkaddr) == EROFS_NULL_ADDR) { 173 165 map->m_flags = 0; 174 166 } else { 175 - map->m_pa = blknr_to_addr(le32_to_cpu(*blkaddr)); 167 + map->m_pa = erofs_pos(sb, le32_to_cpu(*blkaddr)); 176 168 map->m_flags = EROFS_MAP_MAPPED; 177 169 } 178 170 goto out_unlock; 179 171 } 180 172 /* parse chunk indexes */ 181 - idx = kaddr + erofs_blkoff(pos); 173 + idx = kaddr + erofs_blkoff(sb, pos); 182 174 switch (le32_to_cpu(idx->blkaddr)) { 183 175 case EROFS_NULL_ADDR: 184 176 map->m_flags = 0; ··· 186 178 default: 187 179 map->m_deviceid = le16_to_cpu(idx->device_id) & 188 180 EROFS_SB(sb)->device_id_mask; 189 - map->m_pa = blknr_to_addr(le32_to_cpu(idx->blkaddr)); 181 + map->m_pa = erofs_pos(sb, le32_to_cpu(idx->blkaddr)); 190 182 map->m_flags = EROFS_MAP_MAPPED; 191 183 break; 192 184 } ··· 205 197 struct erofs_device_info *dif; 206 198 int id; 207 199 208 - /* primary device by default */ 209 200 map->m_bdev = sb->s_bdev; 210 201 map->m_daxdev = EROFS_SB(sb)->dax_dev; 211 202 map->m_dax_part_off = EROFS_SB(sb)->dax_part_off; ··· 217 210 up_read(&devs->rwsem); 218 211 return -ENODEV; 219 212 } 213 + if (devs->flatdev) { 214 + map->m_pa += erofs_pos(sb, dif->mapped_blkaddr); 215 + up_read(&devs->rwsem); 216 + return 0; 217 + } 220 218 map->m_bdev = dif->bdev; 221 219 map->m_daxdev = dif->dax_dev; 222 220 map->m_dax_part_off = dif->dax_part_off; 223 221 map->m_fscache = dif->fscache; 224 222 up_read(&devs->rwsem); 225 - } else if (devs->extra_devices) { 223 + } else if (devs->extra_devices && !devs->flatdev) { 226 224 down_read(&devs->rwsem); 227 225 idr_for_each_entry(&devs->tree, dif, id) { 228 226 erofs_off_t startoff, length; 229 227 230 228 if (!dif->mapped_blkaddr) 231 229 continue; 232 - startoff = blknr_to_addr(dif->mapped_blkaddr); 233 - length = blknr_to_addr(dif->blocks); 230 + startoff = erofs_pos(sb, dif->mapped_blkaddr); 231 + length = erofs_pos(sb, dif->blocks); 234 232 235 233 if (map->m_pa >= startoff && 236 234 map->m_pa < startoff + length) { ··· 256 244 unsigned int flags, struct iomap *iomap, struct iomap *srcmap) 257 245 { 258 246 int ret; 247 + struct super_block *sb = inode->i_sb; 259 248 struct erofs_map_blocks map; 260 249 struct erofs_map_dev mdev; 261 250 ··· 271 258 .m_deviceid = map.m_deviceid, 272 259 .m_pa = map.m_pa, 273 260 }; 274 - ret = erofs_map_dev(inode->i_sb, &mdev); 261 + ret = erofs_map_dev(sb, &mdev); 275 262 if (ret) 276 263 return ret; 277 264 ··· 297 284 struct erofs_buf buf = __EROFS_BUF_INITIALIZER; 298 285 299 286 iomap->type = IOMAP_INLINE; 300 - ptr = erofs_read_metabuf(&buf, inode->i_sb, 301 - erofs_blknr(mdev.m_pa), EROFS_KMAP); 287 + ptr = erofs_read_metabuf(&buf, sb, 288 + erofs_blknr(sb, mdev.m_pa), EROFS_KMAP); 302 289 if (IS_ERR(ptr)) 303 290 return PTR_ERR(ptr); 304 - iomap->inline_data = ptr + erofs_blkoff(mdev.m_pa); 291 + iomap->inline_data = ptr + erofs_blkoff(sb, mdev.m_pa); 305 292 iomap->private = buf.base; 306 293 } else { 307 294 iomap->type = IOMAP_MAPPED;
+3 -3
fs/erofs/decompressor.c
··· 42 42 if (!sbi->lz4.max_pclusterblks) { 43 43 sbi->lz4.max_pclusterblks = 1; /* reserved case */ 44 44 } else if (sbi->lz4.max_pclusterblks > 45 - Z_EROFS_PCLUSTER_MAX_SIZE / EROFS_BLKSIZ) { 45 + erofs_blknr(sb, Z_EROFS_PCLUSTER_MAX_SIZE)) { 46 46 erofs_err(sb, "too large lz4 pclusterblks %u", 47 47 sbi->lz4.max_pclusterblks); 48 48 return -EINVAL; ··· 221 221 support_0padding = true; 222 222 ret = z_erofs_fixup_insize(rq, headpage + rq->pageofs_in, 223 223 min_t(unsigned int, rq->inputsize, 224 - EROFS_BLKSIZ - rq->pageofs_in)); 224 + rq->sb->s_blocksize - rq->pageofs_in)); 225 225 if (ret) { 226 226 kunmap_atomic(headpage); 227 227 return ret; 228 228 } 229 229 may_inplace = !((rq->pageofs_in + rq->inputsize) & 230 - (EROFS_BLKSIZ - 1)); 230 + (rq->sb->s_blocksize - 1)); 231 231 } 232 232 233 233 inputmargin = rq->pageofs_in;
+2 -2
fs/erofs/decompressor_lzma.c
··· 166 166 /* 1. get the exact LZMA compressed size */ 167 167 kin = kmap(*rq->in); 168 168 err = z_erofs_fixup_insize(rq, kin + rq->pageofs_in, 169 - min_t(unsigned int, rq->inputsize, 170 - EROFS_BLKSIZ - rq->pageofs_in)); 169 + min_t(unsigned int, rq->inputsize, 170 + rq->sb->s_blocksize - rq->pageofs_in)); 171 171 if (err) { 172 172 kunmap(*rq->in); 173 173 return err;
+12 -13
fs/erofs/dir.c
··· 50 50 { 51 51 struct inode *dir = file_inode(f); 52 52 struct erofs_buf buf = __EROFS_BUF_INITIALIZER; 53 + struct super_block *sb = dir->i_sb; 54 + unsigned long bsz = sb->s_blocksize; 53 55 const size_t dirsize = i_size_read(dir); 54 - unsigned int i = ctx->pos / EROFS_BLKSIZ; 55 - unsigned int ofs = ctx->pos % EROFS_BLKSIZ; 56 + unsigned int i = erofs_blknr(sb, ctx->pos); 57 + unsigned int ofs = erofs_blkoff(sb, ctx->pos); 56 58 int err = 0; 57 59 bool initial = true; 58 60 61 + buf.inode = dir; 59 62 while (ctx->pos < dirsize) { 60 63 struct erofs_dirent *de; 61 64 unsigned int nameoff, maxsize; 62 65 63 - de = erofs_bread(&buf, dir, i, EROFS_KMAP); 66 + de = erofs_bread(&buf, i, EROFS_KMAP); 64 67 if (IS_ERR(de)) { 65 - erofs_err(dir->i_sb, 66 - "fail to readdir of logical block %u of nid %llu", 68 + erofs_err(sb, "fail to readdir of logical block %u of nid %llu", 67 69 i, EROFS_I(dir)->nid); 68 70 err = PTR_ERR(de); 69 71 break; 70 72 } 71 73 72 74 nameoff = le16_to_cpu(de->nameoff); 73 - if (nameoff < sizeof(struct erofs_dirent) || 74 - nameoff >= EROFS_BLKSIZ) { 75 - erofs_err(dir->i_sb, 76 - "invalid de[0].nameoff %u @ nid %llu", 75 + if (nameoff < sizeof(struct erofs_dirent) || nameoff >= bsz) { 76 + erofs_err(sb, "invalid de[0].nameoff %u @ nid %llu", 77 77 nameoff, EROFS_I(dir)->nid); 78 78 err = -EFSCORRUPTED; 79 79 break; 80 80 } 81 81 82 - maxsize = min_t(unsigned int, 83 - dirsize - ctx->pos + ofs, EROFS_BLKSIZ); 82 + maxsize = min_t(unsigned int, dirsize - ctx->pos + ofs, bsz); 84 83 85 84 /* search dirents at the arbitrary position */ 86 85 if (initial) { 87 86 initial = false; 88 87 89 88 ofs = roundup(ofs, sizeof(struct erofs_dirent)); 90 - ctx->pos = blknr_to_addr(i) + ofs; 89 + ctx->pos = erofs_pos(sb, i) + ofs; 91 90 if (ofs >= nameoff) 92 91 goto skip_this; 93 92 } ··· 96 97 if (err) 97 98 break; 98 99 skip_this: 99 - ctx->pos = blknr_to_addr(i) + maxsize; 100 + ctx->pos = erofs_pos(sb, i) + maxsize; 100 101 ++i; 101 102 ofs = 0; 102 103 }
+85 -89
fs/erofs/erofs_fs.h
··· 27 27 #define EROFS_FEATURE_INCOMPAT_ZTAILPACKING 0x00000010 28 28 #define EROFS_FEATURE_INCOMPAT_FRAGMENTS 0x00000020 29 29 #define EROFS_FEATURE_INCOMPAT_DEDUPE 0x00000020 30 + #define EROFS_FEATURE_INCOMPAT_XATTR_PREFIXES 0x00000040 30 31 #define EROFS_ALL_FEATURE_INCOMPAT \ 31 32 (EROFS_FEATURE_INCOMPAT_ZERO_PADDING | \ 32 33 EROFS_FEATURE_INCOMPAT_COMPR_CFGS | \ ··· 37 36 EROFS_FEATURE_INCOMPAT_COMPR_HEAD2 | \ 38 37 EROFS_FEATURE_INCOMPAT_ZTAILPACKING | \ 39 38 EROFS_FEATURE_INCOMPAT_FRAGMENTS | \ 40 - EROFS_FEATURE_INCOMPAT_DEDUPE) 39 + EROFS_FEATURE_INCOMPAT_DEDUPE | \ 40 + EROFS_FEATURE_INCOMPAT_XATTR_PREFIXES) 41 41 42 42 #define EROFS_SB_EXTSLOT_SIZE 16 43 43 ··· 55 53 __le32 magic; /* file system magic number */ 56 54 __le32 checksum; /* crc32c(super_block) */ 57 55 __le32 feature_compat; 58 - __u8 blkszbits; /* support block_size == PAGE_SIZE only */ 56 + __u8 blkszbits; /* filesystem block size in bit shift */ 59 57 __u8 sb_extslots; /* superblock size = 128 + sb_extslots * 16 */ 60 58 61 59 __le16 root_nid; /* nid of root directory */ ··· 77 75 } __packed u1; 78 76 __le16 extra_devices; /* # of devices besides the primary device */ 79 77 __le16 devt_slotoff; /* startoff = devt_slotoff * devt_slotsize */ 80 - __u8 reserved[6]; 78 + __u8 dirblkbits; /* directory block size in bit shift */ 79 + __u8 xattr_prefix_count; /* # of long xattr name prefixes */ 80 + __le32 xattr_prefix_start; /* start of long xattr prefixes */ 81 81 __le64 packed_nid; /* nid of the special packed inode */ 82 82 __u8 reserved2[24]; 83 83 }; 84 84 85 85 /* 86 - * erofs inode datalayout (i_format in on-disk inode): 86 + * EROFS inode datalayout (i_format in on-disk inode): 87 87 * 0 - uncompressed flat inode without tail-packing inline data: 88 - * inode, [xattrs], ... | ... | no-holed data 89 88 * 1 - compressed inode with non-compact indexes: 90 - * inode, [xattrs], [map_header], extents ... | ... 91 89 * 2 - uncompressed flat inode with tail-packing inline data: 92 - * inode, [xattrs], tailpacking data, ... | ... | no-holed data 93 90 * 3 - compressed inode with compact indexes: 94 - * inode, [xattrs], map_header, extents ... | ... 95 91 * 4 - chunk-based inode with (optional) multi-device support: 96 - * inode, [xattrs], chunk indexes ... | ... 97 92 * 5~7 - reserved 98 93 */ 99 94 enum { 100 95 EROFS_INODE_FLAT_PLAIN = 0, 101 - EROFS_INODE_FLAT_COMPRESSION_LEGACY = 1, 96 + EROFS_INODE_COMPRESSED_FULL = 1, 102 97 EROFS_INODE_FLAT_INLINE = 2, 103 - EROFS_INODE_FLAT_COMPRESSION = 3, 98 + EROFS_INODE_COMPRESSED_COMPACT = 3, 104 99 EROFS_INODE_CHUNK_BASED = 4, 105 100 EROFS_INODE_DATALAYOUT_MAX 106 101 }; 107 102 108 103 static inline bool erofs_inode_is_data_compressed(unsigned int datamode) 109 104 { 110 - return datamode == EROFS_INODE_FLAT_COMPRESSION || 111 - datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY; 105 + return datamode == EROFS_INODE_COMPRESSED_COMPACT || 106 + datamode == EROFS_INODE_COMPRESSED_FULL; 112 107 } 113 108 114 109 /* bit definitions of inode i_format */ 115 - #define EROFS_I_VERSION_BITS 1 116 - #define EROFS_I_DATALAYOUT_BITS 3 110 + #define EROFS_I_VERSION_MASK 0x01 111 + #define EROFS_I_DATALAYOUT_MASK 0x07 117 112 118 113 #define EROFS_I_VERSION_BIT 0 119 114 #define EROFS_I_DATALAYOUT_BIT 1 115 + #define EROFS_I_ALL_BIT 4 120 116 121 - #define EROFS_I_ALL \ 122 - ((1 << (EROFS_I_DATALAYOUT_BIT + EROFS_I_DATALAYOUT_BITS)) - 1) 117 + #define EROFS_I_ALL ((1 << EROFS_I_ALL_BIT) - 1) 123 118 124 119 /* indicate chunk blkbits, thus 'chunksize = blocksize << chunk blkbits' */ 125 120 #define EROFS_CHUNK_FORMAT_BLKBITS_MASK 0x001F ··· 126 127 #define EROFS_CHUNK_FORMAT_ALL \ 127 128 (EROFS_CHUNK_FORMAT_BLKBITS_MASK | EROFS_CHUNK_FORMAT_INDEXES) 128 129 130 + /* 32-byte on-disk inode */ 131 + #define EROFS_INODE_LAYOUT_COMPACT 0 132 + /* 64-byte on-disk inode */ 133 + #define EROFS_INODE_LAYOUT_EXTENDED 1 134 + 129 135 struct erofs_inode_chunk_info { 130 136 __le16 format; /* chunk blkbits, etc. */ 131 137 __le16 reserved; 138 + }; 139 + 140 + union erofs_inode_i_u { 141 + /* total compressed blocks for compressed inodes */ 142 + __le32 compressed_blocks; 143 + 144 + /* block address for uncompressed flat inodes */ 145 + __le32 raw_blkaddr; 146 + 147 + /* for device files, used to indicate old/new device # */ 148 + __le32 rdev; 149 + 150 + /* for chunk-based files, it contains the summary info */ 151 + struct erofs_inode_chunk_info c; 132 152 }; 133 153 134 154 /* 32-byte reduced form of an ondisk inode */ ··· 160 142 __le16 i_nlink; 161 143 __le32 i_size; 162 144 __le32 i_reserved; 163 - union { 164 - /* total compressed blocks for compressed inodes */ 165 - __le32 compressed_blocks; 166 - /* block address for uncompressed flat inodes */ 167 - __le32 raw_blkaddr; 145 + union erofs_inode_i_u i_u; 168 146 169 - /* for device files, used to indicate old/new device # */ 170 - __le32 rdev; 171 - 172 - /* for chunk-based files, it contains the summary info */ 173 - struct erofs_inode_chunk_info c; 174 - } i_u; 175 - __le32 i_ino; /* only used for 32-bit stat compatibility */ 147 + __le32 i_ino; /* only used for 32-bit stat compatibility */ 176 148 __le16 i_uid; 177 149 __le16 i_gid; 178 150 __le32 i_reserved2; 179 151 }; 180 - 181 - /* 32-byte on-disk inode */ 182 - #define EROFS_INODE_LAYOUT_COMPACT 0 183 - /* 64-byte on-disk inode */ 184 - #define EROFS_INODE_LAYOUT_EXTENDED 1 185 152 186 153 /* 64-byte complete form of an ondisk inode */ 187 154 struct erofs_inode_extended { ··· 177 174 __le16 i_mode; 178 175 __le16 i_reserved; 179 176 __le64 i_size; 180 - union { 181 - /* total compressed blocks for compressed inodes */ 182 - __le32 compressed_blocks; 183 - /* block address for uncompressed flat inodes */ 184 - __le32 raw_blkaddr; 177 + union erofs_inode_i_u i_u; 185 178 186 - /* for device files, used to indicate old/new device # */ 187 - __le32 rdev; 188 - 189 - /* for chunk-based files, it contains the summary info */ 190 - struct erofs_inode_chunk_info c; 191 - } i_u; 192 - 193 - /* only used for 32-bit stat compatibility */ 194 - __le32 i_ino; 195 - 179 + __le32 i_ino; /* only used for 32-bit stat compatibility */ 196 180 __le32 i_uid; 197 181 __le32 i_gid; 198 182 __le64 i_mtime; ··· 187 197 __le32 i_nlink; 188 198 __u8 i_reserved2[16]; 189 199 }; 190 - 191 - #define EROFS_MAX_SHARED_XATTRS (128) 192 - /* h_shared_count between 129 ... 255 are special # */ 193 - #define EROFS_SHARED_XATTR_EXTENT (255) 194 200 195 201 /* 196 202 * inline xattrs (n == i_xattr_icount): ··· 214 228 #define EROFS_XATTR_INDEX_LUSTRE 5 215 229 #define EROFS_XATTR_INDEX_SECURITY 6 216 230 231 + /* 232 + * bit 7 of e_name_index is set when it refers to a long xattr name prefix, 233 + * while the remained lower bits represent the index of the prefix. 234 + */ 235 + #define EROFS_XATTR_LONG_PREFIX 0x80 236 + #define EROFS_XATTR_LONG_PREFIX_MASK 0x7f 237 + 217 238 /* xattr entry (for both inline & shared xattrs) */ 218 239 struct erofs_xattr_entry { 219 240 __u8 e_name_len; /* length of name */ ··· 228 235 __le16 e_value_size; /* size of attribute value */ 229 236 /* followed by e_name and e_value */ 230 237 char e_name[]; /* attribute name */ 238 + }; 239 + 240 + /* long xattr name prefix */ 241 + struct erofs_xattr_long_prefix { 242 + __u8 base_index; /* short xattr name prefix index */ 243 + char infix[]; /* infix apart from short prefix */ 231 244 }; 232 245 233 246 static inline unsigned int erofs_xattr_ibody_size(__le16 i_xattr_icount) ··· 265 266 __le16 device_id; /* back-end storage id (with bits masked) */ 266 267 __le32 blkaddr; /* start block address of this inode chunk */ 267 268 }; 269 + 270 + /* dirent sorts in alphabet order, thus we can do binary search */ 271 + struct erofs_dirent { 272 + __le64 nid; /* node number */ 273 + __le16 nameoff; /* start offset of file name */ 274 + __u8 file_type; /* file type */ 275 + __u8 reserved; /* reserved */ 276 + } __packed; 277 + 278 + /* 279 + * EROFS file types should match generic FT_* types and 280 + * it seems no need to add BUILD_BUG_ONs since potential 281 + * unmatchness will break other fses as well... 282 + */ 283 + 284 + #define EROFS_NAME_LEN 255 268 285 269 286 /* maximum supported size of a physical compression cluster */ 270 287 #define Z_EROFS_PCLUSTER_MAX_SIZE (1024 * 1024) ··· 351 336 __u8 h_clusterbits; 352 337 }; 353 338 354 - #define Z_EROFS_VLE_LEGACY_HEADER_PADDING 8 355 - 356 339 /* 357 - * Fixed-sized output compression on-disk logical cluster type: 340 + * On-disk logical cluster type: 358 341 * 0 - literal (uncompressed) lcluster 359 342 * 1,3 - compressed lcluster (for HEAD lclusters) 360 343 * 2 - compressed lcluster (for NONHEAD lclusters) ··· 376 363 * di_u.delta[1] = distance to the next HEAD lcluster 377 364 */ 378 365 enum { 379 - Z_EROFS_VLE_CLUSTER_TYPE_PLAIN = 0, 380 - Z_EROFS_VLE_CLUSTER_TYPE_HEAD1 = 1, 381 - Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD = 2, 382 - Z_EROFS_VLE_CLUSTER_TYPE_HEAD2 = 3, 383 - Z_EROFS_VLE_CLUSTER_TYPE_MAX 366 + Z_EROFS_LCLUSTER_TYPE_PLAIN = 0, 367 + Z_EROFS_LCLUSTER_TYPE_HEAD1 = 1, 368 + Z_EROFS_LCLUSTER_TYPE_NONHEAD = 2, 369 + Z_EROFS_LCLUSTER_TYPE_HEAD2 = 3, 370 + Z_EROFS_LCLUSTER_TYPE_MAX 384 371 }; 385 372 386 - #define Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS 2 387 - #define Z_EROFS_VLE_DI_CLUSTER_TYPE_BIT 0 373 + #define Z_EROFS_LI_LCLUSTER_TYPE_BITS 2 374 + #define Z_EROFS_LI_LCLUSTER_TYPE_BIT 0 388 375 389 376 /* (noncompact only, HEAD) This pcluster refers to partial decompressed data */ 390 - #define Z_EROFS_VLE_DI_PARTIAL_REF (1 << 15) 377 + #define Z_EROFS_LI_PARTIAL_REF (1 << 15) 391 378 392 379 /* 393 380 * D0_CBLKCNT will be marked _only_ at the 1st non-head lcluster to store the 394 381 * compressed block count of a compressed extent (in logical clusters, aka. 395 382 * block count of a pcluster). 396 383 */ 397 - #define Z_EROFS_VLE_DI_D0_CBLKCNT (1 << 11) 384 + #define Z_EROFS_LI_D0_CBLKCNT (1 << 11) 398 385 399 - struct z_erofs_vle_decompressed_index { 386 + struct z_erofs_lcluster_index { 400 387 __le16 di_advise; 401 388 /* where to decompress in the head lcluster */ 402 389 __le16 di_clusterofs; ··· 413 400 } di_u; 414 401 }; 415 402 416 - #define Z_EROFS_VLE_LEGACY_INDEX_ALIGN(size) \ 417 - (round_up(size, sizeof(struct z_erofs_vle_decompressed_index)) + \ 418 - sizeof(struct z_erofs_map_header) + Z_EROFS_VLE_LEGACY_HEADER_PADDING) 419 - 420 - /* dirent sorts in alphabet order, thus we can do binary search */ 421 - struct erofs_dirent { 422 - __le64 nid; /* node number */ 423 - __le16 nameoff; /* start offset of file name */ 424 - __u8 file_type; /* file type */ 425 - __u8 reserved; /* reserved */ 426 - } __packed; 427 - 428 - /* 429 - * EROFS file types should match generic FT_* types and 430 - * it seems no need to add BUILD_BUG_ONs since potential 431 - * unmatchness will break other fses as well... 432 - */ 433 - 434 - #define EROFS_NAME_LEN 255 403 + #define Z_EROFS_FULL_INDEX_ALIGN(end) \ 404 + (ALIGN(end, 8) + sizeof(struct z_erofs_map_header) + 8) 435 405 436 406 /* check the EROFS on-disk layout strictly at compile time */ 437 407 static inline void erofs_check_ondisk_layout_definitions(void) ··· 431 435 BUILD_BUG_ON(sizeof(struct erofs_inode_chunk_info) != 4); 432 436 BUILD_BUG_ON(sizeof(struct erofs_inode_chunk_index) != 8); 433 437 BUILD_BUG_ON(sizeof(struct z_erofs_map_header) != 8); 434 - BUILD_BUG_ON(sizeof(struct z_erofs_vle_decompressed_index) != 8); 438 + BUILD_BUG_ON(sizeof(struct z_erofs_lcluster_index) != 8); 435 439 BUILD_BUG_ON(sizeof(struct erofs_dirent) != 12); 436 440 /* keep in sync between 2 index structures for better extendibility */ 437 441 BUILD_BUG_ON(sizeof(struct erofs_inode_chunk_index) != 438 - sizeof(struct z_erofs_vle_decompressed_index)); 442 + sizeof(struct z_erofs_lcluster_index)); 439 443 BUILD_BUG_ON(sizeof(struct erofs_deviceslot) != 128); 440 444 441 - BUILD_BUG_ON(BIT(Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS) < 442 - Z_EROFS_VLE_CLUSTER_TYPE_MAX - 1); 445 + BUILD_BUG_ON(BIT(Z_EROFS_LI_LCLUSTER_TYPE_BITS) < 446 + Z_EROFS_LCLUSTER_TYPE_MAX - 1); 443 447 /* exclude old compiler versions like gcc 7.5.0 */ 444 448 BUILD_BUG_ON(__builtin_constant_p(fmh) ? 445 449 fmh != cpu_to_le64(1ULL << 63) : 0);
+3 -2
fs/erofs/fscache.c
··· 209 209 void *src; 210 210 211 211 /* For tail packing layout, the offset may be non-zero. */ 212 - offset = erofs_blkoff(map.m_pa); 213 - blknr = erofs_blknr(map.m_pa); 212 + offset = erofs_blkoff(sb, map.m_pa); 213 + blknr = erofs_blknr(sb, map.m_pa); 214 214 size = map.m_llen; 215 215 216 216 src = erofs_read_metabuf(&buf, sb, blknr, EROFS_KMAP); ··· 460 460 inode->i_size = OFFSET_MAX; 461 461 inode->i_mapping->a_ops = &erofs_fscache_meta_aops; 462 462 mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS); 463 + inode->i_blkbits = EROFS_SB(sb)->blkszbits; 463 464 inode->i_private = ctx; 464 465 465 466 ctx->cookie = cookie;
+20 -16
fs/erofs/inode.c
··· 23 23 unsigned int ifmt; 24 24 int err; 25 25 26 - blkaddr = erofs_blknr(inode_loc); 27 - *ofs = erofs_blkoff(inode_loc); 28 - 29 - erofs_dbg("%s, reading inode nid %llu at %u of blkaddr %u", 30 - __func__, vi->nid, *ofs, blkaddr); 26 + blkaddr = erofs_blknr(sb, inode_loc); 27 + *ofs = erofs_blkoff(sb, inode_loc); 31 28 32 29 kaddr = erofs_read_metabuf(buf, sb, blkaddr, EROFS_KMAP); 33 30 if (IS_ERR(kaddr)) { ··· 55 58 case EROFS_INODE_LAYOUT_EXTENDED: 56 59 vi->inode_isize = sizeof(struct erofs_inode_extended); 57 60 /* check if the extended inode acrosses block boundary */ 58 - if (*ofs + vi->inode_isize <= EROFS_BLKSIZ) { 61 + if (*ofs + vi->inode_isize <= sb->s_blocksize) { 59 62 *ofs += vi->inode_isize; 60 63 die = (struct erofs_inode_extended *)dic; 61 64 } else { 62 - const unsigned int gotten = EROFS_BLKSIZ - *ofs; 65 + const unsigned int gotten = sb->s_blocksize - *ofs; 63 66 64 67 copied = kmalloc(vi->inode_isize, GFP_NOFS); 65 68 if (!copied) { ··· 173 176 err = -EOPNOTSUPP; 174 177 goto err_out; 175 178 } 176 - vi->chunkbits = LOG_BLOCK_SIZE + 179 + vi->chunkbits = sb->s_blocksize_bits + 177 180 (vi->chunkformat & EROFS_CHUNK_FORMAT_BLKBITS_MASK); 178 181 } 179 182 inode->i_mtime.tv_sec = inode->i_ctime.tv_sec; ··· 185 188 if (test_opt(&sbi->opt, DAX_ALWAYS) && S_ISREG(inode->i_mode) && 186 189 vi->datalayout == EROFS_INODE_FLAT_PLAIN) 187 190 inode->i_flags |= S_DAX; 191 + 188 192 if (!nblks) 189 193 /* measure inode.i_blocks as generic filesystems */ 190 - inode->i_blocks = roundup(inode->i_size, EROFS_BLKSIZ) >> 9; 194 + inode->i_blocks = round_up(inode->i_size, sb->s_blocksize) >> 9; 191 195 else 192 - inode->i_blocks = nblks << LOG_SECTORS_PER_BLOCK; 196 + inode->i_blocks = nblks << (sb->s_blocksize_bits - 9); 193 197 return kaddr; 194 198 195 199 bogusimode: ··· 208 210 unsigned int m_pofs) 209 211 { 210 212 struct erofs_inode *vi = EROFS_I(inode); 213 + unsigned int bsz = i_blocksize(inode); 211 214 char *lnk; 212 215 213 216 /* if it cannot be handled with fast symlink scheme */ 214 217 if (vi->datalayout != EROFS_INODE_FLAT_INLINE || 215 - inode->i_size >= EROFS_BLKSIZ || inode->i_size < 0) { 218 + inode->i_size >= bsz || inode->i_size < 0) { 216 219 inode->i_op = &erofs_symlink_iops; 217 220 return 0; 218 221 } ··· 224 225 225 226 m_pofs += vi->xattr_isize; 226 227 /* inline symlink data shouldn't cross block boundary */ 227 - if (m_pofs + inode->i_size > EROFS_BLKSIZ) { 228 + if (m_pofs + inode->i_size > bsz) { 228 229 kfree(lnk); 229 230 erofs_err(inode->i_sb, 230 231 "inline data cross block boundary @ nid %llu", ··· 288 289 } 289 290 290 291 if (erofs_inode_is_data_compressed(vi->datalayout)) { 291 - if (!erofs_is_fscache_mode(inode->i_sb)) 292 - err = z_erofs_fill_inode(inode); 293 - else 294 - err = -EOPNOTSUPP; 292 + #ifdef CONFIG_EROFS_FS_ZIP 293 + if (!erofs_is_fscache_mode(inode->i_sb) && 294 + inode->i_sb->s_blocksize_bits == PAGE_SHIFT) { 295 + inode->i_mapping->a_ops = &z_erofs_aops; 296 + err = 0; 297 + goto out_unlock; 298 + } 299 + #endif 300 + err = -EOPNOTSUPP; 295 301 goto out_unlock; 296 302 } 297 303 inode->i_mapping->a_ops = &erofs_raw_access_aops;
+30 -43
fs/erofs/internal.h
··· 31 31 #define erofs_info(sb, fmt, ...) \ 32 32 _erofs_info(sb, __func__, fmt "\n", ##__VA_ARGS__) 33 33 #ifdef CONFIG_EROFS_FS_DEBUG 34 - #define erofs_dbg(x, ...) pr_debug(x "\n", ##__VA_ARGS__) 35 34 #define DBG_BUGON BUG_ON 36 35 #else 37 - #define erofs_dbg(x, ...) ((void)0) 38 36 #define DBG_BUGON(x) ((void)(x)) 39 37 #endif /* !CONFIG_EROFS_FS_DEBUG */ 40 38 ··· 79 81 struct rw_semaphore rwsem; 80 82 81 83 unsigned int extra_devices; 84 + bool flatdev; 82 85 }; 83 86 84 87 struct erofs_fs_context { ··· 115 116 char *name; 116 117 }; 117 118 119 + struct erofs_xattr_prefix_item { 120 + struct erofs_xattr_long_prefix *prefix; 121 + u8 infix_len; 122 + }; 123 + 118 124 struct erofs_sb_info { 119 125 struct erofs_mount_opts opt; /* options */ 120 126 #ifdef CONFIG_EROFS_FS_ZIP ··· 137 133 struct inode *managed_cache; 138 134 139 135 struct erofs_sb_lz4_info lz4; 140 - struct inode *packed_inode; 141 136 #endif /* CONFIG_EROFS_FS_ZIP */ 137 + struct inode *packed_inode; 142 138 struct erofs_dev_context *devs; 143 139 struct dax_device *dax_dev; 144 140 u64 dax_part_off; ··· 148 144 u32 meta_blkaddr; 149 145 #ifdef CONFIG_EROFS_FS_XATTR 150 146 u32 xattr_blkaddr; 147 + u32 xattr_prefix_start; 148 + u8 xattr_prefix_count; 149 + struct erofs_xattr_prefix_item *xattr_prefixes; 151 150 #endif 152 151 u16 device_id_mask; /* valid bits of device id to be used */ 153 152 154 - /* inode slot unit size in bit shift */ 155 - unsigned char islotbits; 153 + unsigned char islotbits; /* inode slot unit size in bit shift */ 154 + unsigned char blkszbits; /* filesystem block size in bit shift */ 156 155 157 156 u32 sb_size; /* total superblock size */ 158 157 u32 build_time_nsec; ··· 163 156 164 157 /* what we really care is nid, rather than ino.. */ 165 158 erofs_nid_t root_nid; 159 + erofs_nid_t packed_nid; 166 160 /* used for statfs, f_files - f_favail */ 167 161 u64 inos; 168 162 ··· 248 240 VAL != EROFS_LOCKED_MAGIC); 249 241 } 250 242 251 - /* we strictly follow PAGE_SIZE and no buffer head yet */ 252 - #define LOG_BLOCK_SIZE PAGE_SHIFT 253 - 254 - #undef LOG_SECTORS_PER_BLOCK 255 - #define LOG_SECTORS_PER_BLOCK (PAGE_SHIFT - 9) 256 - 257 - #undef SECTORS_PER_BLOCK 258 - #define SECTORS_PER_BLOCK (1 << SECTORS_PER_BLOCK) 259 - 260 - #define EROFS_BLKSIZ (1 << LOG_BLOCK_SIZE) 261 - 262 - #if (EROFS_BLKSIZ % 4096 || !EROFS_BLKSIZ) 263 - #error erofs cannot be used in this platform 264 - #endif 265 - 266 243 enum erofs_kmap_type { 267 244 EROFS_NO_KMAP, /* don't map the buffer */ 268 245 EROFS_KMAP, /* use kmap_local_page() to map the buffer */ 269 246 }; 270 247 271 248 struct erofs_buf { 249 + struct inode *inode; 272 250 struct page *page; 273 251 void *base; 274 252 enum erofs_kmap_type kmap_type; ··· 263 269 264 270 #define ROOT_NID(sb) ((sb)->root_nid) 265 271 266 - #define erofs_blknr(addr) ((addr) / EROFS_BLKSIZ) 267 - #define erofs_blkoff(addr) ((addr) % EROFS_BLKSIZ) 268 - #define blknr_to_addr(nr) ((erofs_off_t)(nr) * EROFS_BLKSIZ) 272 + #define erofs_blknr(sb, addr) ((addr) >> (sb)->s_blocksize_bits) 273 + #define erofs_blkoff(sb, addr) ((addr) & ((sb)->s_blocksize - 1)) 274 + #define erofs_pos(sb, blk) ((erofs_off_t)(blk) << (sb)->s_blocksize_bits) 275 + #define erofs_iblks(i) (round_up((i)->i_size, i_blocksize(i)) >> (i)->i_blkbits) 269 276 270 277 #define EROFS_FEATURE_FUNCS(name, compat, feature) \ 271 278 static inline bool erofs_sb_has_##name(struct erofs_sb_info *sbi) \ ··· 283 288 EROFS_FEATURE_FUNCS(ztailpacking, incompat, INCOMPAT_ZTAILPACKING) 284 289 EROFS_FEATURE_FUNCS(fragments, incompat, INCOMPAT_FRAGMENTS) 285 290 EROFS_FEATURE_FUNCS(dedupe, incompat, INCOMPAT_DEDUPE) 291 + EROFS_FEATURE_FUNCS(xattr_prefixes, incompat, INCOMPAT_XATTR_PREFIXES) 286 292 EROFS_FEATURE_FUNCS(sb_chksum, compat, COMPAT_SB_CHKSUM) 287 293 288 294 /* atomic flag definitions */ ··· 302 306 303 307 unsigned char datalayout; 304 308 unsigned char inode_isize; 305 - unsigned short xattr_isize; 309 + unsigned int xattr_isize; 306 310 307 311 unsigned int xattr_shared_count; 308 312 unsigned int *xattr_shared_xattrs; ··· 339 343 { 340 344 struct erofs_sb_info *sbi = EROFS_I_SB(inode); 341 345 342 - return blknr_to_addr(sbi->meta_blkaddr) + 346 + return erofs_pos(inode->i_sb, sbi->meta_blkaddr) + 343 347 (EROFS_I(inode)->nid << sbi->islotbits); 344 348 } 345 349 346 - static inline unsigned int erofs_bitrange(unsigned int value, unsigned int bit, 347 - unsigned int bits) 350 + static inline unsigned int erofs_inode_version(unsigned int ifmt) 348 351 { 349 - 350 - return (value >> bit) & ((1 << bits) - 1); 352 + return (ifmt >> EROFS_I_VERSION_BIT) & EROFS_I_VERSION_MASK; 351 353 } 352 354 353 - 354 - static inline unsigned int erofs_inode_version(unsigned int value) 355 + static inline unsigned int erofs_inode_datalayout(unsigned int ifmt) 355 356 { 356 - return erofs_bitrange(value, EROFS_I_VERSION_BIT, 357 - EROFS_I_VERSION_BITS); 358 - } 359 - 360 - static inline unsigned int erofs_inode_datalayout(unsigned int value) 361 - { 362 - return erofs_bitrange(value, EROFS_I_DATALAYOUT_BIT, 363 - EROFS_I_DATALAYOUT_BITS); 357 + return (ifmt >> EROFS_I_DATALAYOUT_BIT) & EROFS_I_DATALAYOUT_MASK; 364 358 } 365 359 366 360 /* ··· 437 451 #define EROFS_REG_COOKIE_SHARE 0x0001 438 452 #define EROFS_REG_COOKIE_NEED_NOEXIST 0x0002 439 453 454 + void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf, 455 + erofs_off_t *offset, int *lengthp); 440 456 void erofs_unmap_metabuf(struct erofs_buf *buf); 441 457 void erofs_put_metabuf(struct erofs_buf *buf); 442 - void *erofs_bread(struct erofs_buf *buf, struct inode *inode, 443 - erofs_blk_t blkaddr, enum erofs_kmap_type type); 458 + void *erofs_bread(struct erofs_buf *buf, erofs_blk_t blkaddr, 459 + enum erofs_kmap_type type); 460 + void erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb); 444 461 void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb, 445 462 erofs_blk_t blkaddr, enum erofs_kmap_type type); 446 463 int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *dev); ··· 510 521 int z_erofs_load_lz4_config(struct super_block *sb, 511 522 struct erofs_super_block *dsb, 512 523 struct z_erofs_lz4_cfgs *lz4, int len); 513 - int z_erofs_fill_inode(struct inode *inode); 514 524 int z_erofs_map_blocks_iter(struct inode *inode, struct erofs_map_blocks *map, 515 525 int flags); 516 526 #else ··· 529 541 } 530 542 return 0; 531 543 } 532 - static inline int z_erofs_fill_inode(struct inode *inode) { return -EOPNOTSUPP; } 533 544 #endif /* !CONFIG_EROFS_FS_ZIP */ 534 545 535 546 #ifdef CONFIG_EROFS_FS_ZIP_LZMA
+13 -14
fs/erofs/namei.c
··· 89 89 static void *erofs_find_target_block(struct erofs_buf *target, 90 90 struct inode *dir, struct erofs_qstr *name, int *_ndirents) 91 91 { 92 - int head = 0, back = DIV_ROUND_UP(dir->i_size, EROFS_BLKSIZ) - 1; 92 + unsigned int bsz = i_blocksize(dir); 93 + int head = 0, back = erofs_iblks(dir) - 1; 93 94 unsigned int startprfx = 0, endprfx = 0; 94 95 void *candidate = ERR_PTR(-ENOENT); 95 96 ··· 99 98 struct erofs_buf buf = __EROFS_BUF_INITIALIZER; 100 99 struct erofs_dirent *de; 101 100 102 - de = erofs_bread(&buf, dir, mid, EROFS_KMAP); 101 + buf.inode = dir; 102 + de = erofs_bread(&buf, mid, EROFS_KMAP); 103 103 if (!IS_ERR(de)) { 104 - const int nameoff = nameoff_from_disk(de->nameoff, 105 - EROFS_BLKSIZ); 104 + const int nameoff = nameoff_from_disk(de->nameoff, bsz); 106 105 const int ndirents = nameoff / sizeof(*de); 107 106 int diff; 108 107 unsigned int matched; ··· 122 121 123 122 dname.name = (u8 *)de + nameoff; 124 123 if (ndirents == 1) 125 - dname.end = (u8 *)de + EROFS_BLKSIZ; 124 + dname.end = (u8 *)de + bsz; 126 125 else 127 126 dname.end = (u8 *)de + 128 - nameoff_from_disk(de[1].nameoff, 129 - EROFS_BLKSIZ); 127 + nameoff_from_disk(de[1].nameoff, bsz); 130 128 131 129 /* string comparison without already matched prefix */ 132 130 diff = erofs_dirnamecmp(name, &dname, &matched); ··· 171 171 172 172 qn.name = name->name; 173 173 qn.end = name->name + name->len; 174 + buf.inode = dir; 174 175 175 176 ndirents = 0; 176 177 de = erofs_find_target_block(&buf, dir, &qn, &ndirents); ··· 179 178 return PTR_ERR(de); 180 179 181 180 if (ndirents) 182 - de = find_target_dirent(&qn, (u8 *)de, EROFS_BLKSIZ, ndirents); 181 + de = find_target_dirent(&qn, (u8 *)de, i_blocksize(dir), 182 + ndirents); 183 183 184 184 if (!IS_ERR(de)) { 185 185 *nid = le64_to_cpu(de->nid); ··· 205 203 206 204 err = erofs_namei(dir, &dentry->d_name, &nid, &d_type); 207 205 208 - if (err == -ENOENT) { 206 + if (err == -ENOENT) 209 207 /* negative dentry */ 210 208 inode = NULL; 211 - } else if (err) { 209 + else if (err) 212 210 inode = ERR_PTR(err); 213 - } else { 214 - erofs_dbg("%s, %pd (nid %llu) found, d_type %u", __func__, 215 - dentry, nid, d_type); 211 + else 216 212 inode = erofs_iget(dir->i_sb, nid); 217 - } 218 213 return d_splice_alias(inode, dentry); 219 214 } 220 215
+70 -46
fs/erofs/super.c
··· 52 52 53 53 static int erofs_superblock_csum_verify(struct super_block *sb, void *sbdata) 54 54 { 55 + size_t len = 1 << EROFS_SB(sb)->blkszbits; 55 56 struct erofs_super_block *dsb; 56 57 u32 expected_crc, crc; 57 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 63 if (!dsb) 61 64 return -ENOMEM; 62 65 63 66 expected_crc = le32_to_cpu(dsb->checksum); 64 67 dsb->checksum = 0; 65 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 70 kfree(dsb); 68 71 69 72 if (crc != expected_crc) { ··· 126 123 return true; 127 124 } 128 125 129 - #ifdef CONFIG_EROFS_FS_ZIP 130 126 /* read variable-sized metadata, offset will be aligned by 4-byte */ 131 - static void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf, 132 - erofs_off_t *offset, int *lengthp) 127 + void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf, 128 + erofs_off_t *offset, int *lengthp) 133 129 { 134 130 u8 *buffer, *ptr; 135 131 int len, i, cnt; 136 132 137 133 *offset = round_up(*offset, 4); 138 - ptr = erofs_read_metabuf(buf, sb, erofs_blknr(*offset), EROFS_KMAP); 134 + ptr = erofs_bread(buf, erofs_blknr(sb, *offset), EROFS_KMAP); 139 135 if (IS_ERR(ptr)) 140 136 return ptr; 141 137 142 - len = le16_to_cpu(*(__le16 *)&ptr[erofs_blkoff(*offset)]); 138 + len = le16_to_cpu(*(__le16 *)&ptr[erofs_blkoff(sb, *offset)]); 143 139 if (!len) 144 140 len = U16_MAX + 1; 145 141 buffer = kmalloc(len, GFP_KERNEL); ··· 148 146 *lengthp = len; 149 147 150 148 for (i = 0; i < len; i += cnt) { 151 - cnt = min(EROFS_BLKSIZ - (int)erofs_blkoff(*offset), len - i); 152 - ptr = erofs_read_metabuf(buf, sb, erofs_blknr(*offset), 153 - EROFS_KMAP); 149 + cnt = min_t(int, sb->s_blocksize - erofs_blkoff(sb, *offset), 150 + len - i); 151 + ptr = erofs_bread(buf, erofs_blknr(sb, *offset), EROFS_KMAP); 154 152 if (IS_ERR(ptr)) { 155 153 kfree(buffer); 156 154 return ptr; 157 155 } 158 - memcpy(buffer + i, ptr + erofs_blkoff(*offset), cnt); 156 + memcpy(buffer + i, ptr + erofs_blkoff(sb, *offset), cnt); 159 157 *offset += cnt; 160 158 } 161 159 return buffer; 162 160 } 163 161 162 + #ifdef CONFIG_EROFS_FS_ZIP 164 163 static int erofs_load_compr_cfgs(struct super_block *sb, 165 164 struct erofs_super_block *dsb) 166 165 { ··· 178 175 return -EINVAL; 179 176 } 180 177 178 + erofs_init_metabuf(&buf, sb); 181 179 offset = EROFS_SUPER_OFFSET + sbi->sb_size; 182 180 alg = 0; 183 181 for (algs = sbi->available_compr_algs; algs; algs >>= 1, ++alg) { ··· 232 228 struct block_device *bdev; 233 229 void *ptr; 234 230 235 - ptr = erofs_read_metabuf(buf, sb, erofs_blknr(*pos), EROFS_KMAP); 231 + ptr = erofs_read_metabuf(buf, sb, erofs_blknr(sb, *pos), EROFS_KMAP); 236 232 if (IS_ERR(ptr)) 237 233 return PTR_ERR(ptr); 238 - dis = ptr + erofs_blkoff(*pos); 234 + dis = ptr + erofs_blkoff(sb, *pos); 239 235 240 236 if (!dif->path) { 241 237 if (!dis->tag[0]) { ··· 252 248 if (IS_ERR(fscache)) 253 249 return PTR_ERR(fscache); 254 250 dif->fscache = fscache; 255 - } else { 251 + } else if (!sbi->devs->flatdev) { 256 252 bdev = blkdev_get_by_path(dif->path, FMODE_READ | FMODE_EXCL, 257 253 sb->s_type); 258 254 if (IS_ERR(bdev)) ··· 294 290 if (!ondisk_extradevs) 295 291 return 0; 296 292 293 + if (!sbi->devs->extra_devices && !erofs_is_fscache_mode(sb)) 294 + sbi->devs->flatdev = true; 295 + 297 296 sbi->device_id_mask = roundup_pow_of_two(ondisk_extradevs + 1) - 1; 298 297 pos = le16_to_cpu(dsb->devt_slotoff) * EROFS_DEVT_SLOT_SIZE; 299 298 down_read(&sbi->devs->rwsem); ··· 336 329 struct erofs_sb_info *sbi; 337 330 struct erofs_buf buf = __EROFS_BUF_INITIALIZER; 338 331 struct erofs_super_block *dsb; 339 - unsigned int blkszbits; 340 332 void *data; 341 333 int ret; 342 334 ··· 354 348 goto out; 355 349 } 356 350 351 + sbi->blkszbits = dsb->blkszbits; 352 + if (sbi->blkszbits < 9 || sbi->blkszbits > PAGE_SHIFT) { 353 + erofs_err(sb, "blkszbits %u isn't supported", sbi->blkszbits); 354 + goto out; 355 + } 356 + if (dsb->dirblkbits) { 357 + erofs_err(sb, "dirblkbits %u isn't supported", dsb->dirblkbits); 358 + goto out; 359 + } 360 + 357 361 sbi->feature_compat = le32_to_cpu(dsb->feature_compat); 358 362 if (erofs_sb_has_sb_chksum(sbi)) { 359 363 ret = erofs_superblock_csum_verify(sb, data); ··· 372 356 } 373 357 374 358 ret = -EINVAL; 375 - blkszbits = dsb->blkszbits; 376 - /* 9(512 bytes) + LOG_SECTORS_PER_BLOCK == LOG_BLOCK_SIZE */ 377 - if (blkszbits != LOG_BLOCK_SIZE) { 378 - erofs_err(sb, "blkszbits %u isn't supported on this platform", 379 - blkszbits); 380 - goto out; 381 - } 382 - 383 359 if (!check_layout_compatibility(sb, dsb)) 384 360 goto out; 385 361 386 362 sbi->sb_size = 128 + dsb->sb_extslots * EROFS_SB_EXTSLOT_SIZE; 387 - if (sbi->sb_size > EROFS_BLKSIZ) { 363 + if (sbi->sb_size > PAGE_SIZE - EROFS_SUPER_OFFSET) { 388 364 erofs_err(sb, "invalid sb_extslots %u (more than a fs block)", 389 365 sbi->sb_size); 390 366 goto out; ··· 385 377 sbi->meta_blkaddr = le32_to_cpu(dsb->meta_blkaddr); 386 378 #ifdef CONFIG_EROFS_FS_XATTR 387 379 sbi->xattr_blkaddr = le32_to_cpu(dsb->xattr_blkaddr); 380 + sbi->xattr_prefix_start = le32_to_cpu(dsb->xattr_prefix_start); 381 + sbi->xattr_prefix_count = dsb->xattr_prefix_count; 388 382 #endif 389 383 sbi->islotbits = ilog2(sizeof(struct erofs_inode_compact)); 390 384 sbi->root_nid = le16_to_cpu(dsb->root_nid); 391 - #ifdef CONFIG_EROFS_FS_ZIP 392 - sbi->packed_inode = NULL; 393 - if (erofs_sb_has_fragments(sbi) && dsb->packed_nid) { 394 - sbi->packed_inode = 395 - erofs_iget(sb, le64_to_cpu(dsb->packed_nid)); 396 - if (IS_ERR(sbi->packed_inode)) { 397 - ret = PTR_ERR(sbi->packed_inode); 398 - goto out; 399 - } 400 - } 401 - #endif 385 + sbi->packed_nid = le64_to_cpu(dsb->packed_nid); 402 386 sbi->inos = le64_to_cpu(dsb->inos); 403 387 404 388 sbi->build_time = le64_to_cpu(dsb->build_time); ··· 417 417 /* handle multiple devices */ 418 418 ret = erofs_scan_devices(sb, dsb); 419 419 420 - if (erofs_sb_has_ztailpacking(sbi)) 421 - erofs_info(sb, "EXPERIMENTAL compressed inline data feature in use. Use at your own risk!"); 422 420 if (erofs_is_fscache_mode(sb)) 423 421 erofs_info(sb, "EXPERIMENTAL fscache-based on-demand read feature in use. Use at your own risk!"); 424 422 if (erofs_sb_has_fragments(sbi)) ··· 731 733 sbi->domain_id = ctx->domain_id; 732 734 ctx->domain_id = NULL; 733 735 736 + sbi->blkszbits = PAGE_SHIFT; 734 737 if (erofs_is_fscache_mode(sb)) { 735 - sb->s_blocksize = EROFS_BLKSIZ; 736 - sb->s_blocksize_bits = LOG_BLOCK_SIZE; 738 + sb->s_blocksize = PAGE_SIZE; 739 + sb->s_blocksize_bits = PAGE_SHIFT; 737 740 738 741 err = erofs_fscache_register_fs(sb); 739 742 if (err) ··· 744 745 if (err) 745 746 return err; 746 747 } else { 747 - if (!sb_set_blocksize(sb, EROFS_BLKSIZ)) { 748 - erofs_err(sb, "failed to set erofs blksize"); 748 + if (!sb_set_blocksize(sb, PAGE_SIZE)) { 749 + errorfc(fc, "failed to set initial blksize"); 749 750 return -EINVAL; 750 751 } 751 752 ··· 758 759 if (err) 759 760 return err; 760 761 761 - if (test_opt(&sbi->opt, DAX_ALWAYS)) { 762 - BUILD_BUG_ON(EROFS_BLKSIZ != PAGE_SIZE); 762 + if (sb->s_blocksize_bits != sbi->blkszbits) { 763 + if (erofs_is_fscache_mode(sb)) { 764 + errorfc(fc, "unsupported blksize for fscache mode"); 765 + return -EINVAL; 766 + } 767 + if (!sb_set_blocksize(sb, 1 << sbi->blkszbits)) { 768 + errorfc(fc, "failed to set erofs blksize"); 769 + return -EINVAL; 770 + } 771 + } 763 772 773 + if (test_opt(&sbi->opt, DAX_ALWAYS)) { 764 774 if (!sbi->dax_dev) { 765 775 errorfc(fc, "DAX unsupported by block device. Turning off DAX."); 776 + clear_opt(&sbi->opt, DAX_ALWAYS); 777 + } else if (sbi->blkszbits != PAGE_SHIFT) { 778 + errorfc(fc, "unsupported blocksize for DAX"); 766 779 clear_opt(&sbi->opt, DAX_ALWAYS); 767 780 } 768 781 } ··· 810 799 811 800 erofs_shrinker_register(sb); 812 801 /* sb->s_umount is already locked, SB_ACTIVE and SB_BORN are not set */ 802 + if (erofs_sb_has_fragments(sbi) && sbi->packed_nid) { 803 + sbi->packed_inode = erofs_iget(sb, sbi->packed_nid); 804 + if (IS_ERR(sbi->packed_inode)) { 805 + err = PTR_ERR(sbi->packed_inode); 806 + sbi->packed_inode = NULL; 807 + return err; 808 + } 809 + } 813 810 err = erofs_init_managed_cache(sb); 811 + if (err) 812 + return err; 813 + 814 + err = erofs_xattr_prefixes_init(sb); 814 815 if (err) 815 816 return err; 816 817 ··· 985 962 986 963 erofs_unregister_sysfs(sb); 987 964 erofs_shrinker_unregister(sb); 965 + erofs_xattr_prefixes_cleanup(sb); 988 966 #ifdef CONFIG_EROFS_FS_ZIP 989 967 iput(sbi->managed_cache); 990 968 sbi->managed_cache = NULL; 969 + #endif 991 970 iput(sbi->packed_inode); 992 971 sbi->packed_inode = NULL; 993 - #endif 994 972 erofs_free_dev_context(sbi->devs); 995 973 sbi->devs = NULL; 996 974 erofs_fscache_unregister_fs(sb); ··· 1084 1060 id = huge_encode_dev(sb->s_bdev->bd_dev); 1085 1061 1086 1062 buf->f_type = sb->s_magic; 1087 - buf->f_bsize = EROFS_BLKSIZ; 1063 + buf->f_bsize = sb->s_blocksize; 1088 1064 buf->f_blocks = sbi->total_blocks; 1089 1065 buf->f_bfree = buf->f_bavail = 0; 1090 1066
+161 -63
fs/erofs/xattr.c
··· 7 7 #include <linux/security.h> 8 8 #include "xattr.h" 9 9 10 + static inline erofs_blk_t erofs_xattr_blkaddr(struct super_block *sb, 11 + unsigned int xattr_id) 12 + { 13 + return EROFS_SB(sb)->xattr_blkaddr + 14 + erofs_blknr(sb, xattr_id * sizeof(__u32)); 15 + } 16 + 17 + static inline unsigned int erofs_xattr_blkoff(struct super_block *sb, 18 + unsigned int xattr_id) 19 + { 20 + return erofs_blkoff(sb, xattr_id * sizeof(__u32)); 21 + } 22 + 10 23 struct xattr_iter { 11 24 struct super_block *sb; 12 25 struct erofs_buf buf; ··· 29 16 unsigned int ofs; 30 17 }; 31 18 32 - static int init_inode_xattrs(struct inode *inode) 19 + static int erofs_init_inode_xattrs(struct inode *inode) 33 20 { 34 21 struct erofs_inode *const vi = EROFS_I(inode); 35 22 struct xattr_iter it; ··· 81 68 } 82 69 83 70 it.buf = __EROFS_BUF_INITIALIZER; 84 - it.blkaddr = erofs_blknr(erofs_iloc(inode) + vi->inode_isize); 85 - it.ofs = erofs_blkoff(erofs_iloc(inode) + vi->inode_isize); 71 + it.blkaddr = erofs_blknr(sb, erofs_iloc(inode) + vi->inode_isize); 72 + it.ofs = erofs_blkoff(sb, erofs_iloc(inode) + vi->inode_isize); 86 73 87 74 /* read in shared xattr array (non-atomic, see kmalloc below) */ 88 75 it.kaddr = erofs_read_metabuf(&it.buf, sb, it.blkaddr, EROFS_KMAP); ··· 105 92 it.ofs += sizeof(struct erofs_xattr_ibody_header); 106 93 107 94 for (i = 0; i < vi->xattr_shared_count; ++i) { 108 - if (it.ofs >= EROFS_BLKSIZ) { 95 + if (it.ofs >= sb->s_blocksize) { 109 96 /* cannot be unaligned */ 110 - DBG_BUGON(it.ofs != EROFS_BLKSIZ); 97 + DBG_BUGON(it.ofs != sb->s_blocksize); 111 98 112 99 it.kaddr = erofs_read_metabuf(&it.buf, sb, ++it.blkaddr, 113 100 EROFS_KMAP); ··· 152 139 153 140 static inline int xattr_iter_fixup(struct xattr_iter *it) 154 141 { 155 - if (it->ofs < EROFS_BLKSIZ) 142 + if (it->ofs < it->sb->s_blocksize) 156 143 return 0; 157 144 158 - it->blkaddr += erofs_blknr(it->ofs); 145 + it->blkaddr += erofs_blknr(it->sb, it->ofs); 159 146 it->kaddr = erofs_read_metabuf(&it->buf, it->sb, it->blkaddr, 160 147 EROFS_KMAP); 161 148 if (IS_ERR(it->kaddr)) 162 149 return PTR_ERR(it->kaddr); 163 - it->ofs = erofs_blkoff(it->ofs); 150 + it->ofs = erofs_blkoff(it->sb, it->ofs); 164 151 return 0; 165 152 } 166 153 ··· 170 157 struct erofs_inode *const vi = EROFS_I(inode); 171 158 unsigned int xattr_header_sz, inline_xattr_ofs; 172 159 173 - xattr_header_sz = inlinexattr_header_size(inode); 160 + xattr_header_sz = sizeof(struct erofs_xattr_ibody_header) + 161 + sizeof(u32) * vi->xattr_shared_count; 174 162 if (xattr_header_sz >= vi->xattr_isize) { 175 163 DBG_BUGON(xattr_header_sz > vi->xattr_isize); 176 164 return -ENOATTR; ··· 179 165 180 166 inline_xattr_ofs = vi->inode_isize + xattr_header_sz; 181 167 182 - it->blkaddr = erofs_blknr(erofs_iloc(inode) + inline_xattr_ofs); 183 - it->ofs = erofs_blkoff(erofs_iloc(inode) + inline_xattr_ofs); 168 + it->blkaddr = erofs_blknr(it->sb, erofs_iloc(inode) + inline_xattr_ofs); 169 + it->ofs = erofs_blkoff(it->sb, erofs_iloc(inode) + inline_xattr_ofs); 184 170 it->kaddr = erofs_read_metabuf(&it->buf, inode->i_sb, it->blkaddr, 185 171 EROFS_KMAP); 186 172 if (IS_ERR(it->kaddr)) ··· 236 222 processed = 0; 237 223 238 224 while (processed < entry.e_name_len) { 239 - if (it->ofs >= EROFS_BLKSIZ) { 240 - DBG_BUGON(it->ofs > EROFS_BLKSIZ); 225 + if (it->ofs >= it->sb->s_blocksize) { 226 + DBG_BUGON(it->ofs > it->sb->s_blocksize); 241 227 242 228 err = xattr_iter_fixup(it); 243 229 if (err) ··· 245 231 it->ofs = 0; 246 232 } 247 233 248 - slice = min_t(unsigned int, EROFS_BLKSIZ - it->ofs, 234 + slice = min_t(unsigned int, it->sb->s_blocksize - it->ofs, 249 235 entry.e_name_len - processed); 250 236 251 237 /* handle name */ ··· 271 257 } 272 258 273 259 while (processed < value_sz) { 274 - if (it->ofs >= EROFS_BLKSIZ) { 275 - DBG_BUGON(it->ofs > EROFS_BLKSIZ); 260 + if (it->ofs >= it->sb->s_blocksize) { 261 + DBG_BUGON(it->ofs > it->sb->s_blocksize); 276 262 277 263 err = xattr_iter_fixup(it); 278 264 if (err) ··· 280 266 it->ofs = 0; 281 267 } 282 268 283 - slice = min_t(unsigned int, EROFS_BLKSIZ - it->ofs, 269 + slice = min_t(unsigned int, it->sb->s_blocksize - it->ofs, 284 270 value_sz - processed); 285 271 op->value(it, processed, it->kaddr + it->ofs, slice); 286 272 it->ofs += slice; ··· 297 283 struct xattr_iter it; 298 284 299 285 char *buffer; 300 - int buffer_size, index; 286 + int buffer_size, index, infix_len; 301 287 struct qstr name; 302 288 }; 289 + 290 + static int erofs_xattr_long_entrymatch(struct getxattr_iter *it, 291 + struct erofs_xattr_entry *entry) 292 + { 293 + struct erofs_sb_info *sbi = EROFS_SB(it->it.sb); 294 + struct erofs_xattr_prefix_item *pf = sbi->xattr_prefixes + 295 + (entry->e_name_index & EROFS_XATTR_LONG_PREFIX_MASK); 296 + 297 + if (pf >= sbi->xattr_prefixes + sbi->xattr_prefix_count) 298 + return -ENOATTR; 299 + 300 + if (it->index != pf->prefix->base_index || 301 + it->name.len != entry->e_name_len + pf->infix_len) 302 + return -ENOATTR; 303 + 304 + if (memcmp(it->name.name, pf->prefix->infix, pf->infix_len)) 305 + return -ENOATTR; 306 + 307 + it->infix_len = pf->infix_len; 308 + return 0; 309 + } 303 310 304 311 static int xattr_entrymatch(struct xattr_iter *_it, 305 312 struct erofs_xattr_entry *entry) 306 313 { 307 314 struct getxattr_iter *it = container_of(_it, struct getxattr_iter, it); 308 315 309 - return (it->index != entry->e_name_index || 310 - it->name.len != entry->e_name_len) ? -ENOATTR : 0; 316 + /* should also match the infix for long name prefixes */ 317 + if (entry->e_name_index & EROFS_XATTR_LONG_PREFIX) 318 + return erofs_xattr_long_entrymatch(it, entry); 319 + 320 + if (it->index != entry->e_name_index || 321 + it->name.len != entry->e_name_len) 322 + return -ENOATTR; 323 + it->infix_len = 0; 324 + return 0; 311 325 } 312 326 313 327 static int xattr_namematch(struct xattr_iter *_it, ··· 343 301 { 344 302 struct getxattr_iter *it = container_of(_it, struct getxattr_iter, it); 345 303 346 - return memcmp(buf, it->name.name + processed, len) ? -ENOATTR : 0; 304 + if (memcmp(buf, it->name.name + it->infix_len + processed, len)) 305 + return -ENOATTR; 306 + return 0; 347 307 } 348 308 349 309 static int xattr_checkbuffer(struct xattr_iter *_it, ··· 395 351 static int shared_getxattr(struct inode *inode, struct getxattr_iter *it) 396 352 { 397 353 struct erofs_inode *const vi = EROFS_I(inode); 398 - struct super_block *const sb = inode->i_sb; 399 - struct erofs_sb_info *const sbi = EROFS_SB(sb); 400 - unsigned int i; 354 + struct super_block *const sb = it->it.sb; 355 + unsigned int i, xsid; 401 356 int ret = -ENOATTR; 402 357 403 358 for (i = 0; i < vi->xattr_shared_count; ++i) { 404 - erofs_blk_t blkaddr = 405 - xattrblock_addr(sbi, vi->xattr_shared_xattrs[i]); 406 - 407 - it->it.ofs = xattrblock_offset(sbi, vi->xattr_shared_xattrs[i]); 408 - it->it.kaddr = erofs_read_metabuf(&it->it.buf, sb, blkaddr, 409 - EROFS_KMAP); 359 + xsid = vi->xattr_shared_xattrs[i]; 360 + it->it.blkaddr = erofs_xattr_blkaddr(sb, xsid); 361 + it->it.ofs = erofs_xattr_blkoff(sb, xsid); 362 + it->it.kaddr = erofs_read_metabuf(&it->it.buf, sb, 363 + it->it.blkaddr, EROFS_KMAP); 410 364 if (IS_ERR(it->it.kaddr)) 411 365 return PTR_ERR(it->it.kaddr); 412 - it->it.blkaddr = blkaddr; 413 366 414 367 ret = xattr_foreach(&it->it, &find_xattr_handlers, NULL); 415 368 if (ret != -ENOATTR) ··· 435 394 if (!name) 436 395 return -EINVAL; 437 396 438 - ret = init_inode_xattrs(inode); 397 + ret = erofs_init_inode_xattrs(inode); 439 398 if (ret) 440 399 return ret; 441 400 ··· 462 421 struct dentry *unused, struct inode *inode, 463 422 const char *name, void *buffer, size_t size) 464 423 { 465 - struct erofs_sb_info *const sbi = EROFS_I_SB(inode); 466 - 467 - switch (handler->flags) { 468 - case EROFS_XATTR_INDEX_USER: 469 - if (!test_opt(&sbi->opt, XATTR_USER)) 470 - return -EOPNOTSUPP; 471 - break; 472 - case EROFS_XATTR_INDEX_TRUSTED: 473 - break; 474 - case EROFS_XATTR_INDEX_SECURITY: 475 - break; 476 - default: 477 - return -EINVAL; 478 - } 424 + if (handler->flags == EROFS_XATTR_INDEX_USER && 425 + !test_opt(&EROFS_I_SB(inode)->opt, XATTR_USER)) 426 + return -EOPNOTSUPP; 479 427 480 428 return erofs_getxattr(inode, handler->flags, name, buffer, size); 481 429 } ··· 513 483 { 514 484 struct listxattr_iter *it = 515 485 container_of(_it, struct listxattr_iter, it); 516 - unsigned int prefix_len; 517 - const char *prefix; 486 + unsigned int base_index = entry->e_name_index; 487 + unsigned int prefix_len, infix_len = 0; 488 + const char *prefix, *infix = NULL; 518 489 519 - prefix = erofs_xattr_prefix(entry->e_name_index, it->dentry); 490 + if (entry->e_name_index & EROFS_XATTR_LONG_PREFIX) { 491 + struct erofs_sb_info *sbi = EROFS_SB(_it->sb); 492 + struct erofs_xattr_prefix_item *pf = sbi->xattr_prefixes + 493 + (entry->e_name_index & EROFS_XATTR_LONG_PREFIX_MASK); 494 + 495 + if (pf >= sbi->xattr_prefixes + sbi->xattr_prefix_count) 496 + return 1; 497 + infix = pf->prefix->infix; 498 + infix_len = pf->infix_len; 499 + base_index = pf->prefix->base_index; 500 + } 501 + 502 + prefix = erofs_xattr_prefix(base_index, it->dentry); 520 503 if (!prefix) 521 504 return 1; 522 505 prefix_len = strlen(prefix); 523 506 524 507 if (!it->buffer) { 525 - it->buffer_ofs += prefix_len + entry->e_name_len + 1; 508 + it->buffer_ofs += prefix_len + infix_len + 509 + entry->e_name_len + 1; 526 510 return 1; 527 511 } 528 512 529 - if (it->buffer_ofs + prefix_len 513 + if (it->buffer_ofs + prefix_len + infix_len + 530 514 + entry->e_name_len + 1 > it->buffer_size) 531 515 return -ERANGE; 532 516 533 517 memcpy(it->buffer + it->buffer_ofs, prefix, prefix_len); 534 - it->buffer_ofs += prefix_len; 518 + memcpy(it->buffer + it->buffer_ofs + prefix_len, infix, infix_len); 519 + it->buffer_ofs += prefix_len + infix_len; 535 520 return 0; 536 521 } 537 522 ··· 600 555 { 601 556 struct inode *const inode = d_inode(it->dentry); 602 557 struct erofs_inode *const vi = EROFS_I(inode); 603 - struct super_block *const sb = inode->i_sb; 604 - struct erofs_sb_info *const sbi = EROFS_SB(sb); 605 - unsigned int i; 558 + struct super_block *const sb = it->it.sb; 559 + unsigned int i, xsid; 606 560 int ret = 0; 607 561 608 562 for (i = 0; i < vi->xattr_shared_count; ++i) { 609 - erofs_blk_t blkaddr = 610 - xattrblock_addr(sbi, vi->xattr_shared_xattrs[i]); 611 - 612 - it->it.ofs = xattrblock_offset(sbi, vi->xattr_shared_xattrs[i]); 613 - it->it.kaddr = erofs_read_metabuf(&it->it.buf, sb, blkaddr, 614 - EROFS_KMAP); 563 + xsid = vi->xattr_shared_xattrs[i]; 564 + it->it.blkaddr = erofs_xattr_blkaddr(sb, xsid); 565 + it->it.ofs = erofs_xattr_blkoff(sb, xsid); 566 + it->it.kaddr = erofs_read_metabuf(&it->it.buf, sb, 567 + it->it.blkaddr, EROFS_KMAP); 615 568 if (IS_ERR(it->it.kaddr)) 616 569 return PTR_ERR(it->it.kaddr); 617 - it->it.blkaddr = blkaddr; 618 570 619 571 ret = xattr_foreach(&it->it, &list_xattr_handlers, NULL); 620 572 if (ret) ··· 626 584 int ret; 627 585 struct listxattr_iter it; 628 586 629 - ret = init_inode_xattrs(d_inode(dentry)); 587 + ret = erofs_init_inode_xattrs(d_inode(dentry)); 630 588 if (ret == -ENOATTR) 631 589 return 0; 632 590 if (ret) ··· 644 602 if (ret >= 0 || ret == -ENOATTR) 645 603 ret = shared_listxattr(&it); 646 604 erofs_put_metabuf(&it.it.buf); 605 + return ret; 606 + } 607 + 608 + void erofs_xattr_prefixes_cleanup(struct super_block *sb) 609 + { 610 + struct erofs_sb_info *sbi = EROFS_SB(sb); 611 + int i; 612 + 613 + if (sbi->xattr_prefixes) { 614 + for (i = 0; i < sbi->xattr_prefix_count; i++) 615 + kfree(sbi->xattr_prefixes[i].prefix); 616 + kfree(sbi->xattr_prefixes); 617 + sbi->xattr_prefixes = NULL; 618 + } 619 + } 620 + 621 + int erofs_xattr_prefixes_init(struct super_block *sb) 622 + { 623 + struct erofs_sb_info *sbi = EROFS_SB(sb); 624 + struct erofs_buf buf = __EROFS_BUF_INITIALIZER; 625 + erofs_off_t pos = (erofs_off_t)sbi->xattr_prefix_start << 2; 626 + struct erofs_xattr_prefix_item *pfs; 627 + int ret = 0, i, len; 628 + 629 + if (!sbi->xattr_prefix_count) 630 + return 0; 631 + 632 + pfs = kzalloc(sbi->xattr_prefix_count * sizeof(*pfs), GFP_KERNEL); 633 + if (!pfs) 634 + return -ENOMEM; 635 + 636 + if (erofs_sb_has_fragments(sbi)) 637 + buf.inode = sbi->packed_inode; 638 + else 639 + erofs_init_metabuf(&buf, sb); 640 + 641 + for (i = 0; i < sbi->xattr_prefix_count; i++) { 642 + void *ptr = erofs_read_metadata(sb, &buf, &pos, &len); 643 + 644 + if (IS_ERR(ptr)) { 645 + ret = PTR_ERR(ptr); 646 + break; 647 + } else if (len < sizeof(*pfs->prefix) || 648 + len > EROFS_NAME_LEN + sizeof(*pfs->prefix)) { 649 + kfree(ptr); 650 + ret = -EFSCORRUPTED; 651 + break; 652 + } 653 + pfs[i].prefix = ptr; 654 + pfs[i].infix_len = len - sizeof(struct erofs_xattr_long_prefix); 655 + } 656 + 657 + erofs_put_metabuf(&buf); 658 + sbi->xattr_prefixes = pfs; 659 + if (ret) 660 + erofs_xattr_prefixes_cleanup(sb); 647 661 return ret; 648 662 } 649 663
+4 -23
fs/erofs/xattr.h
··· 13 13 /* Attribute not found */ 14 14 #define ENOATTR ENODATA 15 15 16 - static inline unsigned int inlinexattr_header_size(struct inode *inode) 17 - { 18 - return sizeof(struct erofs_xattr_ibody_header) + 19 - sizeof(u32) * EROFS_I(inode)->xattr_shared_count; 20 - } 21 - 22 - static inline erofs_blk_t xattrblock_addr(struct erofs_sb_info *sbi, 23 - unsigned int xattr_id) 24 - { 25 - #ifdef CONFIG_EROFS_FS_XATTR 26 - return sbi->xattr_blkaddr + 27 - xattr_id * sizeof(__u32) / EROFS_BLKSIZ; 28 - #else 29 - return 0; 30 - #endif 31 - } 32 - 33 - static inline unsigned int xattrblock_offset(struct erofs_sb_info *sbi, 34 - unsigned int xattr_id) 35 - { 36 - return (xattr_id * sizeof(__u32)) % EROFS_BLKSIZ; 37 - } 38 - 39 16 #ifdef CONFIG_EROFS_FS_XATTR 40 17 extern const struct xattr_handler erofs_xattr_user_handler; 41 18 extern const struct xattr_handler erofs_xattr_trusted_handler; ··· 46 69 47 70 extern const struct xattr_handler *erofs_xattr_handlers[]; 48 71 72 + int erofs_xattr_prefixes_init(struct super_block *sb); 73 + void erofs_xattr_prefixes_cleanup(struct super_block *sb); 49 74 int erofs_getxattr(struct inode *, int, const char *, void *, size_t); 50 75 ssize_t erofs_listxattr(struct dentry *, char *, size_t); 51 76 #else 77 + static inline int erofs_xattr_prefixes_init(struct super_block *sb) { return 0; } 78 + static inline void erofs_xattr_prefixes_cleanup(struct super_block *sb) {} 52 79 static inline int erofs_getxattr(struct inode *inode, int index, 53 80 const char *name, void *buffer, 54 81 size_t buffer_size)
+11 -14
fs/erofs/zdata.c
··· 807 807 808 808 if (ztailpacking) { 809 809 pcl->obj.index = 0; /* which indicates ztailpacking */ 810 - pcl->pageofs_in = erofs_blkoff(map->m_pa); 810 + pcl->pageofs_in = erofs_blkoff(fe->inode->i_sb, map->m_pa); 811 811 pcl->tailpacking_size = map->m_plen; 812 812 } else { 813 813 pcl->obj.index = map->m_pa >> PAGE_SHIFT; ··· 930 930 struct page *page, unsigned int pageofs, 931 931 unsigned int len) 932 932 { 933 + struct super_block *sb = inode->i_sb; 933 934 struct inode *packed_inode = EROFS_I_SB(inode)->packed_inode; 934 935 struct erofs_buf buf = __EROFS_BUF_INITIALIZER; 935 936 u8 *src, *dst; ··· 939 938 if (!packed_inode) 940 939 return -EFSCORRUPTED; 941 940 941 + buf.inode = packed_inode; 942 942 pos += EROFS_I(inode)->z_fragmentoff; 943 943 for (i = 0; i < len; i += cnt) { 944 944 cnt = min_t(unsigned int, len - i, 945 - EROFS_BLKSIZ - erofs_blkoff(pos)); 946 - src = erofs_bread(&buf, packed_inode, 947 - erofs_blknr(pos), EROFS_KMAP); 945 + sb->s_blocksize - erofs_blkoff(sb, pos)); 946 + src = erofs_bread(&buf, erofs_blknr(sb, pos), EROFS_KMAP); 948 947 if (IS_ERR(src)) { 949 948 erofs_put_metabuf(&buf); 950 949 return PTR_ERR(src); 951 950 } 952 951 953 952 dst = kmap_local_page(page); 954 - memcpy(dst + pageofs + i, src + erofs_blkoff(pos), cnt); 953 + memcpy(dst + pageofs + i, src + erofs_blkoff(sb, pos), cnt); 955 954 kunmap_local(dst); 956 955 pos += cnt; 957 956 } ··· 979 978 980 979 if (offset + cur < map->m_la || 981 980 offset + cur >= map->m_la + map->m_llen) { 982 - erofs_dbg("out-of-range map @ pos %llu", offset + cur); 983 - 984 981 if (z_erofs_collector_end(fe)) 985 982 fe->backmost = false; 986 983 map->m_la = offset + cur; ··· 1004 1005 void *mp; 1005 1006 1006 1007 mp = erofs_read_metabuf(&fe->map.buf, inode->i_sb, 1007 - erofs_blknr(map->m_pa), EROFS_NO_KMAP); 1008 + erofs_blknr(inode->i_sb, map->m_pa), 1009 + EROFS_NO_KMAP); 1008 1010 if (IS_ERR(mp)) { 1009 1011 err = PTR_ERR(mp); 1010 1012 erofs_err(inode->i_sb, ··· 1103 1103 if (err) 1104 1104 z_erofs_page_mark_eio(page); 1105 1105 z_erofs_onlinepage_endio(page); 1106 - 1107 - erofs_dbg("%s, finish page: %pK spiltted: %u map->m_llen %llu", 1108 - __func__, page, spiltted, map->m_llen); 1109 1106 return err; 1110 1107 } 1111 1108 ··· 1723 1726 1724 1727 /* no device id here, thus it will always succeed */ 1725 1728 mdev = (struct erofs_map_dev) { 1726 - .m_pa = blknr_to_addr(pcl->obj.index), 1729 + .m_pa = erofs_pos(sb, pcl->obj.index), 1727 1730 }; 1728 1731 (void)erofs_map_dev(sb, &mdev); 1729 1732 1730 - cur = erofs_blknr(mdev.m_pa); 1733 + cur = erofs_blknr(sb, mdev.m_pa); 1731 1734 end = cur + pcl->pclusterpages; 1732 1735 1733 1736 do { ··· 1761 1764 1762 1765 last_bdev = mdev.m_bdev; 1763 1766 bio->bi_iter.bi_sector = (sector_t)cur << 1764 - LOG_SECTORS_PER_BLOCK; 1767 + (sb->s_blocksize_bits - 9); 1765 1768 bio->bi_private = q[JQ_SUBMIT]; 1766 1769 if (f->readahead) 1767 1770 bio->bi_opf |= REQ_RAHEAD;
+74 -92
fs/erofs/zmap.c
··· 7 7 #include <asm/unaligned.h> 8 8 #include <trace/events/erofs.h> 9 9 10 - int z_erofs_fill_inode(struct inode *inode) 11 - { 12 - struct erofs_inode *const vi = EROFS_I(inode); 13 - struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb); 14 - 15 - if (!erofs_sb_has_big_pcluster(sbi) && 16 - !erofs_sb_has_ztailpacking(sbi) && !erofs_sb_has_fragments(sbi) && 17 - vi->datalayout == EROFS_INODE_FLAT_COMPRESSION_LEGACY) { 18 - vi->z_advise = 0; 19 - vi->z_algorithmtype[0] = 0; 20 - vi->z_algorithmtype[1] = 0; 21 - vi->z_logical_clusterbits = LOG_BLOCK_SIZE; 22 - set_bit(EROFS_I_Z_INITED_BIT, &vi->flags); 23 - } 24 - inode->i_mapping->a_ops = &z_erofs_aops; 25 - return 0; 26 - } 27 - 28 10 struct z_erofs_maprecorder { 29 11 struct inode *inode; 30 12 struct erofs_map_blocks *map; ··· 27 45 { 28 46 struct inode *const inode = m->inode; 29 47 struct erofs_inode *const vi = EROFS_I(inode); 30 - const erofs_off_t pos = 31 - Z_EROFS_VLE_LEGACY_INDEX_ALIGN(erofs_iloc(inode) + 32 - vi->inode_isize + vi->xattr_isize) + 33 - lcn * sizeof(struct z_erofs_vle_decompressed_index); 34 - struct z_erofs_vle_decompressed_index *di; 48 + const erofs_off_t pos = Z_EROFS_FULL_INDEX_ALIGN(erofs_iloc(inode) + 49 + vi->inode_isize + vi->xattr_isize) + 50 + lcn * sizeof(struct z_erofs_lcluster_index); 51 + struct z_erofs_lcluster_index *di; 35 52 unsigned int advise, type; 36 53 37 54 m->kaddr = erofs_read_metabuf(&m->map->buf, inode->i_sb, 38 - erofs_blknr(pos), EROFS_KMAP); 55 + erofs_blknr(inode->i_sb, pos), EROFS_KMAP); 39 56 if (IS_ERR(m->kaddr)) 40 57 return PTR_ERR(m->kaddr); 41 58 42 - m->nextpackoff = pos + sizeof(struct z_erofs_vle_decompressed_index); 59 + m->nextpackoff = pos + sizeof(struct z_erofs_lcluster_index); 43 60 m->lcn = lcn; 44 - di = m->kaddr + erofs_blkoff(pos); 61 + di = m->kaddr + erofs_blkoff(inode->i_sb, pos); 45 62 46 63 advise = le16_to_cpu(di->di_advise); 47 - type = (advise >> Z_EROFS_VLE_DI_CLUSTER_TYPE_BIT) & 48 - ((1 << Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS) - 1); 64 + type = (advise >> Z_EROFS_LI_LCLUSTER_TYPE_BIT) & 65 + ((1 << Z_EROFS_LI_LCLUSTER_TYPE_BITS) - 1); 49 66 switch (type) { 50 - case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD: 67 + case Z_EROFS_LCLUSTER_TYPE_NONHEAD: 51 68 m->clusterofs = 1 << vi->z_logical_clusterbits; 52 69 m->delta[0] = le16_to_cpu(di->di_u.delta[0]); 53 - if (m->delta[0] & Z_EROFS_VLE_DI_D0_CBLKCNT) { 70 + if (m->delta[0] & Z_EROFS_LI_D0_CBLKCNT) { 54 71 if (!(vi->z_advise & (Z_EROFS_ADVISE_BIG_PCLUSTER_1 | 55 72 Z_EROFS_ADVISE_BIG_PCLUSTER_2))) { 56 73 DBG_BUGON(1); 57 74 return -EFSCORRUPTED; 58 75 } 59 76 m->compressedblks = m->delta[0] & 60 - ~Z_EROFS_VLE_DI_D0_CBLKCNT; 77 + ~Z_EROFS_LI_D0_CBLKCNT; 61 78 m->delta[0] = 1; 62 79 } 63 80 m->delta[1] = le16_to_cpu(di->di_u.delta[1]); 64 81 break; 65 - case Z_EROFS_VLE_CLUSTER_TYPE_PLAIN: 66 - case Z_EROFS_VLE_CLUSTER_TYPE_HEAD1: 67 - case Z_EROFS_VLE_CLUSTER_TYPE_HEAD2: 68 - if (advise & Z_EROFS_VLE_DI_PARTIAL_REF) 82 + case Z_EROFS_LCLUSTER_TYPE_PLAIN: 83 + case Z_EROFS_LCLUSTER_TYPE_HEAD1: 84 + case Z_EROFS_LCLUSTER_TYPE_HEAD2: 85 + if (advise & Z_EROFS_LI_PARTIAL_REF) 69 86 m->partialref = true; 70 87 m->clusterofs = le16_to_cpu(di->di_clusterofs); 88 + if (m->clusterofs >= 1 << vi->z_logical_clusterbits) { 89 + DBG_BUGON(1); 90 + return -EFSCORRUPTED; 91 + } 71 92 m->pblk = le32_to_cpu(di->di_u.blkaddr); 72 93 break; 73 94 default: ··· 106 121 lo = decode_compactedbits(lclusterbits, lomask, 107 122 in, encodebits * i, &type); 108 123 109 - if (type != Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD) 124 + if (type != Z_EROFS_LCLUSTER_TYPE_NONHEAD) 110 125 return d1; 111 126 ++d1; 112 127 } while (++i < vcnt); 113 128 114 - /* vcnt - 1 (Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD) item */ 115 - if (!(lo & Z_EROFS_VLE_DI_D0_CBLKCNT)) 129 + /* vcnt - 1 (Z_EROFS_LCLUSTER_TYPE_NONHEAD) item */ 130 + if (!(lo & Z_EROFS_LI_D0_CBLKCNT)) 116 131 d1 += lo - 1; 117 132 return d1; 118 133 } ··· 141 156 (vcnt << amortizedshift); 142 157 big_pcluster = vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1; 143 158 encodebits = ((vcnt << amortizedshift) - sizeof(__le32)) * 8 / vcnt; 144 - eofs = erofs_blkoff(pos); 159 + eofs = erofs_blkoff(m->inode->i_sb, pos); 145 160 base = round_down(eofs, vcnt << amortizedshift); 146 161 in = m->kaddr + base; 147 162 ··· 150 165 lo = decode_compactedbits(lclusterbits, lomask, 151 166 in, encodebits * i, &type); 152 167 m->type = type; 153 - if (type == Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD) { 168 + if (type == Z_EROFS_LCLUSTER_TYPE_NONHEAD) { 154 169 m->clusterofs = 1 << lclusterbits; 155 170 156 171 /* figure out lookahead_distance: delta[1] if needed */ 157 172 if (lookahead) 158 173 m->delta[1] = get_compacted_la_distance(lclusterbits, 159 174 encodebits, vcnt, in, i); 160 - if (lo & Z_EROFS_VLE_DI_D0_CBLKCNT) { 175 + if (lo & Z_EROFS_LI_D0_CBLKCNT) { 161 176 if (!big_pcluster) { 162 177 DBG_BUGON(1); 163 178 return -EFSCORRUPTED; 164 179 } 165 - m->compressedblks = lo & ~Z_EROFS_VLE_DI_D0_CBLKCNT; 180 + m->compressedblks = lo & ~Z_EROFS_LI_D0_CBLKCNT; 166 181 m->delta[0] = 1; 167 182 return 0; 168 183 } else if (i + 1 != (int)vcnt) { ··· 176 191 */ 177 192 lo = decode_compactedbits(lclusterbits, lomask, 178 193 in, encodebits * (i - 1), &type); 179 - if (type != Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD) 194 + if (type != Z_EROFS_LCLUSTER_TYPE_NONHEAD) 180 195 lo = 0; 181 - else if (lo & Z_EROFS_VLE_DI_D0_CBLKCNT) 196 + else if (lo & Z_EROFS_LI_D0_CBLKCNT) 182 197 lo = 1; 183 198 m->delta[0] = lo + 1; 184 199 return 0; ··· 192 207 --i; 193 208 lo = decode_compactedbits(lclusterbits, lomask, 194 209 in, encodebits * i, &type); 195 - if (type == Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD) 210 + if (type == Z_EROFS_LCLUSTER_TYPE_NONHEAD) 196 211 i -= lo; 197 212 198 213 if (i >= 0) ··· 204 219 --i; 205 220 lo = decode_compactedbits(lclusterbits, lomask, 206 221 in, encodebits * i, &type); 207 - if (type == Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD) { 208 - if (lo & Z_EROFS_VLE_DI_D0_CBLKCNT) { 222 + if (type == Z_EROFS_LCLUSTER_TYPE_NONHEAD) { 223 + if (lo & Z_EROFS_LI_D0_CBLKCNT) { 209 224 --i; 210 - nblk += lo & ~Z_EROFS_VLE_DI_D0_CBLKCNT; 225 + nblk += lo & ~Z_EROFS_LI_D0_CBLKCNT; 211 226 continue; 212 227 } 213 228 /* bigpcluster shouldn't have plain d0 == 1 */ ··· 234 249 const unsigned int lclusterbits = vi->z_logical_clusterbits; 235 250 const erofs_off_t ebase = sizeof(struct z_erofs_map_header) + 236 251 ALIGN(erofs_iloc(inode) + vi->inode_isize + vi->xattr_isize, 8); 237 - const unsigned int totalidx = DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ); 252 + unsigned int totalidx = erofs_iblks(inode); 238 253 unsigned int compacted_4b_initial, compacted_2b; 239 254 unsigned int amortizedshift; 240 255 erofs_off_t pos; ··· 275 290 out: 276 291 pos += lcn * (1 << amortizedshift); 277 292 m->kaddr = erofs_read_metabuf(&m->map->buf, inode->i_sb, 278 - erofs_blknr(pos), EROFS_KMAP); 293 + erofs_blknr(inode->i_sb, pos), EROFS_KMAP); 279 294 if (IS_ERR(m->kaddr)) 280 295 return PTR_ERR(m->kaddr); 281 296 return unpack_compacted_index(m, amortizedshift, pos, lookahead); ··· 286 301 { 287 302 const unsigned int datamode = EROFS_I(m->inode)->datalayout; 288 303 289 - if (datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY) 304 + if (datamode == EROFS_INODE_COMPRESSED_FULL) 290 305 return legacy_load_cluster_from_disk(m, lcn); 291 306 292 - if (datamode == EROFS_INODE_FLAT_COMPRESSION) 307 + if (datamode == EROFS_INODE_COMPRESSED_COMPACT) 293 308 return compacted_load_cluster_from_disk(m, lcn, lookahead); 294 309 295 310 return -EINVAL; ··· 311 326 return err; 312 327 313 328 switch (m->type) { 314 - case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD: 329 + case Z_EROFS_LCLUSTER_TYPE_NONHEAD: 315 330 if (!m->delta[0]) { 316 331 erofs_err(m->inode->i_sb, 317 332 "invalid lookback distance 0 @ nid %llu", ··· 321 336 } 322 337 lookback_distance = m->delta[0]; 323 338 continue; 324 - case Z_EROFS_VLE_CLUSTER_TYPE_PLAIN: 325 - case Z_EROFS_VLE_CLUSTER_TYPE_HEAD1: 326 - case Z_EROFS_VLE_CLUSTER_TYPE_HEAD2: 339 + case Z_EROFS_LCLUSTER_TYPE_PLAIN: 340 + case Z_EROFS_LCLUSTER_TYPE_HEAD1: 341 + case Z_EROFS_LCLUSTER_TYPE_HEAD2: 327 342 m->headtype = m->type; 328 343 m->map->m_la = (lcn << lclusterbits) | m->clusterofs; 329 344 return 0; ··· 345 360 static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m, 346 361 unsigned int initial_lcn) 347 362 { 363 + struct super_block *sb = m->inode->i_sb; 348 364 struct erofs_inode *const vi = EROFS_I(m->inode); 349 365 struct erofs_map_blocks *const map = m->map; 350 366 const unsigned int lclusterbits = vi->z_logical_clusterbits; 351 367 unsigned long lcn; 352 368 int err; 353 369 354 - DBG_BUGON(m->type != Z_EROFS_VLE_CLUSTER_TYPE_PLAIN && 355 - m->type != Z_EROFS_VLE_CLUSTER_TYPE_HEAD1 && 356 - m->type != Z_EROFS_VLE_CLUSTER_TYPE_HEAD2); 370 + DBG_BUGON(m->type != Z_EROFS_LCLUSTER_TYPE_PLAIN && 371 + m->type != Z_EROFS_LCLUSTER_TYPE_HEAD1 && 372 + m->type != Z_EROFS_LCLUSTER_TYPE_HEAD2); 357 373 DBG_BUGON(m->type != m->headtype); 358 374 359 - if (m->headtype == Z_EROFS_VLE_CLUSTER_TYPE_PLAIN || 360 - ((m->headtype == Z_EROFS_VLE_CLUSTER_TYPE_HEAD1) && 375 + if (m->headtype == Z_EROFS_LCLUSTER_TYPE_PLAIN || 376 + ((m->headtype == Z_EROFS_LCLUSTER_TYPE_HEAD1) && 361 377 !(vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1)) || 362 - ((m->headtype == Z_EROFS_VLE_CLUSTER_TYPE_HEAD2) && 378 + ((m->headtype == Z_EROFS_LCLUSTER_TYPE_HEAD2) && 363 379 !(vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_2))) { 364 380 map->m_plen = 1ULL << lclusterbits; 365 381 return 0; ··· 382 396 * BUG_ON in the debugging mode only for developers to notice that. 383 397 */ 384 398 DBG_BUGON(lcn == initial_lcn && 385 - m->type == Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD); 399 + m->type == Z_EROFS_LCLUSTER_TYPE_NONHEAD); 386 400 387 401 switch (m->type) { 388 - case Z_EROFS_VLE_CLUSTER_TYPE_PLAIN: 389 - case Z_EROFS_VLE_CLUSTER_TYPE_HEAD1: 390 - case Z_EROFS_VLE_CLUSTER_TYPE_HEAD2: 402 + case Z_EROFS_LCLUSTER_TYPE_PLAIN: 403 + case Z_EROFS_LCLUSTER_TYPE_HEAD1: 404 + case Z_EROFS_LCLUSTER_TYPE_HEAD2: 391 405 /* 392 406 * if the 1st NONHEAD lcluster is actually PLAIN or HEAD type 393 407 * rather than CBLKCNT, it's a 1 lcluster-sized pcluster. 394 408 */ 395 - m->compressedblks = 1 << (lclusterbits - LOG_BLOCK_SIZE); 409 + m->compressedblks = 1 << (lclusterbits - sb->s_blocksize_bits); 396 410 break; 397 - case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD: 411 + case Z_EROFS_LCLUSTER_TYPE_NONHEAD: 398 412 if (m->delta[0] != 1) 399 413 goto err_bonus_cblkcnt; 400 414 if (m->compressedblks) ··· 408 422 return -EFSCORRUPTED; 409 423 } 410 424 out: 411 - map->m_plen = (u64)m->compressedblks << LOG_BLOCK_SIZE; 425 + map->m_plen = erofs_pos(sb, m->compressedblks); 412 426 return 0; 413 427 err_bonus_cblkcnt: 414 428 erofs_err(m->inode->i_sb, ··· 438 452 if (err) 439 453 return err; 440 454 441 - if (m->type == Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD) { 455 + if (m->type == Z_EROFS_LCLUSTER_TYPE_NONHEAD) { 442 456 DBG_BUGON(!m->delta[1] && 443 457 m->clusterofs != 1 << lclusterbits); 444 - } else if (m->type == Z_EROFS_VLE_CLUSTER_TYPE_PLAIN || 445 - m->type == Z_EROFS_VLE_CLUSTER_TYPE_HEAD1 || 446 - m->type == Z_EROFS_VLE_CLUSTER_TYPE_HEAD2) { 458 + } else if (m->type == Z_EROFS_LCLUSTER_TYPE_PLAIN || 459 + m->type == Z_EROFS_LCLUSTER_TYPE_HEAD1 || 460 + m->type == Z_EROFS_LCLUSTER_TYPE_HEAD2) { 447 461 /* go on until the next HEAD lcluster */ 448 462 if (lcn != headlcn) 449 463 break; ··· 462 476 } 463 477 464 478 static int z_erofs_do_map_blocks(struct inode *inode, 465 - struct erofs_map_blocks *map, 466 - int flags) 479 + struct erofs_map_blocks *map, int flags) 467 480 { 468 481 struct erofs_inode *const vi = EROFS_I(inode); 469 482 bool ztailpacking = vi->z_advise & Z_EROFS_ADVISE_INLINE_PCLUSTER; ··· 492 507 end = (m.lcn + 1ULL) << lclusterbits; 493 508 494 509 switch (m.type) { 495 - case Z_EROFS_VLE_CLUSTER_TYPE_PLAIN: 496 - case Z_EROFS_VLE_CLUSTER_TYPE_HEAD1: 497 - case Z_EROFS_VLE_CLUSTER_TYPE_HEAD2: 510 + case Z_EROFS_LCLUSTER_TYPE_PLAIN: 511 + case Z_EROFS_LCLUSTER_TYPE_HEAD1: 512 + case Z_EROFS_LCLUSTER_TYPE_HEAD2: 498 513 if (endoff >= m.clusterofs) { 499 514 m.headtype = m.type; 500 515 map->m_la = (m.lcn << lclusterbits) | m.clusterofs; ··· 519 534 map->m_flags |= EROFS_MAP_FULL_MAPPED; 520 535 m.delta[0] = 1; 521 536 fallthrough; 522 - case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD: 537 + case Z_EROFS_LCLUSTER_TYPE_NONHEAD: 523 538 /* get the corresponding first chunk */ 524 539 err = z_erofs_extent_lookback(&m, m.delta[0]); 525 540 if (err) ··· 540 555 vi->z_tailextent_headlcn = m.lcn; 541 556 /* for non-compact indexes, fragmentoff is 64 bits */ 542 557 if (fragment && 543 - vi->datalayout == EROFS_INODE_FLAT_COMPRESSION_LEGACY) 558 + vi->datalayout == EROFS_INODE_COMPRESSED_FULL) 544 559 vi->z_fragmentoff |= (u64)m.pblk << 32; 545 560 } 546 561 if (ztailpacking && m.lcn == vi->z_tailextent_headlcn) { ··· 550 565 } else if (fragment && m.lcn == vi->z_tailextent_headlcn) { 551 566 map->m_flags |= EROFS_MAP_FRAGMENT; 552 567 } else { 553 - map->m_pa = blknr_to_addr(m.pblk); 568 + map->m_pa = erofs_pos(inode->i_sb, m.pblk); 554 569 err = z_erofs_get_extent_compressedlen(&m, initial_lcn); 555 570 if (err) 556 571 goto unmap_out; 557 572 } 558 573 559 - if (m.headtype == Z_EROFS_VLE_CLUSTER_TYPE_PLAIN) { 574 + if (m.headtype == Z_EROFS_LCLUSTER_TYPE_PLAIN) { 560 575 if (map->m_llen > map->m_plen) { 561 576 DBG_BUGON(1); 562 577 err = -EFSCORRUPTED; ··· 568 583 else 569 584 map->m_algorithmformat = 570 585 Z_EROFS_COMPRESSION_SHIFTED; 571 - } else if (m.headtype == Z_EROFS_VLE_CLUSTER_TYPE_HEAD2) { 586 + } else if (m.headtype == Z_EROFS_LCLUSTER_TYPE_HEAD2) { 572 587 map->m_algorithmformat = vi->z_algorithmtype[1]; 573 588 } else { 574 589 map->m_algorithmformat = vi->z_algorithmtype[0]; ··· 577 592 if ((flags & EROFS_GET_BLOCKS_FIEMAP) || 578 593 ((flags & EROFS_GET_BLOCKS_READMORE) && 579 594 map->m_algorithmformat == Z_EROFS_COMPRESSION_LZMA && 580 - map->m_llen >= EROFS_BLKSIZ)) { 595 + map->m_llen >= i_blocksize(inode))) { 581 596 err = z_erofs_get_extent_decompressedlen(&m); 582 597 if (!err) 583 598 map->m_flags |= EROFS_MAP_FULL_MAPPED; ··· 585 600 586 601 unmap_out: 587 602 erofs_unmap_metabuf(&m.map->buf); 588 - erofs_dbg("%s, m_la %llu m_pa %llu m_llen %llu m_plen %llu m_flags 0%o", 589 - __func__, map->m_la, map->m_pa, 590 - map->m_llen, map->m_plen, map->m_flags); 591 603 return err; 592 604 } 593 605 ··· 615 633 goto out_unlock; 616 634 617 635 pos = ALIGN(erofs_iloc(inode) + vi->inode_isize + vi->xattr_isize, 8); 618 - kaddr = erofs_read_metabuf(&buf, sb, erofs_blknr(pos), EROFS_KMAP); 636 + kaddr = erofs_read_metabuf(&buf, sb, erofs_blknr(sb, pos), EROFS_KMAP); 619 637 if (IS_ERR(kaddr)) { 620 638 err = PTR_ERR(kaddr); 621 639 goto out_unlock; 622 640 } 623 641 624 - h = kaddr + erofs_blkoff(pos); 642 + h = kaddr + erofs_blkoff(sb, pos); 625 643 /* 626 644 * if the highest bit of the 8-byte map header is set, the whole file 627 645 * is stored in the packed inode. The rest bits keeps z_fragmentoff. ··· 645 663 goto out_put_metabuf; 646 664 } 647 665 648 - vi->z_logical_clusterbits = LOG_BLOCK_SIZE + (h->h_clusterbits & 7); 666 + vi->z_logical_clusterbits = sb->s_blocksize_bits + (h->h_clusterbits & 7); 649 667 if (!erofs_sb_has_big_pcluster(EROFS_SB(sb)) && 650 668 vi->z_advise & (Z_EROFS_ADVISE_BIG_PCLUSTER_1 | 651 669 Z_EROFS_ADVISE_BIG_PCLUSTER_2)) { ··· 654 672 err = -EFSCORRUPTED; 655 673 goto out_put_metabuf; 656 674 } 657 - if (vi->datalayout == EROFS_INODE_FLAT_COMPRESSION && 675 + if (vi->datalayout == EROFS_INODE_COMPRESSED_COMPACT && 658 676 !(vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1) ^ 659 677 !(vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_2)) { 660 678 erofs_err(sb, "big pcluster head1/2 of compact indexes should be consistent for nid %llu", ··· 674 692 erofs_put_metabuf(&map.buf); 675 693 676 694 if (!map.m_plen || 677 - erofs_blkoff(map.m_pa) + map.m_plen > EROFS_BLKSIZ) { 695 + erofs_blkoff(sb, map.m_pa) + map.m_plen > sb->s_blocksize) { 678 696 erofs_err(sb, "invalid tail-packing pclustersize %llu", 679 697 map.m_plen); 680 698 err = -EFSCORRUPTED;
+2 -2
include/trace/events/erofs.h
··· 71 71 TP_fast_assign( 72 72 __entry->dev = inode->i_sb->s_dev; 73 73 __entry->nid = EROFS_I(inode)->nid; 74 - __entry->blkaddr = erofs_blknr(erofs_iloc(inode)); 75 - __entry->ofs = erofs_blkoff(erofs_iloc(inode)); 74 + __entry->blkaddr = erofs_blknr(inode->i_sb, erofs_iloc(inode)); 75 + __entry->ofs = erofs_blkoff(inode->i_sb, erofs_iloc(inode)); 76 76 ), 77 77 78 78 TP_printk("dev = (%d,%d), nid = %llu, blkaddr %u ofs %u",