Orange Pi5 kernel

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

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * QNX4 file system, Linux implementation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Version : 0.2.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Using parts of the xiafs filesystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * History :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * 01-06-1998 by Richard Frowijn : first release.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * 21-06-1998 by Frank Denis : dcache support, fixed error codes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * 04-07-1998 by Frank Denis : first step for rmdir/unlink.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "qnx4.h"
^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)  * check if the filename is correct. For some obscure reason, qnx writes a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * new file twice in the directory entry, first with all possible options at 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * and for a second time the way it is, they want us not to access the qnx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * filesystem when whe are using linux.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static int qnx4_match(int len, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 		      struct buffer_head *bh, unsigned long *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	struct qnx4_inode_entry *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	int namelen, thislen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	if (bh == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		printk(KERN_WARNING "qnx4: matching unassigned buffer !\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	de = (struct qnx4_inode_entry *) (bh->b_data + *offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	*offset += QNX4_DIR_ENTRY_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	if ((de->di_status & QNX4_FILE_LINK) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		namelen = QNX4_NAME_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		namelen = QNX4_SHORT_NAME_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	thislen = strlen( de->di_fname );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	if ( thislen > namelen )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		thislen = namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	if (len != thislen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	if (strncmp(name, de->di_fname, len) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		if ((de->di_status & (QNX4_FILE_USED|QNX4_FILE_LINK)) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) static struct buffer_head *qnx4_find_entry(int len, struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	   const char *name, struct qnx4_inode_entry **res_dir, int *ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	unsigned long block, offset, blkofs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	*res_dir = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	block = offset = blkofs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	while (blkofs * QNX4_BLOCK_SIZE + offset < dir->i_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		if (!bh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 			block = qnx4_block_map(dir, blkofs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 			if (block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 				bh = sb_bread(dir->i_sb, block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 			if (!bh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 				blkofs++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 				continue;
^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) 		*res_dir = (struct qnx4_inode_entry *) (bh->b_data + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		if (qnx4_match(len, name, bh, &offset)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			*ino = block * QNX4_INODES_PER_BLOCK +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			    (offset / QNX4_DIR_ENTRY_SIZE) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 			return bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		if (offset < bh->b_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		blkofs++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	*res_dir = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	return NULL;
^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) struct dentry * qnx4_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	int ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	struct qnx4_inode_entry *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	struct qnx4_link_info *lnk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	const char *name = dentry->d_name.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	int len = dentry->d_name.len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	struct inode *foundinode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	if (!(bh = qnx4_find_entry(len, dir, name, &de, &ino)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	/* The entry is linked, let's get the real info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if ((de->di_status & QNX4_FILE_LINK) == QNX4_FILE_LINK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		lnk = (struct qnx4_link_info *) de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		ino = (le32_to_cpu(lnk->dl_inode_blk) - 1) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)                     QNX4_INODES_PER_BLOCK +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		    lnk->dl_inode_ndx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	foundinode = qnx4_iget(dir->i_sb, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	if (IS_ERR(foundinode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		QNX4DEBUG((KERN_ERR "qnx4: lookup->iget -> error %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			   PTR_ERR(foundinode)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	return d_splice_alias(foundinode, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }