Blame view
fs/ufs/dir.c
15.7 KB
b24413180 License cleanup: ... |
1 |
// SPDX-License-Identifier: GPL-2.0 |
1da177e4c Linux-2.6.12-rc2 |
2 3 4 5 6 7 8 9 10 11 12 13 14 |
/* * linux/fs/ufs/ufs_dir.c * * Copyright (C) 1996 * Adrian Rodriguez (adrian@franklins-tower.rutgers.edu) * Laboratory for Computer Science Research Computing Facility * Rutgers, The State University of New Jersey * * swab support by Francois-Rene Rideau <fare@tunes.org> 19970406 * * 4.4BSD (FreeBSD) support added on February 1st 1998 by * Niels Kristian Bech Jensen <nkbj@image.dk> partially based * on code by Martin von Loewis <martin@mira.isdn.cs.tu-berlin.de>. |
b71034e5e [PATCH] ufs: dire... |
15 16 17 |
* * Migration to usage of "page cache" on May 2006 by * Evgeniy Dushistov <dushistov@mail.ru> based on ext2 code base. |
1da177e4c Linux-2.6.12-rc2 |
18 19 20 21 |
*/ #include <linux/time.h> #include <linux/fs.h> |
82b9d1d0d ufs: convert to n... |
22 |
#include <linux/swap.h> |
bb8c2d66b ufs: use new i_ve... |
23 |
#include <linux/iversion.h> |
1da177e4c Linux-2.6.12-rc2 |
24 |
|
e54205988 drop linux/ufs_fs... |
25 |
#include "ufs_fs.h" |
bcd6d4ecf ufs: move non-lay... |
26 |
#include "ufs.h" |
1da177e4c Linux-2.6.12-rc2 |
27 28 |
#include "swab.h" #include "util.h" |
1da177e4c Linux-2.6.12-rc2 |
29 30 31 32 33 34 |
/* * NOTE! unlike strncmp, ufs_match returns 1 for success, 0 for failure. * * len <= UFS_MAXNAMLEN and de != NULL are guaranteed by caller. */ static inline int ufs_match(struct super_block *sb, int len, |
89031bc79 sanitize const/si... |
35 |
const unsigned char *name, struct ufs_dir_entry *de) |
1da177e4c Linux-2.6.12-rc2 |
36 37 38 39 40 41 42 |
{ if (len != ufs_get_de_namlen(sb, de)) return 0; if (!de->d_ino) return 0; return !memcmp(name, de->d_name, len); } |
82b9d1d0d ufs: convert to n... |
43 |
static int ufs_commit_chunk(struct page *page, loff_t pos, unsigned len) |
1da177e4c Linux-2.6.12-rc2 |
44 |
{ |
82b9d1d0d ufs: convert to n... |
45 46 |
struct address_space *mapping = page->mapping; struct inode *dir = mapping->host; |
b71034e5e [PATCH] ufs: dire... |
47 |
int err = 0; |
82b9d1d0d ufs: convert to n... |
48 |
|
bb8c2d66b ufs: use new i_ve... |
49 |
inode_inc_iversion(dir); |
82b9d1d0d ufs: convert to n... |
50 51 52 53 54 |
block_write_end(NULL, mapping, pos, len, len, page, NULL); if (pos+len > dir->i_size) { i_size_write(dir, pos+len); mark_inode_dirty(dir); } |
b71034e5e [PATCH] ufs: dire... |
55 |
if (IS_DIRSYNC(dir)) |
2b69c8280 mm: drop "wait" p... |
56 |
err = write_one_page(page); |
b71034e5e [PATCH] ufs: dire... |
57 58 59 60 |
else unlock_page(page); return err; } |
1da177e4c Linux-2.6.12-rc2 |
61 |
|
b71034e5e [PATCH] ufs: dire... |
62 63 64 |
static inline void ufs_put_page(struct page *page) { kunmap(page); |
09cbfeaf1 mm, fs: get rid o... |
65 |
put_page(page); |
b71034e5e [PATCH] ufs: dire... |
66 |
} |
1da177e4c Linux-2.6.12-rc2 |
67 |
|
89031bc79 sanitize const/si... |
68 |
ino_t ufs_inode_by_name(struct inode *dir, const struct qstr *qstr) |
b71034e5e [PATCH] ufs: dire... |
69 70 71 72 73 |
{ ino_t res = 0; struct ufs_dir_entry *de; struct page *page; |
080497079 ufs: pass qstr in... |
74 |
de = ufs_find_entry(dir, qstr, &page); |
b71034e5e [PATCH] ufs: dire... |
75 76 77 |
if (de) { res = fs32_to_cpu(dir->i_sb, de->d_ino); ufs_put_page(page); |
1da177e4c Linux-2.6.12-rc2 |
78 |
} |
b71034e5e [PATCH] ufs: dire... |
79 |
return res; |
1da177e4c Linux-2.6.12-rc2 |
80 |
} |
1da177e4c Linux-2.6.12-rc2 |
81 |
|
b71034e5e [PATCH] ufs: dire... |
82 83 |
/* Releases the page */ void ufs_set_link(struct inode *dir, struct ufs_dir_entry *de, |
70d45cdb6 ufs: don't touch ... |
84 85 |
struct page *page, struct inode *inode, bool update_times) |
1da177e4c Linux-2.6.12-rc2 |
86 |
{ |
82b9d1d0d ufs: convert to n... |
87 88 89 |
loff_t pos = page_offset(page) + (char *) de - (char *) page_address(page); unsigned len = fs16_to_cpu(dir->i_sb, de->d_reclen); |
b71034e5e [PATCH] ufs: dire... |
90 |
int err; |
1da177e4c Linux-2.6.12-rc2 |
91 |
|
b71034e5e [PATCH] ufs: dire... |
92 |
lock_page(page); |
f4e420dc4 clean up write_be... |
93 |
err = ufs_prepare_chunk(page, pos, len); |
b71034e5e [PATCH] ufs: dire... |
94 |
BUG_ON(err); |
82b9d1d0d ufs: convert to n... |
95 |
|
b71034e5e [PATCH] ufs: dire... |
96 97 |
de->d_ino = cpu_to_fs32(dir->i_sb, inode->i_ino); ufs_set_de_type(dir->i_sb, de, inode->i_mode); |
82b9d1d0d ufs: convert to n... |
98 99 |
err = ufs_commit_chunk(page, pos, len); |
b71034e5e [PATCH] ufs: dire... |
100 |
ufs_put_page(page); |
70d45cdb6 ufs: don't touch ... |
101 |
if (update_times) |
02027d42c fs: Replace CURRE... |
102 |
dir->i_mtime = dir->i_ctime = current_time(dir); |
b71034e5e [PATCH] ufs: dire... |
103 104 |
mark_inode_dirty(dir); } |
1da177e4c Linux-2.6.12-rc2 |
105 |
|
1da177e4c Linux-2.6.12-rc2 |
106 |
|
be5b82dbf make ext2_get_pag... |
107 |
static bool ufs_check_page(struct page *page) |
b71034e5e [PATCH] ufs: dire... |
108 109 110 111 112 |
{ struct inode *dir = page->mapping->host; struct super_block *sb = dir->i_sb; char *kaddr = page_address(page); unsigned offs, rec_len; |
09cbfeaf1 mm, fs: get rid o... |
113 |
unsigned limit = PAGE_SIZE; |
f336953bf [PATCH] ufs: rest... |
114 |
const unsigned chunk_mask = UFS_SB(sb)->s_uspi->s_dirblksize - 1; |
b71034e5e [PATCH] ufs: dire... |
115 116 |
struct ufs_dir_entry *p; char *error; |
09cbfeaf1 mm, fs: get rid o... |
117 118 |
if ((dir->i_size >> PAGE_SHIFT) == page->index) { limit = dir->i_size & ~PAGE_MASK; |
f336953bf [PATCH] ufs: rest... |
119 |
if (limit & chunk_mask) |
b71034e5e [PATCH] ufs: dire... |
120 121 122 |
goto Ebadsize; if (!limit) goto out; |
1da177e4c Linux-2.6.12-rc2 |
123 |
} |
b71034e5e [PATCH] ufs: dire... |
124 125 126 127 128 129 130 131 132 133 |
for (offs = 0; offs <= limit - UFS_DIR_REC_LEN(1); offs += rec_len) { p = (struct ufs_dir_entry *)(kaddr + offs); rec_len = fs16_to_cpu(sb, p->d_reclen); if (rec_len < UFS_DIR_REC_LEN(1)) goto Eshort; if (rec_len & 3) goto Ealign; if (rec_len < UFS_DIR_REC_LEN(ufs_get_de_namlen(sb, p))) goto Enamelen; |
f336953bf [PATCH] ufs: rest... |
134 |
if (((offs + rec_len - 1) ^ offs) & ~chunk_mask) |
b71034e5e [PATCH] ufs: dire... |
135 136 137 138 139 140 141 142 143 |
goto Espan; if (fs32_to_cpu(sb, p->d_ino) > (UFS_SB(sb)->s_uspi->s_ipg * UFS_SB(sb)->s_uspi->s_ncg)) goto Einumber; } if (offs != limit) goto Eend; out: SetPageChecked(page); |
be5b82dbf make ext2_get_pag... |
144 |
return true; |
b71034e5e [PATCH] ufs: dire... |
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
/* Too bad, we had an error */ Ebadsize: ufs_error(sb, "ufs_check_page", "size of directory #%lu is not a multiple of chunk size", dir->i_ino ); goto fail; Eshort: error = "rec_len is smaller than minimal"; goto bad_entry; Ealign: error = "unaligned directory entry"; goto bad_entry; Enamelen: error = "rec_len is too small for name_len"; goto bad_entry; Espan: error = "directory entry across blocks"; goto bad_entry; Einumber: error = "inode out of bounds"; bad_entry: ufs_error (sb, "ufs_check_page", "bad entry in directory #%lu: %s - " "offset=%lu, rec_len=%d, name_len=%d", |
09cbfeaf1 mm, fs: get rid o... |
171 |
dir->i_ino, error, (page->index<<PAGE_SHIFT)+offs, |
b71034e5e [PATCH] ufs: dire... |
172 173 174 175 |
rec_len, ufs_get_de_namlen(sb, p)); goto fail; Eend: p = (struct ufs_dir_entry *)(kaddr + offs); |
9746077a7 ufs: replace rema... |
176 |
ufs_error(sb, __func__, |
b71034e5e [PATCH] ufs: dire... |
177 178 |
"entry in directory #%lu spans the page boundary" "offset=%lu", |
09cbfeaf1 mm, fs: get rid o... |
179 |
dir->i_ino, (page->index<<PAGE_SHIFT)+offs); |
b71034e5e [PATCH] ufs: dire... |
180 |
fail: |
b71034e5e [PATCH] ufs: dire... |
181 |
SetPageError(page); |
be5b82dbf make ext2_get_pag... |
182 |
return false; |
b71034e5e [PATCH] ufs: dire... |
183 |
} |
1da177e4c Linux-2.6.12-rc2 |
184 |
|
b71034e5e [PATCH] ufs: dire... |
185 186 187 |
static struct page *ufs_get_page(struct inode *dir, unsigned long n) { struct address_space *mapping = dir->i_mapping; |
6fe6900e1 mm: make read_cac... |
188 |
struct page *page = read_mapping_page(mapping, n, NULL); |
b71034e5e [PATCH] ufs: dire... |
189 |
if (!IS_ERR(page)) { |
b71034e5e [PATCH] ufs: dire... |
190 |
kmap(page); |
be5b82dbf make ext2_get_pag... |
191 192 193 194 |
if (unlikely(!PageChecked(page))) { if (PageError(page) || !ufs_check_page(page)) goto fail; } |
1da177e4c Linux-2.6.12-rc2 |
195 |
} |
b71034e5e [PATCH] ufs: dire... |
196 |
return page; |
1da177e4c Linux-2.6.12-rc2 |
197 |
|
b71034e5e [PATCH] ufs: dire... |
198 199 200 |
fail: ufs_put_page(page); return ERR_PTR(-EIO); |
1da177e4c Linux-2.6.12-rc2 |
201 |
} |
b71034e5e [PATCH] ufs: dire... |
202 203 204 205 206 207 |
/* * Return the offset into page `page_nr' of the last valid * byte in that page, plus one. */ static unsigned ufs_last_byte(struct inode *inode, unsigned long page_nr) |
1da177e4c Linux-2.6.12-rc2 |
208 |
{ |
b71034e5e [PATCH] ufs: dire... |
209 |
unsigned last_byte = inode->i_size; |
09cbfeaf1 mm, fs: get rid o... |
210 211 212 |
last_byte -= page_nr << PAGE_SHIFT; if (last_byte > PAGE_SIZE) last_byte = PAGE_SIZE; |
b71034e5e [PATCH] ufs: dire... |
213 |
return last_byte; |
1da177e4c Linux-2.6.12-rc2 |
214 |
} |
b71034e5e [PATCH] ufs: dire... |
215 216 |
static inline struct ufs_dir_entry * ufs_next_entry(struct super_block *sb, struct ufs_dir_entry *p) |
1da177e4c Linux-2.6.12-rc2 |
217 |
{ |
b71034e5e [PATCH] ufs: dire... |
218 219 |
return (struct ufs_dir_entry *)((char *)p + fs16_to_cpu(sb, p->d_reclen)); |
1da177e4c Linux-2.6.12-rc2 |
220 |
} |
b71034e5e [PATCH] ufs: dire... |
221 222 |
struct ufs_dir_entry *ufs_dotdot(struct inode *dir, struct page **p) |
1da177e4c Linux-2.6.12-rc2 |
223 |
{ |
b71034e5e [PATCH] ufs: dire... |
224 225 |
struct page *page = ufs_get_page(dir, 0); struct ufs_dir_entry *de = NULL; |
1da177e4c Linux-2.6.12-rc2 |
226 |
|
b71034e5e [PATCH] ufs: dire... |
227 228 229 230 |
if (!IS_ERR(page)) { de = ufs_next_entry(dir->i_sb, (struct ufs_dir_entry *)page_address(page)); *p = page; |
1da177e4c Linux-2.6.12-rc2 |
231 |
} |
b71034e5e [PATCH] ufs: dire... |
232 |
return de; |
1da177e4c Linux-2.6.12-rc2 |
233 |
} |
b71034e5e [PATCH] ufs: dire... |
234 235 236 237 238 239 240 241 |
/* * ufs_find_entry() * * finds an entry in the specified directory with the wanted name. It * returns the page in which the entry was found, and the entry itself * (as a parameter - res_dir). Page is returned mapped and unlocked. * Entry is guaranteed to be valid. */ |
89031bc79 sanitize const/si... |
242 |
struct ufs_dir_entry *ufs_find_entry(struct inode *dir, const struct qstr *qstr, |
b71034e5e [PATCH] ufs: dire... |
243 |
struct page **res_page) |
1da177e4c Linux-2.6.12-rc2 |
244 |
{ |
b71034e5e [PATCH] ufs: dire... |
245 |
struct super_block *sb = dir->i_sb; |
89031bc79 sanitize const/si... |
246 |
const unsigned char *name = qstr->name; |
080497079 ufs: pass qstr in... |
247 |
int namelen = qstr->len; |
b71034e5e [PATCH] ufs: dire... |
248 249 |
unsigned reclen = UFS_DIR_REC_LEN(namelen); unsigned long start, n; |
5d754ced1 ufs: use dir_page... |
250 |
unsigned long npages = dir_pages(dir); |
b71034e5e [PATCH] ufs: dire... |
251 |
struct page *page = NULL; |
dd187a260 [PATCH] ufs: litt... |
252 |
struct ufs_inode_info *ui = UFS_I(dir); |
b71034e5e [PATCH] ufs: dire... |
253 |
struct ufs_dir_entry *de; |
abf5d15fd [PATCH] ufs: easy... |
254 255 |
UFSD("ENTER, dir_ino %lu, name %s, namlen %u ", dir->i_ino, name, namelen); |
b71034e5e [PATCH] ufs: dire... |
256 257 258 259 260 261 |
if (npages == 0 || namelen > UFS_MAXNAMLEN) goto out; /* OFFSET_CACHE */ *res_page = NULL; |
dd187a260 [PATCH] ufs: litt... |
262 |
start = ui->i_dir_start_lookup; |
b71034e5e [PATCH] ufs: dire... |
263 264 265 266 267 268 269 270 271 272 273 |
if (start >= npages) start = 0; n = start; do { char *kaddr; page = ufs_get_page(dir, n); if (!IS_ERR(page)) { kaddr = page_address(page); de = (struct ufs_dir_entry *) kaddr; kaddr += ufs_last_byte(dir, n) - reclen; while ((char *) de <= kaddr) { |
b71034e5e [PATCH] ufs: dire... |
274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
if (ufs_match(sb, namelen, name, de)) goto found; de = ufs_next_entry(sb, de); } ufs_put_page(page); } if (++n >= npages) n = 0; } while (n != start); out: return NULL; found: *res_page = page; |
dd187a260 [PATCH] ufs: litt... |
288 |
ui->i_dir_start_lookup = n; |
b71034e5e [PATCH] ufs: dire... |
289 |
return de; |
1da177e4c Linux-2.6.12-rc2 |
290 291 292 |
} /* |
b71034e5e [PATCH] ufs: dire... |
293 |
* Parent is locked. |
1da177e4c Linux-2.6.12-rc2 |
294 295 296 |
*/ int ufs_add_link(struct dentry *dentry, struct inode *inode) { |
2b0143b5c VFS: normal files... |
297 |
struct inode *dir = d_inode(dentry->d_parent); |
89031bc79 sanitize const/si... |
298 |
const unsigned char *name = dentry->d_name.name; |
1da177e4c Linux-2.6.12-rc2 |
299 |
int namelen = dentry->d_name.len; |
b71034e5e [PATCH] ufs: dire... |
300 301 |
struct super_block *sb = dir->i_sb; unsigned reclen = UFS_DIR_REC_LEN(namelen); |
f336953bf [PATCH] ufs: rest... |
302 |
const unsigned int chunk_size = UFS_SB(sb)->s_uspi->s_dirblksize; |
b71034e5e [PATCH] ufs: dire... |
303 304 305 |
unsigned short rec_len, name_len; struct page *page = NULL; struct ufs_dir_entry *de; |
5d754ced1 ufs: use dir_page... |
306 |
unsigned long npages = dir_pages(dir); |
b71034e5e [PATCH] ufs: dire... |
307 308 |
unsigned long n; char *kaddr; |
82b9d1d0d ufs: convert to n... |
309 |
loff_t pos; |
1da177e4c Linux-2.6.12-rc2 |
310 |
int err; |
abf5d15fd [PATCH] ufs: easy... |
311 312 |
UFSD("ENTER, name %s, namelen %u ", name, namelen); |
b71034e5e [PATCH] ufs: dire... |
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
/* * We take care of directory expansion in the same loop. * This code plays outside i_size, so it locks the page * to protect that region. */ for (n = 0; n <= npages; n++) { char *dir_end; page = ufs_get_page(dir, n); err = PTR_ERR(page); if (IS_ERR(page)) goto out; lock_page(page); kaddr = page_address(page); dir_end = kaddr + ufs_last_byte(dir, n); de = (struct ufs_dir_entry *)kaddr; |
09cbfeaf1 mm, fs: get rid o... |
330 |
kaddr += PAGE_SIZE - reclen; |
b71034e5e [PATCH] ufs: dire... |
331 332 333 334 |
while ((char *)de <= kaddr) { if ((char *)de == dir_end) { /* We hit i_size */ name_len = 0; |
f336953bf [PATCH] ufs: rest... |
335 336 |
rec_len = chunk_size; de->d_reclen = cpu_to_fs16(sb, chunk_size); |
b71034e5e [PATCH] ufs: dire... |
337 338 |
de->d_ino = 0; goto got_it; |
1da177e4c Linux-2.6.12-rc2 |
339 |
} |
b71034e5e [PATCH] ufs: dire... |
340 |
if (de->d_reclen == 0) { |
9746077a7 ufs: replace rema... |
341 |
ufs_error(dir->i_sb, __func__, |
b71034e5e [PATCH] ufs: dire... |
342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
"zero-length directory entry"); err = -EIO; goto out_unlock; } err = -EEXIST; if (ufs_match(sb, namelen, name, de)) goto out_unlock; name_len = UFS_DIR_REC_LEN(ufs_get_de_namlen(sb, de)); rec_len = fs16_to_cpu(sb, de->d_reclen); if (!de->d_ino && rec_len >= reclen) goto got_it; if (rec_len >= name_len + reclen) goto got_it; de = (struct ufs_dir_entry *) ((char *) de + rec_len); |
1da177e4c Linux-2.6.12-rc2 |
356 |
} |
b71034e5e [PATCH] ufs: dire... |
357 358 |
unlock_page(page); ufs_put_page(page); |
1da177e4c Linux-2.6.12-rc2 |
359 |
} |
b71034e5e [PATCH] ufs: dire... |
360 361 362 363 |
BUG(); return -EINVAL; got_it: |
82b9d1d0d ufs: convert to n... |
364 365 |
pos = page_offset(page) + (char*)de - (char*)page_address(page); |
f4e420dc4 clean up write_be... |
366 |
err = ufs_prepare_chunk(page, pos, rec_len); |
b71034e5e [PATCH] ufs: dire... |
367 368 |
if (err) goto out_unlock; |
1da177e4c Linux-2.6.12-rc2 |
369 |
if (de->d_ino) { |
b71034e5e [PATCH] ufs: dire... |
370 371 372 373 |
struct ufs_dir_entry *de1 = (struct ufs_dir_entry *) ((char *) de + name_len); de1->d_reclen = cpu_to_fs16(sb, rec_len - name_len); de->d_reclen = cpu_to_fs16(sb, name_len); |
1da177e4c Linux-2.6.12-rc2 |
374 375 |
de = de1; } |
b71034e5e [PATCH] ufs: dire... |
376 |
|
1da177e4c Linux-2.6.12-rc2 |
377 |
ufs_set_de_namlen(sb, de, namelen); |
b71034e5e [PATCH] ufs: dire... |
378 |
memcpy(de->d_name, name, namelen + 1); |
1da177e4c Linux-2.6.12-rc2 |
379 380 |
de->d_ino = cpu_to_fs32(sb, inode->i_ino); ufs_set_de_type(sb, de, inode->i_mode); |
b71034e5e [PATCH] ufs: dire... |
381 |
|
82b9d1d0d ufs: convert to n... |
382 |
err = ufs_commit_chunk(page, pos, rec_len); |
02027d42c fs: Replace CURRE... |
383 |
dir->i_mtime = dir->i_ctime = current_time(dir); |
b71034e5e [PATCH] ufs: dire... |
384 |
|
1da177e4c Linux-2.6.12-rc2 |
385 |
mark_inode_dirty(dir); |
b71034e5e [PATCH] ufs: dire... |
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
/* OFFSET_CACHE */ out_put: ufs_put_page(page); out: return err; out_unlock: unlock_page(page); goto out_put; } static inline unsigned ufs_validate_entry(struct super_block *sb, char *base, unsigned offset, unsigned mask) { struct ufs_dir_entry *de = (struct ufs_dir_entry*)(base + offset); struct ufs_dir_entry *p = (struct ufs_dir_entry*)(base + (offset&mask)); |
e0d508f10 ufs: get rid of r... |
402 |
while ((char*)p < (char*)de) |
b71034e5e [PATCH] ufs: dire... |
403 |
p = ufs_next_entry(sb, p); |
b71034e5e [PATCH] ufs: dire... |
404 405 |
return (char *)p - base; } |
1da177e4c Linux-2.6.12-rc2 |
406 |
|
b71034e5e [PATCH] ufs: dire... |
407 408 409 410 411 |
/* * This is blatantly stolen from ext2fs */ static int |
80886298c [readdir] simple ... |
412 |
ufs_readdir(struct file *file, struct dir_context *ctx) |
b71034e5e [PATCH] ufs: dire... |
413 |
{ |
80886298c [readdir] simple ... |
414 415 |
loff_t pos = ctx->pos; struct inode *inode = file_inode(file); |
b71034e5e [PATCH] ufs: dire... |
416 |
struct super_block *sb = inode->i_sb; |
09cbfeaf1 mm, fs: get rid o... |
417 418 |
unsigned int offset = pos & ~PAGE_MASK; unsigned long n = pos >> PAGE_SHIFT; |
5d754ced1 ufs: use dir_page... |
419 |
unsigned long npages = dir_pages(inode); |
f336953bf [PATCH] ufs: rest... |
420 |
unsigned chunk_mask = ~(UFS_SB(sb)->s_uspi->s_dirblksize - 1); |
c472c07bf iversion: Rename ... |
421 |
bool need_revalidate = !inode_eq_iversion(inode, file->f_version); |
b71034e5e [PATCH] ufs: dire... |
422 |
unsigned flags = UFS_SB(sb)->s_flags; |
abf5d15fd [PATCH] ufs: easy... |
423 424 |
UFSD("BEGIN "); |
b71034e5e [PATCH] ufs: dire... |
425 426 427 428 429 430 431 432 433 434 435 |
if (pos > inode->i_size - UFS_DIR_REC_LEN(1)) return 0; for ( ; n < npages; n++, offset = 0) { char *kaddr, *limit; struct ufs_dir_entry *de; struct page *page = ufs_get_page(inode, n); if (IS_ERR(page)) { |
9746077a7 ufs: replace rema... |
436 |
ufs_error(sb, __func__, |
b71034e5e [PATCH] ufs: dire... |
437 438 |
"bad page in #%lu", inode->i_ino); |
09cbfeaf1 mm, fs: get rid o... |
439 |
ctx->pos += PAGE_SIZE - offset; |
b71034e5e [PATCH] ufs: dire... |
440 441 442 443 444 445 |
return -EIO; } kaddr = page_address(page); if (unlikely(need_revalidate)) { if (offset) { offset = ufs_validate_entry(sb, kaddr, offset, chunk_mask); |
09cbfeaf1 mm, fs: get rid o... |
446 |
ctx->pos = (n<<PAGE_SHIFT) + offset; |
b71034e5e [PATCH] ufs: dire... |
447 |
} |
bb8c2d66b ufs: use new i_ve... |
448 449 |
file->f_version = inode_query_iversion(inode); need_revalidate = false; |
b71034e5e [PATCH] ufs: dire... |
450 451 452 453 |
} de = (struct ufs_dir_entry *)(kaddr+offset); limit = kaddr + ufs_last_byte(inode, n) - UFS_DIR_REC_LEN(1); for ( ;(char*)de <= limit; de = ufs_next_entry(sb, de)) { |
b71034e5e [PATCH] ufs: dire... |
454 |
if (de->d_ino) { |
b71034e5e [PATCH] ufs: dire... |
455 |
unsigned char d_type = DT_UNKNOWN; |
abf5d15fd [PATCH] ufs: easy... |
456 457 458 459 460 |
UFSD("filldir(%s,%u) ", de->d_name, fs32_to_cpu(sb, de->d_ino)); UFSD("namlen %u ", ufs_get_de_namlen(sb, de)); |
b71034e5e [PATCH] ufs: dire... |
461 462 463 |
if ((flags & UFS_DE_MASK) == UFS_DE_44BSD) d_type = de->d_u.d_44.d_type; |
80886298c [readdir] simple ... |
464 |
if (!dir_emit(ctx, de->d_name, |
b71034e5e [PATCH] ufs: dire... |
465 |
ufs_get_de_namlen(sb, de), |
80886298c [readdir] simple ... |
466 467 |
fs32_to_cpu(sb, de->d_ino), d_type)) { |
b71034e5e [PATCH] ufs: dire... |
468 469 470 471 |
ufs_put_page(page); return 0; } } |
80886298c [readdir] simple ... |
472 |
ctx->pos += fs16_to_cpu(sb, de->d_reclen); |
b71034e5e [PATCH] ufs: dire... |
473 474 475 |
} ufs_put_page(page); } |
1da177e4c Linux-2.6.12-rc2 |
476 477 |
return 0; } |
b71034e5e [PATCH] ufs: dire... |
478 |
|
1da177e4c Linux-2.6.12-rc2 |
479 480 481 482 |
/* * ufs_delete_entry deletes a directory entry by merging it with the * previous entry. */ |
b71034e5e [PATCH] ufs: dire... |
483 484 |
int ufs_delete_entry(struct inode *inode, struct ufs_dir_entry *dir, struct page * page) |
1da177e4c Linux-2.6.12-rc2 |
485 |
{ |
b71034e5e [PATCH] ufs: dire... |
486 |
struct super_block *sb = inode->i_sb; |
b71034e5e [PATCH] ufs: dire... |
487 |
char *kaddr = page_address(page); |
f336953bf [PATCH] ufs: rest... |
488 |
unsigned from = ((char*)dir - kaddr) & ~(UFS_SB(sb)->s_uspi->s_dirblksize - 1); |
b71034e5e [PATCH] ufs: dire... |
489 |
unsigned to = ((char*)dir - kaddr) + fs16_to_cpu(sb, dir->d_reclen); |
82b9d1d0d ufs: convert to n... |
490 |
loff_t pos; |
b71034e5e [PATCH] ufs: dire... |
491 492 493 |
struct ufs_dir_entry *pde = NULL; struct ufs_dir_entry *de = (struct ufs_dir_entry *) (kaddr + from); int err; |
1da177e4c Linux-2.6.12-rc2 |
494 |
|
abf5d15fd [PATCH] ufs: easy... |
495 496 |
UFSD("ENTER "); |
1da177e4c Linux-2.6.12-rc2 |
497 |
|
abf5d15fd [PATCH] ufs: easy... |
498 499 |
UFSD("ino %u, reclen %u, namlen %u, name %s ", |
b71034e5e [PATCH] ufs: dire... |
500 501 |
fs32_to_cpu(sb, de->d_ino), fs16_to_cpu(sb, de->d_reclen), |
abf5d15fd [PATCH] ufs: easy... |
502 |
ufs_get_de_namlen(sb, de), de->d_name); |
b71034e5e [PATCH] ufs: dire... |
503 504 505 |
while ((char*)de < (char*)dir) { if (de->d_reclen == 0) { |
9746077a7 ufs: replace rema... |
506 |
ufs_error(inode->i_sb, __func__, |
b71034e5e [PATCH] ufs: dire... |
507 508 509 |
"zero-length directory entry"); err = -EIO; goto out; |
1da177e4c Linux-2.6.12-rc2 |
510 |
} |
b71034e5e [PATCH] ufs: dire... |
511 512 |
pde = de; de = ufs_next_entry(sb, de); |
1da177e4c Linux-2.6.12-rc2 |
513 |
} |
b71034e5e [PATCH] ufs: dire... |
514 515 |
if (pde) from = (char*)pde - (char*)page_address(page); |
82b9d1d0d ufs: convert to n... |
516 517 |
pos = page_offset(page) + from; |
b71034e5e [PATCH] ufs: dire... |
518 |
lock_page(page); |
f4e420dc4 clean up write_be... |
519 |
err = ufs_prepare_chunk(page, pos, to - from); |
b71034e5e [PATCH] ufs: dire... |
520 521 |
BUG_ON(err); if (pde) |
82b9d1d0d ufs: convert to n... |
522 |
pde->d_reclen = cpu_to_fs16(sb, to - from); |
b71034e5e [PATCH] ufs: dire... |
523 |
dir->d_ino = 0; |
82b9d1d0d ufs: convert to n... |
524 |
err = ufs_commit_chunk(page, pos, to - from); |
02027d42c fs: Replace CURRE... |
525 |
inode->i_ctime = inode->i_mtime = current_time(inode); |
b71034e5e [PATCH] ufs: dire... |
526 527 528 |
mark_inode_dirty(inode); out: ufs_put_page(page); |
abf5d15fd [PATCH] ufs: easy... |
529 530 |
UFSD("EXIT "); |
b71034e5e [PATCH] ufs: dire... |
531 |
return err; |
1da177e4c Linux-2.6.12-rc2 |
532 533 534 535 536 |
} int ufs_make_empty(struct inode * inode, struct inode *dir) { struct super_block * sb = dir->i_sb; |
b71034e5e [PATCH] ufs: dire... |
537 538 |
struct address_space *mapping = inode->i_mapping; struct page *page = grab_cache_page(mapping, 0); |
f336953bf [PATCH] ufs: rest... |
539 |
const unsigned int chunk_size = UFS_SB(sb)->s_uspi->s_dirblksize; |
1da177e4c Linux-2.6.12-rc2 |
540 |
struct ufs_dir_entry * de; |
b71034e5e [PATCH] ufs: dire... |
541 |
char *base; |
1da177e4c Linux-2.6.12-rc2 |
542 |
int err; |
b71034e5e [PATCH] ufs: dire... |
543 544 |
if (!page) return -ENOMEM; |
82b9d1d0d ufs: convert to n... |
545 |
|
f4e420dc4 clean up write_be... |
546 |
err = ufs_prepare_chunk(page, 0, chunk_size); |
b71034e5e [PATCH] ufs: dire... |
547 548 549 550 |
if (err) { unlock_page(page); goto fail; } |
82b9d1d0d ufs: convert to n... |
551 |
kmap(page); |
b71034e5e [PATCH] ufs: dire... |
552 |
base = (char*)page_address(page); |
09cbfeaf1 mm, fs: get rid o... |
553 |
memset(base, 0, PAGE_SIZE); |
b71034e5e [PATCH] ufs: dire... |
554 555 |
de = (struct ufs_dir_entry *) base; |
1da177e4c Linux-2.6.12-rc2 |
556 |
|
1da177e4c Linux-2.6.12-rc2 |
557 558 559 560 561 562 563 564 565 |
de->d_ino = cpu_to_fs32(sb, inode->i_ino); ufs_set_de_type(sb, de, inode->i_mode); ufs_set_de_namlen(sb, de, 1); de->d_reclen = cpu_to_fs16(sb, UFS_DIR_REC_LEN(1)); strcpy (de->d_name, "."); de = (struct ufs_dir_entry *) ((char *)de + fs16_to_cpu(sb, de->d_reclen)); de->d_ino = cpu_to_fs32(sb, dir->i_ino); ufs_set_de_type(sb, de, dir->i_mode); |
f336953bf [PATCH] ufs: rest... |
566 |
de->d_reclen = cpu_to_fs16(sb, chunk_size - UFS_DIR_REC_LEN(1)); |
1da177e4c Linux-2.6.12-rc2 |
567 568 |
ufs_set_de_namlen(sb, de, 2); strcpy (de->d_name, ".."); |
82b9d1d0d ufs: convert to n... |
569 |
kunmap(page); |
b71034e5e [PATCH] ufs: dire... |
570 |
|
f336953bf [PATCH] ufs: rest... |
571 |
err = ufs_commit_chunk(page, 0, chunk_size); |
b71034e5e [PATCH] ufs: dire... |
572 |
fail: |
09cbfeaf1 mm, fs: get rid o... |
573 |
put_page(page); |
b71034e5e [PATCH] ufs: dire... |
574 |
return err; |
1da177e4c Linux-2.6.12-rc2 |
575 576 577 578 579 |
} /* * routine to check that the specified directory is empty (for rmdir) */ |
b71034e5e [PATCH] ufs: dire... |
580 |
int ufs_empty_dir(struct inode * inode) |
1da177e4c Linux-2.6.12-rc2 |
581 |
{ |
b71034e5e [PATCH] ufs: dire... |
582 583 |
struct super_block *sb = inode->i_sb; struct page *page = NULL; |
5d754ced1 ufs: use dir_page... |
584 |
unsigned long i, npages = dir_pages(inode); |
b71034e5e [PATCH] ufs: dire... |
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 |
for (i = 0; i < npages; i++) { char *kaddr; struct ufs_dir_entry *de; page = ufs_get_page(inode, i); if (IS_ERR(page)) continue; kaddr = page_address(page); de = (struct ufs_dir_entry *)kaddr; kaddr += ufs_last_byte(inode, i) - UFS_DIR_REC_LEN(1); while ((char *)de <= kaddr) { if (de->d_reclen == 0) { |
9746077a7 ufs: replace rema... |
600 |
ufs_error(inode->i_sb, __func__, |
b71034e5e [PATCH] ufs: dire... |
601 602 603 604 |
"zero-length directory entry: " "kaddr=%p, de=%p ", kaddr, de); goto not_empty; |
1da177e4c Linux-2.6.12-rc2 |
605 |
} |
b71034e5e [PATCH] ufs: dire... |
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 |
if (de->d_ino) { u16 namelen=ufs_get_de_namlen(sb, de); /* check for . and .. */ if (de->d_name[0] != '.') goto not_empty; if (namelen > 2) goto not_empty; if (namelen < 2) { if (inode->i_ino != fs32_to_cpu(sb, de->d_ino)) goto not_empty; } else if (de->d_name[1] != '.') goto not_empty; } de = ufs_next_entry(sb, de); |
1da177e4c Linux-2.6.12-rc2 |
621 |
} |
b71034e5e [PATCH] ufs: dire... |
622 |
ufs_put_page(page); |
1da177e4c Linux-2.6.12-rc2 |
623 |
} |
1da177e4c Linux-2.6.12-rc2 |
624 |
return 1; |
b71034e5e [PATCH] ufs: dire... |
625 626 627 628 |
not_empty: ufs_put_page(page); return 0; |
1da177e4c Linux-2.6.12-rc2 |
629 |
} |
4b6f5d20b [PATCH] Make most... |
630 |
const struct file_operations ufs_dir_operations = { |
1da177e4c Linux-2.6.12-rc2 |
631 |
.read = generic_read_dir, |
3b0a3c1ac simple local file... |
632 |
.iterate_shared = ufs_readdir, |
1b061d924 rename the generi... |
633 |
.fsync = generic_file_fsync, |
3222a3e55 [PATCH] fix ->lls... |
634 |
.llseek = generic_file_llseek, |
1da177e4c Linux-2.6.12-rc2 |
635 |
}; |