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)  *  linux/fs/minix/dir.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (C) 1991, 1992 Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  minix directory handling functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *  Updated to filesystem version 3 by Daniel Aragones
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "minix.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/highmem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/swap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) typedef struct minix_dir_entry minix_dirent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) typedef struct minix3_dir_entry minix3_dirent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) static int minix_readdir(struct file *, struct dir_context *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) const struct file_operations minix_dir_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	.llseek		= generic_file_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	.read		= generic_read_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	.iterate_shared	= minix_readdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	.fsync		= generic_file_fsync,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static inline void dir_put_page(struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	kunmap(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * Return the offset into page `page_nr' of the last valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * byte in that page, plus one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static unsigned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) minix_last_byte(struct inode *inode, unsigned long page_nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	unsigned last_byte = PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	if (page_nr == (inode->i_size >> PAGE_SHIFT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		last_byte = inode->i_size & (PAGE_SIZE - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	return last_byte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static int dir_commit_chunk(struct page *page, loff_t pos, unsigned len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	struct address_space *mapping = page->mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	struct inode *dir = mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	block_write_end(NULL, mapping, pos, len, len, page, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (pos+len > dir->i_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		i_size_write(dir, pos+len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		mark_inode_dirty(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	if (IS_DIRSYNC(dir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		err = write_one_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) static struct page * dir_get_page(struct inode *dir, unsigned long n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	struct address_space *mapping = dir->i_mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	struct page *page = read_mapping_page(mapping, n, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (!IS_ERR(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		kmap(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	return page;
^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) static inline void *minix_next_entry(void *de, struct minix_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	return (void*)((char*)de + sbi->s_dirsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static int minix_readdir(struct file *file, struct dir_context *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	struct inode *inode = file_inode(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	struct super_block *sb = inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	struct minix_sb_info *sbi = minix_sb(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	unsigned chunk_size = sbi->s_dirsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	unsigned long npages = dir_pages(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	unsigned long pos = ctx->pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	unsigned offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	unsigned long n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	ctx->pos = pos = ALIGN(pos, chunk_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (pos >= inode->i_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	offset = pos & ~PAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	n = pos >> PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	for ( ; n < npages; n++, offset = 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		char *p, *kaddr, *limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		struct page *page = dir_get_page(inode, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		if (IS_ERR(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		kaddr = (char *)page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		p = kaddr+offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		limit = kaddr + minix_last_byte(inode, n) - chunk_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		for ( ; p <= limit; p = minix_next_entry(p, sbi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			__u32 inumber;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			if (sbi->s_version == MINIX_V3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 				minix3_dirent *de3 = (minix3_dirent *)p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 				name = de3->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 				inumber = de3->inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 				minix_dirent *de = (minix_dirent *)p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 				name = de->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 				inumber = de->inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 			if (inumber) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 				unsigned l = strnlen(name, sbi->s_namelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 				if (!dir_emit(ctx, name, l,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 					      inumber, DT_UNKNOWN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 					dir_put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 					return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			ctx->pos += chunk_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		dir_put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static inline int namecompare(int len, int maxlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	const char * name, const char * buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	if (len < maxlen && buffer[len])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	return !memcmp(name, buffer, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  *	minix_find_entry()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  * finds an entry in the specified directory with the wanted name. It
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  * returns the cache buffer in which the entry was found, and the entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  * itself (as a parameter - res_dir). It does NOT read the inode of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)  * entry - you'll have to do that yourself if you want to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) minix_dirent *minix_find_entry(struct dentry *dentry, struct page **res_page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	const char * name = dentry->d_name.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	int namelen = dentry->d_name.len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	struct inode * dir = d_inode(dentry->d_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	struct super_block * sb = dir->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	struct minix_sb_info * sbi = minix_sb(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	unsigned long n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	unsigned long npages = dir_pages(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	struct page *page = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	char *namx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	__u32 inumber;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	*res_page = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	for (n = 0; n < npages; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		char *kaddr, *limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		page = dir_get_page(dir, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		if (IS_ERR(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		kaddr = (char*)page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		limit = kaddr + minix_last_byte(dir, n) - sbi->s_dirsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		for (p = kaddr; p <= limit; p = minix_next_entry(p, sbi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 			if (sbi->s_version == MINIX_V3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 				minix3_dirent *de3 = (minix3_dirent *)p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 				namx = de3->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 				inumber = de3->inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 				minix_dirent *de = (minix_dirent *)p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 				namx = de->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 				inumber = de->inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 			if (!inumber)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			if (namecompare(namelen, sbi->s_namelen, name, namx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 				goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		dir_put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	*res_page = page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	return (minix_dirent *)p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) int minix_add_link(struct dentry *dentry, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	struct inode *dir = d_inode(dentry->d_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	const char * name = dentry->d_name.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	int namelen = dentry->d_name.len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	struct super_block * sb = dir->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	struct minix_sb_info * sbi = minix_sb(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	struct page *page = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	unsigned long npages = dir_pages(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	unsigned long n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	char *kaddr, *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	minix_dirent *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	minix3_dirent *de3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	loff_t pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	char *namx = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	__u32 inumber;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	 * We take care of directory expansion in the same loop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	 * This code plays outside i_size, so it locks the page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	 * to protect that region.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	for (n = 0; n <= npages; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		char *limit, *dir_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		page = dir_get_page(dir, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		err = PTR_ERR(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		if (IS_ERR(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		lock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		kaddr = (char*)page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		dir_end = kaddr + minix_last_byte(dir, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		limit = kaddr + PAGE_SIZE - sbi->s_dirsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		for (p = kaddr; p <= limit; p = minix_next_entry(p, sbi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			de = (minix_dirent *)p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			de3 = (minix3_dirent *)p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			if (sbi->s_version == MINIX_V3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 				namx = de3->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 				inumber = de3->inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)   				namx = de->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 				inumber = de->inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 			if (p == dir_end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 				/* We hit i_size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 				if (sbi->s_version == MINIX_V3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 					de3->inode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 					de->inode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 				goto got_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 			if (!inumber)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 				goto got_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 			err = -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 			if (namecompare(namelen, sbi->s_namelen, name, namx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 				goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		dir_put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) got_it:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	pos = page_offset(page) + p - (char *)page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	err = minix_prepare_chunk(page, pos, sbi->s_dirsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	memcpy (namx, name, namelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	if (sbi->s_version == MINIX_V3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		memset (namx + namelen, 0, sbi->s_dirsize - namelen - 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		de3->inode = inode->i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		memset (namx + namelen, 0, sbi->s_dirsize - namelen - 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		de->inode = inode->i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	err = dir_commit_chunk(page, pos, sbi->s_dirsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	dir->i_mtime = dir->i_ctime = current_time(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	mark_inode_dirty(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) out_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	dir_put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	goto out_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) int minix_delete_entry(struct minix_dir_entry *de, struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	struct inode *inode = page->mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	char *kaddr = page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	loff_t pos = page_offset(page) + (char*)de - kaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	struct minix_sb_info *sbi = minix_sb(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	unsigned len = sbi->s_dirsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	lock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	err = minix_prepare_chunk(page, pos, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	if (err == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		if (sbi->s_version == MINIX_V3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 			((minix3_dirent *) de)->inode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 			de->inode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		err = dir_commit_chunk(page, pos, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	dir_put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	inode->i_ctime = inode->i_mtime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) int minix_make_empty(struct inode *inode, struct inode *dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	struct page *page = grab_cache_page(inode->i_mapping, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	struct minix_sb_info *sbi = minix_sb(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	char *kaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	if (!page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	err = minix_prepare_chunk(page, 0, 2 * sbi->s_dirsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	kaddr = kmap_atomic(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	memset(kaddr, 0, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	if (sbi->s_version == MINIX_V3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		minix3_dirent *de3 = (minix3_dirent *)kaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		de3->inode = inode->i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		strcpy(de3->name, ".");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		de3 = minix_next_entry(de3, sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		de3->inode = dir->i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		strcpy(de3->name, "..");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		minix_dirent *de = (minix_dirent *)kaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		de->inode = inode->i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		strcpy(de->name, ".");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		de = minix_next_entry(de, sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		de->inode = dir->i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		strcpy(de->name, "..");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	kunmap_atomic(kaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	err = dir_commit_chunk(page, 0, 2 * sbi->s_dirsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)  * routine to check that the specified directory is empty (for rmdir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) int minix_empty_dir(struct inode * inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	struct page *page = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	unsigned long i, npages = dir_pages(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	struct minix_sb_info *sbi = minix_sb(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	__u32 inumber;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	for (i = 0; i < npages; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		char *p, *kaddr, *limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		page = dir_get_page(inode, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		if (IS_ERR(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		kaddr = (char *)page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		limit = kaddr + minix_last_byte(inode, i) - sbi->s_dirsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		for (p = kaddr; p <= limit; p = minix_next_entry(p, sbi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 			if (sbi->s_version == MINIX_V3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 				minix3_dirent *de3 = (minix3_dirent *)p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 				name = de3->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 				inumber = de3->inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 				minix_dirent *de = (minix_dirent *)p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 				name = de->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 				inumber = de->inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 			if (inumber != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 				/* check for . and .. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 				if (name[0] != '.')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 					goto not_empty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 				if (!name[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 					if (inumber != inode->i_ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 						goto not_empty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 				} else if (name[1] != '.')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 					goto not_empty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 				else if (name[2])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 					goto not_empty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		dir_put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) not_empty:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	dir_put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) /* Releases the page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) void minix_set_link(struct minix_dir_entry *de, struct page *page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	struct inode *dir = page->mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	struct minix_sb_info *sbi = minix_sb(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	loff_t pos = page_offset(page) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 			(char *)de-(char*)page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	lock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	err = minix_prepare_chunk(page, pos, sbi->s_dirsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	if (err == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		if (sbi->s_version == MINIX_V3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 			((minix3_dirent *) de)->inode = inode->i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 			de->inode = inode->i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		err = dir_commit_chunk(page, pos, sbi->s_dirsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	dir_put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	dir->i_mtime = dir->i_ctime = current_time(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	mark_inode_dirty(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) struct minix_dir_entry * minix_dotdot (struct inode *dir, struct page **p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	struct page *page = dir_get_page(dir, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	struct minix_sb_info *sbi = minix_sb(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	struct minix_dir_entry *de = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	if (!IS_ERR(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		de = minix_next_entry(page_address(page), sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		*p = page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	return de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) ino_t minix_inode_by_name(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	struct minix_dir_entry *de = minix_find_entry(dentry, &page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	ino_t res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	if (de) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		struct address_space *mapping = page->mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		struct inode *inode = mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		struct minix_sb_info *sbi = minix_sb(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		if (sbi->s_version == MINIX_V3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 			res = ((minix3_dirent *) de)->inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 			res = de->inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		dir_put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) }