^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/hpfs/dnode.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz), 1998-1999
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * handling directory dnode tree - adding, deleteing & searching for dirents
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "hpfs_fn.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) static loff_t get_pos(struct dnode *d, struct hpfs_dirent *fde)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) struct hpfs_dirent *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) struct hpfs_dirent *de_end = dnode_end_de(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) int i = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) for (de = dnode_first_de(d); de < de_end; de = de_next_de(de)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) if (de == fde) return ((loff_t) le32_to_cpu(d->self) << 4) | (loff_t)i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) pr_info("%s(): not_found\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) return ((loff_t)le32_to_cpu(d->self) << 4) | (loff_t)1;
^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) int hpfs_add_pos(struct inode *inode, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct hpfs_inode_info *hpfs_inode = hpfs_i(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) loff_t **ppos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) if (hpfs_inode->i_rddir_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) for (; hpfs_inode->i_rddir_off[i]; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) if (hpfs_inode->i_rddir_off[i] == pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) if (!(i&0x0f)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) ppos = kmalloc_array(i + 0x11, sizeof(loff_t *), GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) if (!ppos) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) pr_err("out of memory for position list\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) if (hpfs_inode->i_rddir_off) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) memcpy(ppos, hpfs_inode->i_rddir_off, i * sizeof(loff_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) kfree(hpfs_inode->i_rddir_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) hpfs_inode->i_rddir_off = ppos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) hpfs_inode->i_rddir_off[i] = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) hpfs_inode->i_rddir_off[i + 1] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) void hpfs_del_pos(struct inode *inode, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct hpfs_inode_info *hpfs_inode = hpfs_i(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) loff_t **i, **j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) if (!hpfs_inode->i_rddir_off) goto not_f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) for (i = hpfs_inode->i_rddir_off; *i; i++) if (*i == pos) goto fnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) goto not_f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) fnd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) for (j = i + 1; *j; j++) ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) *i = *(j - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) *(j - 1) = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) if (j - 1 == hpfs_inode->i_rddir_off) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) kfree(hpfs_inode->i_rddir_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) hpfs_inode->i_rddir_off = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) not_f:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /*pr_warn("position pointer %p->%08x not found\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) pos, (int)*pos);*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return;
^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) static void for_all_poss(struct inode *inode, void (*f)(loff_t *, loff_t, loff_t),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) loff_t p1, loff_t p2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct hpfs_inode_info *hpfs_inode = hpfs_i(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) loff_t **i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if (!hpfs_inode->i_rddir_off) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) for (i = hpfs_inode->i_rddir_off; *i; i++) (*f)(*i, p1, p2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) static void hpfs_pos_subst(loff_t *p, loff_t f, loff_t t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) if (*p == f) *p = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) /*void hpfs_hpfs_pos_substd(loff_t *p, loff_t f, loff_t t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if ((*p & ~0x3f) == (f & ~0x3f)) *p = (t & ~0x3f) | (*p & 0x3f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) static void hpfs_pos_ins(loff_t *p, loff_t d, loff_t c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if ((*p & ~0x3f) == (d & ~0x3f) && (*p & 0x3f) >= (d & 0x3f)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) int n = (*p & 0x3f) + c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (n > 0x3f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) pr_err("%s(): %08x + %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) __func__, (int)*p, (int)c >> 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) *p = (*p & ~0x3f) | n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^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) static void hpfs_pos_del(loff_t *p, loff_t d, loff_t c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) if ((*p & ~0x3f) == (d & ~0x3f) && (*p & 0x3f) >= (d & 0x3f)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) int n = (*p & 0x3f) - c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (n < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) pr_err("%s(): %08x - %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) __func__, (int)*p, (int)c >> 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) *p = (*p & ~0x3f) | n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static struct hpfs_dirent *dnode_pre_last_de(struct dnode *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct hpfs_dirent *de, *de_end, *dee = NULL, *deee = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) de_end = dnode_end_de(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) for (de = dnode_first_de(d); de < de_end; de = de_next_de(de)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) deee = dee; dee = de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return deee;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static struct hpfs_dirent *dnode_last_de(struct dnode *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct hpfs_dirent *de, *de_end, *dee = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) de_end = dnode_end_de(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) for (de = dnode_first_de(d); de < de_end; de = de_next_de(de)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) dee = de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return dee;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static void set_last_pointer(struct super_block *s, struct dnode *d, dnode_secno ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct hpfs_dirent *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (!(de = dnode_last_de(d))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) hpfs_error(s, "set_last_pointer: empty dnode %08x", le32_to_cpu(d->self));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (hpfs_sb(s)->sb_chk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (de->down) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) hpfs_error(s, "set_last_pointer: dnode %08x has already last pointer %08x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) le32_to_cpu(d->self), de_down_pointer(de));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (le16_to_cpu(de->length) != 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) hpfs_error(s, "set_last_pointer: bad last dirent in dnode %08x", le32_to_cpu(d->self));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) if (ptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) le32_add_cpu(&d->first_free, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (le32_to_cpu(d->first_free) > 2048) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) hpfs_error(s, "set_last_pointer: too long dnode %08x", le32_to_cpu(d->self));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) le32_add_cpu(&d->first_free, -4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) de->length = cpu_to_le16(36);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) de->down = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) *(__le32 *)((char *)de + 32) = cpu_to_le32(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) /* Add an entry to dnode and don't care if it grows over 2048 bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) struct hpfs_dirent *hpfs_add_de(struct super_block *s, struct dnode *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) const unsigned char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) unsigned namelen, secno down_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct hpfs_dirent *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct hpfs_dirent *de_end = dnode_end_de(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) unsigned d_size = de_size(namelen, down_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) for (de = dnode_first_de(d); de < de_end; de = de_next_de(de)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) int c = hpfs_compare_names(s, name, namelen, de->name, de->namelen, de->last);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (!c) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) hpfs_error(s, "name (%c,%d) already exists in dnode %08x", *name, namelen, le32_to_cpu(d->self));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) if (c < 0) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) memmove((char *)de + d_size, de, (char *)de_end - (char *)de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) memset(de, 0, d_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (down_ptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) *(__le32 *)((char *)de + d_size - 4) = cpu_to_le32(down_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) de->down = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) de->length = cpu_to_le16(d_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) de->not_8x3 = hpfs_is_name_long(name, namelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) de->namelen = namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) memcpy(de->name, name, namelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) le32_add_cpu(&d->first_free, d_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* Delete dirent and don't care about its subtree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) static void hpfs_delete_de(struct super_block *s, struct dnode *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) struct hpfs_dirent *de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) if (de->last) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) hpfs_error(s, "attempt to delete last dirent in dnode %08x", le32_to_cpu(d->self));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) d->first_free = cpu_to_le32(le32_to_cpu(d->first_free) - le16_to_cpu(de->length));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) memmove(de, de_next_de(de), le32_to_cpu(d->first_free) + (char *)d - (char *)de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static void fix_up_ptrs(struct super_block *s, struct dnode *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) struct hpfs_dirent *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) struct hpfs_dirent *de_end = dnode_end_de(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) dnode_secno dno = le32_to_cpu(d->self);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) for (de = dnode_first_de(d); de < de_end; de = de_next_de(de))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) if (de->down) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) struct quad_buffer_head qbh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) struct dnode *dd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if ((dd = hpfs_map_dnode(s, de_down_pointer(de), &qbh))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (le32_to_cpu(dd->up) != dno || dd->root_dnode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) dd->up = cpu_to_le32(dno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) dd->root_dnode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) hpfs_mark_4buffers_dirty(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) hpfs_brelse4(&qbh);
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) /* Add an entry to dnode and do dnode splitting if required */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static int hpfs_add_to_dnode(struct inode *i, dnode_secno dno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) const unsigned char *name, unsigned namelen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct hpfs_dirent *new_de, dnode_secno down_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) struct quad_buffer_head qbh, qbh1, qbh2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct dnode *d, *ad, *rd, *nd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) dnode_secno adno, rdno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) struct hpfs_dirent *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) struct hpfs_dirent nde;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) unsigned char *nname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) int h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) int pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) struct fnode *fnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) int c1, c2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) if (!(nname = kmalloc(256, GFP_NOFS))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) pr_err("out of memory, can't add to dnode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) go_up:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (namelen >= 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) hpfs_error(i->i_sb, "%s(): namelen == %d", __func__, namelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) kfree(nd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) kfree(nname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) if (!(d = hpfs_map_dnode(i->i_sb, dno, &qbh))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) kfree(nd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) kfree(nname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) go_up_a:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) if (hpfs_sb(i->i_sb)->sb_chk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) if (hpfs_stop_cycles(i->i_sb, dno, &c1, &c2, "hpfs_add_to_dnode")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) kfree(nd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) kfree(nname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (le32_to_cpu(d->first_free) + de_size(namelen, down_ptr) <= 2048) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) loff_t t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) copy_de(de=hpfs_add_de(i->i_sb, d, name, namelen, down_ptr), new_de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) t = get_pos(d, de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) for_all_poss(i, hpfs_pos_ins, t, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) for_all_poss(i, hpfs_pos_subst, 4, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) for_all_poss(i, hpfs_pos_subst, 5, t + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) hpfs_mark_4buffers_dirty(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) kfree(nd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) kfree(nname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) if (!nd) if (!(nd = kmalloc(0x924, GFP_NOFS))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) /* 0x924 is a max size of dnode after adding a dirent with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) max name length. We alloc this only once. There must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) not be any error while splitting dnodes, otherwise the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) whole directory, not only file we're adding, would
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) be lost. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) pr_err("out of memory for dnode splitting\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) kfree(nname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) memcpy(nd, d, le32_to_cpu(d->first_free));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) copy_de(de = hpfs_add_de(i->i_sb, nd, name, namelen, down_ptr), new_de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) for_all_poss(i, hpfs_pos_ins, get_pos(nd, de), 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) h = ((char *)dnode_last_de(nd) - (char *)nd) / 2 + 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) if (!(ad = hpfs_alloc_dnode(i->i_sb, le32_to_cpu(d->up), &adno, &qbh1))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) hpfs_error(i->i_sb, "unable to alloc dnode - dnode tree will be corrupted");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) kfree(nd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) kfree(nname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) i->i_size += 2048;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) i->i_blocks += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) pos = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) for (de = dnode_first_de(nd); (char *)de_next_de(de) - (char *)nd < h; de = de_next_de(de)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) copy_de(hpfs_add_de(i->i_sb, ad, de->name, de->namelen, de->down ? de_down_pointer(de) : 0), de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) for_all_poss(i, hpfs_pos_subst, ((loff_t)dno << 4) | pos, ((loff_t)adno << 4) | pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) pos++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) copy_de(new_de = &nde, de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) memcpy(nname, de->name, de->namelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) name = nname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) namelen = de->namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) for_all_poss(i, hpfs_pos_subst, ((loff_t)dno << 4) | pos, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) down_ptr = adno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) set_last_pointer(i->i_sb, ad, de->down ? de_down_pointer(de) : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) de = de_next_de(de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) memmove((char *)nd + 20, de, le32_to_cpu(nd->first_free) + (char *)nd - (char *)de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) le32_add_cpu(&nd->first_free, -((char *)de - (char *)nd - 20));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) memcpy(d, nd, le32_to_cpu(nd->first_free));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) for_all_poss(i, hpfs_pos_del, (loff_t)dno << 4, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) fix_up_ptrs(i->i_sb, ad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) if (!d->root_dnode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) ad->up = d->up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) dno = le32_to_cpu(ad->up);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) hpfs_mark_4buffers_dirty(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) hpfs_mark_4buffers_dirty(&qbh1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) hpfs_brelse4(&qbh1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) goto go_up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) if (!(rd = hpfs_alloc_dnode(i->i_sb, le32_to_cpu(d->up), &rdno, &qbh2))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) hpfs_error(i->i_sb, "unable to alloc dnode - dnode tree will be corrupted");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) hpfs_brelse4(&qbh1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) kfree(nd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) kfree(nname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) i->i_size += 2048;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) i->i_blocks += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) rd->root_dnode = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) rd->up = d->up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) if (!(fnode = hpfs_map_fnode(i->i_sb, le32_to_cpu(d->up), &bh))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) hpfs_free_dnode(i->i_sb, rdno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) hpfs_brelse4(&qbh1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) hpfs_brelse4(&qbh2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) kfree(nd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) kfree(nname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) fnode->u.external[0].disk_secno = cpu_to_le32(rdno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) mark_buffer_dirty(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) hpfs_i(i)->i_dno = rdno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) d->up = ad->up = cpu_to_le32(rdno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) d->root_dnode = ad->root_dnode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) hpfs_mark_4buffers_dirty(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) hpfs_mark_4buffers_dirty(&qbh1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) hpfs_brelse4(&qbh1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) qbh = qbh2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) set_last_pointer(i->i_sb, rd, dno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) dno = rdno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) d = rd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) goto go_up_a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) * Add an entry to directory btree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) * I hate such crazy directory structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) * It's easy to read but terrible to write.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) * I wrote this directory code 4 times.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) * I hope, now it's finally bug-free.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) int hpfs_add_dirent(struct inode *i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) const unsigned char *name, unsigned namelen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) struct hpfs_dirent *new_de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) struct dnode *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) struct hpfs_dirent *de, *de_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) struct quad_buffer_head qbh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) dnode_secno dno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) int c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) int c1, c2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) dno = hpfs_inode->i_dno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) down:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) if (hpfs_sb(i->i_sb)->sb_chk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) if (hpfs_stop_cycles(i->i_sb, dno, &c1, &c2, "hpfs_add_dirent")) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) if (!(d = hpfs_map_dnode(i->i_sb, dno, &qbh))) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) de_end = dnode_end_de(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) for (de = dnode_first_de(d); de < de_end; de = de_next_de(de)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (!(c = hpfs_compare_names(i->i_sb, name, namelen, de->name, de->namelen, de->last))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) if (c < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) if (de->down) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) dno = de_down_pointer(de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) goto down;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) if (hpfs_check_free_dnodes(i->i_sb, FREE_DNODES_ADD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) c = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) goto ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) c = hpfs_add_to_dnode(i, dno, name, namelen, new_de, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) ret:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) return c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) * Find dirent with higher name in 'from' subtree and move it to 'to' dnode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) * Return the dnode we moved from (to be checked later if it's empty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) static secno move_to_top(struct inode *i, dnode_secno from, dnode_secno to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) dnode_secno dno, ddno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) dnode_secno chk_up = to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) struct dnode *dnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) struct quad_buffer_head qbh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) struct hpfs_dirent *de, *nde;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) int a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) loff_t t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) int c1, c2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) dno = from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) if (hpfs_sb(i->i_sb)->sb_chk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) if (hpfs_stop_cycles(i->i_sb, dno, &c1, &c2, "move_to_top"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) if (!(dnode = hpfs_map_dnode(i->i_sb, dno, &qbh))) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) if (hpfs_sb(i->i_sb)->sb_chk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) if (le32_to_cpu(dnode->up) != chk_up) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) hpfs_error(i->i_sb, "move_to_top: up pointer from %08x should be %08x, is %08x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) dno, chk_up, le32_to_cpu(dnode->up));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) chk_up = dno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) if (!(de = dnode_last_de(dnode))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) hpfs_error(i->i_sb, "move_to_top: dnode %08x has no last de", dno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) if (!de->down) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) dno = de_down_pointer(de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) while (!(de = dnode_pre_last_de(dnode))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) dnode_secno up = le32_to_cpu(dnode->up);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) hpfs_free_dnode(i->i_sb, dno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) i->i_size -= 2048;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) i->i_blocks -= 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) for_all_poss(i, hpfs_pos_subst, ((loff_t)dno << 4) | 1, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) if (up == to) return to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) if (!(dnode = hpfs_map_dnode(i->i_sb, up, &qbh))) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) if (dnode->root_dnode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) hpfs_error(i->i_sb, "move_to_top: got to root_dnode while moving from %08x to %08x", from, to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) de = dnode_last_de(dnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) if (!de || !de->down) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) hpfs_error(i->i_sb, "move_to_top: dnode %08x doesn't point down to %08x", up, dno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) le32_add_cpu(&dnode->first_free, -4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) le16_add_cpu(&de->length, -4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) de->down = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) hpfs_mark_4buffers_dirty(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) dno = up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) t = get_pos(dnode, de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) for_all_poss(i, hpfs_pos_subst, t, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) for_all_poss(i, hpfs_pos_subst, t + 1, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) if (!(nde = kmalloc(le16_to_cpu(de->length), GFP_NOFS))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) hpfs_error(i->i_sb, "out of memory for dirent - directory will be corrupted");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) memcpy(nde, de, le16_to_cpu(de->length));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) ddno = de->down ? de_down_pointer(de) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) hpfs_delete_de(i->i_sb, dnode, de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) set_last_pointer(i->i_sb, dnode, ddno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) hpfs_mark_4buffers_dirty(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) a = hpfs_add_to_dnode(i, to, nde->name, nde->namelen, nde, from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) kfree(nde);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) if (a) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) return dno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) * Check if a dnode is empty and delete it from the tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) * (chkdsk doesn't like empty dnodes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) static void delete_empty_dnode(struct inode *i, dnode_secno dno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) struct quad_buffer_head qbh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) struct dnode *dnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) dnode_secno down, up, ndown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) int p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) struct hpfs_dirent *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) int c1, c2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) try_it_again:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) if (hpfs_stop_cycles(i->i_sb, dno, &c1, &c2, "delete_empty_dnode")) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) if (!(dnode = hpfs_map_dnode(i->i_sb, dno, &qbh))) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) if (le32_to_cpu(dnode->first_free) > 56) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) if (le32_to_cpu(dnode->first_free) == 52 || le32_to_cpu(dnode->first_free) == 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) struct hpfs_dirent *de_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) int root = dnode->root_dnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) up = le32_to_cpu(dnode->up);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) de = dnode_first_de(dnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) down = de->down ? de_down_pointer(de) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) if (hpfs_sb(i->i_sb)->sb_chk) if (root && !down) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) hpfs_error(i->i_sb, "delete_empty_dnode: root dnode %08x is empty", dno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) hpfs_free_dnode(i->i_sb, dno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) i->i_size -= 2048;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) i->i_blocks -= 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) if (root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) struct fnode *fnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) struct dnode *d1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) struct quad_buffer_head qbh1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) if (hpfs_sb(i->i_sb)->sb_chk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) if (up != i->i_ino) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) hpfs_error(i->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) "bad pointer to fnode, dnode %08x, pointing to %08x, should be %08lx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) dno, up,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) (unsigned long)i->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) if ((d1 = hpfs_map_dnode(i->i_sb, down, &qbh1))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) d1->up = cpu_to_le32(up);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) d1->root_dnode = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) hpfs_mark_4buffers_dirty(&qbh1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) hpfs_brelse4(&qbh1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) if ((fnode = hpfs_map_fnode(i->i_sb, up, &bh))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) fnode->u.external[0].disk_secno = cpu_to_le32(down);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) mark_buffer_dirty(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) hpfs_inode->i_dno = down;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) for_all_poss(i, hpfs_pos_subst, ((loff_t)dno << 4) | 1, (loff_t) 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) if (!(dnode = hpfs_map_dnode(i->i_sb, up, &qbh))) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) p = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) de_end = dnode_end_de(dnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) for (de = dnode_first_de(dnode); de < de_end; de = de_next_de(de), p++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) if (de->down) if (de_down_pointer(de) == dno) goto fnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) hpfs_error(i->i_sb, "delete_empty_dnode: pointer to dnode %08x not found in dnode %08x", dno, up);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) fnd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) for_all_poss(i, hpfs_pos_subst, ((loff_t)dno << 4) | 1, ((loff_t)up << 4) | p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) if (!down) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) de->down = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) le16_add_cpu(&de->length, -4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) le32_add_cpu(&dnode->first_free, -4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) memmove(de_next_de(de), (char *)de_next_de(de) + 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) (char *)dnode + le32_to_cpu(dnode->first_free) - (char *)de_next_de(de));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) struct dnode *d1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) struct quad_buffer_head qbh1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) *(dnode_secno *) ((void *) de + le16_to_cpu(de->length) - 4) = down;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) if ((d1 = hpfs_map_dnode(i->i_sb, down, &qbh1))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) d1->up = cpu_to_le32(up);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) hpfs_mark_4buffers_dirty(&qbh1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) hpfs_brelse4(&qbh1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) hpfs_error(i->i_sb, "delete_empty_dnode: dnode %08x, first_free == %03x", dno, le32_to_cpu(dnode->first_free));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) if (!de->last) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) struct hpfs_dirent *de_next = de_next_de(de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) struct hpfs_dirent *de_cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) struct dnode *d1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) struct quad_buffer_head qbh1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) if (!de_next->down) goto endm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) ndown = de_down_pointer(de_next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) if (!(de_cp = kmalloc(le16_to_cpu(de->length), GFP_NOFS))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) pr_err("out of memory for dtree balancing\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) goto endm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) memcpy(de_cp, de, le16_to_cpu(de->length));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) hpfs_delete_de(i->i_sb, dnode, de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) hpfs_mark_4buffers_dirty(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) for_all_poss(i, hpfs_pos_subst, ((loff_t)up << 4) | p, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) for_all_poss(i, hpfs_pos_del, ((loff_t)up << 4) | p, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) if (de_cp->down) if ((d1 = hpfs_map_dnode(i->i_sb, de_down_pointer(de_cp), &qbh1))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) d1->up = cpu_to_le32(ndown);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) hpfs_mark_4buffers_dirty(&qbh1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) hpfs_brelse4(&qbh1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) hpfs_add_to_dnode(i, ndown, de_cp->name, de_cp->namelen, de_cp, de_cp->down ? de_down_pointer(de_cp) : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) /*pr_info("UP-TO-DNODE: %08x (ndown = %08x, down = %08x, dno = %08x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) up, ndown, down, dno);*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) dno = up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) kfree(de_cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) goto try_it_again;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) struct hpfs_dirent *de_prev = dnode_pre_last_de(dnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) struct hpfs_dirent *de_cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) struct dnode *d1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) struct quad_buffer_head qbh1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) dnode_secno dlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) if (!de_prev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) hpfs_error(i->i_sb, "delete_empty_dnode: empty dnode %08x", up);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) hpfs_mark_4buffers_dirty(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) dno = up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) goto try_it_again;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) if (!de_prev->down) goto endm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) ndown = de_down_pointer(de_prev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) if ((d1 = hpfs_map_dnode(i->i_sb, ndown, &qbh1))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) struct hpfs_dirent *del = dnode_last_de(d1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) dlp = del->down ? de_down_pointer(del) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) if (!dlp && down) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) if (le32_to_cpu(d1->first_free) > 2044) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) if (hpfs_sb(i->i_sb)->sb_chk >= 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) pr_err("unbalanced dnode tree, see hpfs.txt 4 more info\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) pr_err("terminating balancing operation\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) hpfs_brelse4(&qbh1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) goto endm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) if (hpfs_sb(i->i_sb)->sb_chk >= 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) pr_err("unbalanced dnode tree, see hpfs.txt 4 more info\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) pr_err("goin'on\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) le16_add_cpu(&del->length, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) del->down = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) le32_add_cpu(&d1->first_free, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) if (dlp && !down) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) le16_add_cpu(&del->length, -4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) del->down = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) le32_add_cpu(&d1->first_free, -4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) } else if (down)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) *(__le32 *) ((void *) del + le16_to_cpu(del->length) - 4) = cpu_to_le32(down);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) } else goto endm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) if (!(de_cp = kmalloc(le16_to_cpu(de_prev->length), GFP_NOFS))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) pr_err("out of memory for dtree balancing\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) hpfs_brelse4(&qbh1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) goto endm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) hpfs_mark_4buffers_dirty(&qbh1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) hpfs_brelse4(&qbh1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) memcpy(de_cp, de_prev, le16_to_cpu(de_prev->length));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) hpfs_delete_de(i->i_sb, dnode, de_prev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) if (!de_prev->down) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) le16_add_cpu(&de_prev->length, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) de_prev->down = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) le32_add_cpu(&dnode->first_free, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) *(__le32 *) ((void *) de_prev + le16_to_cpu(de_prev->length) - 4) = cpu_to_le32(ndown);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) hpfs_mark_4buffers_dirty(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) for_all_poss(i, hpfs_pos_subst, ((loff_t)up << 4) | (p - 1), 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) for_all_poss(i, hpfs_pos_subst, ((loff_t)up << 4) | p, ((loff_t)up << 4) | (p - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) if (down) if ((d1 = hpfs_map_dnode(i->i_sb, de_down_pointer(de), &qbh1))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) d1->up = cpu_to_le32(ndown);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) hpfs_mark_4buffers_dirty(&qbh1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) hpfs_brelse4(&qbh1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) hpfs_add_to_dnode(i, ndown, de_cp->name, de_cp->namelen, de_cp, dlp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) dno = up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) kfree(de_cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) goto try_it_again;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) endm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) hpfs_mark_4buffers_dirty(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) /* Delete dirent from directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) int hpfs_remove_dirent(struct inode *i, dnode_secno dno, struct hpfs_dirent *de,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) struct quad_buffer_head *qbh, int depth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) struct dnode *dnode = qbh->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) dnode_secno down = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) loff_t t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) if (de->first || de->last) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) hpfs_error(i->i_sb, "hpfs_remove_dirent: attempt to delete first or last dirent in dnode %08x", dno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) hpfs_brelse4(qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) if (de->down) down = de_down_pointer(de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) if (depth && (de->down || (de == dnode_first_de(dnode) && de_next_de(de)->last))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) if (hpfs_check_free_dnodes(i->i_sb, FREE_DNODES_DEL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) hpfs_brelse4(qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) return 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) for_all_poss(i, hpfs_pos_del, (t = get_pos(dnode, de)) + 1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) hpfs_delete_de(i->i_sb, dnode, de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) hpfs_mark_4buffers_dirty(qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) hpfs_brelse4(qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) if (down) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) dnode_secno a = move_to_top(i, down, dno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) for_all_poss(i, hpfs_pos_subst, 5, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) if (a) delete_empty_dnode(i, a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) return !a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) delete_empty_dnode(i, dno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) void hpfs_count_dnodes(struct super_block *s, dnode_secno dno, int *n_dnodes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) int *n_subdirs, int *n_items)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) struct dnode *dnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) struct quad_buffer_head qbh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) struct hpfs_dirent *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) dnode_secno ptr, odno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) int c1, c2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) int d1, d2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) go_down:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) if (n_dnodes) (*n_dnodes)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) if (hpfs_sb(s)->sb_chk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) if (hpfs_stop_cycles(s, dno, &c1, &c2, "hpfs_count_dnodes #1")) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) ptr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) go_up:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) if (!(dnode = hpfs_map_dnode(s, dno, &qbh))) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) if (hpfs_sb(s)->sb_chk) if (odno && odno != -1 && le32_to_cpu(dnode->up) != odno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) hpfs_error(s, "hpfs_count_dnodes: bad up pointer; dnode %08x, down %08x points to %08x", odno, dno, le32_to_cpu(dnode->up));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) de = dnode_first_de(dnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) if (ptr) while(1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) if (de->down) if (de_down_pointer(de) == ptr) goto process_de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) if (de->last) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) hpfs_error(s, "hpfs_count_dnodes: pointer to dnode %08x not found in dnode %08x, got here from %08x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) ptr, dno, odno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) de = de_next_de(de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) next_de:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) if (de->down) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) odno = dno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) dno = de_down_pointer(de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) goto go_down;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) process_de:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) if (!de->first && !de->last && de->directory && n_subdirs) (*n_subdirs)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) if (!de->first && !de->last && n_items) (*n_items)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) if ((de = de_next_de(de)) < dnode_end_de(dnode)) goto next_de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) ptr = dno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) dno = le32_to_cpu(dnode->up);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) if (dnode->root_dnode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) if (hpfs_sb(s)->sb_chk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) if (hpfs_stop_cycles(s, ptr, &d1, &d2, "hpfs_count_dnodes #2")) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) odno = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) goto go_up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) static struct hpfs_dirent *map_nth_dirent(struct super_block *s, dnode_secno dno, int n,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) struct quad_buffer_head *qbh, struct dnode **dn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) struct hpfs_dirent *de, *de_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) struct dnode *dnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) dnode = hpfs_map_dnode(s, dno, qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) if (!dnode) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) if (dn) *dn=dnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) de = dnode_first_de(dnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) de_end = dnode_end_de(dnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) for (i = 1; de < de_end; i++, de = de_next_de(de)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) if (i == n) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) return de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) if (de->last) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) hpfs_brelse4(qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) hpfs_error(s, "map_nth_dirent: n too high; dnode = %08x, requested %08x", dno, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) dnode_secno hpfs_de_as_down_as_possible(struct super_block *s, dnode_secno dno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) struct quad_buffer_head qbh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) dnode_secno d = dno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) dnode_secno up = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) struct hpfs_dirent *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) int c1, c2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) again:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) if (hpfs_sb(s)->sb_chk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) if (hpfs_stop_cycles(s, d, &c1, &c2, "hpfs_de_as_down_as_possible"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) return d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) if (!(de = map_nth_dirent(s, d, 1, &qbh, NULL))) return dno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) if (hpfs_sb(s)->sb_chk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) if (up && le32_to_cpu(((struct dnode *)qbh.data)->up) != up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) hpfs_error(s, "hpfs_de_as_down_as_possible: bad up pointer; dnode %08x, down %08x points to %08x", up, d, le32_to_cpu(((struct dnode *)qbh.data)->up));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) if (!de->down) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) return d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) up = d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) d = de_down_pointer(de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) goto again;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) struct hpfs_dirent *map_pos_dirent(struct inode *inode, loff_t *posp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) struct quad_buffer_head *qbh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) loff_t pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) unsigned c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) dnode_secno dno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) struct hpfs_dirent *de, *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) struct hpfs_dirent *up_de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) struct hpfs_dirent *end_up_de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) struct dnode *dnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) struct dnode *up_dnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) struct quad_buffer_head qbh0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) pos = *posp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) dno = pos >> 6 << 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) pos &= 077;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) if (!(de = map_nth_dirent(inode->i_sb, dno, pos, qbh, &dnode)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) /* Going to the next dirent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) if ((d = de_next_de(de)) < dnode_end_de(dnode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) if (!(++*posp & 077)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) hpfs_error(inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) "map_pos_dirent: pos crossed dnode boundary; pos = %08llx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) (unsigned long long)*posp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) /* We're going down the tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) if (d->down) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) *posp = ((loff_t) hpfs_de_as_down_as_possible(inode->i_sb, de_down_pointer(d)) << 4) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) return de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) /* Going up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) if (dnode->root_dnode) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) if (!(up_dnode = hpfs_map_dnode(inode->i_sb, le32_to_cpu(dnode->up), &qbh0)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) end_up_de = dnode_end_de(up_dnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) c = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) for (up_de = dnode_first_de(up_dnode); up_de < end_up_de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) up_de = de_next_de(up_de)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) if (!(++c & 077)) hpfs_error(inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) "map_pos_dirent: pos crossed dnode boundary; dnode = %08x", le32_to_cpu(dnode->up));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) if (up_de->down && de_down_pointer(up_de) == dno) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) *posp = ((loff_t) le32_to_cpu(dnode->up) << 4) + c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) hpfs_brelse4(&qbh0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) return de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) hpfs_error(inode->i_sb, "map_pos_dirent: pointer to dnode %08x not found in parent dnode %08x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) dno, le32_to_cpu(dnode->up));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) hpfs_brelse4(&qbh0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) *posp = 12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) return de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) /* Find a dirent in tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) struct hpfs_dirent *map_dirent(struct inode *inode, dnode_secno dno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) const unsigned char *name, unsigned len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) dnode_secno *dd, struct quad_buffer_head *qbh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) struct dnode *dnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) struct hpfs_dirent *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) struct hpfs_dirent *de_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) int c1, c2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) if (!S_ISDIR(inode->i_mode)) hpfs_error(inode->i_sb, "map_dirent: not a directory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) again:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) if (hpfs_sb(inode->i_sb)->sb_chk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) if (hpfs_stop_cycles(inode->i_sb, dno, &c1, &c2, "map_dirent")) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) if (!(dnode = hpfs_map_dnode(inode->i_sb, dno, qbh))) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) de_end = dnode_end_de(dnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) for (de = dnode_first_de(dnode); de < de_end; de = de_next_de(de)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) int t = hpfs_compare_names(inode->i_sb, name, len, de->name, de->namelen, de->last);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) if (!t) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) if (dd) *dd = dno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) return de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) if (t < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) if (de->down) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) dno = de_down_pointer(de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) hpfs_brelse4(qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) goto again;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) hpfs_brelse4(qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) * Remove empty directory. In normal cases it is only one dnode with two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) * entries, but we must handle also such obscure cases when it's a tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) * of empty dnodes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) void hpfs_remove_dtree(struct super_block *s, dnode_secno dno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) struct quad_buffer_head qbh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) struct dnode *dnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) struct hpfs_dirent *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) dnode_secno d1, d2, rdno = dno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) if (!(dnode = hpfs_map_dnode(s, dno, &qbh))) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) de = dnode_first_de(dnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) if (de->last) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) if (de->down) d1 = de_down_pointer(de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) else goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) hpfs_free_dnode(s, dno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) dno = d1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) } else break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) if (!de->first) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) d1 = de->down ? de_down_pointer(de) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) de = de_next_de(de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) if (!de->last) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) d2 = de->down ? de_down_pointer(de) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) hpfs_free_dnode(s, dno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) while (d1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) if (!(dnode = hpfs_map_dnode(s, dno = d1, &qbh))) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) de = dnode_first_de(dnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) if (!de->last) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) d1 = de->down ? de_down_pointer(de) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) hpfs_free_dnode(s, dno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) d1 = d2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) d2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) } while (d1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) hpfs_free_dnode(s, dno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) hpfs_error(s, "directory %08x is corrupted or not empty", rdno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) * Find dirent for specified fnode. Use truncated 15-char name in fnode as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) * a help for searching.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) struct hpfs_dirent *map_fnode_dirent(struct super_block *s, fnode_secno fno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) struct fnode *f, struct quad_buffer_head *qbh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) unsigned char *name1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) unsigned char *name2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) int name1len, name2len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) struct dnode *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) dnode_secno dno, downd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) struct fnode *upf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) struct hpfs_dirent *de, *de_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) int c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) int c1, c2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) int d1, d2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) name1 = f->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) if (!(name2 = kmalloc(256, GFP_NOFS))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) pr_err("out of memory, can't map dirent\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) if (f->len <= 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) memcpy(name2, name1, name1len = name2len = f->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) memcpy(name2, name1, 15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) memset(name2 + 15, 0xff, 256 - 15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) /*name2[15] = 0xff;*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) name1len = 15; name2len = 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) if (!(upf = hpfs_map_fnode(s, le32_to_cpu(f->up), &bh))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) kfree(name2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) if (!fnode_is_dir(upf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) hpfs_error(s, "fnode %08x has non-directory parent %08x", fno, le32_to_cpu(f->up));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) kfree(name2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) dno = le32_to_cpu(upf->u.external[0].disk_secno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) go_down:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) downd = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) go_up:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) if (!(d = hpfs_map_dnode(s, dno, qbh))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) kfree(name2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) de_end = dnode_end_de(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) de = dnode_first_de(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) if (downd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) while (de < de_end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) if (de->down) if (de_down_pointer(de) == downd) goto f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) de = de_next_de(de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) hpfs_error(s, "pointer to dnode %08x not found in dnode %08x", downd, dno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) hpfs_brelse4(qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) kfree(name2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) next_de:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) if (le32_to_cpu(de->fnode) == fno) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) kfree(name2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) return de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) c = hpfs_compare_names(s, name1, name1len, de->name, de->namelen, de->last);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) if (c < 0 && de->down) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) dno = de_down_pointer(de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) hpfs_brelse4(qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) if (hpfs_sb(s)->sb_chk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) if (hpfs_stop_cycles(s, dno, &c1, &c2, "map_fnode_dirent #1")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) kfree(name2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) goto go_down;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) f:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) if (le32_to_cpu(de->fnode) == fno) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) kfree(name2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) return de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) c = hpfs_compare_names(s, name2, name2len, de->name, de->namelen, de->last);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) if (c < 0 && !de->last) goto not_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) if ((de = de_next_de(de)) < de_end) goto next_de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) if (d->root_dnode) goto not_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) downd = dno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) dno = le32_to_cpu(d->up);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) hpfs_brelse4(qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) if (hpfs_sb(s)->sb_chk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) if (hpfs_stop_cycles(s, downd, &d1, &d2, "map_fnode_dirent #2")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) kfree(name2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) goto go_up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) not_found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) hpfs_brelse4(qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) hpfs_error(s, "dirent for fnode %08x not found", fno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) kfree(name2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) }