18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci#include <linux/buffer_head.h> 38c2ecf20Sopenharmony_ci#include "minix.h" 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_cienum {DIRECT = 7, DEPTH = 4}; /* Have triple indirect */ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_citypedef u32 block_t; /* 32 bit, host order */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_cistatic inline unsigned long block_to_cpu(block_t n) 108c2ecf20Sopenharmony_ci{ 118c2ecf20Sopenharmony_ci return n; 128c2ecf20Sopenharmony_ci} 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_cistatic inline block_t cpu_to_block(unsigned long n) 158c2ecf20Sopenharmony_ci{ 168c2ecf20Sopenharmony_ci return n; 178c2ecf20Sopenharmony_ci} 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_cistatic inline block_t *i_data(struct inode *inode) 208c2ecf20Sopenharmony_ci{ 218c2ecf20Sopenharmony_ci return (block_t *)minix_i(inode)->u.i2_data; 228c2ecf20Sopenharmony_ci} 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#define DIRCOUNT 7 258c2ecf20Sopenharmony_ci#define INDIRCOUNT(sb) (1 << ((sb)->s_blocksize_bits - 2)) 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_cistatic int block_to_path(struct inode * inode, long block, int offsets[DEPTH]) 288c2ecf20Sopenharmony_ci{ 298c2ecf20Sopenharmony_ci int n = 0; 308c2ecf20Sopenharmony_ci struct super_block *sb = inode->i_sb; 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci if (block < 0) { 338c2ecf20Sopenharmony_ci printk("MINIX-fs: block_to_path: block %ld < 0 on dev %pg\n", 348c2ecf20Sopenharmony_ci block, sb->s_bdev); 358c2ecf20Sopenharmony_ci return 0; 368c2ecf20Sopenharmony_ci } 378c2ecf20Sopenharmony_ci if ((u64)block * (u64)sb->s_blocksize >= sb->s_maxbytes) 388c2ecf20Sopenharmony_ci return 0; 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci if (block < DIRCOUNT) { 418c2ecf20Sopenharmony_ci offsets[n++] = block; 428c2ecf20Sopenharmony_ci } else if ((block -= DIRCOUNT) < INDIRCOUNT(sb)) { 438c2ecf20Sopenharmony_ci offsets[n++] = DIRCOUNT; 448c2ecf20Sopenharmony_ci offsets[n++] = block; 458c2ecf20Sopenharmony_ci } else if ((block -= INDIRCOUNT(sb)) < INDIRCOUNT(sb) * INDIRCOUNT(sb)) { 468c2ecf20Sopenharmony_ci offsets[n++] = DIRCOUNT + 1; 478c2ecf20Sopenharmony_ci offsets[n++] = block / INDIRCOUNT(sb); 488c2ecf20Sopenharmony_ci offsets[n++] = block % INDIRCOUNT(sb); 498c2ecf20Sopenharmony_ci } else { 508c2ecf20Sopenharmony_ci block -= INDIRCOUNT(sb) * INDIRCOUNT(sb); 518c2ecf20Sopenharmony_ci offsets[n++] = DIRCOUNT + 2; 528c2ecf20Sopenharmony_ci offsets[n++] = (block / INDIRCOUNT(sb)) / INDIRCOUNT(sb); 538c2ecf20Sopenharmony_ci offsets[n++] = (block / INDIRCOUNT(sb)) % INDIRCOUNT(sb); 548c2ecf20Sopenharmony_ci offsets[n++] = block % INDIRCOUNT(sb); 558c2ecf20Sopenharmony_ci } 568c2ecf20Sopenharmony_ci return n; 578c2ecf20Sopenharmony_ci} 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci#include "itree_common.c" 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ciint V2_minix_get_block(struct inode * inode, long block, 628c2ecf20Sopenharmony_ci struct buffer_head *bh_result, int create) 638c2ecf20Sopenharmony_ci{ 648c2ecf20Sopenharmony_ci return get_block(inode, block, bh_result, create); 658c2ecf20Sopenharmony_ci} 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_civoid V2_minix_truncate(struct inode * inode) 688c2ecf20Sopenharmony_ci{ 698c2ecf20Sopenharmony_ci truncate(inode); 708c2ecf20Sopenharmony_ci} 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ciunsigned V2_minix_blocks(loff_t size, struct super_block *sb) 738c2ecf20Sopenharmony_ci{ 748c2ecf20Sopenharmony_ci return nblocks(size, sb); 758c2ecf20Sopenharmony_ci} 76