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/sysv/dir.c |
| 4 | * |
| 5 | * minix/dir.c |
| 6 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 7 | * |
| 8 | * coh/dir.c |
| 9 | * Copyright (C) 1993 Pascal Haible, Bruno Haible |
| 10 | * |
| 11 | * sysv/dir.c |
| 12 | * Copyright (C) 1993 Bruno Haible |
| 13 | * |
| 14 | * SystemV/Coherent directory handling functions |
| 15 | */ |
| 16 | |
| 17 | #include <linux/pagemap.h> |
| 18 | #include <linux/highmem.h> |
Nick Piggin | 26a6441 | 2007-10-16 01:25:21 -0700 | [diff] [blame] | 19 | #include <linux/swap.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include "sysv.h" |
| 21 | |
Al Viro | 8088629 | 2013-05-15 18:51:49 -0400 | [diff] [blame] | 22 | static int sysv_readdir(struct file *, struct dir_context *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 24 | const struct file_operations sysv_dir_operations = { |
Al Viro | 5ac3455 | 2009-06-16 23:59:37 -0400 | [diff] [blame] | 25 | .llseek = generic_file_llseek, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | .read = generic_read_dir, |
Al Viro | 3b0a3c1 | 2016-04-20 23:42:46 -0400 | [diff] [blame] | 27 | .iterate_shared = sysv_readdir, |
Christoph Hellwig | 1b061d9 | 2010-05-26 17:53:41 +0200 | [diff] [blame] | 28 | .fsync = generic_file_fsync, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | }; |
| 30 | |
| 31 | static inline void dir_put_page(struct page *page) |
| 32 | { |
| 33 | kunmap(page); |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 34 | put_page(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Nick Piggin | 26a6441 | 2007-10-16 01:25:21 -0700 | [diff] [blame] | 37 | static int dir_commit_chunk(struct page *page, loff_t pos, unsigned len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | { |
Nick Piggin | 26a6441 | 2007-10-16 01:25:21 -0700 | [diff] [blame] | 39 | struct address_space *mapping = page->mapping; |
| 40 | struct inode *dir = mapping->host; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | int err = 0; |
| 42 | |
Nick Piggin | 26a6441 | 2007-10-16 01:25:21 -0700 | [diff] [blame] | 43 | block_write_end(NULL, mapping, pos, len, len, page, NULL); |
| 44 | if (pos+len > dir->i_size) { |
| 45 | i_size_write(dir, pos+len); |
| 46 | mark_inode_dirty(dir); |
| 47 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | if (IS_DIRSYNC(dir)) |
Jeff Layton | 2b69c82 | 2017-07-05 15:26:48 -0400 | [diff] [blame] | 49 | err = write_one_page(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | else |
| 51 | unlock_page(page); |
| 52 | return err; |
| 53 | } |
| 54 | |
| 55 | static struct page * dir_get_page(struct inode *dir, unsigned long n) |
| 56 | { |
| 57 | struct address_space *mapping = dir->i_mapping; |
Pekka Enberg | 090d2b1 | 2006-06-23 02:05:08 -0700 | [diff] [blame] | 58 | struct page *page = read_mapping_page(mapping, n, NULL); |
Nick Piggin | 6fe6900 | 2007-05-06 14:49:04 -0700 | [diff] [blame] | 59 | if (!IS_ERR(page)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | kmap(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | return page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Al Viro | 8088629 | 2013-05-15 18:51:49 -0400 | [diff] [blame] | 64 | static int sysv_readdir(struct file *file, struct dir_context *ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | { |
Al Viro | 8088629 | 2013-05-15 18:51:49 -0400 | [diff] [blame] | 66 | unsigned long pos = ctx->pos; |
| 67 | struct inode *inode = file_inode(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | struct super_block *sb = inode->i_sb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | unsigned long npages = dir_pages(inode); |
Al Viro | 8088629 | 2013-05-15 18:51:49 -0400 | [diff] [blame] | 70 | unsigned offset; |
| 71 | unsigned long n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
Al Viro | 8088629 | 2013-05-15 18:51:49 -0400 | [diff] [blame] | 73 | ctx->pos = pos = (pos + SYSV_DIRSIZE-1) & ~(SYSV_DIRSIZE-1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | if (pos >= inode->i_size) |
Al Viro | 8088629 | 2013-05-15 18:51:49 -0400 | [diff] [blame] | 75 | return 0; |
| 76 | |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 77 | offset = pos & ~PAGE_MASK; |
| 78 | n = pos >> PAGE_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
| 80 | for ( ; n < npages; n++, offset = 0) { |
| 81 | char *kaddr, *limit; |
| 82 | struct sysv_dir_entry *de; |
| 83 | struct page *page = dir_get_page(inode, n); |
| 84 | |
| 85 | if (IS_ERR(page)) |
| 86 | continue; |
| 87 | kaddr = (char *)page_address(page); |
| 88 | de = (struct sysv_dir_entry *)(kaddr+offset); |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 89 | limit = kaddr + PAGE_SIZE - SYSV_DIRSIZE; |
Al Viro | 8088629 | 2013-05-15 18:51:49 -0400 | [diff] [blame] | 90 | for ( ;(char*)de <= limit; de++, ctx->pos += sizeof(*de)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | char *name = de->name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
| 93 | if (!de->inode) |
| 94 | continue; |
| 95 | |
Al Viro | 8088629 | 2013-05-15 18:51:49 -0400 | [diff] [blame] | 96 | if (!dir_emit(ctx, name, strnlen(name,SYSV_NAMELEN), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | fs16_to_cpu(SYSV_SB(sb), de->inode), |
Al Viro | 8088629 | 2013-05-15 18:51:49 -0400 | [diff] [blame] | 98 | DT_UNKNOWN)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | dir_put_page(page); |
Al Viro | 8088629 | 2013-05-15 18:51:49 -0400 | [diff] [blame] | 100 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | dir_put_page(page); |
| 104 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | /* compare strings: name[0..len-1] (not zero-terminated) and |
| 109 | * buffer[0..] (filled with zeroes up to buffer[0..maxlen-1]) |
| 110 | */ |
| 111 | static inline int namecompare(int len, int maxlen, |
| 112 | const char * name, const char * buffer) |
| 113 | { |
| 114 | if (len < maxlen && buffer[len]) |
| 115 | return 0; |
| 116 | return !memcmp(name, buffer, len); |
| 117 | } |
| 118 | |
| 119 | /* |
| 120 | * sysv_find_entry() |
| 121 | * |
| 122 | * finds an entry in the specified directory with the wanted name. It |
| 123 | * returns the cache buffer in which the entry was found, and the entry |
| 124 | * itself (as a parameter - res_dir). It does NOT read the inode of the |
| 125 | * entry - you'll have to do that yourself if you want to. |
| 126 | */ |
| 127 | struct sysv_dir_entry *sysv_find_entry(struct dentry *dentry, struct page **res_page) |
| 128 | { |
| 129 | const char * name = dentry->d_name.name; |
| 130 | int namelen = dentry->d_name.len; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 131 | struct inode * dir = d_inode(dentry->d_parent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | unsigned long start, n; |
| 133 | unsigned long npages = dir_pages(dir); |
| 134 | struct page *page = NULL; |
| 135 | struct sysv_dir_entry *de; |
| 136 | |
| 137 | *res_page = NULL; |
| 138 | |
| 139 | start = SYSV_I(dir)->i_dir_start_lookup; |
| 140 | if (start >= npages) |
| 141 | start = 0; |
| 142 | n = start; |
| 143 | |
| 144 | do { |
| 145 | char *kaddr; |
| 146 | page = dir_get_page(dir, n); |
| 147 | if (!IS_ERR(page)) { |
| 148 | kaddr = (char*)page_address(page); |
| 149 | de = (struct sysv_dir_entry *) kaddr; |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 150 | kaddr += PAGE_SIZE - SYSV_DIRSIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | for ( ; (char *) de <= kaddr ; de++) { |
| 152 | if (!de->inode) |
| 153 | continue; |
| 154 | if (namecompare(namelen, SYSV_NAMELEN, |
| 155 | name, de->name)) |
| 156 | goto found; |
| 157 | } |
Dan Carpenter | 404e781 | 2010-04-21 12:30:32 +0200 | [diff] [blame] | 158 | dir_put_page(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
| 161 | if (++n >= npages) |
| 162 | n = 0; |
| 163 | } while (n != start); |
| 164 | |
| 165 | return NULL; |
| 166 | |
| 167 | found: |
| 168 | SYSV_I(dir)->i_dir_start_lookup = n; |
| 169 | *res_page = page; |
| 170 | return de; |
| 171 | } |
| 172 | |
| 173 | int sysv_add_link(struct dentry *dentry, struct inode *inode) |
| 174 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 175 | struct inode *dir = d_inode(dentry->d_parent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | const char * name = dentry->d_name.name; |
| 177 | int namelen = dentry->d_name.len; |
| 178 | struct page *page = NULL; |
| 179 | struct sysv_dir_entry * de; |
| 180 | unsigned long npages = dir_pages(dir); |
| 181 | unsigned long n; |
| 182 | char *kaddr; |
Nick Piggin | 26a6441 | 2007-10-16 01:25:21 -0700 | [diff] [blame] | 183 | loff_t pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | int err; |
| 185 | |
| 186 | /* We take care of directory expansion in the same loop */ |
| 187 | for (n = 0; n <= npages; n++) { |
| 188 | page = dir_get_page(dir, n); |
| 189 | err = PTR_ERR(page); |
| 190 | if (IS_ERR(page)) |
| 191 | goto out; |
| 192 | kaddr = (char*)page_address(page); |
| 193 | de = (struct sysv_dir_entry *)kaddr; |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 194 | kaddr += PAGE_SIZE - SYSV_DIRSIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | while ((char *)de <= kaddr) { |
| 196 | if (!de->inode) |
| 197 | goto got_it; |
| 198 | err = -EEXIST; |
| 199 | if (namecompare(namelen, SYSV_NAMELEN, name, de->name)) |
| 200 | goto out_page; |
| 201 | de++; |
| 202 | } |
| 203 | dir_put_page(page); |
| 204 | } |
| 205 | BUG(); |
| 206 | return -EINVAL; |
| 207 | |
| 208 | got_it: |
Nick Piggin | 26a6441 | 2007-10-16 01:25:21 -0700 | [diff] [blame] | 209 | pos = page_offset(page) + |
| 210 | (char*)de - (char*)page_address(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | lock_page(page); |
Christoph Hellwig | f4e420d | 2010-06-04 11:29:56 +0200 | [diff] [blame] | 212 | err = sysv_prepare_chunk(page, pos, SYSV_DIRSIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | if (err) |
| 214 | goto out_unlock; |
| 215 | memcpy (de->name, name, namelen); |
| 216 | memset (de->name + namelen, 0, SYSV_DIRSIZE - namelen - 2); |
| 217 | de->inode = cpu_to_fs16(SYSV_SB(inode->i_sb), inode->i_ino); |
Nick Piggin | 26a6441 | 2007-10-16 01:25:21 -0700 | [diff] [blame] | 218 | err = dir_commit_chunk(page, pos, SYSV_DIRSIZE); |
Deepa Dinamani | 02027d4 | 2016-09-14 07:48:05 -0700 | [diff] [blame] | 219 | dir->i_mtime = dir->i_ctime = current_time(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | mark_inode_dirty(dir); |
| 221 | out_page: |
| 222 | dir_put_page(page); |
| 223 | out: |
| 224 | return err; |
| 225 | out_unlock: |
| 226 | unlock_page(page); |
| 227 | goto out_page; |
| 228 | } |
| 229 | |
| 230 | int sysv_delete_entry(struct sysv_dir_entry *de, struct page *page) |
| 231 | { |
Christoph Hellwig | f4e420d | 2010-06-04 11:29:56 +0200 | [diff] [blame] | 232 | struct inode *inode = page->mapping->host; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | char *kaddr = (char*)page_address(page); |
Nick Piggin | 26a6441 | 2007-10-16 01:25:21 -0700 | [diff] [blame] | 234 | loff_t pos = page_offset(page) + (char *)de - kaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | int err; |
| 236 | |
| 237 | lock_page(page); |
Christoph Hellwig | f4e420d | 2010-06-04 11:29:56 +0200 | [diff] [blame] | 238 | err = sysv_prepare_chunk(page, pos, SYSV_DIRSIZE); |
Eric Sesterhenn | d6735bf | 2006-04-02 13:39:21 +0200 | [diff] [blame] | 239 | BUG_ON(err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | de->inode = 0; |
Nick Piggin | 26a6441 | 2007-10-16 01:25:21 -0700 | [diff] [blame] | 241 | err = dir_commit_chunk(page, pos, SYSV_DIRSIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | dir_put_page(page); |
Deepa Dinamani | 02027d4 | 2016-09-14 07:48:05 -0700 | [diff] [blame] | 243 | inode->i_ctime = inode->i_mtime = current_time(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | mark_inode_dirty(inode); |
| 245 | return err; |
| 246 | } |
| 247 | |
| 248 | int sysv_make_empty(struct inode *inode, struct inode *dir) |
| 249 | { |
Christoph Hellwig | f4e420d | 2010-06-04 11:29:56 +0200 | [diff] [blame] | 250 | struct page *page = grab_cache_page(inode->i_mapping, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | struct sysv_dir_entry * de; |
| 252 | char *base; |
| 253 | int err; |
| 254 | |
| 255 | if (!page) |
| 256 | return -ENOMEM; |
Christoph Hellwig | f4e420d | 2010-06-04 11:29:56 +0200 | [diff] [blame] | 257 | err = sysv_prepare_chunk(page, 0, 2 * SYSV_DIRSIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | if (err) { |
| 259 | unlock_page(page); |
| 260 | goto fail; |
| 261 | } |
Nick Piggin | 26a6441 | 2007-10-16 01:25:21 -0700 | [diff] [blame] | 262 | kmap(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
| 264 | base = (char*)page_address(page); |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 265 | memset(base, 0, PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
| 267 | de = (struct sysv_dir_entry *) base; |
| 268 | de->inode = cpu_to_fs16(SYSV_SB(inode->i_sb), inode->i_ino); |
| 269 | strcpy(de->name,"."); |
| 270 | de++; |
| 271 | de->inode = cpu_to_fs16(SYSV_SB(inode->i_sb), dir->i_ino); |
| 272 | strcpy(de->name,".."); |
| 273 | |
Nick Piggin | 26a6441 | 2007-10-16 01:25:21 -0700 | [diff] [blame] | 274 | kunmap(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | err = dir_commit_chunk(page, 0, 2 * SYSV_DIRSIZE); |
| 276 | fail: |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 277 | put_page(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | return err; |
| 279 | } |
| 280 | |
| 281 | /* |
| 282 | * routine to check that the specified directory is empty (for rmdir) |
| 283 | */ |
| 284 | int sysv_empty_dir(struct inode * inode) |
| 285 | { |
| 286 | struct super_block *sb = inode->i_sb; |
| 287 | struct page *page = NULL; |
| 288 | unsigned long i, npages = dir_pages(inode); |
| 289 | |
| 290 | for (i = 0; i < npages; i++) { |
| 291 | char *kaddr; |
| 292 | struct sysv_dir_entry * de; |
| 293 | page = dir_get_page(inode, i); |
| 294 | |
| 295 | if (IS_ERR(page)) |
| 296 | continue; |
| 297 | |
| 298 | kaddr = (char *)page_address(page); |
| 299 | de = (struct sysv_dir_entry *)kaddr; |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 300 | kaddr += PAGE_SIZE-SYSV_DIRSIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
| 302 | for ( ;(char *)de <= kaddr; de++) { |
| 303 | if (!de->inode) |
| 304 | continue; |
| 305 | /* check for . and .. */ |
| 306 | if (de->name[0] != '.') |
| 307 | goto not_empty; |
| 308 | if (!de->name[1]) { |
| 309 | if (de->inode == cpu_to_fs16(SYSV_SB(sb), |
| 310 | inode->i_ino)) |
| 311 | continue; |
| 312 | goto not_empty; |
| 313 | } |
| 314 | if (de->name[1] != '.' || de->name[2]) |
| 315 | goto not_empty; |
| 316 | } |
| 317 | dir_put_page(page); |
| 318 | } |
| 319 | return 1; |
| 320 | |
| 321 | not_empty: |
| 322 | dir_put_page(page); |
| 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | /* Releases the page */ |
| 327 | void sysv_set_link(struct sysv_dir_entry *de, struct page *page, |
| 328 | struct inode *inode) |
| 329 | { |
Christoph Hellwig | f4e420d | 2010-06-04 11:29:56 +0200 | [diff] [blame] | 330 | struct inode *dir = page->mapping->host; |
Nick Piggin | 26a6441 | 2007-10-16 01:25:21 -0700 | [diff] [blame] | 331 | loff_t pos = page_offset(page) + |
| 332 | (char *)de-(char*)page_address(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | int err; |
| 334 | |
| 335 | lock_page(page); |
Christoph Hellwig | f4e420d | 2010-06-04 11:29:56 +0200 | [diff] [blame] | 336 | err = sysv_prepare_chunk(page, pos, SYSV_DIRSIZE); |
Eric Sesterhenn | d6735bf | 2006-04-02 13:39:21 +0200 | [diff] [blame] | 337 | BUG_ON(err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | de->inode = cpu_to_fs16(SYSV_SB(inode->i_sb), inode->i_ino); |
Nick Piggin | 26a6441 | 2007-10-16 01:25:21 -0700 | [diff] [blame] | 339 | err = dir_commit_chunk(page, pos, SYSV_DIRSIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | dir_put_page(page); |
Deepa Dinamani | 02027d4 | 2016-09-14 07:48:05 -0700 | [diff] [blame] | 341 | dir->i_mtime = dir->i_ctime = current_time(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | mark_inode_dirty(dir); |
| 343 | } |
| 344 | |
| 345 | struct sysv_dir_entry * sysv_dotdot (struct inode *dir, struct page **p) |
| 346 | { |
| 347 | struct page *page = dir_get_page(dir, 0); |
| 348 | struct sysv_dir_entry *de = NULL; |
| 349 | |
| 350 | if (!IS_ERR(page)) { |
| 351 | de = (struct sysv_dir_entry*) page_address(page) + 1; |
| 352 | *p = page; |
| 353 | } |
| 354 | return de; |
| 355 | } |
| 356 | |
| 357 | ino_t sysv_inode_by_name(struct dentry *dentry) |
| 358 | { |
| 359 | struct page *page; |
| 360 | struct sysv_dir_entry *de = sysv_find_entry (dentry, &page); |
| 361 | ino_t res = 0; |
| 362 | |
| 363 | if (de) { |
| 364 | res = fs16_to_cpu(SYSV_SB(dentry->d_sb), de->inode); |
| 365 | dir_put_page(page); |
| 366 | } |
| 367 | return res; |
| 368 | } |