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)  * PURPOSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  *  Super block routines for the OSTA-UDF(tm) filesystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  * DESCRIPTION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  *  OSTA-UDF(tm) = Optical Storage Technology Association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *  Universal Disk Format.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  *  This code is based on version 2.00 of the UDF specification,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  *  and revision 3 of the ECMA 167 standard [equivalent to ISO 13346].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  *    http://www.osta.org/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  *    https://www.ecma.ch/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  *    https://www.iso.org/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  * COPYRIGHT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  *  This file is distributed under the terms of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)  *  License (GPL). Copies of the GPL can be obtained from:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  *    ftp://prep.ai.mit.edu/pub/gnu/GPL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  *  Each contributing author retains all rights to their own work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  *  (C) 1998 Dave Boynton
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)  *  (C) 1998-2004 Ben Fennema
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)  *  (C) 2000 Stelias Computing Inc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27)  * HISTORY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  *  09/24/98 dgb  changed to allow compiling outside of kernel, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30)  *                added some debugging.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31)  *  10/01/98 dgb  updated to allow (some) possibility of compiling w/2.0.34
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32)  *  10/16/98      attempting some multi-session support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33)  *  10/17/98      added freespace count for "df"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34)  *  11/11/98 gr   added novrs option
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35)  *  11/26/98 dgb  added fileset,anchor mount options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36)  *  12/06/98 blf  really hosed things royally. vat/sparing support. sequenced
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37)  *                vol descs. rewrote option handling based on isofs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38)  *  12/20/98      find the free space bitmap (if it exists)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #include "udfdecl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #include <linux/parser.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) #include <linux/cdrom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #include <linux/nls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #include <linux/vfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #include <linux/mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #include <linux/bitmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #include <linux/crc-itu-t.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) #include <linux/log2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) #include <asm/byteorder.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) #include <linux/iversion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) #include "udf_sb.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) #include "udf_i.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 	VDS_POS_PRIMARY_VOL_DESC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 	VDS_POS_UNALLOC_SPACE_DESC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 	VDS_POS_LOGICAL_VOL_DESC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 	VDS_POS_IMP_USE_VOL_DESC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 	VDS_POS_LENGTH
^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) #define VSD_FIRST_SECTOR_OFFSET		32768
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) #define VSD_MAX_SECTOR_OFFSET		0x800000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80)  * Maximum number of Terminating Descriptor / Logical Volume Integrity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81)  * Descriptor redirections. The chosen numbers are arbitrary - just that we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82)  * hopefully don't limit any real use of rewritten inode on write-once media
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83)  * but avoid looping for too long on corrupted media.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) #define UDF_MAX_TD_NESTING 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) #define UDF_MAX_LVID_NESTING 1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) enum { UDF_MAX_LINKS = 0xffff };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) /* These are the "meat" - everything else is stuffing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) static int udf_fill_super(struct super_block *, void *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) static void udf_put_super(struct super_block *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) static int udf_sync_fs(struct super_block *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) static int udf_remount_fs(struct super_block *, int *, char *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) static void udf_load_logicalvolint(struct super_block *, struct kernel_extent_ad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) static void udf_open_lvid(struct super_block *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) static void udf_close_lvid(struct super_block *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) static unsigned int udf_count_free(struct super_block *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) static int udf_statfs(struct dentry *, struct kstatfs *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) static int udf_show_options(struct seq_file *, struct dentry *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) struct logicalVolIntegrityDescImpUse *udf_sb_lvidiu(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	struct logicalVolIntegrityDesc *lvid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 	unsigned int partnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 	unsigned int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 	if (!UDF_SB(sb)->s_lvid_bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	lvid = (struct logicalVolIntegrityDesc *)UDF_SB(sb)->s_lvid_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	partnum = le32_to_cpu(lvid->numOfPartitions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	/* The offset is to skip freeSpaceTable and sizeTable arrays */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 	offset = partnum * 2 * sizeof(uint32_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	return (struct logicalVolIntegrityDescImpUse *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 					(((uint8_t *)(lvid + 1)) + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) /* UDF filesystem type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) static struct dentry *udf_mount(struct file_system_type *fs_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 		      int flags, const char *dev_name, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	return mount_bdev(fs_type, flags, dev_name, data, udf_fill_super);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) static struct file_system_type udf_fstype = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	.name		= "udf",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	.mount		= udf_mount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	.kill_sb	= kill_block_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	.fs_flags	= FS_REQUIRES_DEV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) MODULE_ALIAS_FS("udf");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) static struct kmem_cache *udf_inode_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) static struct inode *udf_alloc_inode(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	struct udf_inode_info *ei;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	ei = kmem_cache_alloc(udf_inode_cachep, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	if (!ei)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	ei->i_unique = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	ei->i_lenExtents = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	ei->i_lenStreams = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	ei->i_next_alloc_block = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	ei->i_next_alloc_goal = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	ei->i_strat4096 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	ei->i_streamdir = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	init_rwsem(&ei->i_data_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	ei->cached_extent.lstart = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	spin_lock_init(&ei->i_extent_cache_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	inode_set_iversion(&ei->vfs_inode, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	return &ei->vfs_inode;
^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 udf_free_in_core_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	kmem_cache_free(udf_inode_cachep, UDF_I(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) static void init_once(void *foo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	struct udf_inode_info *ei = (struct udf_inode_info *)foo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	ei->i_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	inode_init_once(&ei->vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) static int __init init_inodecache(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	udf_inode_cachep = kmem_cache_create("udf_inode_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 					     sizeof(struct udf_inode_info),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 					     0, (SLAB_RECLAIM_ACCOUNT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 						 SLAB_MEM_SPREAD |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 						 SLAB_ACCOUNT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 					     init_once);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	if (!udf_inode_cachep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) static void destroy_inodecache(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	 * Make sure all delayed rcu free inodes are flushed before we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	 * destroy cache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	rcu_barrier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	kmem_cache_destroy(udf_inode_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) /* Superblock operations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) static const struct super_operations udf_sb_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	.alloc_inode	= udf_alloc_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	.free_inode	= udf_free_in_core_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	.write_inode	= udf_write_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	.evict_inode	= udf_evict_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	.put_super	= udf_put_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	.sync_fs	= udf_sync_fs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	.statfs		= udf_statfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	.remount_fs	= udf_remount_fs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	.show_options	= udf_show_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) struct udf_options {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	unsigned char novrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	unsigned int blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	unsigned int session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	unsigned int lastblock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	unsigned int anchor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	unsigned int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	umode_t umask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	kgid_t gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	kuid_t uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	umode_t fmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	umode_t dmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	struct nls_table *nls_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) static int __init init_udf_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	err = init_inodecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 		goto out1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	err = register_filesystem(&udf_fstype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	destroy_inodecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) out1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) static void __exit exit_udf_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	unregister_filesystem(&udf_fstype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	destroy_inodecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) static int udf_sb_alloc_partition_maps(struct super_block *sb, u32 count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	struct udf_sb_info *sbi = UDF_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	sbi->s_partmaps = kcalloc(count, sizeof(*sbi->s_partmaps), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	if (!sbi->s_partmaps) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 		sbi->s_partitions = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	sbi->s_partitions = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) static void udf_sb_free_bitmap(struct udf_bitmap *bitmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	int nr_groups = bitmap->s_nr_groups;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	for (i = 0; i < nr_groups; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 		brelse(bitmap->s_block_bitmap[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	kvfree(bitmap);
^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 void udf_free_partition(struct udf_part_map *map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	struct udf_meta_data *mdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 		iput(map->s_uspace.s_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 		udf_sb_free_bitmap(map->s_uspace.s_bitmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	if (map->s_partition_type == UDF_SPARABLE_MAP15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 		for (i = 0; i < 4; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 			brelse(map->s_type_specific.s_sparing.s_spar_map[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	else if (map->s_partition_type == UDF_METADATA_MAP25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 		mdata = &map->s_type_specific.s_metadata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 		iput(mdata->s_metadata_fe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 		mdata->s_metadata_fe = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 		iput(mdata->s_mirror_fe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 		mdata->s_mirror_fe = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 		iput(mdata->s_bitmap_fe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 		mdata->s_bitmap_fe = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) static void udf_sb_free_partitions(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	struct udf_sb_info *sbi = UDF_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	if (!sbi->s_partmaps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	for (i = 0; i < sbi->s_partitions; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 		udf_free_partition(&sbi->s_partmaps[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	kfree(sbi->s_partmaps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	sbi->s_partmaps = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) static int udf_show_options(struct seq_file *seq, struct dentry *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	struct super_block *sb = root->d_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	struct udf_sb_info *sbi = UDF_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 		seq_puts(seq, ",nostrict");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	if (UDF_QUERY_FLAG(sb, UDF_FLAG_BLOCKSIZE_SET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 		seq_printf(seq, ",bs=%lu", sb->s_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	if (UDF_QUERY_FLAG(sb, UDF_FLAG_UNHIDE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 		seq_puts(seq, ",unhide");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	if (UDF_QUERY_FLAG(sb, UDF_FLAG_UNDELETE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 		seq_puts(seq, ",undelete");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	if (!UDF_QUERY_FLAG(sb, UDF_FLAG_USE_AD_IN_ICB))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 		seq_puts(seq, ",noadinicb");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	if (UDF_QUERY_FLAG(sb, UDF_FLAG_USE_SHORT_AD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 		seq_puts(seq, ",shortad");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_FORGET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 		seq_puts(seq, ",uid=forget");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_FORGET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 		seq_puts(seq, ",gid=forget");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_SET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 		seq_printf(seq, ",uid=%u", from_kuid(&init_user_ns, sbi->s_uid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 	if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_SET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 		seq_printf(seq, ",gid=%u", from_kgid(&init_user_ns, sbi->s_gid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	if (sbi->s_umask != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 		seq_printf(seq, ",umask=%ho", sbi->s_umask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	if (sbi->s_fmode != UDF_INVALID_MODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 		seq_printf(seq, ",mode=%ho", sbi->s_fmode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	if (sbi->s_dmode != UDF_INVALID_MODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 		seq_printf(seq, ",dmode=%ho", sbi->s_dmode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	if (UDF_QUERY_FLAG(sb, UDF_FLAG_SESSION_SET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 		seq_printf(seq, ",session=%d", sbi->s_session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	if (UDF_QUERY_FLAG(sb, UDF_FLAG_LASTBLOCK_SET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 		seq_printf(seq, ",lastblock=%u", sbi->s_last_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	if (sbi->s_anchor != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 		seq_printf(seq, ",anchor=%u", sbi->s_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	if (sbi->s_nls_map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 		seq_printf(seq, ",iocharset=%s", sbi->s_nls_map->charset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 		seq_puts(seq, ",iocharset=utf8");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357)  * udf_parse_options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359)  * PURPOSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360)  *	Parse mount options.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362)  * DESCRIPTION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363)  *	The following mount options are supported:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365)  *	gid=		Set the default group.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366)  *	umask=		Set the default umask.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367)  *	mode=		Set the default file permissions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368)  *	dmode=		Set the default directory permissions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369)  *	uid=		Set the default user.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370)  *	bs=		Set the block size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371)  *	unhide		Show otherwise hidden files.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372)  *	undelete	Show deleted files in lists.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373)  *	adinicb		Embed data in the inode (default)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374)  *	noadinicb	Don't embed data in the inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375)  *	shortad		Use short ad's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376)  *	longad		Use long ad's (default)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377)  *	nostrict	Unset strict conformance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378)  *	iocharset=	Set the NLS character set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380)  *	The remaining are for debugging and disaster recovery:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382)  *	novrs		Skip volume sequence recognition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384)  *	The following expect a offset from 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386)  *	session=	Set the CDROM session (default= last session)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387)  *	anchor=		Override standard anchor location. (default= 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388)  *	volume=		Override the VolumeDesc location. (unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389)  *	partition=	Override the PartitionDesc location. (unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390)  *	lastblock=	Set the last block of the filesystem/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392)  *	The following expect a offset from the partition root.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394)  *	fileset=	Override the fileset block location. (unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395)  *	rootdir=	Override the root directory location. (unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396)  *		WARNING: overriding the rootdir to a non-directory may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397)  *		yield highly unpredictable results.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399)  * PRE-CONDITIONS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400)  *	options		Pointer to mount options string.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401)  *	uopts		Pointer to mount options variable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403)  * POST-CONDITIONS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404)  *	<return>	1	Mount options parsed okay.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405)  *	<return>	0	Error parsing mount options.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407)  * HISTORY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408)  *	July 1, 1997 - Andrew E. Mileski
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409)  *	Written, tested, and released.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	Opt_novrs, Opt_nostrict, Opt_bs, Opt_unhide, Opt_undelete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 	Opt_noadinicb, Opt_adinicb, Opt_shortad, Opt_longad,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 	Opt_gid, Opt_uid, Opt_umask, Opt_session, Opt_lastblock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	Opt_anchor, Opt_volume, Opt_partition, Opt_fileset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	Opt_rootdir, Opt_utf8, Opt_iocharset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	Opt_err, Opt_uforget, Opt_uignore, Opt_gforget, Opt_gignore,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	Opt_fmode, Opt_dmode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) static const match_table_t tokens = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	{Opt_novrs,	"novrs"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	{Opt_nostrict,	"nostrict"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	{Opt_bs,	"bs=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	{Opt_unhide,	"unhide"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	{Opt_undelete,	"undelete"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	{Opt_noadinicb,	"noadinicb"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	{Opt_adinicb,	"adinicb"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	{Opt_shortad,	"shortad"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	{Opt_longad,	"longad"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	{Opt_uforget,	"uid=forget"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	{Opt_uignore,	"uid=ignore"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	{Opt_gforget,	"gid=forget"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	{Opt_gignore,	"gid=ignore"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	{Opt_gid,	"gid=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	{Opt_uid,	"uid=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	{Opt_umask,	"umask=%o"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	{Opt_session,	"session=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	{Opt_lastblock,	"lastblock=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	{Opt_anchor,	"anchor=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	{Opt_volume,	"volume=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	{Opt_partition,	"partition=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	{Opt_fileset,	"fileset=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	{Opt_rootdir,	"rootdir=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	{Opt_utf8,	"utf8"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	{Opt_iocharset,	"iocharset=%s"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	{Opt_fmode,     "mode=%o"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	{Opt_dmode,     "dmode=%o"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	{Opt_err,	NULL}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) static int udf_parse_options(char *options, struct udf_options *uopt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 			     bool remount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	int option;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	uopt->novrs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	uopt->session = 0xFFFFFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	uopt->lastblock = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	uopt->anchor = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	if (!options)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	while ((p = strsep(&options, ",")) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 		substring_t args[MAX_OPT_ARGS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 		int token;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 		unsigned n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 		if (!*p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 		token = match_token(p, tokens, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 		switch (token) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 		case Opt_novrs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 			uopt->novrs = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 		case Opt_bs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 			if (match_int(&args[0], &option))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 			n = option;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 			if (n != 512 && n != 1024 && n != 2048 && n != 4096)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 			uopt->blocksize = n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 			uopt->flags |= (1 << UDF_FLAG_BLOCKSIZE_SET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 		case Opt_unhide:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 			uopt->flags |= (1 << UDF_FLAG_UNHIDE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 		case Opt_undelete:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 			uopt->flags |= (1 << UDF_FLAG_UNDELETE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 		case Opt_noadinicb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 			uopt->flags &= ~(1 << UDF_FLAG_USE_AD_IN_ICB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 		case Opt_adinicb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 			uopt->flags |= (1 << UDF_FLAG_USE_AD_IN_ICB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 		case Opt_shortad:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 			uopt->flags |= (1 << UDF_FLAG_USE_SHORT_AD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 		case Opt_longad:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 			uopt->flags &= ~(1 << UDF_FLAG_USE_SHORT_AD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 		case Opt_gid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 			if (match_int(args, &option))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 			uopt->gid = make_kgid(current_user_ns(), option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 			if (!gid_valid(uopt->gid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 			uopt->flags |= (1 << UDF_FLAG_GID_SET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 		case Opt_uid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 			if (match_int(args, &option))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 			uopt->uid = make_kuid(current_user_ns(), option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 			if (!uid_valid(uopt->uid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 			uopt->flags |= (1 << UDF_FLAG_UID_SET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 		case Opt_umask:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 			if (match_octal(args, &option))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 			uopt->umask = option;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 		case Opt_nostrict:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 			uopt->flags &= ~(1 << UDF_FLAG_STRICT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 		case Opt_session:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 			if (match_int(args, &option))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 			uopt->session = option;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 			if (!remount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 				uopt->flags |= (1 << UDF_FLAG_SESSION_SET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 		case Opt_lastblock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 			if (match_int(args, &option))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 			uopt->lastblock = option;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 			if (!remount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 				uopt->flags |= (1 << UDF_FLAG_LASTBLOCK_SET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 		case Opt_anchor:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 			if (match_int(args, &option))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 			uopt->anchor = option;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 		case Opt_volume:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 		case Opt_partition:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 		case Opt_fileset:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 		case Opt_rootdir:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 			/* Ignored (never implemented properly) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 		case Opt_utf8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 			if (!remount) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 				unload_nls(uopt->nls_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 				uopt->nls_map = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 		case Opt_iocharset:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 			if (!remount) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 				unload_nls(uopt->nls_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 				uopt->nls_map = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 			/* When nls_map is not loaded then UTF-8 is used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 			if (!remount && strcmp(args[0].from, "utf8") != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 				uopt->nls_map = load_nls(args[0].from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 				if (!uopt->nls_map) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 					pr_err("iocharset %s not found\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 						args[0].from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 					return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 		case Opt_uforget:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 			uopt->flags |= (1 << UDF_FLAG_UID_FORGET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 		case Opt_uignore:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 		case Opt_gignore:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 			/* These options are superseeded by uid=<number> */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 		case Opt_gforget:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 			uopt->flags |= (1 << UDF_FLAG_GID_FORGET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 		case Opt_fmode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 			if (match_octal(args, &option))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 			uopt->fmode = option & 0777;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 		case Opt_dmode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 			if (match_octal(args, &option))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 			uopt->dmode = option & 0777;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 			pr_err("bad mount option \"%s\" or missing value\n", p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) static int udf_remount_fs(struct super_block *sb, int *flags, char *options)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	struct udf_options uopt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	struct udf_sb_info *sbi = UDF_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	if (!(*flags & SB_RDONLY) && UDF_QUERY_FLAG(sb, UDF_FLAG_RW_INCOMPAT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 		return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	sync_filesystem(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	uopt.flags = sbi->s_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	uopt.uid   = sbi->s_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	uopt.gid   = sbi->s_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	uopt.umask = sbi->s_umask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	uopt.fmode = sbi->s_fmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	uopt.dmode = sbi->s_dmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	uopt.nls_map = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	if (!udf_parse_options(options, &uopt, true))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	write_lock(&sbi->s_cred_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	sbi->s_flags = uopt.flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	sbi->s_uid   = uopt.uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	sbi->s_gid   = uopt.gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	sbi->s_umask = uopt.umask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	sbi->s_fmode = uopt.fmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	sbi->s_dmode = uopt.dmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	write_unlock(&sbi->s_cred_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	if ((bool)(*flags & SB_RDONLY) == sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	if (*flags & SB_RDONLY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 		udf_close_lvid(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 		udf_open_lvid(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648)  * Check VSD descriptor. Returns -1 in case we are at the end of volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649)  * recognition area, 0 if the descriptor is valid but non-interesting, 1 if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650)  * we found one of NSR descriptors we are looking for.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) static int identify_vsd(const struct volStructDesc *vsd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	if (!memcmp(vsd->stdIdent, VSD_STD_ID_CD001, VSD_STD_ID_LEN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 		switch (vsd->structType) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 		case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 			udf_debug("ISO9660 Boot Record found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 		case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 			udf_debug("ISO9660 Primary Volume Descriptor found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 		case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 			udf_debug("ISO9660 Supplementary Volume Descriptor found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 		case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 			udf_debug("ISO9660 Volume Partition Descriptor found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 		case 255:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 			udf_debug("ISO9660 Volume Descriptor Set Terminator found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 			udf_debug("ISO9660 VRS (%u) found\n", vsd->structType);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	} else if (!memcmp(vsd->stdIdent, VSD_STD_ID_BEA01, VSD_STD_ID_LEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 		; /* ret = 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	else if (!memcmp(vsd->stdIdent, VSD_STD_ID_NSR02, VSD_STD_ID_LEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 		ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	else if (!memcmp(vsd->stdIdent, VSD_STD_ID_NSR03, VSD_STD_ID_LEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 		ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	else if (!memcmp(vsd->stdIdent, VSD_STD_ID_BOOT2, VSD_STD_ID_LEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 		; /* ret = 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	else if (!memcmp(vsd->stdIdent, VSD_STD_ID_CDW02, VSD_STD_ID_LEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 		; /* ret = 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 		/* TEA01 or invalid id : end of volume recognition area */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 		ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696)  * Check Volume Structure Descriptors (ECMA 167 2/9.1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697)  * We also check any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698)  * @return   1 if NSR02 or NSR03 found,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699)  *	    -1 if first sector read error, 0 otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) static int udf_check_vsd(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	struct volStructDesc *vsd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	loff_t sector = VSD_FIRST_SECTOR_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	int sectorsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	struct buffer_head *bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	int nsr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	struct udf_sb_info *sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	loff_t session_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	sbi = UDF_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	if (sb->s_blocksize < sizeof(struct volStructDesc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 		sectorsize = sizeof(struct volStructDesc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 		sectorsize = sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	session_offset = (loff_t)sbi->s_session << sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	sector += session_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	udf_debug("Starting at sector %u (%lu byte sectors)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 		  (unsigned int)(sector >> sb->s_blocksize_bits),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 		  sb->s_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	/* Process the sequence (if applicable). The hard limit on the sector
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	 * offset is arbitrary, hopefully large enough so that all valid UDF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	 * filesystems will be recognised. There is no mention of an upper
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	 * bound to the size of the volume recognition area in the standard.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	 *  The limit will prevent the code to read all the sectors of a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	 * specially crafted image (like a bluray disc full of CD001 sectors),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	 * potentially causing minutes or even hours of uninterruptible I/O
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	 * activity. This actually happened with uninitialised SSD partitions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	 * (all 0xFF) before the check for the limit and all valid IDs were
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 	 * added */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	for (; !nsr && sector < VSD_MAX_SECTOR_OFFSET; sector += sectorsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 		/* Read a block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 		bh = udf_tread(sb, sector >> sb->s_blocksize_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 		if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		vsd = (struct volStructDesc *)(bh->b_data +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 					      (sector & (sb->s_blocksize - 1)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 		nsr = identify_vsd(vsd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 		/* Found NSR or end? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 		if (nsr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 			brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 		 * Special handling for improperly formatted VRS (e.g., Win10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 		 * where components are separated by 2048 bytes even though
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 		 * sectors are 4K
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 		if (sb->s_blocksize == 4096) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 			nsr = identify_vsd(vsd + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 			/* Ignore unknown IDs... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 			if (nsr < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 				nsr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 		brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 	if (nsr > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	else if (!bh && sector - session_offset == VSD_FIRST_SECTOR_OFFSET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) static int udf_verify_domain_identifier(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 					struct regid *ident, char *dname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	struct domainIdentSuffix *suffix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	if (memcmp(ident->ident, UDF_ID_COMPLIANT, strlen(UDF_ID_COMPLIANT))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 		udf_warn(sb, "Not OSTA UDF compliant %s descriptor.\n", dname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 		goto force_ro;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	if (ident->flags & ENTITYID_FLAGS_DIRTY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 		udf_warn(sb, "Possibly not OSTA UDF compliant %s descriptor.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 			 dname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 		goto force_ro;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	suffix = (struct domainIdentSuffix *)ident->identSuffix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	if ((suffix->domainFlags & DOMAIN_FLAGS_HARD_WRITE_PROTECT) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	    (suffix->domainFlags & DOMAIN_FLAGS_SOFT_WRITE_PROTECT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 		if (!sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 			udf_warn(sb, "Descriptor for %s marked write protected."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 				 " Forcing read only mount.\n", dname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 		goto force_ro;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) force_ro:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	if (!sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 		return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	UDF_SET_FLAG(sb, UDF_FLAG_RW_INCOMPAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) static int udf_load_fileset(struct super_block *sb, struct fileSetDesc *fset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 			    struct kernel_lb_addr *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	ret = udf_verify_domain_identifier(sb, &fset->domainIdent, "file set");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	*root = lelb_to_cpu(fset->rootDirectoryICB.extLocation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	UDF_SB(sb)->s_serial_number = le16_to_cpu(fset->descTag.tagSerialNum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	udf_debug("Rootdir at block=%u, partition=%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 		  root->logicalBlockNum, root->partitionReferenceNum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) static int udf_find_fileset(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 			    struct kernel_lb_addr *fileset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 			    struct kernel_lb_addr *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	struct buffer_head *bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	uint16_t ident;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	if (fileset->logicalBlockNum == 0xFFFFFFFF &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	    fileset->partitionReferenceNum == 0xFFFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	bh = udf_read_ptagged(sb, fileset, 0, &ident);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	if (ident != TAG_IDENT_FSD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 		brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	udf_debug("Fileset at block=%u, partition=%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 		  fileset->logicalBlockNum, fileset->partitionReferenceNum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 	UDF_SB(sb)->s_partition = fileset->partitionReferenceNum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	ret = udf_load_fileset(sb, (struct fileSetDesc *)bh->b_data, root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848)  * Load primary Volume Descriptor Sequence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850)  * Return <0 on error, 0 on success. -EAGAIN is special meaning next sequence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851)  * should be tried.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) static int udf_load_pvoldesc(struct super_block *sb, sector_t block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	struct primaryVolDesc *pvoldesc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	uint8_t *outstr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	uint16_t ident;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	struct timestamp *ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	outstr = kmalloc(128, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	if (!outstr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	bh = udf_read_tagged(sb, block, block, &ident);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	if (!bh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 		ret = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 		goto out2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	if (ident != TAG_IDENT_PVD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 		goto out_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	pvoldesc = (struct primaryVolDesc *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	udf_disk_stamp_to_time(&UDF_SB(sb)->s_record_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 			      pvoldesc->recordingDateAndTime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	ts = &pvoldesc->recordingDateAndTime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	udf_debug("recording time %04u/%02u/%02u %02u:%02u (%x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 		  le16_to_cpu(ts->year), ts->month, ts->day, ts->hour,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 		  ts->minute, le16_to_cpu(ts->typeAndTimezone));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	ret = udf_dstrCS0toChar(sb, outstr, 31, pvoldesc->volIdent, 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 		strcpy(UDF_SB(sb)->s_volume_ident, "InvalidName");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 		pr_warn("incorrect volume identification, setting to "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 			"'InvalidName'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 		strncpy(UDF_SB(sb)->s_volume_ident, outstr, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	udf_debug("volIdent[] = '%s'\n", UDF_SB(sb)->s_volume_ident);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	ret = udf_dstrCS0toChar(sb, outstr, 127, pvoldesc->volSetIdent, 128);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 		goto out_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	outstr[ret] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	udf_debug("volSetIdent[] = '%s'\n", outstr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) out_bh:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) out2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	kfree(outstr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) struct inode *udf_find_metadata_inode_efe(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 					u32 meta_file_loc, u32 partition_ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	struct kernel_lb_addr addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	struct inode *metadata_fe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	addr.logicalBlockNum = meta_file_loc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	addr.partitionReferenceNum = partition_ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	metadata_fe = udf_iget_special(sb, &addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	if (IS_ERR(metadata_fe)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 		udf_warn(sb, "metadata inode efe not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 		return metadata_fe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	if (UDF_I(metadata_fe)->i_alloc_type != ICBTAG_FLAG_AD_SHORT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 		udf_warn(sb, "metadata inode efe does not have short allocation descriptors!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 		iput(metadata_fe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 		return ERR_PTR(-EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	return metadata_fe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) static int udf_load_metadata_files(struct super_block *sb, int partition,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 				   int type1_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	struct udf_sb_info *sbi = UDF_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	struct udf_part_map *map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	struct udf_meta_data *mdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	struct kernel_lb_addr addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	struct inode *fe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	map = &sbi->s_partmaps[partition];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	mdata = &map->s_type_specific.s_metadata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	mdata->s_phys_partition_ref = type1_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	/* metadata address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	udf_debug("Metadata file location: block = %u part = %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 		  mdata->s_meta_file_loc, mdata->s_phys_partition_ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	fe = udf_find_metadata_inode_efe(sb, mdata->s_meta_file_loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 					 mdata->s_phys_partition_ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	if (IS_ERR(fe)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 		/* mirror file entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 		udf_debug("Mirror metadata file location: block = %u part = %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 			  mdata->s_mirror_file_loc, mdata->s_phys_partition_ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 		fe = udf_find_metadata_inode_efe(sb, mdata->s_mirror_file_loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 						 mdata->s_phys_partition_ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 		if (IS_ERR(fe)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 			udf_err(sb, "Both metadata and mirror metadata inode efe can not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 			return PTR_ERR(fe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 		mdata->s_mirror_fe = fe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 		mdata->s_metadata_fe = fe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	 * bitmap file entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	 * Note:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	 * Load only if bitmap file location differs from 0xFFFFFFFF (DCN-5102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	if (mdata->s_bitmap_file_loc != 0xFFFFFFFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 		addr.logicalBlockNum = mdata->s_bitmap_file_loc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 		addr.partitionReferenceNum = mdata->s_phys_partition_ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 		udf_debug("Bitmap file location: block = %u part = %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 			  addr.logicalBlockNum, addr.partitionReferenceNum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 		fe = udf_iget_special(sb, &addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 		if (IS_ERR(fe)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 			if (sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 				udf_warn(sb, "bitmap inode efe not found but it's ok since the disc is mounted read-only\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 			else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 				udf_err(sb, "bitmap inode efe not found and attempted read-write mount\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 				return PTR_ERR(fe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 			mdata->s_bitmap_fe = fe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	udf_debug("udf_load_metadata_files Ok\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) int udf_compute_nr_groups(struct super_block *sb, u32 partition)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	return DIV_ROUND_UP(map->s_partition_len +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 			    (sizeof(struct spaceBitmapDesc) << 3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 			    sb->s_blocksize * 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) static struct udf_bitmap *udf_sb_alloc_bitmap(struct super_block *sb, u32 index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	struct udf_bitmap *bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	int nr_groups = udf_compute_nr_groups(sb, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	bitmap = kvzalloc(struct_size(bitmap, s_block_bitmap, nr_groups),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 			  GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	if (!bitmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	bitmap->s_nr_groups = nr_groups;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	return bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) static int check_partition_desc(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 				struct partitionDesc *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 				struct udf_part_map *map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	bool umap, utable, fmap, ftable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	struct partitionHeaderDesc *phd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 	switch (le32_to_cpu(p->accessType)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 	case PD_ACCESS_TYPE_READ_ONLY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	case PD_ACCESS_TYPE_WRITE_ONCE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 	case PD_ACCESS_TYPE_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 		goto force_ro;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	/* No Partition Header Descriptor? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	if (strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR02) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 	    strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR03))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 		goto force_ro;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 	phd = (struct partitionHeaderDesc *)p->partitionContentsUse;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	utable = phd->unallocSpaceTable.extLength;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	umap = phd->unallocSpaceBitmap.extLength;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	ftable = phd->freedSpaceTable.extLength;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	fmap = phd->freedSpaceBitmap.extLength;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	/* No allocation info? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	if (!utable && !umap && !ftable && !fmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 		goto force_ro;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	/* We don't support blocks that require erasing before overwrite */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	if (ftable || fmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 		goto force_ro;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	/* UDF 2.60: 2.3.3 - no mixing of tables & bitmaps, no VAT. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	if (utable && umap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 		goto force_ro;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	if (map->s_partition_type == UDF_VIRTUAL_MAP15 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	    map->s_partition_type == UDF_VIRTUAL_MAP20 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	    map->s_partition_type == UDF_METADATA_MAP25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 		goto force_ro;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) force_ro:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	if (!sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 		return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	UDF_SET_FLAG(sb, UDF_FLAG_RW_INCOMPAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) static int udf_fill_partdesc_info(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 		struct partitionDesc *p, int p_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	struct udf_part_map *map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	struct udf_sb_info *sbi = UDF_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	struct partitionHeaderDesc *phd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 	map = &sbi->s_partmaps[p_index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 	map->s_partition_len = le32_to_cpu(p->partitionLength); /* blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	map->s_partition_root = le32_to_cpu(p->partitionStartingLocation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 		map->s_partition_flags |= UDF_PART_FLAG_READ_ONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 		map->s_partition_flags |= UDF_PART_FLAG_WRITE_ONCE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 		map->s_partition_flags |= UDF_PART_FLAG_REWRITABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 		map->s_partition_flags |= UDF_PART_FLAG_OVERWRITABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 	udf_debug("Partition (%d type %x) starts at physical %u, block length %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 		  p_index, map->s_partition_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 		  map->s_partition_root, map->s_partition_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	err = check_partition_desc(sb, p, map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	 * Skip loading allocation info it we cannot ever write to the fs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	 * This is a correctness thing as we may have decided to force ro mount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	 * to avoid allocation info we don't support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	if (UDF_QUERY_FLAG(sb, UDF_FLAG_RW_INCOMPAT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	phd = (struct partitionHeaderDesc *)p->partitionContentsUse;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	if (phd->unallocSpaceTable.extLength) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 		struct kernel_lb_addr loc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 			.logicalBlockNum = le32_to_cpu(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 				phd->unallocSpaceTable.extPosition),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 			.partitionReferenceNum = p_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 		struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 		inode = udf_iget_special(sb, &loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 		if (IS_ERR(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 			udf_debug("cannot load unallocSpaceTable (part %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 				  p_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 			return PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 		map->s_uspace.s_table = inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 		map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_TABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 		udf_debug("unallocSpaceTable (part %d) @ %lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 			  p_index, map->s_uspace.s_table->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	if (phd->unallocSpaceBitmap.extLength) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 		struct udf_bitmap *bitmap = udf_sb_alloc_bitmap(sb, p_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 		if (!bitmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 		map->s_uspace.s_bitmap = bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 		bitmap->s_extPosition = le32_to_cpu(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 				phd->unallocSpaceBitmap.extPosition);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 		map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_BITMAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 		udf_debug("unallocSpaceBitmap (part %d) @ %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 			  p_index, bitmap->s_extPosition);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) static void udf_find_vat_block(struct super_block *sb, int p_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 			       int type1_index, sector_t start_block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	struct udf_sb_info *sbi = UDF_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	struct udf_part_map *map = &sbi->s_partmaps[p_index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 	sector_t vat_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	struct kernel_lb_addr ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	 * VAT file entry is in the last recorded block. Some broken disks have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 	 * it a few blocks before so try a bit harder...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 	ino.partitionReferenceNum = type1_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	for (vat_block = start_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	     vat_block >= map->s_partition_root &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	     vat_block >= start_block - 3; vat_block--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 		ino.logicalBlockNum = vat_block - map->s_partition_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 		inode = udf_iget_special(sb, &ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 		if (!IS_ERR(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 			sbi->s_vat_inode = inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) static int udf_load_vat(struct super_block *sb, int p_index, int type1_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	struct udf_sb_info *sbi = UDF_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 	struct udf_part_map *map = &sbi->s_partmaps[p_index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	struct buffer_head *bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 	struct udf_inode_info *vati;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	uint32_t pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	struct virtualAllocationTable20 *vat20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	sector_t blocks = i_size_read(sb->s_bdev->bd_inode) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 			  sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	udf_find_vat_block(sb, p_index, type1_index, sbi->s_last_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 	if (!sbi->s_vat_inode &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	    sbi->s_last_block != blocks - 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 		pr_notice("Failed to read VAT inode from the last recorded block (%lu), retrying with the last block of the device (%lu).\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 			  (unsigned long)sbi->s_last_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 			  (unsigned long)blocks - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 		udf_find_vat_block(sb, p_index, type1_index, blocks - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 	if (!sbi->s_vat_inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 	if (map->s_partition_type == UDF_VIRTUAL_MAP15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 		map->s_type_specific.s_virtual.s_start_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 		map->s_type_specific.s_virtual.s_num_entries =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 			(sbi->s_vat_inode->i_size - 36) >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 	} else if (map->s_partition_type == UDF_VIRTUAL_MAP20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 		vati = UDF_I(sbi->s_vat_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 		if (vati->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 			pos = udf_block_map(sbi->s_vat_inode, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 			bh = sb_bread(sb, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 			if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 				return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 			vat20 = (struct virtualAllocationTable20 *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 			vat20 = (struct virtualAllocationTable20 *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 							vati->i_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 		map->s_type_specific.s_virtual.s_start_offset =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 			le16_to_cpu(vat20->lengthHeader);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 		map->s_type_specific.s_virtual.s_num_entries =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 			(sbi->s_vat_inode->i_size -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 				map->s_type_specific.s_virtual.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 					s_start_offset) >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 		brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222)  * Load partition descriptor block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224)  * Returns <0 on error, 0 on success, -EAGAIN is special - try next descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225)  * sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) static int udf_load_partdesc(struct super_block *sb, sector_t block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	struct partitionDesc *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 	struct udf_part_map *map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 	struct udf_sb_info *sbi = UDF_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 	int i, type1_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 	uint16_t partitionNumber;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 	uint16_t ident;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 	bh = udf_read_tagged(sb, block, block, &ident);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 	if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 	if (ident != TAG_IDENT_PD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 		goto out_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	p = (struct partitionDesc *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 	partitionNumber = le16_to_cpu(p->partitionNumber);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	/* First scan for TYPE1 and SPARABLE partitions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 	for (i = 0; i < sbi->s_partitions; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 		map = &sbi->s_partmaps[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 		udf_debug("Searching map: (%u == %u)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 			  map->s_partition_num, partitionNumber);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 		if (map->s_partition_num == partitionNumber &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 		    (map->s_partition_type == UDF_TYPE1_MAP15 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 		     map->s_partition_type == UDF_SPARABLE_MAP15))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 	if (i >= sbi->s_partitions) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 		udf_debug("Partition (%u) not found in partition map\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 			  partitionNumber);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 		goto out_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 	ret = udf_fill_partdesc_info(sb, p, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 		goto out_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 	 * Now rescan for VIRTUAL or METADATA partitions when SPARABLE and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 	 * PHYSICAL partitions are already set up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 	type1_idx = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 	map = NULL; /* supress 'maybe used uninitialized' warning */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 	for (i = 0; i < sbi->s_partitions; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 		map = &sbi->s_partmaps[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 		if (map->s_partition_num == partitionNumber &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 		    (map->s_partition_type == UDF_VIRTUAL_MAP15 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 		     map->s_partition_type == UDF_VIRTUAL_MAP20 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 		     map->s_partition_type == UDF_METADATA_MAP25))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 	if (i >= sbi->s_partitions) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 		goto out_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 	ret = udf_fill_partdesc_info(sb, p, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 		goto out_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 	if (map->s_partition_type == UDF_METADATA_MAP25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 		ret = udf_load_metadata_files(sb, i, type1_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 		if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 			udf_err(sb, "error loading MetaData partition map %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 				i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 			goto out_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 		 * If we have a partition with virtual map, we don't handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 		 * writing to it (we overwrite blocks instead of relocating
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 		 * them).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 		if (!sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 			ret = -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 			goto out_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 		UDF_SET_FLAG(sb, UDF_FLAG_RW_INCOMPAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 		ret = udf_load_vat(sb, i, type1_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 			goto out_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) out_bh:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 	/* In case loading failed, we handle cleanup in udf_fill_super */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 	brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) static int udf_load_sparable_map(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 				 struct udf_part_map *map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 				 struct sparablePartitionMap *spm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 	uint32_t loc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 	uint16_t ident;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	struct sparingTable *st;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 	struct udf_sparing_data *sdata = &map->s_type_specific.s_sparing;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 	map->s_partition_type = UDF_SPARABLE_MAP15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 	sdata->s_packet_len = le16_to_cpu(spm->packetLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 	if (!is_power_of_2(sdata->s_packet_len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 		udf_err(sb, "error loading logical volume descriptor: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 			"Invalid packet length %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 			(unsigned)sdata->s_packet_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 	if (spm->numSparingTables > 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 		udf_err(sb, "error loading logical volume descriptor: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 			"Too many sparing tables (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 			(int)spm->numSparingTables);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 	if (le32_to_cpu(spm->sizeSparingTable) > sb->s_blocksize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 		udf_err(sb, "error loading logical volume descriptor: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 			"Too big sparing table size (%u)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 			le32_to_cpu(spm->sizeSparingTable));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 	for (i = 0; i < spm->numSparingTables; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 		loc = le32_to_cpu(spm->locSparingTable[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 		bh = udf_read_tagged(sb, loc, loc, &ident);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 		if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 		st = (struct sparingTable *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 		if (ident != 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 		    strncmp(st->sparingIdent.ident, UDF_ID_SPARING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 			    strlen(UDF_ID_SPARING)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 		    sizeof(*st) + le16_to_cpu(st->reallocationTableLen) >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 							sb->s_blocksize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 			brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 		sdata->s_spar_map[i] = bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 	map->s_partition_func = udf_get_pblock_spar15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) static int udf_load_logicalvol(struct super_block *sb, sector_t block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 			       struct kernel_lb_addr *fileset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 	struct logicalVolDesc *lvd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 	int i, offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 	uint8_t type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 	struct udf_sb_info *sbi = UDF_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 	struct genericPartitionMap *gpm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 	uint16_t ident;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 	unsigned int table_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 	bh = udf_read_tagged(sb, block, block, &ident);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 	if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 	BUG_ON(ident != TAG_IDENT_LVD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 	lvd = (struct logicalVolDesc *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 	table_len = le32_to_cpu(lvd->mapTableLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 	if (table_len > sb->s_blocksize - sizeof(*lvd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 		udf_err(sb, "error loading logical volume descriptor: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 			"Partition table too long (%u > %lu)\n", table_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 			sb->s_blocksize - sizeof(*lvd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 		goto out_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 	ret = udf_verify_domain_identifier(sb, &lvd->domainIdent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 					   "logical volume");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 		goto out_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 	ret = udf_sb_alloc_partition_maps(sb, le32_to_cpu(lvd->numPartitionMaps));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 		goto out_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 	for (i = 0, offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 	     i < sbi->s_partitions && offset < table_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 	     i++, offset += gpm->partitionMapLength) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 		struct udf_part_map *map = &sbi->s_partmaps[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 		gpm = (struct genericPartitionMap *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 				&(lvd->partitionMaps[offset]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 		type = gpm->partitionMapType;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 		if (type == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 			struct genericPartitionMap1 *gpm1 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 				(struct genericPartitionMap1 *)gpm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 			map->s_partition_type = UDF_TYPE1_MAP15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 			map->s_volumeseqnum = le16_to_cpu(gpm1->volSeqNum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 			map->s_partition_num = le16_to_cpu(gpm1->partitionNum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 			map->s_partition_func = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 		} else if (type == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 			struct udfPartitionMap2 *upm2 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 						(struct udfPartitionMap2 *)gpm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 			if (!strncmp(upm2->partIdent.ident, UDF_ID_VIRTUAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 						strlen(UDF_ID_VIRTUAL))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 				u16 suf =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 					le16_to_cpu(((__le16 *)upm2->partIdent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 							identSuffix)[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 				if (suf < 0x0200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 					map->s_partition_type =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 							UDF_VIRTUAL_MAP15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 					map->s_partition_func =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 							udf_get_pblock_virt15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 					map->s_partition_type =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 							UDF_VIRTUAL_MAP20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 					map->s_partition_func =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 							udf_get_pblock_virt20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 			} else if (!strncmp(upm2->partIdent.ident,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 						UDF_ID_SPARABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 						strlen(UDF_ID_SPARABLE))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 				ret = udf_load_sparable_map(sb, map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 					(struct sparablePartitionMap *)gpm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 				if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 					goto out_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 			} else if (!strncmp(upm2->partIdent.ident,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 						UDF_ID_METADATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 						strlen(UDF_ID_METADATA))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 				struct udf_meta_data *mdata =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 					&map->s_type_specific.s_metadata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 				struct metadataPartitionMap *mdm =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 						(struct metadataPartitionMap *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 						&(lvd->partitionMaps[offset]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 				udf_debug("Parsing Logical vol part %d type %u  id=%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 					  i, type, UDF_ID_METADATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 				map->s_partition_type = UDF_METADATA_MAP25;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 				map->s_partition_func = udf_get_pblock_meta25;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 				mdata->s_meta_file_loc   =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 					le32_to_cpu(mdm->metadataFileLoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 				mdata->s_mirror_file_loc =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 					le32_to_cpu(mdm->metadataMirrorFileLoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 				mdata->s_bitmap_file_loc =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 					le32_to_cpu(mdm->metadataBitmapFileLoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 				mdata->s_alloc_unit_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 					le32_to_cpu(mdm->allocUnitSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 				mdata->s_align_unit_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 					le16_to_cpu(mdm->alignUnitSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 				if (mdm->flags & 0x01)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 					mdata->s_flags |= MF_DUPLICATE_MD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 				udf_debug("Metadata Ident suffix=0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 					  le16_to_cpu(*(__le16 *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 						      mdm->partIdent.identSuffix));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 				udf_debug("Metadata part num=%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 					  le16_to_cpu(mdm->partitionNum));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 				udf_debug("Metadata part alloc unit size=%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 					  le32_to_cpu(mdm->allocUnitSize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 				udf_debug("Metadata file loc=%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 					  le32_to_cpu(mdm->metadataFileLoc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 				udf_debug("Mirror file loc=%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 					  le32_to_cpu(mdm->metadataMirrorFileLoc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 				udf_debug("Bitmap file loc=%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 					  le32_to_cpu(mdm->metadataBitmapFileLoc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 				udf_debug("Flags: %d %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 					  mdata->s_flags, mdm->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 				udf_debug("Unknown ident: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 					  upm2->partIdent.ident);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 			map->s_volumeseqnum = le16_to_cpu(upm2->volSeqNum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 			map->s_partition_num = le16_to_cpu(upm2->partitionNum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 		udf_debug("Partition (%d:%u) type %u on volume %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 			  i, map->s_partition_num, type, map->s_volumeseqnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 	if (fileset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 		struct long_ad *la = (struct long_ad *)&(lvd->logicalVolContentsUse[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 		*fileset = lelb_to_cpu(la->extLocation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 		udf_debug("FileSet found in LogicalVolDesc at block=%u, partition=%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 			  fileset->logicalBlockNum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 			  fileset->partitionReferenceNum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 	if (lvd->integritySeqExt.extLength)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 		udf_load_logicalvolint(sb, leea_to_cpu(lvd->integritySeqExt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 	if (!sbi->s_lvid_bh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 		/* We can't generate unique IDs without a valid LVID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 		if (sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 			UDF_SET_FLAG(sb, UDF_FLAG_RW_INCOMPAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 			udf_warn(sb, "Damaged or missing LVID, forcing "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 				     "readonly mount\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 			ret = -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) out_bh:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 	brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536)  * Find the prevailing Logical Volume Integrity Descriptor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) static void udf_load_logicalvolint(struct super_block *sb, struct kernel_extent_ad loc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 	struct buffer_head *bh, *final_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 	uint16_t ident;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 	struct udf_sb_info *sbi = UDF_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 	struct logicalVolIntegrityDesc *lvid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 	int indirections = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 	u32 parts, impuselen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 	while (++indirections <= UDF_MAX_LVID_NESTING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 		final_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 		while (loc.extLength > 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 			(bh = udf_read_tagged(sb, loc.extLocation,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 					loc.extLocation, &ident))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 			if (ident != TAG_IDENT_LVID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 				brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 			brelse(final_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 			final_bh = bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 			loc.extLength -= sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 			loc.extLocation++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 		if (!final_bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 		brelse(sbi->s_lvid_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 		sbi->s_lvid_bh = final_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 		lvid = (struct logicalVolIntegrityDesc *)final_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 		if (lvid->nextIntegrityExt.extLength == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 			goto check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 		loc = leea_to_cpu(lvid->nextIntegrityExt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 	udf_warn(sb, "Too many LVID indirections (max %u), ignoring.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 		UDF_MAX_LVID_NESTING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 	brelse(sbi->s_lvid_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 	sbi->s_lvid_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) check:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 	parts = le32_to_cpu(lvid->numOfPartitions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 	impuselen = le32_to_cpu(lvid->lengthOfImpUse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 	if (parts >= sb->s_blocksize || impuselen >= sb->s_blocksize ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 	    sizeof(struct logicalVolIntegrityDesc) + impuselen +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 	    2 * parts * sizeof(u32) > sb->s_blocksize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 		udf_warn(sb, "Corrupted LVID (parts=%u, impuselen=%u), "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 			 "ignoring.\n", parts, impuselen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596)  * Step for reallocation of table of partition descriptor sequence numbers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597)  * Must be power of 2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) #define PART_DESC_ALLOC_STEP 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) struct part_desc_seq_scan_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 	struct udf_vds_record rec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 	u32 partnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) struct desc_seq_scan_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 	struct udf_vds_record vds[VDS_POS_LENGTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 	unsigned int size_part_descs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 	unsigned int num_part_descs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 	struct part_desc_seq_scan_data *part_descs_loc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) static struct udf_vds_record *handle_partition_descriptor(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 				struct buffer_head *bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 				struct desc_seq_scan_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 	struct partitionDesc *desc = (struct partitionDesc *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 	int partnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 	partnum = le16_to_cpu(desc->partitionNumber);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 	for (i = 0; i < data->num_part_descs; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 		if (partnum == data->part_descs_loc[i].partnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 			return &(data->part_descs_loc[i].rec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 	if (data->num_part_descs >= data->size_part_descs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 		struct part_desc_seq_scan_data *new_loc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 		unsigned int new_size = ALIGN(partnum, PART_DESC_ALLOC_STEP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 		new_loc = kcalloc(new_size, sizeof(*new_loc), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 		if (!new_loc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 			return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 		memcpy(new_loc, data->part_descs_loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 		       data->size_part_descs * sizeof(*new_loc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 		kfree(data->part_descs_loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 		data->part_descs_loc = new_loc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 		data->size_part_descs = new_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 	return &(data->part_descs_loc[data->num_part_descs++].rec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) static struct udf_vds_record *get_volume_descriptor_record(uint16_t ident,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 		struct buffer_head *bh, struct desc_seq_scan_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 	switch (ident) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 	case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 		return &(data->vds[VDS_POS_PRIMARY_VOL_DESC]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 	case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 		return &(data->vds[VDS_POS_IMP_USE_VOL_DESC]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 	case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 		return &(data->vds[VDS_POS_LOGICAL_VOL_DESC]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 	case TAG_IDENT_USD: /* ISO 13346 3/10.8 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 		return &(data->vds[VDS_POS_UNALLOC_SPACE_DESC]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 	case TAG_IDENT_PD: /* ISO 13346 3/10.5 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 		return handle_partition_descriptor(bh, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661)  * Process a main/reserve volume descriptor sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662)  *   @block		First block of first extent of the sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663)  *   @lastblock		Lastblock of first extent of the sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664)  *   @fileset		There we store extent containing root fileset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666)  * Returns <0 on error, 0 on success. -EAGAIN is special - try next descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667)  * sequence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) static noinline int udf_process_sequence(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 		struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 		sector_t block, sector_t lastblock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 		struct kernel_lb_addr *fileset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 	struct buffer_head *bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 	struct udf_vds_record *curr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 	struct generic_desc *gd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 	struct volDescPtr *vdp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 	bool done = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 	uint32_t vdsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 	uint16_t ident;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 	unsigned int indirections = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 	struct desc_seq_scan_data data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 	memset(data.vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 	data.size_part_descs = PART_DESC_ALLOC_STEP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 	data.num_part_descs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 	data.part_descs_loc = kcalloc(data.size_part_descs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 				      sizeof(*data.part_descs_loc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 				      GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 	if (!data.part_descs_loc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 	 * Read the main descriptor sequence and find which descriptors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 	 * are in it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 	for (; (!done && block <= lastblock); block++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 		bh = udf_read_tagged(sb, block, block, &ident);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 		if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 		/* Process each descriptor (ISO 13346 3/8.3-8.4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 		gd = (struct generic_desc *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 		vdsn = le32_to_cpu(gd->volDescSeqNum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 		switch (ident) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 		case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) 			if (++indirections > UDF_MAX_TD_NESTING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 				udf_err(sb, "too many Volume Descriptor "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 					"Pointers (max %u supported)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 					UDF_MAX_TD_NESTING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 				brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 				ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 			vdp = (struct volDescPtr *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 			block = le32_to_cpu(vdp->nextVolDescSeqExt.extLocation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 			lastblock = le32_to_cpu(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 				vdp->nextVolDescSeqExt.extLength) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 				sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 			lastblock += block - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 			/* For loop is going to increment 'block' again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 			block--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 		case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 		case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 		case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 		case TAG_IDENT_USD: /* ISO 13346 3/10.8 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 		case TAG_IDENT_PD: /* ISO 13346 3/10.5 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 			curr = get_volume_descriptor_record(ident, bh, &data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 			if (IS_ERR(curr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 				brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 				ret = PTR_ERR(curr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 			/* Descriptor we don't care about? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 			if (!curr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 			if (vdsn >= curr->volDescSeqNum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 				curr->volDescSeqNum = vdsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 				curr->block = block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 		case TAG_IDENT_TD: /* ISO 13346 3/10.9 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 			done = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 		brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 	 * Now read interesting descriptors again and process them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 	 * in a suitable order
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 	if (!data.vds[VDS_POS_PRIMARY_VOL_DESC].block) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 		udf_err(sb, "Primary Volume Descriptor not found!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 		ret = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 	ret = udf_load_pvoldesc(sb, data.vds[VDS_POS_PRIMARY_VOL_DESC].block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 	if (data.vds[VDS_POS_LOGICAL_VOL_DESC].block) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 		ret = udf_load_logicalvol(sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 				data.vds[VDS_POS_LOGICAL_VOL_DESC].block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 				fileset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 	/* Now handle prevailing Partition Descriptors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 	for (i = 0; i < data.num_part_descs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 		ret = udf_load_partdesc(sb, data.part_descs_loc[i].rec.block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 	kfree(data.part_descs_loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786)  * Load Volume Descriptor Sequence described by anchor in bh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788)  * Returns <0 on error, 0 on success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) static int udf_load_sequence(struct super_block *sb, struct buffer_head *bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 			     struct kernel_lb_addr *fileset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 	struct anchorVolDescPtr *anchor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 	sector_t main_s, main_e, reserve_s, reserve_e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 	anchor = (struct anchorVolDescPtr *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 	/* Locate the main sequence */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 	main_s = le32_to_cpu(anchor->mainVolDescSeqExt.extLocation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 	main_e = le32_to_cpu(anchor->mainVolDescSeqExt.extLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 	main_e = main_e >> sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 	main_e += main_s - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 	/* Locate the reserve sequence */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 	reserve_s = le32_to_cpu(anchor->reserveVolDescSeqExt.extLocation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 	reserve_e = le32_to_cpu(anchor->reserveVolDescSeqExt.extLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 	reserve_e = reserve_e >> sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 	reserve_e += reserve_s - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 	/* Process the main & reserve sequences */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 	/* responsible for finding the PartitionDesc(s) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 	ret = udf_process_sequence(sb, main_s, main_e, fileset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 	if (ret != -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 	udf_sb_free_partitions(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 	ret = udf_process_sequence(sb, reserve_s, reserve_e, fileset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 		udf_sb_free_partitions(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 		/* No sequence was OK, return -EIO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 		if (ret == -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828)  * Check whether there is an anchor block in the given block and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829)  * load Volume Descriptor Sequence if so.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831)  * Returns <0 on error, 0 on success, -EAGAIN is special - try next anchor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832)  * block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) static int udf_check_anchor_block(struct super_block *sb, sector_t block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 				  struct kernel_lb_addr *fileset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 	uint16_t ident;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 	if (UDF_QUERY_FLAG(sb, UDF_FLAG_VARCONV) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 	    udf_fixed_to_variable(block) >=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 	    i_size_read(sb->s_bdev->bd_inode) >> sb->s_blocksize_bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 	bh = udf_read_tagged(sb, block, block, &ident);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 	if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 	if (ident != TAG_IDENT_AVDP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 		brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 	ret = udf_load_sequence(sb, bh, fileset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 	brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859)  * Search for an anchor volume descriptor pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861)  * Returns < 0 on error, 0 on success. -EAGAIN is special - try next set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862)  * of anchors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) static int udf_scan_anchors(struct super_block *sb, sector_t *lastblock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 			    struct kernel_lb_addr *fileset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 	sector_t last[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 	struct udf_sb_info *sbi = UDF_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 	int last_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 	/* First try user provided anchor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 	if (sbi->s_anchor) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 		ret = udf_check_anchor_block(sb, sbi->s_anchor, fileset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 		if (ret != -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 	 * according to spec, anchor is in either:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) 	 *     block 256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 	 *     lastblock-256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) 	 *     lastblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 	 *  however, if the disc isn't closed, it could be 512.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 	ret = udf_check_anchor_block(sb, sbi->s_session + 256, fileset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 	if (ret != -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 	 * The trouble is which block is the last one. Drives often misreport
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) 	 * this so we try various possibilities.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) 	last[last_count++] = *lastblock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) 	if (*lastblock >= 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) 		last[last_count++] = *lastblock - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) 	last[last_count++] = *lastblock + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) 	if (*lastblock >= 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) 		last[last_count++] = *lastblock - 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) 	if (*lastblock >= 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) 		last[last_count++] = *lastblock - 150;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 	if (*lastblock >= 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) 		last[last_count++] = *lastblock - 152;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) 	for (i = 0; i < last_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 		if (last[i] >= i_size_read(sb->s_bdev->bd_inode) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 				sb->s_blocksize_bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) 		ret = udf_check_anchor_block(sb, last[i], fileset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 		if (ret != -EAGAIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) 			if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) 				*lastblock = last[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) 		if (last[i] < 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 		ret = udf_check_anchor_block(sb, last[i] - 256, fileset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) 		if (ret != -EAGAIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) 			if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) 				*lastblock = last[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) 	/* Finally try block 512 in case media is open */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 	return udf_check_anchor_block(sb, sbi->s_session + 512, fileset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929)  * Find an anchor volume descriptor and load Volume Descriptor Sequence from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930)  * area specified by it. The function expects sbi->s_lastblock to be the last
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931)  * block on the media.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933)  * Return <0 on error, 0 if anchor found. -EAGAIN is special meaning anchor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934)  * was not found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) static int udf_find_anchor(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) 			   struct kernel_lb_addr *fileset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) 	struct udf_sb_info *sbi = UDF_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 	sector_t lastblock = sbi->s_last_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 	ret = udf_scan_anchors(sb, &lastblock, fileset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) 	if (ret != -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) 	/* No anchor found? Try VARCONV conversion of block numbers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 	UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) 	lastblock = udf_variable_to_fixed(sbi->s_last_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) 	/* Firstly, we try to not convert number of the last block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) 	ret = udf_scan_anchors(sb, &lastblock, fileset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) 	if (ret != -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) 	lastblock = sbi->s_last_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 	/* Secondly, we try with converted number of the last block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) 	ret = udf_scan_anchors(sb, &lastblock, fileset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 		/* VARCONV didn't help. Clear it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) 		UDF_CLEAR_FLAG(sb, UDF_FLAG_VARCONV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) 	if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) 		sbi->s_last_block = lastblock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969)  * Check Volume Structure Descriptor, find Anchor block and load Volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970)  * Descriptor Sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972)  * Returns < 0 on error, 0 on success. -EAGAIN is special meaning anchor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973)  * block was not found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) static int udf_load_vrs(struct super_block *sb, struct udf_options *uopt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) 			int silent, struct kernel_lb_addr *fileset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) 	struct udf_sb_info *sbi = UDF_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) 	int nsr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) 	if (!sb_set_blocksize(sb, uopt->blocksize)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) 		if (!silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 			udf_warn(sb, "Bad block size\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) 	sbi->s_last_block = uopt->lastblock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) 	if (!uopt->novrs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) 		/* Check that it is NSR02 compliant */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) 		nsr = udf_check_vsd(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) 		if (!nsr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) 			if (!silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) 				udf_warn(sb, "No VRS found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) 		if (nsr == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) 			udf_debug("Failed to read sector at offset %d. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) 				  "Assuming open disc. Skipping validity "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) 				  "check\n", VSD_FIRST_SECTOR_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) 		if (!sbi->s_last_block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) 			sbi->s_last_block = udf_get_last_block(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) 		udf_debug("Validity check skipped because of novrs option\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) 	/* Look for anchor block and load Volume Descriptor Sequence */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) 	sbi->s_anchor = uopt->anchor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) 	ret = udf_find_anchor(sb, fileset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) 		if (!silent && ret == -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) 			udf_warn(sb, "No anchor found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) static void udf_finalize_lvid(struct logicalVolIntegrityDesc *lvid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) 	struct timespec64 ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) 	ktime_get_real_ts64(&ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) 	udf_time_to_disk_stamp(&lvid->recordingDateAndTime, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) 	lvid->descTag.descCRC = cpu_to_le16(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) 		crc_itu_t(0, (char *)lvid + sizeof(struct tag),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) 			le16_to_cpu(lvid->descTag.descCRCLength)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) 	lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) static void udf_open_lvid(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) 	struct udf_sb_info *sbi = UDF_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) 	struct buffer_head *bh = sbi->s_lvid_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) 	struct logicalVolIntegrityDesc *lvid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) 	struct logicalVolIntegrityDescImpUse *lvidiu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) 	if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) 	lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) 	lvidiu = udf_sb_lvidiu(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) 	if (!lvidiu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) 	mutex_lock(&sbi->s_alloc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) 	lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) 	lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) 	if (le32_to_cpu(lvid->integrityType) == LVID_INTEGRITY_TYPE_CLOSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) 		lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_OPEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) 		UDF_SET_FLAG(sb, UDF_FLAG_INCONSISTENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) 	udf_finalize_lvid(lvid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) 	mark_buffer_dirty(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) 	sbi->s_lvid_dirty = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) 	mutex_unlock(&sbi->s_alloc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) 	/* Make opening of filesystem visible on the media immediately */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) 	sync_dirty_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) static void udf_close_lvid(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) 	struct udf_sb_info *sbi = UDF_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) 	struct buffer_head *bh = sbi->s_lvid_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) 	struct logicalVolIntegrityDesc *lvid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) 	struct logicalVolIntegrityDescImpUse *lvidiu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) 	if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) 	lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) 	lvidiu = udf_sb_lvidiu(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) 	if (!lvidiu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) 	mutex_lock(&sbi->s_alloc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) 	lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) 	lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) 	if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) 		lvidiu->maxUDFWriteRev = cpu_to_le16(UDF_MAX_WRITE_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) 	if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFReadRev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) 		lvidiu->minUDFReadRev = cpu_to_le16(sbi->s_udfrev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) 	if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFWriteRev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) 		lvidiu->minUDFWriteRev = cpu_to_le16(sbi->s_udfrev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) 	if (!UDF_QUERY_FLAG(sb, UDF_FLAG_INCONSISTENT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) 		lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) 	 * We set buffer uptodate unconditionally here to avoid spurious
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) 	 * warnings from mark_buffer_dirty() when previous EIO has marked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) 	 * the buffer as !uptodate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) 	set_buffer_uptodate(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) 	udf_finalize_lvid(lvid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) 	mark_buffer_dirty(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) 	sbi->s_lvid_dirty = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) 	mutex_unlock(&sbi->s_alloc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) 	/* Make closing of filesystem visible on the media immediately */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) 	sync_dirty_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) u64 lvid_get_unique_id(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) 	struct udf_sb_info *sbi = UDF_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) 	struct logicalVolIntegrityDesc *lvid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) 	struct logicalVolHeaderDesc *lvhd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) 	u64 uniqueID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) 	u64 ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) 	bh = sbi->s_lvid_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) 	if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) 	lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) 	lvhd = (struct logicalVolHeaderDesc *)lvid->logicalVolContentsUse;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) 	mutex_lock(&sbi->s_alloc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) 	ret = uniqueID = le64_to_cpu(lvhd->uniqueID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) 	if (!(++uniqueID & 0xFFFFFFFF))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) 		uniqueID += 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) 	lvhd->uniqueID = cpu_to_le64(uniqueID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) 	udf_updated_lvid(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) 	mutex_unlock(&sbi->s_alloc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) static int udf_fill_super(struct super_block *sb, void *options, int silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) 	int ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) 	struct inode *inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) 	struct udf_options uopt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) 	struct kernel_lb_addr rootdir, fileset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) 	struct udf_sb_info *sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) 	bool lvid_open = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) 	uopt.flags = (1 << UDF_FLAG_USE_AD_IN_ICB) | (1 << UDF_FLAG_STRICT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) 	/* By default we'll use overflow[ug]id when UDF inode [ug]id == -1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) 	uopt.uid = make_kuid(current_user_ns(), overflowuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) 	uopt.gid = make_kgid(current_user_ns(), overflowgid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) 	uopt.umask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) 	uopt.fmode = UDF_INVALID_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) 	uopt.dmode = UDF_INVALID_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) 	uopt.nls_map = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) 	sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) 	if (!sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) 	sb->s_fs_info = sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) 	mutex_init(&sbi->s_alloc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) 	if (!udf_parse_options((char *)options, &uopt, false))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) 		goto parse_options_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) 	fileset.logicalBlockNum = 0xFFFFFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) 	fileset.partitionReferenceNum = 0xFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) 	sbi->s_flags = uopt.flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) 	sbi->s_uid = uopt.uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) 	sbi->s_gid = uopt.gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) 	sbi->s_umask = uopt.umask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) 	sbi->s_fmode = uopt.fmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) 	sbi->s_dmode = uopt.dmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) 	sbi->s_nls_map = uopt.nls_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) 	rwlock_init(&sbi->s_cred_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) 	if (uopt.session == 0xFFFFFFFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) 		sbi->s_session = udf_get_last_session(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) 		sbi->s_session = uopt.session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) 	udf_debug("Multi-session=%d\n", sbi->s_session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) 	/* Fill in the rest of the superblock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) 	sb->s_op = &udf_sb_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) 	sb->s_export_op = &udf_export_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) 	sb->s_magic = UDF_SUPER_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) 	sb->s_time_gran = 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) 	if (uopt.flags & (1 << UDF_FLAG_BLOCKSIZE_SET)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) 		ret = udf_load_vrs(sb, &uopt, silent, &fileset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) 		uopt.blocksize = bdev_logical_block_size(sb->s_bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) 		while (uopt.blocksize <= 4096) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) 			ret = udf_load_vrs(sb, &uopt, silent, &fileset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) 			if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) 				if (!silent && ret != -EACCES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) 					pr_notice("Scanning with blocksize %u failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) 						  uopt.blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) 				brelse(sbi->s_lvid_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) 				sbi->s_lvid_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) 				 * EACCES is special - we want to propagate to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) 				 * upper layers that we cannot handle RW mount.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) 				if (ret == -EACCES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) 			uopt.blocksize <<= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) 		if (ret == -EAGAIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) 			udf_warn(sb, "No partition found (1)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) 			ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) 		goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) 	udf_debug("Lastblock=%u\n", sbi->s_last_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) 	if (sbi->s_lvid_bh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) 		struct logicalVolIntegrityDescImpUse *lvidiu =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) 							udf_sb_lvidiu(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) 		uint16_t minUDFReadRev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) 		uint16_t minUDFWriteRev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) 		if (!lvidiu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) 			ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) 			goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) 		minUDFReadRev = le16_to_cpu(lvidiu->minUDFReadRev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) 		minUDFWriteRev = le16_to_cpu(lvidiu->minUDFWriteRev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) 		if (minUDFReadRev > UDF_MAX_READ_VERSION) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) 			udf_err(sb, "minUDFReadRev=%x (max is %x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) 				minUDFReadRev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) 				UDF_MAX_READ_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) 			ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) 			goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) 		} else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) 			if (!sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) 				ret = -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) 				goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) 			UDF_SET_FLAG(sb, UDF_FLAG_RW_INCOMPAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) 		sbi->s_udfrev = minUDFWriteRev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) 		if (minUDFReadRev >= UDF_VERS_USE_EXTENDED_FE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) 			UDF_SET_FLAG(sb, UDF_FLAG_USE_EXTENDED_FE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) 		if (minUDFReadRev >= UDF_VERS_USE_STREAMS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) 			UDF_SET_FLAG(sb, UDF_FLAG_USE_STREAMS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) 	if (!sbi->s_partitions) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) 		udf_warn(sb, "No partition found (2)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) 		goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) 	if (sbi->s_partmaps[sbi->s_partition].s_partition_flags &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) 			UDF_PART_FLAG_READ_ONLY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) 		if (!sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) 			ret = -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) 			goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) 		UDF_SET_FLAG(sb, UDF_FLAG_RW_INCOMPAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) 	ret = udf_find_fileset(sb, &fileset, &rootdir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) 		udf_warn(sb, "No fileset found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) 		goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) 	if (!silent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) 		struct timestamp ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) 		udf_time_to_disk_stamp(&ts, sbi->s_record_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) 		udf_info("Mounting volume '%s', timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) 			 sbi->s_volume_ident,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) 			 le16_to_cpu(ts.year), ts.month, ts.day,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) 			 ts.hour, ts.minute, le16_to_cpu(ts.typeAndTimezone));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) 	if (!sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) 		udf_open_lvid(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) 		lvid_open = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) 	/* Assign the root inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) 	/* assign inodes by physical block number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) 	/* perhaps it's not extensible enough, but for now ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) 	inode = udf_iget(sb, &rootdir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) 	if (IS_ERR(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) 		udf_err(sb, "Error in udf_iget, block=%u, partition=%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) 		       rootdir.logicalBlockNum, rootdir.partitionReferenceNum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) 		ret = PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) 		goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) 	/* Allocate a dentry for the root inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) 	sb->s_root = d_make_root(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) 	if (!sb->s_root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) 		udf_err(sb, "Couldn't allocate root dentry\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) 		goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) 	sb->s_maxbytes = MAX_LFS_FILESIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) 	sb->s_max_links = UDF_MAX_LINKS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) error_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) 	iput(sbi->s_vat_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) parse_options_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) 	unload_nls(uopt.nls_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) 	if (lvid_open)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) 		udf_close_lvid(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) 	brelse(sbi->s_lvid_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) 	udf_sb_free_partitions(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) 	kfree(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) 	sb->s_fs_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) void _udf_err(struct super_block *sb, const char *function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) 	      const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) 	struct va_format vaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) 	va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) 	va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) 	vaf.fmt = fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) 	vaf.va = &args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) 	pr_err("error (device %s): %s: %pV", sb->s_id, function, &vaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) 	va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) void _udf_warn(struct super_block *sb, const char *function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) 	       const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) 	struct va_format vaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) 	va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) 	va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) 	vaf.fmt = fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) 	vaf.va = &args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) 	pr_warn("warning (device %s): %s: %pV", sb->s_id, function, &vaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) 	va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) static void udf_put_super(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) 	struct udf_sb_info *sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) 	sbi = UDF_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) 	iput(sbi->s_vat_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) 	unload_nls(sbi->s_nls_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) 	if (!sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) 		udf_close_lvid(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) 	brelse(sbi->s_lvid_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) 	udf_sb_free_partitions(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) 	mutex_destroy(&sbi->s_alloc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) 	kfree(sb->s_fs_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) 	sb->s_fs_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) static int udf_sync_fs(struct super_block *sb, int wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) 	struct udf_sb_info *sbi = UDF_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) 	mutex_lock(&sbi->s_alloc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) 	if (sbi->s_lvid_dirty) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) 		struct buffer_head *bh = sbi->s_lvid_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) 		struct logicalVolIntegrityDesc *lvid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) 		lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) 		udf_finalize_lvid(lvid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) 		 * Blockdevice will be synced later so we don't have to submit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) 		 * the buffer for IO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) 		mark_buffer_dirty(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) 		sbi->s_lvid_dirty = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) 	mutex_unlock(&sbi->s_alloc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) static int udf_statfs(struct dentry *dentry, struct kstatfs *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) 	struct super_block *sb = dentry->d_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) 	struct udf_sb_info *sbi = UDF_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) 	struct logicalVolIntegrityDescImpUse *lvidiu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) 	u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) 	lvidiu = udf_sb_lvidiu(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) 	buf->f_type = UDF_SUPER_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) 	buf->f_bsize = sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) 	buf->f_blocks = sbi->s_partmaps[sbi->s_partition].s_partition_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) 	buf->f_bfree = udf_count_free(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) 	buf->f_bavail = buf->f_bfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) 	 * Let's pretend each free block is also a free 'inode' since UDF does
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) 	 * not have separate preallocated table of inodes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) 	buf->f_files = (lvidiu != NULL ? (le32_to_cpu(lvidiu->numFiles) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) 					  le32_to_cpu(lvidiu->numDirs)) : 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) 			+ buf->f_bfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) 	buf->f_ffree = buf->f_bfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) 	buf->f_namelen = UDF_NAME_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) 	buf->f_fsid = u64_to_fsid(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) static unsigned int udf_count_free_bitmap(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) 					  struct udf_bitmap *bitmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) 	struct buffer_head *bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) 	unsigned int accum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) 	int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) 	udf_pblk_t block = 0, newblock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) 	struct kernel_lb_addr loc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) 	uint32_t bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) 	uint8_t *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) 	uint16_t ident;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) 	struct spaceBitmapDesc *bm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) 	loc.logicalBlockNum = bitmap->s_extPosition;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) 	loc.partitionReferenceNum = UDF_SB(sb)->s_partition;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) 	bh = udf_read_ptagged(sb, &loc, 0, &ident);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) 	if (!bh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) 		udf_err(sb, "udf_count_free failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) 	} else if (ident != TAG_IDENT_SBD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) 		brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) 		udf_err(sb, "udf_count_free failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) 	bm = (struct spaceBitmapDesc *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) 	bytes = le32_to_cpu(bm->numOfBytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) 	index = sizeof(struct spaceBitmapDesc); /* offset in first block only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) 	ptr = (uint8_t *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) 	while (bytes > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) 		u32 cur_bytes = min_t(u32, bytes, sb->s_blocksize - index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) 		accum += bitmap_weight((const unsigned long *)(ptr + index),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) 					cur_bytes * 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) 		bytes -= cur_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) 		if (bytes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) 			brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) 			newblock = udf_get_lb_pblock(sb, &loc, ++block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) 			bh = udf_tread(sb, newblock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) 			if (!bh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) 				udf_debug("read failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) 			index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) 			ptr = (uint8_t *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) 	brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) 	return accum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) static unsigned int udf_count_free_table(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) 					 struct inode *table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) 	unsigned int accum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) 	uint32_t elen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) 	struct kernel_lb_addr eloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) 	int8_t etype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) 	struct extent_position epos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) 	mutex_lock(&UDF_SB(sb)->s_alloc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) 	epos.block = UDF_I(table)->i_location;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) 	epos.offset = sizeof(struct unallocSpaceEntry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) 	epos.bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) 	while ((etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) 		accum += (elen >> table->i_sb->s_blocksize_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) 	brelse(epos.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) 	mutex_unlock(&UDF_SB(sb)->s_alloc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) 	return accum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) static unsigned int udf_count_free(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) 	unsigned int accum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) 	struct udf_sb_info *sbi = UDF_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) 	struct udf_part_map *map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) 	unsigned int part = sbi->s_partition;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) 	int ptype = sbi->s_partmaps[part].s_partition_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) 	if (ptype == UDF_METADATA_MAP25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) 		part = sbi->s_partmaps[part].s_type_specific.s_metadata.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) 							s_phys_partition_ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) 	} else if (ptype == UDF_VIRTUAL_MAP15 || ptype == UDF_VIRTUAL_MAP20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) 		 * Filesystems with VAT are append-only and we cannot write to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510)  		 * them. Let's just report 0 here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) 	if (sbi->s_lvid_bh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) 		struct logicalVolIntegrityDesc *lvid =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) 			(struct logicalVolIntegrityDesc *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) 			sbi->s_lvid_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) 		if (le32_to_cpu(lvid->numOfPartitions) > part) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) 			accum = le32_to_cpu(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) 					lvid->freeSpaceTable[part]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) 			if (accum == 0xFFFFFFFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) 				accum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) 	if (accum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) 		return accum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) 	map = &sbi->s_partmaps[part];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) 	if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) 		accum += udf_count_free_bitmap(sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) 					       map->s_uspace.s_bitmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) 	if (accum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) 		return accum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) 	if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) 		accum += udf_count_free_table(sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) 					      map->s_uspace.s_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) 	return accum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) MODULE_AUTHOR("Ben Fennema");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) MODULE_DESCRIPTION("Universal Disk Format Filesystem");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) module_init(init_udf_fs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) module_exit(exit_udf_fs)