^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/ext2/dir.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 1992, 1993, 1994, 1995
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Remy Card (card@masi.ibp.fr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Laboratoire MASI - Institut Blaise Pascal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Universite Pierre et Marie Curie (Paris VI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * linux/fs/minix/dir.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Copyright (C) 1991, 1992 Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * ext2 directory handling functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * Big-endian to little-endian byte-swapping/bitmaps by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * David S. Miller (davem@caip.rutgers.edu), 1995
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * All code that works with directory layout had been switched to pagecache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * and moved here. AV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include "ext2.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/swap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/iversion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) typedef struct ext2_dir_entry_2 ext2_dirent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * Tests against MAX_REC_LEN etc were put in place for 64k block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * sizes; if that is not possible on this arch, we can skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * those tests and speed things up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static inline unsigned ext2_rec_len_from_disk(__le16 dlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) unsigned len = le16_to_cpu(dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #if (PAGE_SIZE >= 65536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) if (len == EXT2_MAX_REC_LEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) return 1 << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) return len;
^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 inline __le16 ext2_rec_len_to_disk(unsigned len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #if (PAGE_SIZE >= 65536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if (len == (1 << 16))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) return cpu_to_le16(EXT2_MAX_REC_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) BUG_ON(len > (1 << 16));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return cpu_to_le16(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * ext2 uses block-sized chunks. Arguably, sector-sized ones would be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * more robust, but we have what we have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static inline unsigned ext2_chunk_size(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) return inode->i_sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static inline void ext2_put_page(struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) kunmap(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^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) * Return the offset into page `page_nr' of the last valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * byte in that page, plus one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static unsigned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) ext2_last_byte(struct inode *inode, unsigned long page_nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) unsigned last_byte = inode->i_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) last_byte -= page_nr << PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (last_byte > PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) last_byte = PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) return last_byte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static int ext2_commit_chunk(struct page *page, loff_t pos, unsigned len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct address_space *mapping = page->mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct inode *dir = mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) inode_inc_iversion(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) block_write_end(NULL, mapping, pos, len, len, page, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (pos+len > dir->i_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) i_size_write(dir, pos+len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) mark_inode_dirty(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (IS_DIRSYNC(dir)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) err = write_one_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) err = sync_inode_metadata(dir, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static bool ext2_check_page(struct page *page, int quiet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct inode *dir = page->mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct super_block *sb = dir->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) unsigned chunk_size = ext2_chunk_size(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) char *kaddr = page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) u32 max_inumber = le32_to_cpu(EXT2_SB(sb)->s_es->s_inodes_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) unsigned offs, rec_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) unsigned limit = PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) ext2_dirent *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) char *error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if ((dir->i_size >> PAGE_SHIFT) == page->index) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) limit = dir->i_size & ~PAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) if (limit & (chunk_size - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) goto Ebadsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) if (!limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) for (offs = 0; offs <= limit - EXT2_DIR_REC_LEN(1); offs += rec_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) p = (ext2_dirent *)(kaddr + offs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) rec_len = ext2_rec_len_from_disk(p->rec_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (unlikely(rec_len < EXT2_DIR_REC_LEN(1)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) goto Eshort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (unlikely(rec_len & 3))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) goto Ealign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (unlikely(rec_len < EXT2_DIR_REC_LEN(p->name_len)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) goto Enamelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) if (unlikely(((offs + rec_len - 1) ^ offs) & ~(chunk_size-1)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) goto Espan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (unlikely(le32_to_cpu(p->inode) > max_inumber))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) goto Einumber;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (offs != limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) goto Eend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) SetPageChecked(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) /* Too bad, we had an error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) Ebadsize:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) if (!quiet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) ext2_error(sb, __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) "size of directory #%lu is not a multiple "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) "of chunk size", dir->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) Eshort:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) error = "rec_len is smaller than minimal";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) goto bad_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) Ealign:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) error = "unaligned directory entry";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) goto bad_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) Enamelen:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) error = "rec_len is too small for name_len";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) goto bad_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) Espan:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) error = "directory entry across blocks";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) goto bad_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) Einumber:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) error = "inode out of bounds";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) bad_entry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (!quiet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) ext2_error(sb, __func__, "bad entry in directory #%lu: : %s - "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) "offset=%lu, inode=%lu, rec_len=%d, name_len=%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) dir->i_ino, error, (page->index<<PAGE_SHIFT)+offs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) (unsigned long) le32_to_cpu(p->inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) rec_len, p->name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) Eend:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) if (!quiet) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) p = (ext2_dirent *)(kaddr + offs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) ext2_error(sb, "ext2_check_page",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) "entry in directory #%lu spans the page boundary"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) "offset=%lu, inode=%lu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) dir->i_ino, (page->index<<PAGE_SHIFT)+offs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) (unsigned long) le32_to_cpu(p->inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) SetPageError(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static struct page * ext2_get_page(struct inode *dir, unsigned long n,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) int quiet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) struct address_space *mapping = dir->i_mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) struct page *page = read_mapping_page(mapping, n, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) if (!IS_ERR(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) kmap(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (unlikely(!PageChecked(page))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) if (PageError(page) || !ext2_check_page(page, quiet))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) ext2_put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return ERR_PTR(-EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^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) * NOTE! unlike strncmp, ext2_match returns 1 for success, 0 for failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * len <= EXT2_NAME_LEN and de != NULL are guaranteed by caller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static inline int ext2_match (int len, const char * const name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) struct ext2_dir_entry_2 * de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (len != de->name_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if (!de->inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) return !memcmp(name, de->name, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * p is at least 6 bytes before the end of page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static inline ext2_dirent *ext2_next_entry(ext2_dirent *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) return (ext2_dirent *)((char *)p +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) ext2_rec_len_from_disk(p->rec_len));
^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 inline unsigned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) ext2_validate_entry(char *base, unsigned offset, unsigned mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) ext2_dirent *de = (ext2_dirent*)(base + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) ext2_dirent *p = (ext2_dirent*)(base + (offset&mask));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) while ((char*)p < (char*)de) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) if (p->rec_len == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) p = ext2_next_entry(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) return (char *)p - base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static inline void ext2_set_de_type(ext2_dirent *de, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (EXT2_HAS_INCOMPAT_FEATURE(inode->i_sb, EXT2_FEATURE_INCOMPAT_FILETYPE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) de->file_type = fs_umode_to_ftype(inode->i_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) de->file_type = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) ext2_readdir(struct file *file, struct dir_context *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) loff_t pos = ctx->pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) struct inode *inode = file_inode(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) struct super_block *sb = inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) unsigned int offset = pos & ~PAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) unsigned long n = pos >> PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) unsigned long npages = dir_pages(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) unsigned chunk_mask = ~(ext2_chunk_size(inode)-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) bool need_revalidate = !inode_eq_iversion(inode, file->f_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) bool has_filetype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (pos > inode->i_size - EXT2_DIR_REC_LEN(1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) has_filetype =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) EXT2_HAS_INCOMPAT_FEATURE(sb, EXT2_FEATURE_INCOMPAT_FILETYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) for ( ; n < npages; n++, offset = 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) char *kaddr, *limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) ext2_dirent *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) struct page *page = ext2_get_page(inode, n, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (IS_ERR(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) ext2_error(sb, __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) "bad page in #%lu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) ctx->pos += PAGE_SIZE - offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) return PTR_ERR(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) kaddr = page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (unlikely(need_revalidate)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) if (offset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) offset = ext2_validate_entry(kaddr, offset, chunk_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) ctx->pos = (n<<PAGE_SHIFT) + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) file->f_version = inode_query_iversion(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) need_revalidate = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) de = (ext2_dirent *)(kaddr+offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) limit = kaddr + ext2_last_byte(inode, n) - EXT2_DIR_REC_LEN(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) for ( ;(char*)de <= limit; de = ext2_next_entry(de)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) if (de->rec_len == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) ext2_error(sb, __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) "zero-length directory entry");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) ext2_put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) if (de->inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) unsigned char d_type = DT_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) if (has_filetype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) d_type = fs_ftype_to_dtype(de->file_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if (!dir_emit(ctx, de->name, de->name_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) le32_to_cpu(de->inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) d_type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) ext2_put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) ctx->pos += ext2_rec_len_from_disk(de->rec_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) ext2_put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) * ext2_find_entry()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) * finds an entry in the specified directory with the wanted name. It
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) * returns the page in which the entry was found (as a parameter - res_page),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) * and the entry itself. Page is returned mapped and unlocked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) * Entry is guaranteed to be valid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) struct ext2_dir_entry_2 *ext2_find_entry (struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) const struct qstr *child, struct page **res_page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) const char *name = child->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) int namelen = child->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) unsigned reclen = EXT2_DIR_REC_LEN(namelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) unsigned long start, n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) unsigned long npages = dir_pages(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) struct page *page = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) struct ext2_inode_info *ei = EXT2_I(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) ext2_dirent * de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) if (npages == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) /* OFFSET_CACHE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) *res_page = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) start = ei->i_dir_start_lookup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) if (start >= npages)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) n = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) char *kaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) page = ext2_get_page(dir, n, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) if (IS_ERR(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) return ERR_CAST(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) kaddr = page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) de = (ext2_dirent *) kaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) kaddr += ext2_last_byte(dir, n) - reclen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) while ((char *) de <= kaddr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) if (de->rec_len == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) ext2_error(dir->i_sb, __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) "zero-length directory entry");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) ext2_put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (ext2_match(namelen, name, de))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) de = ext2_next_entry(de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) ext2_put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) if (++n >= npages)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) /* next page is past the blocks we've got */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) if (unlikely(n > (dir->i_blocks >> (PAGE_SHIFT - 9)))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) ext2_error(dir->i_sb, __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) "dir %lu size %lld exceeds block count %llu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) dir->i_ino, dir->i_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) (unsigned long long)dir->i_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) } while (n != start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) return ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) *res_page = page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) ei->i_dir_start_lookup = n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) return de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) struct ext2_dir_entry_2 * ext2_dotdot (struct inode *dir, struct page **p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) struct page *page = ext2_get_page(dir, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) ext2_dirent *de = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) if (!IS_ERR(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) de = ext2_next_entry((ext2_dirent *) page_address(page));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) *p = page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) return de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) int ext2_inode_by_name(struct inode *dir, const struct qstr *child, ino_t *ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) struct ext2_dir_entry_2 *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) de = ext2_find_entry(dir, child, &page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) if (IS_ERR(de))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) return PTR_ERR(de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) *ino = le32_to_cpu(de->inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) ext2_put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) static int ext2_prepare_chunk(struct page *page, loff_t pos, unsigned len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) return __block_write_begin(page, pos, len, ext2_get_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) /* Releases the page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) void ext2_set_link(struct inode *dir, struct ext2_dir_entry_2 *de,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) struct page *page, struct inode *inode, int update_times)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) loff_t pos = page_offset(page) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) (char *) de - (char *) page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) unsigned len = ext2_rec_len_from_disk(de->rec_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) lock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) err = ext2_prepare_chunk(page, pos, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) BUG_ON(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) de->inode = cpu_to_le32(inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) ext2_set_de_type(de, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) err = ext2_commit_chunk(page, pos, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) ext2_put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) if (update_times)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) dir->i_mtime = dir->i_ctime = current_time(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) EXT2_I(dir)->i_flags &= ~EXT2_BTREE_FL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) mark_inode_dirty(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) * Parent is locked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) int ext2_add_link (struct dentry *dentry, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) struct inode *dir = d_inode(dentry->d_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) const char *name = dentry->d_name.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) int namelen = dentry->d_name.len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) unsigned chunk_size = ext2_chunk_size(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) unsigned reclen = EXT2_DIR_REC_LEN(namelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) unsigned short rec_len, name_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) struct page *page = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) ext2_dirent * de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) unsigned long npages = dir_pages(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) unsigned long n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) char *kaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) loff_t pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) * We take care of directory expansion in the same loop.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) * This code plays outside i_size, so it locks the page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) * to protect that region.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) for (n = 0; n <= npages; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) char *dir_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) page = ext2_get_page(dir, n, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) err = PTR_ERR(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) if (IS_ERR(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) lock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) kaddr = page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) dir_end = kaddr + ext2_last_byte(dir, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) de = (ext2_dirent *)kaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) kaddr += PAGE_SIZE - reclen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) while ((char *)de <= kaddr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) if ((char *)de == dir_end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) /* We hit i_size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) name_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) rec_len = chunk_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) de->rec_len = ext2_rec_len_to_disk(chunk_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) de->inode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) goto got_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) if (de->rec_len == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) ext2_error(dir->i_sb, __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) "zero-length directory entry");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) err = -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) if (ext2_match (namelen, name, de))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) name_len = EXT2_DIR_REC_LEN(de->name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) rec_len = ext2_rec_len_from_disk(de->rec_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) if (!de->inode && rec_len >= reclen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) goto got_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) if (rec_len >= name_len + reclen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) goto got_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) de = (ext2_dirent *) ((char *) de + rec_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) ext2_put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) got_it:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) pos = page_offset(page) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) (char*)de - (char*)page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) err = ext2_prepare_chunk(page, pos, rec_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) if (de->inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) ext2_dirent *de1 = (ext2_dirent *) ((char *) de + name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) de1->rec_len = ext2_rec_len_to_disk(rec_len - name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) de->rec_len = ext2_rec_len_to_disk(name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) de = de1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) de->name_len = namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) memcpy(de->name, name, namelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) de->inode = cpu_to_le32(inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) ext2_set_de_type (de, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) err = ext2_commit_chunk(page, pos, rec_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) dir->i_mtime = dir->i_ctime = current_time(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) EXT2_I(dir)->i_flags &= ~EXT2_BTREE_FL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) mark_inode_dirty(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) /* OFFSET_CACHE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) out_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) ext2_put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) goto out_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) * ext2_delete_entry deletes a directory entry by merging it with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) * previous entry. Page is up-to-date. Releases the page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) int ext2_delete_entry (struct ext2_dir_entry_2 * dir, struct page * page )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) struct inode *inode = page->mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) char *kaddr = page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) unsigned from = ((char*)dir - kaddr) & ~(ext2_chunk_size(inode)-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) unsigned to = ((char *)dir - kaddr) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) ext2_rec_len_from_disk(dir->rec_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) loff_t pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) ext2_dirent * pde = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) ext2_dirent * de = (ext2_dirent *) (kaddr + from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) while ((char*)de < (char*)dir) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) if (de->rec_len == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) ext2_error(inode->i_sb, __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) "zero-length directory entry");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) pde = de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) de = ext2_next_entry(de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) if (pde)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) from = (char*)pde - (char*)page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) pos = page_offset(page) + from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) lock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) err = ext2_prepare_chunk(page, pos, to - from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) BUG_ON(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) if (pde)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) pde->rec_len = ext2_rec_len_to_disk(to - from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) dir->inode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) err = ext2_commit_chunk(page, pos, to - from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) inode->i_ctime = inode->i_mtime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) EXT2_I(inode)->i_flags &= ~EXT2_BTREE_FL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) ext2_put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) * Set the first fragment of directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) int ext2_make_empty(struct inode *inode, struct inode *parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) struct page *page = grab_cache_page(inode->i_mapping, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) unsigned chunk_size = ext2_chunk_size(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) struct ext2_dir_entry_2 * de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) void *kaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) if (!page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) err = ext2_prepare_chunk(page, 0, chunk_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) kaddr = kmap_atomic(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) memset(kaddr, 0, chunk_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) de = (struct ext2_dir_entry_2 *)kaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) de->name_len = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) de->rec_len = ext2_rec_len_to_disk(EXT2_DIR_REC_LEN(1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) memcpy (de->name, ".\0\0", 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) de->inode = cpu_to_le32(inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) ext2_set_de_type (de, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) de = (struct ext2_dir_entry_2 *)(kaddr + EXT2_DIR_REC_LEN(1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) de->name_len = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) de->rec_len = ext2_rec_len_to_disk(chunk_size - EXT2_DIR_REC_LEN(1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) de->inode = cpu_to_le32(parent->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) memcpy (de->name, "..\0", 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) ext2_set_de_type (de, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) kunmap_atomic(kaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) err = ext2_commit_chunk(page, 0, chunk_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) * routine to check that the specified directory is empty (for rmdir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) int ext2_empty_dir (struct inode * inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) struct page *page = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) unsigned long i, npages = dir_pages(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) int dir_has_error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) for (i = 0; i < npages; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) char *kaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) ext2_dirent * de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) page = ext2_get_page(inode, i, dir_has_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) if (IS_ERR(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) dir_has_error = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) kaddr = page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) de = (ext2_dirent *)kaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) kaddr += ext2_last_byte(inode, i) - EXT2_DIR_REC_LEN(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) while ((char *)de <= kaddr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) if (de->rec_len == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) ext2_error(inode->i_sb, __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) "zero-length directory entry");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) printk("kaddr=%p, de=%p\n", kaddr, de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) goto not_empty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) if (de->inode != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) /* check for . and .. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) if (de->name[0] != '.')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) goto not_empty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) if (de->name_len > 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) goto not_empty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) if (de->name_len < 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) if (de->inode !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) cpu_to_le32(inode->i_ino))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) goto not_empty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) } else if (de->name[1] != '.')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) goto not_empty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) de = ext2_next_entry(de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) ext2_put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) not_empty:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) ext2_put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) const struct file_operations ext2_dir_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) .llseek = generic_file_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) .read = generic_read_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) .iterate_shared = ext2_readdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) .unlocked_ioctl = ext2_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) .compat_ioctl = ext2_compat_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) .fsync = ext2_fsync,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) };