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)  * ialloc.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)  *	Inode allocation handling 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)  * COPYRIGHT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *	This file is distributed under the terms of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *	License (GPL). Copies of the GPL can be obtained from:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *		ftp://prep.ai.mit.edu/pub/gnu/GPL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *	Each contributing author retains all rights to their own work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *  (C) 1998-2001 Ben Fennema
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * HISTORY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *  02/24/99 blf  Created.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "udfdecl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include "udf_i.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include "udf_sb.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) void udf_free_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	struct super_block *sb = inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	struct udf_sb_info *sbi = UDF_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct logicalVolIntegrityDescImpUse *lvidiu = udf_sb_lvidiu(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	if (lvidiu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		mutex_lock(&sbi->s_alloc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		if (S_ISDIR(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 			le32_add_cpu(&lvidiu->numDirs, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 			le32_add_cpu(&lvidiu->numFiles, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		udf_updated_lvid(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		mutex_unlock(&sbi->s_alloc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	udf_free_blocks(sb, NULL, &UDF_I(inode)->i_location, 0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) struct inode *udf_new_inode(struct inode *dir, umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct super_block *sb = dir->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	struct udf_sb_info *sbi = UDF_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	udf_pblk_t block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	uint32_t start = UDF_I(dir)->i_location.logicalBlockNum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	struct udf_inode_info *iinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct udf_inode_info *dinfo = UDF_I(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct logicalVolIntegrityDescImpUse *lvidiu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	inode = new_inode(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	iinfo = UDF_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_EXTENDED_FE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		iinfo->i_efe = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		if (UDF_VERS_USE_EXTENDED_FE > sbi->s_udfrev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 			sbi->s_udfrev = UDF_VERS_USE_EXTENDED_FE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		iinfo->i_data = kzalloc(inode->i_sb->s_blocksize -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 					sizeof(struct extendedFileEntry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 					GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		iinfo->i_efe = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		iinfo->i_data = kzalloc(inode->i_sb->s_blocksize -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 					sizeof(struct fileEntry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 					GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	if (!iinfo->i_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		make_bad_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	err = -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	block = udf_new_block(dir->i_sb, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			      dinfo->i_location.partitionReferenceNum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			      start, &err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		make_bad_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	lvidiu = udf_sb_lvidiu(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	if (lvidiu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		iinfo->i_unique = lvid_get_unique_id(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		inode->i_generation = iinfo->i_unique;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		mutex_lock(&sbi->s_alloc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		if (S_ISDIR(mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			le32_add_cpu(&lvidiu->numDirs, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			le32_add_cpu(&lvidiu->numFiles, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		udf_updated_lvid(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		mutex_unlock(&sbi->s_alloc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	inode_init_owner(inode, dir, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_SET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		inode->i_uid = sbi->s_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_SET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		inode->i_gid = sbi->s_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	iinfo->i_location.logicalBlockNum = block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	iinfo->i_location.partitionReferenceNum =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 				dinfo->i_location.partitionReferenceNum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	inode->i_ino = udf_get_lb_pblock(sb, &iinfo->i_location, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	inode->i_blocks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	iinfo->i_lenEAttr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	iinfo->i_lenAlloc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	iinfo->i_use = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	iinfo->i_checkpoint = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	iinfo->i_extraPerms = FE_PERM_U_CHATTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	udf_update_extra_perms(inode, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_AD_IN_ICB))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	else if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		iinfo->i_alloc_type = ICBTAG_FLAG_AD_SHORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		iinfo->i_alloc_type = ICBTAG_FLAG_AD_LONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	iinfo->i_crtime = inode->i_mtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if (unlikely(insert_inode_locked(inode) < 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		make_bad_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		return ERR_PTR(-EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }