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) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  linux/fs/sysv/inode.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  minix/inode.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Copyright (C) 1991, 1992  Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  xenix/inode.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *  Copyright (C) 1992  Doug Evans
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *  coh/inode.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *  Copyright (C) 1993  Pascal Haible, Bruno Haible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *  sysv/inode.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *  Copyright (C) 1993  Paul B. Monday
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *  sysv/inode.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *  Copyright (C) 1993  Bruno Haible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *  Copyright (C) 1997, 1998  Krzysztof G. Baranowski
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *  This file contains code for read/parsing the superblock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include "sysv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * The following functions try to recognize specific filesystems.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * We recognize:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * - Xenix FS by its magic number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * - SystemV FS by its magic number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * - Coherent FS by its funny fname/fpack field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * - SCO AFS by s_nfree == 0xffff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * - V7 FS has no distinguishing features.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * We discriminate among SystemV4 and SystemV2 FS by the assumption that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * the time stamp is not < 01-01-1980.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	JAN_1_1980 = (10*365 + 2) * 24 * 60 * 60
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static void detected_xenix(struct sysv_sb_info *sbi, unsigned *max_links)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct buffer_head *bh1 = sbi->s_bh1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	struct buffer_head *bh2 = sbi->s_bh2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	struct xenix_super_block * sbd1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	struct xenix_super_block * sbd2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	if (bh1 != bh2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		sbd1 = sbd2 = (struct xenix_super_block *) bh1->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		/* block size = 512, so bh1 != bh2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		sbd1 = (struct xenix_super_block *) bh1->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		sbd2 = (struct xenix_super_block *) (bh2->b_data - 512);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	*max_links = XENIX_LINK_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	sbi->s_fic_size = XENIX_NICINOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	sbi->s_flc_size = XENIX_NICFREE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	sbi->s_sbd1 = (char *)sbd1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	sbi->s_sbd2 = (char *)sbd2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	sbi->s_sb_fic_count = &sbd1->s_ninode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	sbi->s_sb_fic_inodes = &sbd1->s_inode[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	sbi->s_sb_total_free_inodes = &sbd2->s_tinode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	sbi->s_bcache_count = &sbd1->s_nfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	sbi->s_bcache = &sbd1->s_free[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	sbi->s_free_blocks = &sbd2->s_tfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	sbi->s_sb_time = &sbd2->s_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	sbi->s_firstdatazone = fs16_to_cpu(sbi, sbd1->s_isize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	sbi->s_nzones = fs32_to_cpu(sbi, sbd1->s_fsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) static void detected_sysv4(struct sysv_sb_info *sbi, unsigned *max_links)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	struct sysv4_super_block * sbd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	struct buffer_head *bh1 = sbi->s_bh1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	struct buffer_head *bh2 = sbi->s_bh2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	if (bh1 == bh2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		sbd = (struct sysv4_super_block *) (bh1->b_data + BLOCK_SIZE/2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		sbd = (struct sysv4_super_block *) bh2->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	*max_links = SYSV_LINK_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	sbi->s_fic_size = SYSV_NICINOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	sbi->s_flc_size = SYSV_NICFREE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	sbi->s_sbd1 = (char *)sbd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	sbi->s_sbd2 = (char *)sbd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	sbi->s_sb_fic_count = &sbd->s_ninode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	sbi->s_sb_fic_inodes = &sbd->s_inode[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	sbi->s_sb_total_free_inodes = &sbd->s_tinode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	sbi->s_bcache_count = &sbd->s_nfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	sbi->s_bcache = &sbd->s_free[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	sbi->s_free_blocks = &sbd->s_tfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	sbi->s_sb_time = &sbd->s_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	sbi->s_sb_state = &sbd->s_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	sbi->s_firstdatazone = fs16_to_cpu(sbi, sbd->s_isize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	sbi->s_nzones = fs32_to_cpu(sbi, sbd->s_fsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static void detected_sysv2(struct sysv_sb_info *sbi, unsigned *max_links)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	struct sysv2_super_block *sbd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	struct buffer_head *bh1 = sbi->s_bh1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	struct buffer_head *bh2 = sbi->s_bh2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	if (bh1 == bh2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		sbd = (struct sysv2_super_block *) (bh1->b_data + BLOCK_SIZE/2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		sbd = (struct sysv2_super_block *) bh2->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	*max_links = SYSV_LINK_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	sbi->s_fic_size = SYSV_NICINOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	sbi->s_flc_size = SYSV_NICFREE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	sbi->s_sbd1 = (char *)sbd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	sbi->s_sbd2 = (char *)sbd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	sbi->s_sb_fic_count = &sbd->s_ninode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	sbi->s_sb_fic_inodes = &sbd->s_inode[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	sbi->s_sb_total_free_inodes = &sbd->s_tinode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	sbi->s_bcache_count = &sbd->s_nfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	sbi->s_bcache = &sbd->s_free[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	sbi->s_free_blocks = &sbd->s_tfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	sbi->s_sb_time = &sbd->s_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	sbi->s_sb_state = &sbd->s_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	sbi->s_firstdatazone = fs16_to_cpu(sbi, sbd->s_isize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	sbi->s_nzones = fs32_to_cpu(sbi, sbd->s_fsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static void detected_coherent(struct sysv_sb_info *sbi, unsigned *max_links)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	struct coh_super_block * sbd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	struct buffer_head *bh1 = sbi->s_bh1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	sbd = (struct coh_super_block *) bh1->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	*max_links = COH_LINK_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	sbi->s_fic_size = COH_NICINOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	sbi->s_flc_size = COH_NICFREE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	sbi->s_sbd1 = (char *)sbd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	sbi->s_sbd2 = (char *)sbd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	sbi->s_sb_fic_count = &sbd->s_ninode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	sbi->s_sb_fic_inodes = &sbd->s_inode[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	sbi->s_sb_total_free_inodes = &sbd->s_tinode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	sbi->s_bcache_count = &sbd->s_nfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	sbi->s_bcache = &sbd->s_free[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	sbi->s_free_blocks = &sbd->s_tfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	sbi->s_sb_time = &sbd->s_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	sbi->s_firstdatazone = fs16_to_cpu(sbi, sbd->s_isize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	sbi->s_nzones = fs32_to_cpu(sbi, sbd->s_fsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static void detected_v7(struct sysv_sb_info *sbi, unsigned *max_links)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	struct buffer_head *bh2 = sbi->s_bh2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	struct v7_super_block *sbd = (struct v7_super_block *)bh2->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	*max_links = V7_LINK_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	sbi->s_fic_size = V7_NICINOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	sbi->s_flc_size = V7_NICFREE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	sbi->s_sbd1 = (char *)sbd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	sbi->s_sbd2 = (char *)sbd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	sbi->s_sb_fic_count = &sbd->s_ninode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	sbi->s_sb_fic_inodes = &sbd->s_inode[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	sbi->s_sb_total_free_inodes = &sbd->s_tinode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	sbi->s_bcache_count = &sbd->s_nfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	sbi->s_bcache = &sbd->s_free[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	sbi->s_free_blocks = &sbd->s_tfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	sbi->s_sb_time = &sbd->s_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	sbi->s_firstdatazone = fs16_to_cpu(sbi, sbd->s_isize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	sbi->s_nzones = fs32_to_cpu(sbi, sbd->s_fsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static int detect_xenix(struct sysv_sb_info *sbi, struct buffer_head *bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	struct xenix_super_block *sbd = (struct xenix_super_block *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	if (*(__le32 *)&sbd->s_magic == cpu_to_le32(0x2b5544))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		sbi->s_bytesex = BYTESEX_LE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	else if (*(__be32 *)&sbd->s_magic == cpu_to_be32(0x2b5544))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		sbi->s_bytesex = BYTESEX_BE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	switch (fs32_to_cpu(sbi, sbd->s_type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		sbi->s_type = FSTYPE_XENIX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		sbi->s_type = FSTYPE_XENIX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		return 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static int detect_sysv(struct sysv_sb_info *sbi, struct buffer_head *bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	struct super_block *sb = sbi->s_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	/* All relevant fields are at the same offsets in R2 and R4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	struct sysv4_super_block * sbd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	u32 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	sbd = (struct sysv4_super_block *) (bh->b_data + BLOCK_SIZE/2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	if (*(__le32 *)&sbd->s_magic == cpu_to_le32(0xfd187e20))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		sbi->s_bytesex = BYTESEX_LE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	else if (*(__be32 *)&sbd->s_magic == cpu_to_be32(0xfd187e20))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		sbi->s_bytesex = BYTESEX_BE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	type = fs32_to_cpu(sbi, sbd->s_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)  
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)  	if (fs16_to_cpu(sbi, sbd->s_nfree) == 0xffff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)  		sbi->s_type = FSTYPE_AFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		sbi->s_forced_ro = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)  		if (!sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)  			printk("SysV FS: SCO EAFS on %s detected, " 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)  				"forcing read-only mode.\n", 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)  				sb->s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)  		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)  		return type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)  	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)  
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	if (fs32_to_cpu(sbi, sbd->s_time) < JAN_1_1980) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		/* this is likely to happen on SystemV2 FS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		if (type > 3 || type < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		sbi->s_type = FSTYPE_SYSV2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		return type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	if ((type > 3 || type < 1) && (type > 0x30 || type < 0x10))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	/* On Interactive Unix (ISC) Version 4.0/3.x s_type field = 0x10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	   0x20 or 0x30 indicates that symbolic links and the 14-character
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	   filename limit is gone. Due to lack of information about this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)            feature read-only mode seems to be a reasonable approach... -KGB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	if (type >= 0x10) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		printk("SysV FS: can't handle long file names on %s, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		       "forcing read-only mode.\n", sb->s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		sbi->s_forced_ro = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	sbi->s_type = FSTYPE_SYSV4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	return type >= 0x10 ? type >> 4 : type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static int detect_coherent(struct sysv_sb_info *sbi, struct buffer_head *bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	struct coh_super_block * sbd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	sbd = (struct coh_super_block *) (bh->b_data + BLOCK_SIZE/2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	if ((memcmp(sbd->s_fname,"noname",6) && memcmp(sbd->s_fname,"xxxxx ",6))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	    || (memcmp(sbd->s_fpack,"nopack",6) && memcmp(sbd->s_fpack,"xxxxx\n",6)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	sbi->s_bytesex = BYTESEX_PDP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	sbi->s_type = FSTYPE_COH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static int detect_sysv_odd(struct sysv_sb_info *sbi, struct buffer_head *bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	int size = detect_sysv(sbi, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	return size>2 ? 0 : size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) static struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	int block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	int (*test)(struct sysv_sb_info *, struct buffer_head *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) } flavours[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	{1, detect_xenix},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	{0, detect_sysv},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	{0, detect_coherent},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	{9, detect_sysv_odd},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	{15,detect_sysv_odd},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	{18,detect_sysv},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) static char *flavour_names[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	[FSTYPE_XENIX]	= "Xenix",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	[FSTYPE_SYSV4]	= "SystemV",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	[FSTYPE_SYSV2]	= "SystemV Release 2",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	[FSTYPE_COH]	= "Coherent",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	[FSTYPE_V7]	= "V7",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	[FSTYPE_AFS]	= "AFS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) static void (*flavour_setup[])(struct sysv_sb_info *, unsigned *) = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	[FSTYPE_XENIX]	= detected_xenix,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	[FSTYPE_SYSV4]	= detected_sysv4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	[FSTYPE_SYSV2]	= detected_sysv2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	[FSTYPE_COH]	= detected_coherent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	[FSTYPE_V7]	= detected_v7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	[FSTYPE_AFS]	= detected_sysv4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) static int complete_read_super(struct super_block *sb, int silent, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	struct sysv_sb_info *sbi = SYSV_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	struct inode *root_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	char *found = flavour_names[sbi->s_type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	u_char n_bits = size+8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	int bsize = 1 << n_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	int bsize_4 = bsize >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	sbi->s_firstinodezone = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	flavour_setup[sbi->s_type](sbi, &sb->s_max_links);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	sbi->s_ndatazones = sbi->s_nzones - sbi->s_firstdatazone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	sbi->s_inodes_per_block = bsize >> 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	sbi->s_inodes_per_block_1 = (bsize >> 6)-1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	sbi->s_inodes_per_block_bits = n_bits-6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	sbi->s_ind_per_block = bsize_4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	sbi->s_ind_per_block_2 = bsize_4*bsize_4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	sbi->s_toobig_block = 10 + bsize_4 * (1 + bsize_4 * (1 + bsize_4));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	sbi->s_ind_per_block_bits = n_bits-2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	sbi->s_ninodes = (sbi->s_firstdatazone - sbi->s_firstinodezone)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		<< sbi->s_inodes_per_block_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	if (!silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		printk("VFS: Found a %s FS (block size = %ld) on device %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		       found, sb->s_blocksize, sb->s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	sb->s_magic = SYSV_MAGIC_BASE + sbi->s_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	/* set up enough so that it can read an inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	sb->s_op = &sysv_sops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	if (sbi->s_forced_ro)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		sb->s_flags |= SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	root_inode = sysv_iget(sb, SYSV_ROOT_INO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	if (IS_ERR(root_inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		printk("SysV FS: get root inode failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	sb->s_root = d_make_root(root_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	if (!sb->s_root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		printk("SysV FS: get root dentry failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) static int sysv_fill_super(struct super_block *sb, void *data, int silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	struct buffer_head *bh1, *bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	struct sysv_sb_info *sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	unsigned long blocknr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	int size = 0, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	BUILD_BUG_ON(1024 != sizeof (struct xenix_super_block));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	BUILD_BUG_ON(512 != sizeof (struct sysv4_super_block));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	BUILD_BUG_ON(512 != sizeof (struct sysv2_super_block));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	BUILD_BUG_ON(500 != sizeof (struct coh_super_block));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	BUILD_BUG_ON(64 != sizeof (struct sysv_inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	sbi = kzalloc(sizeof(struct sysv_sb_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	if (!sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	sbi->s_sb = sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	sbi->s_block_base = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	mutex_init(&sbi->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	sb->s_fs_info = sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	sb->s_time_min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	sb->s_time_max = U32_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	sb_set_blocksize(sb, BLOCK_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	for (i = 0; i < ARRAY_SIZE(flavours) && !size; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		bh = sb_bread(sb, flavours[i].block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		size = flavours[i].test(SYSV_SB(sb), bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	if (!size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		goto Eunknown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	switch (size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 			blocknr = bh->b_blocknr << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 			brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 			sb_set_blocksize(sb, 512);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 			bh1 = sb_bread(sb, blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 			bh = sb_bread(sb, blocknr + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 			bh1 = bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 			blocknr = bh->b_blocknr >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 			brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 			sb_set_blocksize(sb, 2048);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 			bh1 = bh = sb_bread(sb, blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 			goto Ebadsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	if (bh && bh1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		sbi->s_bh1 = bh1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		sbi->s_bh2 = bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		if (complete_read_super(sb, silent, size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	brelse(bh1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	sb_set_blocksize(sb, BLOCK_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	printk("oldfs: cannot read superblock\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	kfree(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) Eunknown:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	if (!silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		printk("VFS: unable to find oldfs superblock on device %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 			sb->s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) Ebadsize:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	if (!silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		printk("VFS: oldfs: unsupported block size (%dKb)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 			1<<(size-2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) static int v7_sanity_check(struct super_block *sb, struct buffer_head *bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	struct v7_super_block *v7sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	struct sysv_inode *v7i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	struct buffer_head *bh2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	struct sysv_sb_info *sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	sbi = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	/* plausibility check on superblock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	v7sb = (struct v7_super_block *) bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	if (fs16_to_cpu(sbi, v7sb->s_nfree) > V7_NICFREE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	    fs16_to_cpu(sbi, v7sb->s_ninode) > V7_NICINOD ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	    fs32_to_cpu(sbi, v7sb->s_fsize) > V7_MAXSIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	/* plausibility check on root inode: it is a directory,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	   with a nonzero size that is a multiple of 16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	bh2 = sb_bread(sb, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	if (bh2 == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	v7i = (struct sysv_inode *)(bh2->b_data + 64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	if ((fs16_to_cpu(sbi, v7i->i_mode) & ~0777) != S_IFDIR ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	    (fs32_to_cpu(sbi, v7i->i_size) == 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	    (fs32_to_cpu(sbi, v7i->i_size) & 017) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	    (fs32_to_cpu(sbi, v7i->i_size) > V7_NFILES *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	     sizeof(struct sysv_dir_entry))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		brelse(bh2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	brelse(bh2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) static int v7_fill_super(struct super_block *sb, void *data, int silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	struct sysv_sb_info *sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	if (440 != sizeof (struct v7_super_block))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		panic("V7 FS: bad super-block size");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	if (64 != sizeof (struct sysv_inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		panic("sysv fs: bad i-node size");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	sbi = kzalloc(sizeof(struct sysv_sb_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	if (!sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	sbi->s_sb = sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	sbi->s_block_base = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	sbi->s_type = FSTYPE_V7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	mutex_init(&sbi->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	sb->s_fs_info = sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	sb->s_time_min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	sb->s_time_max = U32_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	sb_set_blocksize(sb, 512);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	if ((bh = sb_bread(sb, 1)) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 		if (!silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 			printk("VFS: unable to read V7 FS superblock on "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 			       "device %s.\n", sb->s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 		goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	/* Try PDP-11 UNIX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	sbi->s_bytesex = BYTESEX_PDP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	if (v7_sanity_check(sb, bh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 		goto detected;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	/* Try PC/IX, v7/x86 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	sbi->s_bytesex = BYTESEX_LE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	if (v7_sanity_check(sb, bh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		goto detected;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) detected:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	sbi->s_bh1 = bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	sbi->s_bh2 = bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	if (complete_read_super(sb, silent, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	printk(KERN_ERR "VFS: could not find a valid V7 on %s.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 		sb->s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	kfree(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) /* Every kernel module contains stuff like this. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) static struct dentry *sysv_mount(struct file_system_type *fs_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	int flags, const char *dev_name, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	return mount_bdev(fs_type, flags, dev_name, data, sysv_fill_super);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) static struct dentry *v7_mount(struct file_system_type *fs_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	int flags, const char *dev_name, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	return mount_bdev(fs_type, flags, dev_name, data, v7_fill_super);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) static struct file_system_type sysv_fs_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	.name		= "sysv",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	.mount		= sysv_mount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	.kill_sb	= kill_block_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	.fs_flags	= FS_REQUIRES_DEV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) MODULE_ALIAS_FS("sysv");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) static struct file_system_type v7_fs_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	.name		= "v7",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	.mount		= v7_mount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	.kill_sb	= kill_block_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	.fs_flags	= FS_REQUIRES_DEV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) MODULE_ALIAS_FS("v7");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) MODULE_ALIAS("v7");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) static int __init init_sysv_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	error = sysv_init_icache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	error = register_filesystem(&sysv_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 		goto destroy_icache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	error = register_filesystem(&v7_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 		goto unregister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) unregister:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	unregister_filesystem(&sysv_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) destroy_icache:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	sysv_destroy_icache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) static void __exit exit_sysv_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	unregister_filesystem(&sysv_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	unregister_filesystem(&v7_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	sysv_destroy_icache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) module_init(init_sysv_fs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) module_exit(exit_sysv_fs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);