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