^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/dir.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) * directory VFS functions
^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 <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "hpfs_fn.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) static int hpfs_dir_release(struct inode *inode, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) hpfs_lock(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) hpfs_del_pos(inode, &filp->f_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) /*hpfs_write_if_changed(inode);*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) hpfs_unlock(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) /* This is slow, but it's not used often */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static loff_t hpfs_dir_lseek(struct file *filp, loff_t off, int whence)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) loff_t new_off = off + (whence == 1 ? filp->f_pos : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) loff_t pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct quad_buffer_head qbh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct inode *i = file_inode(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct super_block *s = i->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /* Somebody else will have to figure out what to do here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) if (whence == SEEK_DATA || whence == SEEK_HOLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) inode_lock(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) hpfs_lock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /*pr_info("dir lseek\n");*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) if (new_off == 0 || new_off == 1 || new_off == 11 || new_off == 12 || new_off == 13) goto ok;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) pos = ((loff_t) hpfs_de_as_down_as_possible(s, hpfs_inode->i_dno) << 4) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) while (pos != new_off) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) if (map_pos_dirent(i, &pos, &qbh)) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) else goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (pos == 12) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) if (unlikely(hpfs_add_pos(i, &filp->f_pos) < 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) hpfs_unlock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) inode_unlock(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) ok:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) filp->f_pos = new_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) hpfs_unlock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) inode_unlock(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return new_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) /*pr_warn("illegal lseek: %016llx\n", new_off);*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) hpfs_unlock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) inode_unlock(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return -ESPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static int hpfs_readdir(struct file *file, struct dir_context *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct inode *inode = file_inode(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct hpfs_inode_info *hpfs_inode = hpfs_i(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct quad_buffer_head qbh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct hpfs_dirent *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) int lc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) loff_t next_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) unsigned char *tempname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) int c1, c2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) hpfs_lock(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if (hpfs_sb(inode->i_sb)->sb_chk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) if (hpfs_chk_sectors(inode->i_sb, inode->i_ino, 1, "dir_fnode")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) ret = -EFSERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if (hpfs_chk_sectors(inode->i_sb, hpfs_inode->i_dno, 4, "dir_dnode")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) ret = -EFSERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (hpfs_sb(inode->i_sb)->sb_chk >= 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct fnode *fno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) int e = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (!(fno = hpfs_map_fnode(inode->i_sb, inode->i_ino, &bh))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) ret = -EIOERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (!fnode_is_dir(fno)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) e = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) hpfs_error(inode->i_sb, "not a directory, fnode %08lx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) (unsigned long)inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (hpfs_inode->i_dno != le32_to_cpu(fno->u.external[0].disk_secno)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) e = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) hpfs_error(inode->i_sb, "corrupted inode: i_dno == %08x, fnode -> dnode == %08x", hpfs_inode->i_dno, le32_to_cpu(fno->u.external[0].disk_secno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (e) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) ret = -EFSERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) goto out;
^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) lc = hpfs_sb(inode->i_sb)->sb_lowercase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (ctx->pos == 12) { /* diff -r requires this (note, that diff -r */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) ctx->pos = 13; /* also fails on msdos filesystem in 2.0) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (ctx->pos == 13) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) ret = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) again:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /* This won't work when cycle is longer than number of dirents
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) accepted by filldir, but what can I do?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) maybe killall -9 ls helps */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (hpfs_sb(inode->i_sb)->sb_chk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) if (hpfs_stop_cycles(inode->i_sb, ctx->pos, &c1, &c2, "hpfs_readdir")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) ret = -EFSERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (ctx->pos == 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) if (ctx->pos == 3 || ctx->pos == 4 || ctx->pos == 5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) pr_err("pos==%d\n", (int)ctx->pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (ctx->pos == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (!dir_emit_dot(file, ctx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) ctx->pos = 11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (ctx->pos == 11) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) if (!dir_emit(ctx, "..", 2, hpfs_inode->i_parent_dir, DT_DIR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) ctx->pos = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (ctx->pos == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) ret = hpfs_add_pos(inode, &file->f_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (unlikely(ret < 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) ctx->pos = ((loff_t) hpfs_de_as_down_as_possible(inode->i_sb, hpfs_inode->i_dno) << 4) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) next_pos = ctx->pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (!(de = map_pos_dirent(inode, &next_pos, &qbh))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) ctx->pos = next_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) ret = -EIOERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (de->first || de->last) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) if (hpfs_sb(inode->i_sb)->sb_chk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (de->first && !de->last && (de->namelen != 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) || de ->name[0] != 1 || de->name[1] != 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) hpfs_error(inode->i_sb, "hpfs_readdir: bad ^A^A entry; pos = %08lx", (unsigned long)ctx->pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if (de->last && (de->namelen != 1 || de ->name[0] != 255))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) hpfs_error(inode->i_sb, "hpfs_readdir: bad \\377 entry; pos = %08lx", (unsigned long)ctx->pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) ctx->pos = next_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) goto again;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) tempname = hpfs_translate_name(inode->i_sb, de->name, de->namelen, lc, de->not_8x3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (!dir_emit(ctx, tempname, de->namelen, le32_to_cpu(de->fnode), DT_UNKNOWN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (tempname != de->name) kfree(tempname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) ctx->pos = next_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (tempname != de->name) kfree(tempname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) hpfs_unlock(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * lookup. Search the specified directory for the specified name, set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * *result to the corresponding inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * lookup uses the inode number to tell read_inode whether it is reading
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) * the inode of a directory or a file -- file ino's are odd, directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * ino's are even. read_inode avoids i/o for file inodes; everything
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * needed is up here in the directory. (And file fnodes are out in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * the boondocks.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) * - M.P.: this is over, sometimes we've got to read file's fnode for eas
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) * inode numbers are just fnode sector numbers; iget lock is used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * to tell read_inode to read fnode or not.
^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) struct dentry *hpfs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) const unsigned char *name = dentry->d_name.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) unsigned len = dentry->d_name.len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) struct quad_buffer_head qbh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) struct hpfs_dirent *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) ino_t ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) struct inode *result = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) struct hpfs_inode_info *hpfs_result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) hpfs_lock(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if ((err = hpfs_chk_name(name, &len))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (err == -ENAMETOOLONG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) hpfs_unlock(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return ERR_PTR(-ENAMETOOLONG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) goto end_add;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * '.' and '..' will never be passed here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) de = map_dirent(dir, hpfs_i(dir)->i_dno, name, len, NULL, &qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * This is not really a bailout, just means file not found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (!de) goto end;
^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) * Get inode number, what we're after.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) ino = le32_to_cpu(de->fnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) * Go find or make an inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) result = iget_locked(dir->i_sb, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (!result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) hpfs_error(dir->i_sb, "hpfs_lookup: can't get inode");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) result = ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) goto bail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (result->i_state & I_NEW) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) hpfs_init_inode(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) if (de->directory)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) hpfs_read_inode(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) else if (le32_to_cpu(de->ea_size) && hpfs_sb(dir->i_sb)->sb_eas)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) hpfs_read_inode(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) result->i_mode |= S_IFREG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) result->i_mode &= ~0111;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) result->i_op = &hpfs_file_iops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) result->i_fop = &hpfs_file_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) set_nlink(result, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) unlock_new_inode(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) hpfs_result = hpfs_i(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (!de->directory) hpfs_result->i_parent_dir = dir->i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) if (de->has_acl || de->has_xtd_perm) if (!sb_rdonly(dir->i_sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) hpfs_error(result->i_sb, "ACLs or XPERM found. This is probably HPFS386. This driver doesn't support it now. Send me some info on these structures");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) iput(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) result = ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) goto bail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) * Fill in the info from the directory if this is a newly created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (!result->i_ctime.tv_sec) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) if (!(result->i_ctime.tv_sec = local_to_gmt(dir->i_sb, le32_to_cpu(de->creation_date))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) result->i_ctime.tv_sec = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) result->i_ctime.tv_nsec = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) result->i_mtime.tv_sec = local_to_gmt(dir->i_sb, le32_to_cpu(de->write_date));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) result->i_mtime.tv_nsec = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) result->i_atime.tv_sec = local_to_gmt(dir->i_sb, le32_to_cpu(de->read_date));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) result->i_atime.tv_nsec = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) hpfs_result->i_ea_size = le32_to_cpu(de->ea_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) if (!hpfs_result->i_ea_mode && de->read_only)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) result->i_mode &= ~0222;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (!de->directory) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) if (result->i_size == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) result->i_size = le32_to_cpu(de->file_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) result->i_data.a_ops = &hpfs_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) hpfs_i(result)->mmu_private = result->i_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) * i_blocks should count the fnode and any anodes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) * We count 1 for the fnode and don't bother about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) * anodes -- the disk heads are on the directory band
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) * and we want them to stay there.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) result->i_blocks = 1 + ((result->i_size + 511) >> 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) bail1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) hpfs_brelse4(&qbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) * Made it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) end_add:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) hpfs_unlock(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) return d_splice_alias(result, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) const struct file_operations hpfs_dir_ops =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) .llseek = hpfs_dir_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) .read = generic_read_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) .iterate_shared = hpfs_readdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) .release = hpfs_dir_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) .fsync = hpfs_file_fsync,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) .unlocked_ioctl = hpfs_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) .compat_ioctl = compat_ptr_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) };