dir.c (e631ddba588783edd521c5a89f7b2902772fb691) | dir.c (182ec4eee397543101a6db8906ed88727d3f7e53) |
---|---|
1/* 2 * JFFS2 -- Journalling Flash File System, Version 2. 3 * 4 * Copyright (C) 2001-2003 Red Hat, Inc. 5 * 6 * Created by David Woodhouse <dwmw2@infradead.org> 7 * 8 * For licensing information, see the file 'LICENCE' in this directory. 9 * | 1/* 2 * JFFS2 -- Journalling Flash File System, Version 2. 3 * 4 * Copyright (C) 2001-2003 Red Hat, Inc. 5 * 6 * Created by David Woodhouse <dwmw2@infradead.org> 7 * 8 * For licensing information, see the file 'LICENCE' in this directory. 9 * |
10 * $Id: dir.c,v 1.89 2005/09/07 08:34:54 havasi Exp $ | 10 * $Id: dir.c,v 1.90 2005/11/07 11:14:39 gleixner Exp $ |
11 * 12 */ 13 14#include <linux/kernel.h> 15#include <linux/slab.h> 16#include <linux/sched.h> 17#include <linux/fs.h> 18#include <linux/crc32.h> --- 40 unchanged lines hidden (view full) --- 59 .rename = jffs2_rename, 60 .setattr = jffs2_setattr, 61}; 62 63/***********************************************************************/ 64 65 66/* We keep the dirent list sorted in increasing order of name hash, | 11 * 12 */ 13 14#include <linux/kernel.h> 15#include <linux/slab.h> 16#include <linux/sched.h> 17#include <linux/fs.h> 18#include <linux/crc32.h> --- 40 unchanged lines hidden (view full) --- 59 .rename = jffs2_rename, 60 .setattr = jffs2_setattr, 61}; 62 63/***********************************************************************/ 64 65 66/* We keep the dirent list sorted in increasing order of name hash, |
67 and we use the same hash function as the dentries. Makes this | 67 and we use the same hash function as the dentries. Makes this |
68 nice and simple 69*/ 70static struct dentry *jffs2_lookup(struct inode *dir_i, struct dentry *target, 71 struct nameidata *nd) 72{ 73 struct jffs2_inode_info *dir_f; 74 struct jffs2_sb_info *c; 75 struct jffs2_full_dirent *fd = NULL, *fd_list; --- 4 unchanged lines hidden (view full) --- 80 81 dir_f = JFFS2_INODE_INFO(dir_i); 82 c = JFFS2_SB_INFO(dir_i->i_sb); 83 84 down(&dir_f->sem); 85 86 /* NB: The 2.2 backport will need to explicitly check for '.' and '..' here */ 87 for (fd_list = dir_f->dents; fd_list && fd_list->nhash <= target->d_name.hash; fd_list = fd_list->next) { | 68 nice and simple 69*/ 70static struct dentry *jffs2_lookup(struct inode *dir_i, struct dentry *target, 71 struct nameidata *nd) 72{ 73 struct jffs2_inode_info *dir_f; 74 struct jffs2_sb_info *c; 75 struct jffs2_full_dirent *fd = NULL, *fd_list; --- 4 unchanged lines hidden (view full) --- 80 81 dir_f = JFFS2_INODE_INFO(dir_i); 82 c = JFFS2_SB_INFO(dir_i->i_sb); 83 84 down(&dir_f->sem); 85 86 /* NB: The 2.2 backport will need to explicitly check for '.' and '..' here */ 87 for (fd_list = dir_f->dents; fd_list && fd_list->nhash <= target->d_name.hash; fd_list = fd_list->next) { |
88 if (fd_list->nhash == target->d_name.hash && | 88 if (fd_list->nhash == target->d_name.hash && |
89 (!fd || fd_list->version > fd->version) && 90 strlen(fd_list->name) == target->d_name.len && 91 !strncmp(fd_list->name, target->d_name.name, target->d_name.len)) { 92 fd = fd_list; 93 } 94 } 95 if (fd) 96 ino = fd->ino; --- 45 unchanged lines hidden (view full) --- 142 143 curofs=1; 144 down(&f->sem); 145 for (fd = f->dents; fd; fd = fd->next) { 146 147 curofs++; 148 /* First loop: curofs = 2; offset = 2 */ 149 if (curofs < offset) { | 89 (!fd || fd_list->version > fd->version) && 90 strlen(fd_list->name) == target->d_name.len && 91 !strncmp(fd_list->name, target->d_name.name, target->d_name.len)) { 92 fd = fd_list; 93 } 94 } 95 if (fd) 96 ino = fd->ino; --- 45 unchanged lines hidden (view full) --- 142 143 curofs=1; 144 down(&f->sem); 145 for (fd = f->dents; fd; fd = fd->next) { 146 147 curofs++; 148 /* First loop: curofs = 2; offset = 2 */ 149 if (curofs < offset) { |
150 D2(printk(KERN_DEBUG "Skipping dirent: \"%s\", ino #%u, type %d, because curofs %ld < offset %ld\n", | 150 D2(printk(KERN_DEBUG "Skipping dirent: \"%s\", ino #%u, type %d, because curofs %ld < offset %ld\n", |
151 fd->name, fd->ino, fd->type, curofs, offset)); 152 continue; 153 } 154 if (!fd->ino) { 155 D2(printk(KERN_DEBUG "Skipping deletion dirent \"%s\"\n", fd->name)); 156 offset++; 157 continue; 158 } --- 18 unchanged lines hidden (view full) --- 177 struct jffs2_inode_info *f, *dir_f; 178 struct jffs2_sb_info *c; 179 struct inode *inode; 180 int ret; 181 182 ri = jffs2_alloc_raw_inode(); 183 if (!ri) 184 return -ENOMEM; | 151 fd->name, fd->ino, fd->type, curofs, offset)); 152 continue; 153 } 154 if (!fd->ino) { 155 D2(printk(KERN_DEBUG "Skipping deletion dirent \"%s\"\n", fd->name)); 156 offset++; 157 continue; 158 } --- 18 unchanged lines hidden (view full) --- 177 struct jffs2_inode_info *f, *dir_f; 178 struct jffs2_sb_info *c; 179 struct inode *inode; 180 int ret; 181 182 ri = jffs2_alloc_raw_inode(); 183 if (!ri) 184 return -ENOMEM; |
185 | 185 |
186 c = JFFS2_SB_INFO(dir_i->i_sb); 187 188 D1(printk(KERN_DEBUG "jffs2_create()\n")); 189 190 inode = jffs2_new_inode(dir_i, mode, ri); 191 192 if (IS_ERR(inode)) { 193 D1(printk(KERN_DEBUG "jffs2_new_inode() failed\n")); --- 4 unchanged lines hidden (view full) --- 198 inode->i_op = &jffs2_file_inode_operations; 199 inode->i_fop = &jffs2_file_operations; 200 inode->i_mapping->a_ops = &jffs2_file_address_operations; 201 inode->i_mapping->nrpages = 0; 202 203 f = JFFS2_INODE_INFO(inode); 204 dir_f = JFFS2_INODE_INFO(dir_i); 205 | 186 c = JFFS2_SB_INFO(dir_i->i_sb); 187 188 D1(printk(KERN_DEBUG "jffs2_create()\n")); 189 190 inode = jffs2_new_inode(dir_i, mode, ri); 191 192 if (IS_ERR(inode)) { 193 D1(printk(KERN_DEBUG "jffs2_new_inode() failed\n")); --- 4 unchanged lines hidden (view full) --- 198 inode->i_op = &jffs2_file_inode_operations; 199 inode->i_fop = &jffs2_file_operations; 200 inode->i_mapping->a_ops = &jffs2_file_address_operations; 201 inode->i_mapping->nrpages = 0; 202 203 f = JFFS2_INODE_INFO(inode); 204 dir_f = JFFS2_INODE_INFO(dir_i); 205 |
206 ret = jffs2_do_create(c, dir_f, f, ri, | 206 ret = jffs2_do_create(c, dir_f, f, ri, |
207 dentry->d_name.name, dentry->d_name.len); 208 209 if (ret) { 210 make_bad_inode(inode); 211 iput(inode); 212 jffs2_free_raw_inode(ri); 213 return ret; 214 } --- 14 unchanged lines hidden (view full) --- 229static int jffs2_unlink(struct inode *dir_i, struct dentry *dentry) 230{ 231 struct jffs2_sb_info *c = JFFS2_SB_INFO(dir_i->i_sb); 232 struct jffs2_inode_info *dir_f = JFFS2_INODE_INFO(dir_i); 233 struct jffs2_inode_info *dead_f = JFFS2_INODE_INFO(dentry->d_inode); 234 int ret; 235 uint32_t now = get_seconds(); 236 | 207 dentry->d_name.name, dentry->d_name.len); 208 209 if (ret) { 210 make_bad_inode(inode); 211 iput(inode); 212 jffs2_free_raw_inode(ri); 213 return ret; 214 } --- 14 unchanged lines hidden (view full) --- 229static int jffs2_unlink(struct inode *dir_i, struct dentry *dentry) 230{ 231 struct jffs2_sb_info *c = JFFS2_SB_INFO(dir_i->i_sb); 232 struct jffs2_inode_info *dir_f = JFFS2_INODE_INFO(dir_i); 233 struct jffs2_inode_info *dead_f = JFFS2_INODE_INFO(dentry->d_inode); 234 int ret; 235 uint32_t now = get_seconds(); 236 |
237 ret = jffs2_do_unlink(c, dir_f, dentry->d_name.name, | 237 ret = jffs2_do_unlink(c, dir_f, dentry->d_name.name, |
238 dentry->d_name.len, dead_f, now); 239 if (dead_f->inocache) 240 dentry->d_inode->i_nlink = dead_f->inocache->nlink; 241 if (!ret) 242 dir_i->i_mtime = dir_i->i_ctime = ITIME(now); 243 return ret; 244} 245/***********************************************************************/ --- 52 unchanged lines hidden (view full) --- 298 if it grows much more than this */ 299 if (targetlen > 254) 300 return -EINVAL; 301 302 ri = jffs2_alloc_raw_inode(); 303 304 if (!ri) 305 return -ENOMEM; | 238 dentry->d_name.len, dead_f, now); 239 if (dead_f->inocache) 240 dentry->d_inode->i_nlink = dead_f->inocache->nlink; 241 if (!ret) 242 dir_i->i_mtime = dir_i->i_ctime = ITIME(now); 243 return ret; 244} 245/***********************************************************************/ --- 52 unchanged lines hidden (view full) --- 298 if it grows much more than this */ 299 if (targetlen > 254) 300 return -EINVAL; 301 302 ri = jffs2_alloc_raw_inode(); 303 304 if (!ri) 305 return -ENOMEM; |
306 | 306 |
307 c = JFFS2_SB_INFO(dir_i->i_sb); | 307 c = JFFS2_SB_INFO(dir_i->i_sb); |
308 309 /* Try to reserve enough space for both node and dirent. 310 * Just the node will do for now, though | 308 309 /* Try to reserve enough space for both node and dirent. 310 * Just the node will do for now, though |
311 */ 312 namelen = dentry->d_name.len; 313 ret = jffs2_reserve_space(c, sizeof(*ri) + targetlen, &phys_ofs, &alloclen, 314 ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE); 315 316 if (ret) { 317 jffs2_free_raw_inode(ri); 318 return ret; --- 14 unchanged lines hidden (view full) --- 333 inode->i_size = targetlen; 334 ri->isize = ri->dsize = ri->csize = cpu_to_je32(inode->i_size); 335 ri->totlen = cpu_to_je32(sizeof(*ri) + inode->i_size); 336 ri->hdr_crc = cpu_to_je32(crc32(0, ri, sizeof(struct jffs2_unknown_node)-4)); 337 338 ri->compr = JFFS2_COMPR_NONE; 339 ri->data_crc = cpu_to_je32(crc32(0, target, targetlen)); 340 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); | 311 */ 312 namelen = dentry->d_name.len; 313 ret = jffs2_reserve_space(c, sizeof(*ri) + targetlen, &phys_ofs, &alloclen, 314 ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE); 315 316 if (ret) { 317 jffs2_free_raw_inode(ri); 318 return ret; --- 14 unchanged lines hidden (view full) --- 333 inode->i_size = targetlen; 334 ri->isize = ri->dsize = ri->csize = cpu_to_je32(inode->i_size); 335 ri->totlen = cpu_to_je32(sizeof(*ri) + inode->i_size); 336 ri->hdr_crc = cpu_to_je32(crc32(0, ri, sizeof(struct jffs2_unknown_node)-4)); 337 338 ri->compr = JFFS2_COMPR_NONE; 339 ri->data_crc = cpu_to_je32(crc32(0, target, targetlen)); 340 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); |
341 | 341 |
342 fn = jffs2_write_dnode(c, f, ri, target, targetlen, phys_ofs, ALLOC_NORMAL); 343 344 jffs2_free_raw_inode(ri); 345 346 if (IS_ERR(fn)) { 347 /* Eeek. Wave bye bye */ 348 up(&f->sem); 349 jffs2_complete_reservation(c); --- 9 unchanged lines hidden (view full) --- 359 jffs2_complete_reservation(c); 360 jffs2_clear_inode(inode); 361 return -ENOMEM; 362 } 363 364 memcpy(f->target, target, targetlen + 1); 365 D1(printk(KERN_DEBUG "jffs2_symlink: symlink's target '%s' cached\n", (char *)f->target)); 366 | 342 fn = jffs2_write_dnode(c, f, ri, target, targetlen, phys_ofs, ALLOC_NORMAL); 343 344 jffs2_free_raw_inode(ri); 345 346 if (IS_ERR(fn)) { 347 /* Eeek. Wave bye bye */ 348 up(&f->sem); 349 jffs2_complete_reservation(c); --- 9 unchanged lines hidden (view full) --- 359 jffs2_complete_reservation(c); 360 jffs2_clear_inode(inode); 361 return -ENOMEM; 362 } 363 364 memcpy(f->target, target, targetlen + 1); 365 D1(printk(KERN_DEBUG "jffs2_symlink: symlink's target '%s' cached\n", (char *)f->target)); 366 |
367 /* No data here. Only a metadata node, which will be | 367 /* No data here. Only a metadata node, which will be |
368 obsoleted by the first data write 369 */ 370 f->metadata = fn; 371 up(&f->sem); 372 373 jffs2_complete_reservation(c); 374 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, 375 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); --- 26 unchanged lines hidden (view full) --- 402 rd->nsize = namelen; 403 rd->type = DT_LNK; 404 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); 405 rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen)); 406 407 fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, ALLOC_NORMAL); 408 409 if (IS_ERR(fd)) { | 368 obsoleted by the first data write 369 */ 370 f->metadata = fn; 371 up(&f->sem); 372 373 jffs2_complete_reservation(c); 374 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, 375 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); --- 26 unchanged lines hidden (view full) --- 402 rd->nsize = namelen; 403 rd->type = DT_LNK; 404 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); 405 rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen)); 406 407 fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, ALLOC_NORMAL); 408 409 if (IS_ERR(fd)) { |
410 /* dirent failed to write. Delete the inode normally | 410 /* dirent failed to write. Delete the inode normally |
411 as if it were the final unlink() */ 412 jffs2_complete_reservation(c); 413 jffs2_free_raw_dirent(rd); 414 up(&dir_f->sem); 415 jffs2_clear_inode(inode); 416 return PTR_ERR(fd); 417 } 418 --- 26 unchanged lines hidden (view full) --- 445 uint32_t alloclen, phys_ofs; 446 int ret; 447 448 mode |= S_IFDIR; 449 450 ri = jffs2_alloc_raw_inode(); 451 if (!ri) 452 return -ENOMEM; | 411 as if it were the final unlink() */ 412 jffs2_complete_reservation(c); 413 jffs2_free_raw_dirent(rd); 414 up(&dir_f->sem); 415 jffs2_clear_inode(inode); 416 return PTR_ERR(fd); 417 } 418 --- 26 unchanged lines hidden (view full) --- 445 uint32_t alloclen, phys_ofs; 446 int ret; 447 448 mode |= S_IFDIR; 449 450 ri = jffs2_alloc_raw_inode(); 451 if (!ri) 452 return -ENOMEM; |
453 | 453 |
454 c = JFFS2_SB_INFO(dir_i->i_sb); 455 | 454 c = JFFS2_SB_INFO(dir_i->i_sb); 455 |
456 /* Try to reserve enough space for both node and dirent. 457 * Just the node will do for now, though | 456 /* Try to reserve enough space for both node and dirent. 457 * Just the node will do for now, though |
458 */ 459 namelen = dentry->d_name.len; 460 ret = jffs2_reserve_space(c, sizeof(*ri), &phys_ofs, &alloclen, ALLOC_NORMAL, 461 JFFS2_SUMMARY_INODE_SIZE); 462 463 if (ret) { 464 jffs2_free_raw_inode(ri); 465 return ret; --- 11 unchanged lines hidden (view full) --- 477 inode->i_fop = &jffs2_dir_operations; 478 /* Directories get nlink 2 at start */ 479 inode->i_nlink = 2; 480 481 f = JFFS2_INODE_INFO(inode); 482 483 ri->data_crc = cpu_to_je32(0); 484 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); | 458 */ 459 namelen = dentry->d_name.len; 460 ret = jffs2_reserve_space(c, sizeof(*ri), &phys_ofs, &alloclen, ALLOC_NORMAL, 461 JFFS2_SUMMARY_INODE_SIZE); 462 463 if (ret) { 464 jffs2_free_raw_inode(ri); 465 return ret; --- 11 unchanged lines hidden (view full) --- 477 inode->i_fop = &jffs2_dir_operations; 478 /* Directories get nlink 2 at start */ 479 inode->i_nlink = 2; 480 481 f = JFFS2_INODE_INFO(inode); 482 483 ri->data_crc = cpu_to_je32(0); 484 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); |
485 | 485 |
486 fn = jffs2_write_dnode(c, f, ri, NULL, 0, phys_ofs, ALLOC_NORMAL); 487 488 jffs2_free_raw_inode(ri); 489 490 if (IS_ERR(fn)) { 491 /* Eeek. Wave bye bye */ 492 up(&f->sem); 493 jffs2_complete_reservation(c); 494 jffs2_clear_inode(inode); 495 return PTR_ERR(fn); 496 } | 486 fn = jffs2_write_dnode(c, f, ri, NULL, 0, phys_ofs, ALLOC_NORMAL); 487 488 jffs2_free_raw_inode(ri); 489 490 if (IS_ERR(fn)) { 491 /* Eeek. Wave bye bye */ 492 up(&f->sem); 493 jffs2_complete_reservation(c); 494 jffs2_clear_inode(inode); 495 return PTR_ERR(fn); 496 } |
497 /* No data here. Only a metadata node, which will be | 497 /* No data here. Only a metadata node, which will be |
498 obsoleted by the first data write 499 */ 500 f->metadata = fn; 501 up(&f->sem); 502 503 jffs2_complete_reservation(c); 504 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, 505 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); 506 if (ret) { 507 /* Eep. */ 508 jffs2_clear_inode(inode); 509 return ret; 510 } | 498 obsoleted by the first data write 499 */ 500 f->metadata = fn; 501 up(&f->sem); 502 503 jffs2_complete_reservation(c); 504 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, 505 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); 506 if (ret) { 507 /* Eep. */ 508 jffs2_clear_inode(inode); 509 return ret; 510 } |
511 | 511 |
512 rd = jffs2_alloc_raw_dirent(); 513 if (!rd) { 514 /* Argh. Now we treat it like a normal delete */ 515 jffs2_complete_reservation(c); 516 jffs2_clear_inode(inode); 517 return -ENOMEM; 518 } 519 --- 10 unchanged lines hidden (view full) --- 530 rd->ino = cpu_to_je32(inode->i_ino); 531 rd->mctime = cpu_to_je32(get_seconds()); 532 rd->nsize = namelen; 533 rd->type = DT_DIR; 534 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); 535 rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen)); 536 537 fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, ALLOC_NORMAL); | 512 rd = jffs2_alloc_raw_dirent(); 513 if (!rd) { 514 /* Argh. Now we treat it like a normal delete */ 515 jffs2_complete_reservation(c); 516 jffs2_clear_inode(inode); 517 return -ENOMEM; 518 } 519 --- 10 unchanged lines hidden (view full) --- 530 rd->ino = cpu_to_je32(inode->i_ino); 531 rd->mctime = cpu_to_je32(get_seconds()); 532 rd->nsize = namelen; 533 rd->type = DT_DIR; 534 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); 535 rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen)); 536 537 fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, ALLOC_NORMAL); |
538 | 538 |
539 if (IS_ERR(fd)) { | 539 if (IS_ERR(fd)) { |
540 /* dirent failed to write. Delete the inode normally | 540 /* dirent failed to write. Delete the inode normally |
541 as if it were the final unlink() */ 542 jffs2_complete_reservation(c); 543 jffs2_free_raw_dirent(rd); 544 up(&dir_f->sem); 545 jffs2_clear_inode(inode); 546 return PTR_ERR(fd); 547 } 548 --- 45 unchanged lines hidden (view full) --- 594 int ret; 595 596 if (!old_valid_dev(rdev)) 597 return -EINVAL; 598 599 ri = jffs2_alloc_raw_inode(); 600 if (!ri) 601 return -ENOMEM; | 541 as if it were the final unlink() */ 542 jffs2_complete_reservation(c); 543 jffs2_free_raw_dirent(rd); 544 up(&dir_f->sem); 545 jffs2_clear_inode(inode); 546 return PTR_ERR(fd); 547 } 548 --- 45 unchanged lines hidden (view full) --- 594 int ret; 595 596 if (!old_valid_dev(rdev)) 597 return -EINVAL; 598 599 ri = jffs2_alloc_raw_inode(); 600 if (!ri) 601 return -ENOMEM; |
602 | 602 |
603 c = JFFS2_SB_INFO(dir_i->i_sb); | 603 c = JFFS2_SB_INFO(dir_i->i_sb); |
604 | 604 |
605 if (S_ISBLK(mode) || S_ISCHR(mode)) { 606 dev = cpu_to_je16(old_encode_dev(rdev)); 607 devlen = sizeof(dev); 608 } | 605 if (S_ISBLK(mode) || S_ISCHR(mode)) { 606 dev = cpu_to_je16(old_encode_dev(rdev)); 607 devlen = sizeof(dev); 608 } |
609 610 /* Try to reserve enough space for both node and dirent. 611 * Just the node will do for now, though | 609 610 /* Try to reserve enough space for both node and dirent. 611 * Just the node will do for now, though |
612 */ 613 namelen = dentry->d_name.len; 614 ret = jffs2_reserve_space(c, sizeof(*ri) + devlen, &phys_ofs, &alloclen, 615 ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE); 616 617 if (ret) { 618 jffs2_free_raw_inode(ri); 619 return ret; --- 13 unchanged lines hidden (view full) --- 633 634 ri->dsize = ri->csize = cpu_to_je32(devlen); 635 ri->totlen = cpu_to_je32(sizeof(*ri) + devlen); 636 ri->hdr_crc = cpu_to_je32(crc32(0, ri, sizeof(struct jffs2_unknown_node)-4)); 637 638 ri->compr = JFFS2_COMPR_NONE; 639 ri->data_crc = cpu_to_je32(crc32(0, &dev, devlen)); 640 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); | 612 */ 613 namelen = dentry->d_name.len; 614 ret = jffs2_reserve_space(c, sizeof(*ri) + devlen, &phys_ofs, &alloclen, 615 ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE); 616 617 if (ret) { 618 jffs2_free_raw_inode(ri); 619 return ret; --- 13 unchanged lines hidden (view full) --- 633 634 ri->dsize = ri->csize = cpu_to_je32(devlen); 635 ri->totlen = cpu_to_je32(sizeof(*ri) + devlen); 636 ri->hdr_crc = cpu_to_je32(crc32(0, ri, sizeof(struct jffs2_unknown_node)-4)); 637 638 ri->compr = JFFS2_COMPR_NONE; 639 ri->data_crc = cpu_to_je32(crc32(0, &dev, devlen)); 640 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); |
641 | 641 |
642 fn = jffs2_write_dnode(c, f, ri, (char *)&dev, devlen, phys_ofs, ALLOC_NORMAL); 643 644 jffs2_free_raw_inode(ri); 645 646 if (IS_ERR(fn)) { 647 /* Eeek. Wave bye bye */ 648 up(&f->sem); 649 jffs2_complete_reservation(c); 650 jffs2_clear_inode(inode); 651 return PTR_ERR(fn); 652 } | 642 fn = jffs2_write_dnode(c, f, ri, (char *)&dev, devlen, phys_ofs, ALLOC_NORMAL); 643 644 jffs2_free_raw_inode(ri); 645 646 if (IS_ERR(fn)) { 647 /* Eeek. Wave bye bye */ 648 up(&f->sem); 649 jffs2_complete_reservation(c); 650 jffs2_clear_inode(inode); 651 return PTR_ERR(fn); 652 } |
653 /* No data here. Only a metadata node, which will be | 653 /* No data here. Only a metadata node, which will be |
654 obsoleted by the first data write 655 */ 656 f->metadata = fn; 657 up(&f->sem); 658 659 jffs2_complete_reservation(c); 660 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, 661 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); --- 27 unchanged lines hidden (view full) --- 689 690 /* XXX: This is ugly. */ 691 rd->type = (mode & S_IFMT) >> 12; 692 693 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); 694 rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen)); 695 696 fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, ALLOC_NORMAL); | 654 obsoleted by the first data write 655 */ 656 f->metadata = fn; 657 up(&f->sem); 658 659 jffs2_complete_reservation(c); 660 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, 661 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); --- 27 unchanged lines hidden (view full) --- 689 690 /* XXX: This is ugly. */ 691 rd->type = (mode & S_IFMT) >> 12; 692 693 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); 694 rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen)); 695 696 fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, ALLOC_NORMAL); |
697 | 697 |
698 if (IS_ERR(fd)) { | 698 if (IS_ERR(fd)) { |
699 /* dirent failed to write. Delete the inode normally | 699 /* dirent failed to write. Delete the inode normally |
700 as if it were the final unlink() */ 701 jffs2_complete_reservation(c); 702 jffs2_free_raw_dirent(rd); 703 up(&dir_f->sem); 704 jffs2_clear_inode(inode); 705 return PTR_ERR(fd); 706 } 707 --- 17 unchanged lines hidden (view full) --- 725 struct inode *new_dir_i, struct dentry *new_dentry) 726{ 727 int ret; 728 struct jffs2_sb_info *c = JFFS2_SB_INFO(old_dir_i->i_sb); 729 struct jffs2_inode_info *victim_f = NULL; 730 uint8_t type; 731 uint32_t now; 732 | 700 as if it were the final unlink() */ 701 jffs2_complete_reservation(c); 702 jffs2_free_raw_dirent(rd); 703 up(&dir_f->sem); 704 jffs2_clear_inode(inode); 705 return PTR_ERR(fd); 706 } 707 --- 17 unchanged lines hidden (view full) --- 725 struct inode *new_dir_i, struct dentry *new_dentry) 726{ 727 int ret; 728 struct jffs2_sb_info *c = JFFS2_SB_INFO(old_dir_i->i_sb); 729 struct jffs2_inode_info *victim_f = NULL; 730 uint8_t type; 731 uint32_t now; 732 |
733 /* The VFS will check for us and prevent trying to rename a | 733 /* The VFS will check for us and prevent trying to rename a |
734 * file over a directory and vice versa, but if it's a directory, 735 * the VFS can't check whether the victim is empty. The filesystem 736 * needs to do that for itself. 737 */ 738 if (new_dentry->d_inode) { 739 victim_f = JFFS2_INODE_INFO(new_dentry->d_inode); 740 if (S_ISDIR(new_dentry->d_inode->i_mode)) { 741 struct jffs2_full_dirent *fd; --- 5 unchanged lines hidden (view full) --- 747 return -ENOTEMPTY; 748 } 749 } 750 up(&victim_f->sem); 751 } 752 } 753 754 /* XXX: We probably ought to alloc enough space for | 734 * file over a directory and vice versa, but if it's a directory, 735 * the VFS can't check whether the victim is empty. The filesystem 736 * needs to do that for itself. 737 */ 738 if (new_dentry->d_inode) { 739 victim_f = JFFS2_INODE_INFO(new_dentry->d_inode); 740 if (S_ISDIR(new_dentry->d_inode->i_mode)) { 741 struct jffs2_full_dirent *fd; --- 5 unchanged lines hidden (view full) --- 747 return -ENOTEMPTY; 748 } 749 } 750 up(&victim_f->sem); 751 } 752 } 753 754 /* XXX: We probably ought to alloc enough space for |
755 both nodes at the same time. Writing the new link, | 755 both nodes at the same time. Writing the new link, |
756 then getting -ENOSPC, is quite bad :) 757 */ 758 759 /* Make a hard link */ | 756 then getting -ENOSPC, is quite bad :) 757 */ 758 759 /* Make a hard link */ |
760 | 760 |
761 /* XXX: This is ugly */ 762 type = (old_dentry->d_inode->i_mode & S_IFMT) >> 12; 763 if (!type) type = DT_REG; 764 765 now = get_seconds(); | 761 /* XXX: This is ugly */ 762 type = (old_dentry->d_inode->i_mode & S_IFMT) >> 12; 763 if (!type) type = DT_REG; 764 765 now = get_seconds(); |
766 ret = jffs2_do_link(c, JFFS2_INODE_INFO(new_dir_i), | 766 ret = jffs2_do_link(c, JFFS2_INODE_INFO(new_dir_i), |
767 old_dentry->d_inode->i_ino, type, 768 new_dentry->d_name.name, new_dentry->d_name.len, now); 769 770 if (ret) 771 return ret; 772 773 if (victim_f) { 774 /* There was a victim. Kill it off nicely */ 775 new_dentry->d_inode->i_nlink--; 776 /* Don't oops if the victim was a dirent pointing to an 777 inode which didn't exist. */ 778 if (victim_f->inocache) { 779 down(&victim_f->sem); 780 victim_f->inocache->nlink--; 781 up(&victim_f->sem); 782 } 783 } 784 | 767 old_dentry->d_inode->i_ino, type, 768 new_dentry->d_name.name, new_dentry->d_name.len, now); 769 770 if (ret) 771 return ret; 772 773 if (victim_f) { 774 /* There was a victim. Kill it off nicely */ 775 new_dentry->d_inode->i_nlink--; 776 /* Don't oops if the victim was a dirent pointing to an 777 inode which didn't exist. */ 778 if (victim_f->inocache) { 779 down(&victim_f->sem); 780 victim_f->inocache->nlink--; 781 up(&victim_f->sem); 782 } 783 } 784 |
785 /* If it was a directory we moved, and there was no victim, | 785 /* If it was a directory we moved, and there was no victim, |
786 increase i_nlink on its new parent */ 787 if (S_ISDIR(old_dentry->d_inode->i_mode) && !victim_f) 788 new_dir_i->i_nlink++; 789 790 /* Unlink the original */ | 786 increase i_nlink on its new parent */ 787 if (S_ISDIR(old_dentry->d_inode->i_mode) && !victim_f) 788 new_dir_i->i_nlink++; 789 790 /* Unlink the original */ |
791 ret = jffs2_do_unlink(c, JFFS2_INODE_INFO(old_dir_i), | 791 ret = jffs2_do_unlink(c, JFFS2_INODE_INFO(old_dir_i), |
792 old_dentry->d_name.name, old_dentry->d_name.len, NULL, now); 793 794 /* We don't touch inode->i_nlink */ 795 796 if (ret) { 797 /* Oh shit. We really ought to make a single node which can do both atomically */ 798 struct jffs2_inode_info *f = JFFS2_INODE_INFO(old_dentry->d_inode); 799 down(&f->sem); --- 21 unchanged lines hidden --- | 792 old_dentry->d_name.name, old_dentry->d_name.len, NULL, now); 793 794 /* We don't touch inode->i_nlink */ 795 796 if (ret) { 797 /* Oh shit. We really ought to make a single node which can do both atomically */ 798 struct jffs2_inode_info *f = JFFS2_INODE_INFO(old_dentry->d_inode); 799 down(&f->sem); --- 21 unchanged lines hidden --- |