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/namei.c |
| 4 | * |
| 5 | * Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz), 1998-1999 |
| 6 | * |
| 7 | * adding & removing files & directories |
| 8 | */ |
Alexey Dobriyan | e8edc6e | 2007-05-21 01:22:52 +0400 | [diff] [blame] | 9 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include "hpfs_fn.h" |
| 11 | |
Mikulas Patocka | f49a26e | 2015-09-02 22:51:53 +0200 | [diff] [blame] | 12 | static void hpfs_update_directory_times(struct inode *dir) |
| 13 | { |
Arnd Bergmann | f08957d0 | 2018-08-17 15:43:54 -0700 | [diff] [blame^] | 14 | time64_t t = local_to_gmt(dir->i_sb, local_get_seconds(dir->i_sb)); |
Mikulas Patocka | f49a26e | 2015-09-02 22:51:53 +0200 | [diff] [blame] | 15 | if (t == dir->i_mtime.tv_sec && |
| 16 | t == dir->i_ctime.tv_sec) |
| 17 | return; |
| 18 | dir->i_mtime.tv_sec = dir->i_ctime.tv_sec = t; |
| 19 | dir->i_mtime.tv_nsec = dir->i_ctime.tv_nsec = 0; |
| 20 | hpfs_write_inode_nolock(dir); |
| 21 | } |
| 22 | |
Al Viro | 18bb1db | 2011-07-26 01:41:39 -0400 | [diff] [blame] | 23 | static int hpfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | { |
Al Viro | 7e7742e | 2010-01-31 17:09:29 -0500 | [diff] [blame] | 25 | const unsigned char *name = dentry->d_name.name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | unsigned len = dentry->d_name.len; |
| 27 | struct quad_buffer_head qbh0; |
| 28 | struct buffer_head *bh; |
| 29 | struct hpfs_dirent *de; |
| 30 | struct fnode *fnode; |
| 31 | struct dnode *dnode; |
| 32 | struct inode *result; |
| 33 | fnode_secno fno; |
| 34 | dnode_secno dno; |
| 35 | int r; |
| 36 | struct hpfs_dirent dee; |
| 37 | int err; |
Al Viro | 7e7742e | 2010-01-31 17:09:29 -0500 | [diff] [blame] | 38 | if ((err = hpfs_chk_name(name, &len))) return err==-ENOENT ? -EINVAL : err; |
Arnd Bergmann | 9a311b9 | 2011-01-22 20:26:12 +0100 | [diff] [blame] | 39 | hpfs_lock(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | err = -ENOSPC; |
| 41 | fnode = hpfs_alloc_fnode(dir->i_sb, hpfs_i(dir)->i_dno, &fno, &bh); |
| 42 | if (!fnode) |
| 43 | goto bail; |
Mikulas Patocka | 7d23ce3 | 2011-05-08 20:43:06 +0200 | [diff] [blame] | 44 | dnode = hpfs_alloc_dnode(dir->i_sb, fno, &dno, &qbh0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | if (!dnode) |
| 46 | goto bail1; |
| 47 | memset(&dee, 0, sizeof dee); |
| 48 | dee.directory = 1; |
| 49 | if (!(mode & 0222)) dee.read_only = 1; |
| 50 | /*dee.archive = 0;*/ |
| 51 | dee.hidden = name[0] == '.'; |
Mikulas Patocka | 0b69760 | 2011-05-08 20:44:26 +0200 | [diff] [blame] | 52 | dee.fnode = cpu_to_le32(fno); |
Arnd Bergmann | f08957d0 | 2018-08-17 15:43:54 -0700 | [diff] [blame^] | 53 | dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(local_get_seconds(dir->i_sb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | result = new_inode(dir->i_sb); |
| 55 | if (!result) |
| 56 | goto bail2; |
| 57 | hpfs_init_inode(result); |
| 58 | result->i_ino = fno; |
| 59 | hpfs_i(result)->i_parent_dir = dir->i_ino; |
| 60 | hpfs_i(result)->i_dno = dno; |
Mikulas Patocka | 0b69760 | 2011-05-08 20:44:26 +0200 | [diff] [blame] | 61 | result->i_ctime.tv_sec = result->i_mtime.tv_sec = result->i_atime.tv_sec = local_to_gmt(dir->i_sb, le32_to_cpu(dee.creation_date)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | result->i_ctime.tv_nsec = 0; |
| 63 | result->i_mtime.tv_nsec = 0; |
| 64 | result->i_atime.tv_nsec = 0; |
| 65 | hpfs_i(result)->i_ea_size = 0; |
| 66 | result->i_mode |= S_IFDIR; |
| 67 | result->i_op = &hpfs_dir_iops; |
| 68 | result->i_fop = &hpfs_dir_ops; |
| 69 | result->i_blocks = 4; |
| 70 | result->i_size = 2048; |
Miklos Szeredi | bfe8684 | 2011-10-28 14:13:29 +0200 | [diff] [blame] | 71 | set_nlink(result, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | if (dee.read_only) |
| 73 | result->i_mode &= ~0222; |
| 74 | |
Mikulas Patocka | 7d23ce3 | 2011-05-08 20:43:06 +0200 | [diff] [blame] | 75 | r = hpfs_add_dirent(dir, name, len, &dee); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | if (r == 1) |
| 77 | goto bail3; |
| 78 | if (r == -1) { |
| 79 | err = -EEXIST; |
| 80 | goto bail3; |
| 81 | } |
| 82 | fnode->len = len; |
| 83 | memcpy(fnode->name, name, len > 15 ? 15 : len); |
Mikulas Patocka | 0b69760 | 2011-05-08 20:44:26 +0200 | [diff] [blame] | 84 | fnode->up = cpu_to_le32(dir->i_ino); |
Al Viro | c4c9954 | 2012-04-06 14:30:07 -0400 | [diff] [blame] | 85 | fnode->flags |= FNODE_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | fnode->btree.n_free_nodes = 7; |
| 87 | fnode->btree.n_used_nodes = 1; |
Mikulas Patocka | 0b69760 | 2011-05-08 20:44:26 +0200 | [diff] [blame] | 88 | fnode->btree.first_free = cpu_to_le16(0x14); |
| 89 | fnode->u.external[0].disk_secno = cpu_to_le32(dno); |
| 90 | fnode->u.external[0].file_secno = cpu_to_le32(-1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | dnode->root_dnode = 1; |
Mikulas Patocka | 0b69760 | 2011-05-08 20:44:26 +0200 | [diff] [blame] | 92 | dnode->up = cpu_to_le32(fno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | de = hpfs_add_de(dir->i_sb, dnode, "\001\001", 2, 0); |
Arnd Bergmann | f08957d0 | 2018-08-17 15:43:54 -0700 | [diff] [blame^] | 94 | de->creation_date = de->write_date = de->read_date = cpu_to_le32(local_get_seconds(dir->i_sb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | if (!(mode & 0222)) de->read_only = 1; |
| 96 | de->first = de->directory = 1; |
| 97 | /*de->hidden = de->system = 0;*/ |
Mikulas Patocka | 0b69760 | 2011-05-08 20:44:26 +0200 | [diff] [blame] | 98 | de->fnode = cpu_to_le32(fno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | mark_buffer_dirty(bh); |
| 100 | brelse(bh); |
| 101 | hpfs_mark_4buffers_dirty(&qbh0); |
| 102 | hpfs_brelse4(&qbh0); |
Dave Hansen | d8c76e6 | 2006-09-30 23:29:04 -0700 | [diff] [blame] | 103 | inc_nlink(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | insert_inode_hash(result); |
| 105 | |
Eric W. Biederman | 0e1a43c | 2012-02-07 16:27:53 -0800 | [diff] [blame] | 106 | if (!uid_eq(result->i_uid, current_fsuid()) || |
| 107 | !gid_eq(result->i_gid, current_fsgid()) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | result->i_mode != (mode | S_IFDIR)) { |
David Howells | de395b8 | 2008-11-14 10:38:55 +1100 | [diff] [blame] | 109 | result->i_uid = current_fsuid(); |
| 110 | result->i_gid = current_fsgid(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | result->i_mode = mode | S_IFDIR; |
| 112 | hpfs_write_inode_nolock(result); |
| 113 | } |
Mikulas Patocka | f49a26e | 2015-09-02 22:51:53 +0200 | [diff] [blame] | 114 | hpfs_update_directory_times(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | d_instantiate(dentry, result); |
Arnd Bergmann | 9a311b9 | 2011-01-22 20:26:12 +0100 | [diff] [blame] | 116 | hpfs_unlock(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | return 0; |
| 118 | bail3: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | iput(result); |
| 120 | bail2: |
| 121 | hpfs_brelse4(&qbh0); |
| 122 | hpfs_free_dnode(dir->i_sb, dno); |
| 123 | bail1: |
| 124 | brelse(bh); |
| 125 | hpfs_free_sectors(dir->i_sb, fno, 1); |
| 126 | bail: |
Arnd Bergmann | 9a311b9 | 2011-01-22 20:26:12 +0100 | [diff] [blame] | 127 | hpfs_unlock(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | return err; |
| 129 | } |
| 130 | |
Al Viro | ebfc3b4 | 2012-06-10 18:05:36 -0400 | [diff] [blame] | 131 | static int hpfs_create(struct inode *dir, struct dentry *dentry, umode_t mode, bool excl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | { |
Al Viro | 7e7742e | 2010-01-31 17:09:29 -0500 | [diff] [blame] | 133 | const unsigned char *name = dentry->d_name.name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | unsigned len = dentry->d_name.len; |
| 135 | struct inode *result = NULL; |
| 136 | struct buffer_head *bh; |
| 137 | struct fnode *fnode; |
| 138 | fnode_secno fno; |
| 139 | int r; |
| 140 | struct hpfs_dirent dee; |
| 141 | int err; |
Al Viro | 7e7742e | 2010-01-31 17:09:29 -0500 | [diff] [blame] | 142 | if ((err = hpfs_chk_name(name, &len))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | return err==-ENOENT ? -EINVAL : err; |
Arnd Bergmann | 9a311b9 | 2011-01-22 20:26:12 +0100 | [diff] [blame] | 144 | hpfs_lock(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | err = -ENOSPC; |
| 146 | fnode = hpfs_alloc_fnode(dir->i_sb, hpfs_i(dir)->i_dno, &fno, &bh); |
| 147 | if (!fnode) |
| 148 | goto bail; |
| 149 | memset(&dee, 0, sizeof dee); |
| 150 | if (!(mode & 0222)) dee.read_only = 1; |
| 151 | dee.archive = 1; |
| 152 | dee.hidden = name[0] == '.'; |
Mikulas Patocka | 0b69760 | 2011-05-08 20:44:26 +0200 | [diff] [blame] | 153 | dee.fnode = cpu_to_le32(fno); |
Arnd Bergmann | f08957d0 | 2018-08-17 15:43:54 -0700 | [diff] [blame^] | 154 | dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(local_get_seconds(dir->i_sb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
| 156 | result = new_inode(dir->i_sb); |
| 157 | if (!result) |
| 158 | goto bail1; |
| 159 | |
| 160 | hpfs_init_inode(result); |
| 161 | result->i_ino = fno; |
| 162 | result->i_mode |= S_IFREG; |
| 163 | result->i_mode &= ~0111; |
| 164 | result->i_op = &hpfs_file_iops; |
| 165 | result->i_fop = &hpfs_file_ops; |
Miklos Szeredi | bfe8684 | 2011-10-28 14:13:29 +0200 | [diff] [blame] | 166 | set_nlink(result, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | hpfs_i(result)->i_parent_dir = dir->i_ino; |
Mikulas Patocka | 0b69760 | 2011-05-08 20:44:26 +0200 | [diff] [blame] | 168 | result->i_ctime.tv_sec = result->i_mtime.tv_sec = result->i_atime.tv_sec = local_to_gmt(dir->i_sb, le32_to_cpu(dee.creation_date)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | result->i_ctime.tv_nsec = 0; |
| 170 | result->i_mtime.tv_nsec = 0; |
| 171 | result->i_atime.tv_nsec = 0; |
| 172 | hpfs_i(result)->i_ea_size = 0; |
| 173 | if (dee.read_only) |
| 174 | result->i_mode &= ~0222; |
| 175 | result->i_blocks = 1; |
| 176 | result->i_size = 0; |
| 177 | result->i_data.a_ops = &hpfs_aops; |
| 178 | hpfs_i(result)->mmu_private = 0; |
| 179 | |
Mikulas Patocka | 7d23ce3 | 2011-05-08 20:43:06 +0200 | [diff] [blame] | 180 | r = hpfs_add_dirent(dir, name, len, &dee); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | if (r == 1) |
| 182 | goto bail2; |
| 183 | if (r == -1) { |
| 184 | err = -EEXIST; |
| 185 | goto bail2; |
| 186 | } |
| 187 | fnode->len = len; |
| 188 | memcpy(fnode->name, name, len > 15 ? 15 : len); |
Mikulas Patocka | 0b69760 | 2011-05-08 20:44:26 +0200 | [diff] [blame] | 189 | fnode->up = cpu_to_le32(dir->i_ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | mark_buffer_dirty(bh); |
| 191 | brelse(bh); |
| 192 | |
| 193 | insert_inode_hash(result); |
| 194 | |
Eric W. Biederman | 0e1a43c | 2012-02-07 16:27:53 -0800 | [diff] [blame] | 195 | if (!uid_eq(result->i_uid, current_fsuid()) || |
| 196 | !gid_eq(result->i_gid, current_fsgid()) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | result->i_mode != (mode | S_IFREG)) { |
David Howells | de395b8 | 2008-11-14 10:38:55 +1100 | [diff] [blame] | 198 | result->i_uid = current_fsuid(); |
| 199 | result->i_gid = current_fsgid(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | result->i_mode = mode | S_IFREG; |
| 201 | hpfs_write_inode_nolock(result); |
| 202 | } |
Mikulas Patocka | f49a26e | 2015-09-02 22:51:53 +0200 | [diff] [blame] | 203 | hpfs_update_directory_times(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | d_instantiate(dentry, result); |
Arnd Bergmann | 9a311b9 | 2011-01-22 20:26:12 +0100 | [diff] [blame] | 205 | hpfs_unlock(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | return 0; |
| 207 | |
| 208 | bail2: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | iput(result); |
| 210 | bail1: |
| 211 | brelse(bh); |
| 212 | hpfs_free_sectors(dir->i_sb, fno, 1); |
| 213 | bail: |
Arnd Bergmann | 9a311b9 | 2011-01-22 20:26:12 +0100 | [diff] [blame] | 214 | hpfs_unlock(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | return err; |
| 216 | } |
| 217 | |
Al Viro | 1a67aaf | 2011-07-26 01:52:52 -0400 | [diff] [blame] | 218 | static int hpfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | { |
Al Viro | 7e7742e | 2010-01-31 17:09:29 -0500 | [diff] [blame] | 220 | const unsigned char *name = dentry->d_name.name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | unsigned len = dentry->d_name.len; |
| 222 | struct buffer_head *bh; |
| 223 | struct fnode *fnode; |
| 224 | fnode_secno fno; |
| 225 | int r; |
| 226 | struct hpfs_dirent dee; |
| 227 | struct inode *result = NULL; |
| 228 | int err; |
Al Viro | 7e7742e | 2010-01-31 17:09:29 -0500 | [diff] [blame] | 229 | if ((err = hpfs_chk_name(name, &len))) return err==-ENOENT ? -EINVAL : err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | if (hpfs_sb(dir->i_sb)->sb_eas < 2) return -EPERM; |
Arnd Bergmann | 9a311b9 | 2011-01-22 20:26:12 +0100 | [diff] [blame] | 231 | hpfs_lock(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | err = -ENOSPC; |
| 233 | fnode = hpfs_alloc_fnode(dir->i_sb, hpfs_i(dir)->i_dno, &fno, &bh); |
| 234 | if (!fnode) |
| 235 | goto bail; |
| 236 | memset(&dee, 0, sizeof dee); |
| 237 | if (!(mode & 0222)) dee.read_only = 1; |
| 238 | dee.archive = 1; |
| 239 | dee.hidden = name[0] == '.'; |
Mikulas Patocka | 0b69760 | 2011-05-08 20:44:26 +0200 | [diff] [blame] | 240 | dee.fnode = cpu_to_le32(fno); |
Arnd Bergmann | f08957d0 | 2018-08-17 15:43:54 -0700 | [diff] [blame^] | 241 | dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(local_get_seconds(dir->i_sb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
| 243 | result = new_inode(dir->i_sb); |
| 244 | if (!result) |
| 245 | goto bail1; |
| 246 | |
| 247 | hpfs_init_inode(result); |
| 248 | result->i_ino = fno; |
| 249 | hpfs_i(result)->i_parent_dir = dir->i_ino; |
Mikulas Patocka | 0b69760 | 2011-05-08 20:44:26 +0200 | [diff] [blame] | 250 | result->i_ctime.tv_sec = result->i_mtime.tv_sec = result->i_atime.tv_sec = local_to_gmt(dir->i_sb, le32_to_cpu(dee.creation_date)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | result->i_ctime.tv_nsec = 0; |
| 252 | result->i_mtime.tv_nsec = 0; |
| 253 | result->i_atime.tv_nsec = 0; |
| 254 | hpfs_i(result)->i_ea_size = 0; |
David Howells | de395b8 | 2008-11-14 10:38:55 +1100 | [diff] [blame] | 255 | result->i_uid = current_fsuid(); |
| 256 | result->i_gid = current_fsgid(); |
Miklos Szeredi | bfe8684 | 2011-10-28 14:13:29 +0200 | [diff] [blame] | 257 | set_nlink(result, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | result->i_size = 0; |
| 259 | result->i_blocks = 1; |
| 260 | init_special_inode(result, mode, rdev); |
| 261 | |
Mikulas Patocka | 7d23ce3 | 2011-05-08 20:43:06 +0200 | [diff] [blame] | 262 | r = hpfs_add_dirent(dir, name, len, &dee); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | if (r == 1) |
| 264 | goto bail2; |
| 265 | if (r == -1) { |
| 266 | err = -EEXIST; |
| 267 | goto bail2; |
| 268 | } |
| 269 | fnode->len = len; |
| 270 | memcpy(fnode->name, name, len > 15 ? 15 : len); |
Mikulas Patocka | 0b69760 | 2011-05-08 20:44:26 +0200 | [diff] [blame] | 271 | fnode->up = cpu_to_le32(dir->i_ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | mark_buffer_dirty(bh); |
| 273 | |
| 274 | insert_inode_hash(result); |
| 275 | |
| 276 | hpfs_write_inode_nolock(result); |
Mikulas Patocka | f49a26e | 2015-09-02 22:51:53 +0200 | [diff] [blame] | 277 | hpfs_update_directory_times(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | d_instantiate(dentry, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | brelse(bh); |
Arnd Bergmann | 9a311b9 | 2011-01-22 20:26:12 +0100 | [diff] [blame] | 280 | hpfs_unlock(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | return 0; |
| 282 | bail2: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | iput(result); |
| 284 | bail1: |
| 285 | brelse(bh); |
| 286 | hpfs_free_sectors(dir->i_sb, fno, 1); |
| 287 | bail: |
Arnd Bergmann | 9a311b9 | 2011-01-22 20:26:12 +0100 | [diff] [blame] | 288 | hpfs_unlock(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | return err; |
| 290 | } |
| 291 | |
| 292 | static int hpfs_symlink(struct inode *dir, struct dentry *dentry, const char *symlink) |
| 293 | { |
Al Viro | 7e7742e | 2010-01-31 17:09:29 -0500 | [diff] [blame] | 294 | const unsigned char *name = dentry->d_name.name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | unsigned len = dentry->d_name.len; |
| 296 | struct buffer_head *bh; |
| 297 | struct fnode *fnode; |
| 298 | fnode_secno fno; |
| 299 | int r; |
| 300 | struct hpfs_dirent dee; |
| 301 | struct inode *result; |
| 302 | int err; |
Al Viro | 7e7742e | 2010-01-31 17:09:29 -0500 | [diff] [blame] | 303 | if ((err = hpfs_chk_name(name, &len))) return err==-ENOENT ? -EINVAL : err; |
Arnd Bergmann | 9a311b9 | 2011-01-22 20:26:12 +0100 | [diff] [blame] | 304 | hpfs_lock(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | if (hpfs_sb(dir->i_sb)->sb_eas < 2) { |
Arnd Bergmann | 9a311b9 | 2011-01-22 20:26:12 +0100 | [diff] [blame] | 306 | hpfs_unlock(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | return -EPERM; |
| 308 | } |
| 309 | err = -ENOSPC; |
| 310 | fnode = hpfs_alloc_fnode(dir->i_sb, hpfs_i(dir)->i_dno, &fno, &bh); |
| 311 | if (!fnode) |
| 312 | goto bail; |
| 313 | memset(&dee, 0, sizeof dee); |
| 314 | dee.archive = 1; |
| 315 | dee.hidden = name[0] == '.'; |
Mikulas Patocka | 0b69760 | 2011-05-08 20:44:26 +0200 | [diff] [blame] | 316 | dee.fnode = cpu_to_le32(fno); |
Arnd Bergmann | f08957d0 | 2018-08-17 15:43:54 -0700 | [diff] [blame^] | 317 | dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(local_get_seconds(dir->i_sb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
| 319 | result = new_inode(dir->i_sb); |
| 320 | if (!result) |
| 321 | goto bail1; |
| 322 | result->i_ino = fno; |
| 323 | hpfs_init_inode(result); |
| 324 | hpfs_i(result)->i_parent_dir = dir->i_ino; |
Mikulas Patocka | 0b69760 | 2011-05-08 20:44:26 +0200 | [diff] [blame] | 325 | result->i_ctime.tv_sec = result->i_mtime.tv_sec = result->i_atime.tv_sec = local_to_gmt(dir->i_sb, le32_to_cpu(dee.creation_date)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | result->i_ctime.tv_nsec = 0; |
| 327 | result->i_mtime.tv_nsec = 0; |
| 328 | result->i_atime.tv_nsec = 0; |
| 329 | hpfs_i(result)->i_ea_size = 0; |
| 330 | result->i_mode = S_IFLNK | 0777; |
David Howells | de395b8 | 2008-11-14 10:38:55 +1100 | [diff] [blame] | 331 | result->i_uid = current_fsuid(); |
| 332 | result->i_gid = current_fsgid(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | result->i_blocks = 1; |
Miklos Szeredi | bfe8684 | 2011-10-28 14:13:29 +0200 | [diff] [blame] | 334 | set_nlink(result, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | result->i_size = strlen(symlink); |
Al Viro | 21fc61c | 2015-11-17 01:07:57 -0500 | [diff] [blame] | 336 | inode_nohighmem(result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | result->i_op = &page_symlink_inode_operations; |
| 338 | result->i_data.a_ops = &hpfs_symlink_aops; |
| 339 | |
Mikulas Patocka | 7d23ce3 | 2011-05-08 20:43:06 +0200 | [diff] [blame] | 340 | r = hpfs_add_dirent(dir, name, len, &dee); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | if (r == 1) |
| 342 | goto bail2; |
| 343 | if (r == -1) { |
| 344 | err = -EEXIST; |
| 345 | goto bail2; |
| 346 | } |
| 347 | fnode->len = len; |
| 348 | memcpy(fnode->name, name, len > 15 ? 15 : len); |
Mikulas Patocka | 0b69760 | 2011-05-08 20:44:26 +0200 | [diff] [blame] | 349 | fnode->up = cpu_to_le32(dir->i_ino); |
Al Viro | 7e7742e | 2010-01-31 17:09:29 -0500 | [diff] [blame] | 350 | hpfs_set_ea(result, fnode, "SYMLINK", symlink, strlen(symlink)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | mark_buffer_dirty(bh); |
| 352 | brelse(bh); |
| 353 | |
| 354 | insert_inode_hash(result); |
| 355 | |
| 356 | hpfs_write_inode_nolock(result); |
Mikulas Patocka | f49a26e | 2015-09-02 22:51:53 +0200 | [diff] [blame] | 357 | hpfs_update_directory_times(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | d_instantiate(dentry, result); |
Arnd Bergmann | 9a311b9 | 2011-01-22 20:26:12 +0100 | [diff] [blame] | 359 | hpfs_unlock(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | return 0; |
| 361 | bail2: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | iput(result); |
| 363 | bail1: |
| 364 | brelse(bh); |
| 365 | hpfs_free_sectors(dir->i_sb, fno, 1); |
| 366 | bail: |
Arnd Bergmann | 9a311b9 | 2011-01-22 20:26:12 +0100 | [diff] [blame] | 367 | hpfs_unlock(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | return err; |
| 369 | } |
| 370 | |
| 371 | static int hpfs_unlink(struct inode *dir, struct dentry *dentry) |
| 372 | { |
Al Viro | 7e7742e | 2010-01-31 17:09:29 -0500 | [diff] [blame] | 373 | const unsigned char *name = dentry->d_name.name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | unsigned len = dentry->d_name.len; |
| 375 | struct quad_buffer_head qbh; |
| 376 | struct hpfs_dirent *de; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 377 | struct inode *inode = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | dnode_secno dno; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | int r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | int err; |
| 381 | |
Arnd Bergmann | 9a311b9 | 2011-01-22 20:26:12 +0100 | [diff] [blame] | 382 | hpfs_lock(dir->i_sb); |
Al Viro | 7e7742e | 2010-01-31 17:09:29 -0500 | [diff] [blame] | 383 | hpfs_adjust_length(name, &len); |
Mikulas Patocka | b6853f7 | 2016-02-25 18:17:38 +0100 | [diff] [blame] | 384 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | err = -ENOENT; |
Al Viro | 7e7742e | 2010-01-31 17:09:29 -0500 | [diff] [blame] | 386 | de = map_dirent(dir, hpfs_i(dir)->i_dno, name, len, &dno, &qbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | if (!de) |
| 388 | goto out; |
| 389 | |
| 390 | err = -EPERM; |
| 391 | if (de->first) |
| 392 | goto out1; |
| 393 | |
| 394 | err = -EISDIR; |
| 395 | if (de->directory) |
| 396 | goto out1; |
| 397 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | r = hpfs_remove_dirent(dir, dno, de, &qbh, 1); |
| 399 | switch (r) { |
| 400 | case 1: |
| 401 | hpfs_error(dir->i_sb, "there was error when removing dirent"); |
| 402 | err = -EFSERROR; |
| 403 | break; |
Mikulas Patocka | b6853f7 | 2016-02-25 18:17:38 +0100 | [diff] [blame] | 404 | case 2: /* no space for deleting */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | err = -ENOSPC; |
Mikulas Patocka | b6853f7 | 2016-02-25 18:17:38 +0100 | [diff] [blame] | 406 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | default: |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 408 | drop_nlink(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | err = 0; |
| 410 | } |
| 411 | goto out; |
| 412 | |
| 413 | out1: |
| 414 | hpfs_brelse4(&qbh); |
| 415 | out: |
Mikulas Patocka | f49a26e | 2015-09-02 22:51:53 +0200 | [diff] [blame] | 416 | if (!err) |
| 417 | hpfs_update_directory_times(dir); |
Arnd Bergmann | 9a311b9 | 2011-01-22 20:26:12 +0100 | [diff] [blame] | 418 | hpfs_unlock(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | return err; |
| 420 | } |
| 421 | |
| 422 | static int hpfs_rmdir(struct inode *dir, struct dentry *dentry) |
| 423 | { |
Al Viro | 7e7742e | 2010-01-31 17:09:29 -0500 | [diff] [blame] | 424 | const unsigned char *name = dentry->d_name.name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | unsigned len = dentry->d_name.len; |
| 426 | struct quad_buffer_head qbh; |
| 427 | struct hpfs_dirent *de; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 428 | struct inode *inode = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | dnode_secno dno; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | int n_items = 0; |
| 431 | int err; |
| 432 | int r; |
| 433 | |
Al Viro | 7e7742e | 2010-01-31 17:09:29 -0500 | [diff] [blame] | 434 | hpfs_adjust_length(name, &len); |
Arnd Bergmann | 9a311b9 | 2011-01-22 20:26:12 +0100 | [diff] [blame] | 435 | hpfs_lock(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | err = -ENOENT; |
Al Viro | 7e7742e | 2010-01-31 17:09:29 -0500 | [diff] [blame] | 437 | de = map_dirent(dir, hpfs_i(dir)->i_dno, name, len, &dno, &qbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | if (!de) |
| 439 | goto out; |
| 440 | |
| 441 | err = -EPERM; |
| 442 | if (de->first) |
| 443 | goto out1; |
| 444 | |
| 445 | err = -ENOTDIR; |
| 446 | if (!de->directory) |
| 447 | goto out1; |
| 448 | |
| 449 | hpfs_count_dnodes(dir->i_sb, hpfs_i(inode)->i_dno, NULL, NULL, &n_items); |
| 450 | err = -ENOTEMPTY; |
| 451 | if (n_items) |
| 452 | goto out1; |
| 453 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | r = hpfs_remove_dirent(dir, dno, de, &qbh, 1); |
| 455 | switch (r) { |
| 456 | case 1: |
| 457 | hpfs_error(dir->i_sb, "there was error when removing dirent"); |
| 458 | err = -EFSERROR; |
| 459 | break; |
| 460 | case 2: |
| 461 | err = -ENOSPC; |
| 462 | break; |
| 463 | default: |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 464 | drop_nlink(dir); |
Dave Hansen | ce71ec3 | 2006-09-30 23:29:06 -0700 | [diff] [blame] | 465 | clear_nlink(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | err = 0; |
| 467 | } |
| 468 | goto out; |
| 469 | out1: |
| 470 | hpfs_brelse4(&qbh); |
| 471 | out: |
Mikulas Patocka | f49a26e | 2015-09-02 22:51:53 +0200 | [diff] [blame] | 472 | if (!err) |
| 473 | hpfs_update_directory_times(dir); |
Arnd Bergmann | 9a311b9 | 2011-01-22 20:26:12 +0100 | [diff] [blame] | 474 | hpfs_unlock(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | return err; |
| 476 | } |
| 477 | |
| 478 | static int hpfs_symlink_readpage(struct file *file, struct page *page) |
| 479 | { |
Al Viro | 21fc61c | 2015-11-17 01:07:57 -0500 | [diff] [blame] | 480 | char *link = page_address(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | struct inode *i = page->mapping->host; |
| 482 | struct fnode *fnode; |
| 483 | struct buffer_head *bh; |
| 484 | int err; |
| 485 | |
| 486 | err = -EIO; |
Arnd Bergmann | 9a311b9 | 2011-01-22 20:26:12 +0100 | [diff] [blame] | 487 | hpfs_lock(i->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | if (!(fnode = hpfs_map_fnode(i->i_sb, i->i_ino, &bh))) |
| 489 | goto fail; |
| 490 | err = hpfs_read_ea(i->i_sb, fnode, "SYMLINK", link, PAGE_SIZE); |
| 491 | brelse(bh); |
| 492 | if (err) |
| 493 | goto fail; |
Arnd Bergmann | 9a311b9 | 2011-01-22 20:26:12 +0100 | [diff] [blame] | 494 | hpfs_unlock(i->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | SetPageUptodate(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | unlock_page(page); |
| 497 | return 0; |
| 498 | |
| 499 | fail: |
Arnd Bergmann | 9a311b9 | 2011-01-22 20:26:12 +0100 | [diff] [blame] | 500 | hpfs_unlock(i->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | SetPageError(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | unlock_page(page); |
| 503 | return err; |
| 504 | } |
| 505 | |
Christoph Hellwig | f5e54d6 | 2006-06-28 04:26:44 -0700 | [diff] [blame] | 506 | const struct address_space_operations hpfs_symlink_aops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | .readpage = hpfs_symlink_readpage |
| 508 | }; |
| 509 | |
| 510 | static int hpfs_rename(struct inode *old_dir, struct dentry *old_dentry, |
Miklos Szeredi | f03b8ad | 2016-09-27 11:03:57 +0200 | [diff] [blame] | 511 | struct inode *new_dir, struct dentry *new_dentry, |
| 512 | unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | { |
Al Viro | 7e7742e | 2010-01-31 17:09:29 -0500 | [diff] [blame] | 514 | const unsigned char *old_name = old_dentry->d_name.name; |
| 515 | unsigned old_len = old_dentry->d_name.len; |
| 516 | const unsigned char *new_name = new_dentry->d_name.name; |
| 517 | unsigned new_len = new_dentry->d_name.len; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 518 | struct inode *i = d_inode(old_dentry); |
| 519 | struct inode *new_inode = d_inode(new_dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | struct quad_buffer_head qbh, qbh1; |
| 521 | struct hpfs_dirent *dep, *nde; |
| 522 | struct hpfs_dirent de; |
| 523 | dnode_secno dno; |
| 524 | int r; |
| 525 | struct buffer_head *bh; |
| 526 | struct fnode *fnode; |
| 527 | int err; |
Sage Weil | e4eaac0 | 2011-05-24 13:06:07 -0700 | [diff] [blame] | 528 | |
Miklos Szeredi | f03b8ad | 2016-09-27 11:03:57 +0200 | [diff] [blame] | 529 | if (flags & ~RENAME_NOREPLACE) |
| 530 | return -EINVAL; |
| 531 | |
Al Viro | 7e7742e | 2010-01-31 17:09:29 -0500 | [diff] [blame] | 532 | if ((err = hpfs_chk_name(new_name, &new_len))) return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | err = 0; |
Al Viro | 7e7742e | 2010-01-31 17:09:29 -0500 | [diff] [blame] | 534 | hpfs_adjust_length(old_name, &old_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | |
Arnd Bergmann | 9a311b9 | 2011-01-22 20:26:12 +0100 | [diff] [blame] | 536 | hpfs_lock(i->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | /* order doesn't matter, due to VFS exclusion */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | |
| 539 | /* Erm? Moving over the empty non-busy directory is perfectly legal */ |
| 540 | if (new_inode && S_ISDIR(new_inode->i_mode)) { |
| 541 | err = -EINVAL; |
| 542 | goto end1; |
| 543 | } |
| 544 | |
Al Viro | 7e7742e | 2010-01-31 17:09:29 -0500 | [diff] [blame] | 545 | if (!(dep = map_dirent(old_dir, hpfs_i(old_dir)->i_dno, old_name, old_len, &dno, &qbh))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | hpfs_error(i->i_sb, "lookup succeeded but map dirent failed"); |
| 547 | err = -ENOENT; |
| 548 | goto end1; |
| 549 | } |
| 550 | copy_de(&de, dep); |
| 551 | de.hidden = new_name[0] == '.'; |
| 552 | |
| 553 | if (new_inode) { |
| 554 | int r; |
| 555 | if ((r = hpfs_remove_dirent(old_dir, dno, dep, &qbh, 1)) != 2) { |
Al Viro | 7e7742e | 2010-01-31 17:09:29 -0500 | [diff] [blame] | 556 | if ((nde = map_dirent(new_dir, hpfs_i(new_dir)->i_dno, new_name, new_len, NULL, &qbh1))) { |
Dave Hansen | ce71ec3 | 2006-09-30 23:29:06 -0700 | [diff] [blame] | 557 | clear_nlink(new_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | copy_de(nde, &de); |
| 559 | memcpy(nde->name, new_name, new_len); |
| 560 | hpfs_mark_4buffers_dirty(&qbh1); |
| 561 | hpfs_brelse4(&qbh1); |
| 562 | goto end; |
| 563 | } |
| 564 | hpfs_error(new_dir->i_sb, "hpfs_rename: could not find dirent"); |
| 565 | err = -EFSERROR; |
| 566 | goto end1; |
| 567 | } |
| 568 | err = r == 2 ? -ENOSPC : r == 1 ? -EFSERROR : 0; |
| 569 | goto end1; |
| 570 | } |
| 571 | |
| 572 | if (new_dir == old_dir) hpfs_brelse4(&qbh); |
| 573 | |
Mikulas Patocka | 7d23ce3 | 2011-05-08 20:43:06 +0200 | [diff] [blame] | 574 | if ((r = hpfs_add_dirent(new_dir, new_name, new_len, &de))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | if (r == -1) hpfs_error(new_dir->i_sb, "hpfs_rename: dirent already exists!"); |
| 576 | err = r == 1 ? -ENOSPC : -EFSERROR; |
| 577 | if (new_dir != old_dir) hpfs_brelse4(&qbh); |
| 578 | goto end1; |
| 579 | } |
| 580 | |
| 581 | if (new_dir == old_dir) |
Al Viro | 7e7742e | 2010-01-31 17:09:29 -0500 | [diff] [blame] | 582 | if (!(dep = map_dirent(old_dir, hpfs_i(old_dir)->i_dno, old_name, old_len, &dno, &qbh))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | hpfs_error(i->i_sb, "lookup succeeded but map dirent failed at #2"); |
| 584 | err = -ENOENT; |
| 585 | goto end1; |
| 586 | } |
| 587 | |
| 588 | if ((r = hpfs_remove_dirent(old_dir, dno, dep, &qbh, 0))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | hpfs_error(i->i_sb, "hpfs_rename: could not remove dirent"); |
| 590 | err = r == 2 ? -ENOSPC : -EFSERROR; |
| 591 | goto end1; |
| 592 | } |
Mikulas Patocka | 7d23ce3 | 2011-05-08 20:43:06 +0200 | [diff] [blame] | 593 | |
Mikulas Patocka | f49a26e | 2015-09-02 22:51:53 +0200 | [diff] [blame] | 594 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | hpfs_i(i)->i_parent_dir = new_dir->i_ino; |
| 596 | if (S_ISDIR(i->i_mode)) { |
Dave Hansen | d8c76e6 | 2006-09-30 23:29:04 -0700 | [diff] [blame] | 597 | inc_nlink(new_dir); |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 598 | drop_nlink(old_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | } |
| 600 | if ((fnode = hpfs_map_fnode(i->i_sb, i->i_ino, &bh))) { |
Mikulas Patocka | 0b69760 | 2011-05-08 20:44:26 +0200 | [diff] [blame] | 601 | fnode->up = cpu_to_le32(new_dir->i_ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | fnode->len = new_len; |
| 603 | memcpy(fnode->name, new_name, new_len>15?15:new_len); |
| 604 | if (new_len < 15) memset(&fnode->name[new_len], 0, 15 - new_len); |
| 605 | mark_buffer_dirty(bh); |
| 606 | brelse(bh); |
| 607 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | end1: |
Mikulas Patocka | f49a26e | 2015-09-02 22:51:53 +0200 | [diff] [blame] | 609 | if (!err) { |
| 610 | hpfs_update_directory_times(old_dir); |
| 611 | hpfs_update_directory_times(new_dir); |
| 612 | } |
Arnd Bergmann | 9a311b9 | 2011-01-22 20:26:12 +0100 | [diff] [blame] | 613 | hpfs_unlock(i->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | return err; |
| 615 | } |
| 616 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 617 | const struct inode_operations hpfs_dir_iops = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | { |
| 619 | .create = hpfs_create, |
| 620 | .lookup = hpfs_lookup, |
| 621 | .unlink = hpfs_unlink, |
| 622 | .symlink = hpfs_symlink, |
| 623 | .mkdir = hpfs_mkdir, |
| 624 | .rmdir = hpfs_rmdir, |
| 625 | .mknod = hpfs_mknod, |
Miklos Szeredi | 2773bf0 | 2016-09-27 11:03:58 +0200 | [diff] [blame] | 626 | .rename = hpfs_rename, |
Christoph Hellwig | ca30bc9 | 2008-08-11 00:27:59 +0200 | [diff] [blame] | 627 | .setattr = hpfs_setattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | }; |