Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * super.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2001-2002 Will Dyson <will_dyson@pobox.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Licensed under the GNU GPL. See the file COPYING for details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <asm/page.h> /* for PAGE_SIZE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "befs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "super.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * befs_load_sb -- Read from disk and properly byteswap all the fields
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * of the befs superblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) befs_load_sb(struct super_block *sb, befs_super_block *disk_sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	struct befs_sb_info *befs_sb = BEFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	/* Check the byte order of the filesystem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	if (disk_sb->fs_byte_order == BEFS_BYTEORDER_NATIVE_LE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 		befs_sb->byte_order = BEFS_BYTESEX_LE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	else if (disk_sb->fs_byte_order == BEFS_BYTEORDER_NATIVE_BE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 		befs_sb->byte_order = BEFS_BYTESEX_BE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	befs_sb->magic1 = fs32_to_cpu(sb, disk_sb->magic1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	befs_sb->magic2 = fs32_to_cpu(sb, disk_sb->magic2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	befs_sb->magic3 = fs32_to_cpu(sb, disk_sb->magic3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	befs_sb->block_size = fs32_to_cpu(sb, disk_sb->block_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	befs_sb->block_shift = fs32_to_cpu(sb, disk_sb->block_shift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	befs_sb->num_blocks = fs64_to_cpu(sb, disk_sb->num_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	befs_sb->used_blocks = fs64_to_cpu(sb, disk_sb->used_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	befs_sb->inode_size = fs32_to_cpu(sb, disk_sb->inode_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	befs_sb->blocks_per_ag = fs32_to_cpu(sb, disk_sb->blocks_per_ag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	befs_sb->ag_shift = fs32_to_cpu(sb, disk_sb->ag_shift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	befs_sb->num_ags = fs32_to_cpu(sb, disk_sb->num_ags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	befs_sb->flags = fs32_to_cpu(sb, disk_sb->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	befs_sb->log_blocks = fsrun_to_cpu(sb, disk_sb->log_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	befs_sb->log_start = fs64_to_cpu(sb, disk_sb->log_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	befs_sb->log_end = fs64_to_cpu(sb, disk_sb->log_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	befs_sb->root_dir = fsrun_to_cpu(sb, disk_sb->root_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	befs_sb->indices = fsrun_to_cpu(sb, disk_sb->indices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	befs_sb->nls = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	return BEFS_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) befs_check_sb(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	struct befs_sb_info *befs_sb = BEFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	/* Check magic headers of super block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	if ((befs_sb->magic1 != BEFS_SUPER_MAGIC1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	    || (befs_sb->magic2 != BEFS_SUPER_MAGIC2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	    || (befs_sb->magic3 != BEFS_SUPER_MAGIC3)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		befs_error(sb, "invalid magic header");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		return BEFS_ERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	 * Check blocksize of BEFS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	 * Blocksize of BEFS is 1024, 2048, 4096 or 8192.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	if ((befs_sb->block_size != 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	    && (befs_sb->block_size != 2048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	    && (befs_sb->block_size != 4096)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	    && (befs_sb->block_size != 8192)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		befs_error(sb, "invalid blocksize: %u", befs_sb->block_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		return BEFS_ERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	if (befs_sb->block_size > PAGE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		befs_error(sb, "blocksize(%u) cannot be larger "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			   "than system pagesize(%lu)", befs_sb->block_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			   PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		return BEFS_ERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	 * block_shift and block_size encode the same information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	 * in different ways as a consistency check.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	if ((1 << befs_sb->block_shift) != befs_sb->block_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		befs_error(sb, "block_shift disagrees with block_size. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			   "Corruption likely.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		return BEFS_ERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	/* ag_shift also encodes the same information as blocks_per_ag in a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	 * different way, non-fatal consistency check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	if ((1 << befs_sb->ag_shift) != befs_sb->blocks_per_ag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		befs_error(sb, "ag_shift disagrees with blocks_per_ag.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	if (befs_sb->log_start != befs_sb->log_end ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	    befs_sb->flags == BEFS_DIRTY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		befs_error(sb, "Filesystem not clean! There are blocks in the "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 			   "journal. You must boot into BeOS and mount this "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			   "volume to make it clean.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		return BEFS_ERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	return BEFS_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }