diff options
Diffstat (limited to 'ufs/sizes.c')
-rw-r--r-- | ufs/sizes.c | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/ufs/sizes.c b/ufs/sizes.c index a0b090d3..58cbfc98 100644 --- a/ufs/sizes.c +++ b/ufs/sizes.c @@ -1,5 +1,5 @@ /* File growth and truncation - Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation + Copyright (C) 1993, 1994, 1995, 1996, 1997, 1999 Free Software Foundation This file is part of the GNU Hurd. @@ -82,8 +82,7 @@ diskfs_truncate (struct node *np, np->allocsize = length; /* temporary */ bsize = blksize (sblock, np, lblkno (sblock, length)); np->allocsize = savesize; - diskfs_node_rdwr (np, (void *) zeroblock, length, - bsize - offset, 1, 0, 0); + diskfs_node_rdwr (np, zeroblock, length, bsize - offset, 1, 0, 0); diskfs_file_update (np, 1); } @@ -105,10 +104,14 @@ diskfs_truncate (struct node *np, pager_change_attributes (upi->p, MAY_CACHE, MEMORY_OBJECT_COPY_NONE, 1); obj = diskfs_get_filemap (np, VM_PROT_READ | VM_PROT_WRITE); - poke_pages (obj, round_page (length), round_page (np->allocsize)); - mach_port_deallocate (mach_task_self (), obj); - pager_flush_some (upi->p, round_page (length), - np->allocsize - length, 1); + if (obj != MACH_PORT_NULL) + { + /* XXX should cope with errors from diskfs_get_filemap */ + poke_pages (obj, round_page (length), round_page (np->allocsize)); + mach_port_deallocate (mach_task_self (), obj); + pager_flush_some (upi->p, round_page (length), + np->allocsize - length, 1); + } ports_port_deref (upi->p); } @@ -321,7 +324,7 @@ indir_release (struct node *np, daddr_t bno, int level) the block from the kernel's memory, making sure we do it synchronously--and BEFORE we attach it to the free list with ffs_blkfree. */ - pager_flush_some (disk_pager, fsaddr (sblock, bno), sblock->fs_bsize, 1); + pager_flush_some (diskfs_disk_pager, fsaddr (sblock, bno), sblock->fs_bsize, 1); /* We should also take this block off the inode's list of dirty indirect blocks if it's there. */ @@ -389,7 +392,8 @@ block_extended (struct node *np, don't get paged in from disk. */ if (round_page (old_size) < round_page (new_size)) offer_data (np, lbn * sblock->fs_bsize + round_page (old_size), - round_page (new_size) - round_page (old_size), zeroblock); + round_page (new_size) - round_page (old_size), + (vm_address_t)zeroblock); if (old_pbn != new_pbn) { @@ -400,6 +404,11 @@ block_extended (struct node *np, /* Map in this part of the file */ mapobj = diskfs_get_filemap (np, VM_PROT_WRITE | VM_PROT_READ); + + /* XXX Should cope with errors from diskfs_get_filemap and back + out the operation here. */ + assert (mapobj); + err = vm_map (mach_task_self (), &mapaddr, round_page (old_size), 0, 1, mapobj, lbn * sblock->fs_bsize, 0, VM_PROT_READ|VM_PROT_WRITE, VM_PROT_READ|VM_PROT_WRITE, 0); @@ -430,7 +439,7 @@ block_extended (struct node *np, /* Undo mapping */ mach_port_deallocate (mach_task_self (), mapobj); - vm_deallocate (mach_task_self (), mapaddr, round_page (old_size)); + munmap ((caddr_t) mapaddr, round_page (old_size)); /* Now it's OK to free the old block */ ffs_blkfree (np, old_pbn, old_size); @@ -477,6 +486,9 @@ diskfs_grow (struct node *np, /* This reference will ensure that NP->dn->fileinfo stays allocated. */ pagerpt = diskfs_get_filemap (np, VM_PROT_WRITE|VM_PROT_READ); + if (pagerpt == MACH_PORT_NULL) + return errno; + /* The new last block of the file. */ lbn = lblkno (sblock, end - 1); @@ -553,7 +565,8 @@ diskfs_grow (struct node *np, goto out; - offer_data (np, lbn * sblock->fs_bsize, size, zeroblock); + offer_data (np, lbn * sblock->fs_bsize, size, + (vm_address_t)zeroblock); write_disk_entry (di->di_db[lbn], bno); record_poke (di, sizeof (struct dinode)); np->dn_set_ctime = 1; @@ -647,7 +660,8 @@ diskfs_grow (struct node *np, sblock->fs_bsize, &bno, 0); if (err) goto out; - offer_data (np, lbn * sblock->fs_bsize, sblock->fs_bsize, zeroblock); + offer_data (np, lbn * sblock->fs_bsize, sblock->fs_bsize, + (vm_address_t)zeroblock); indirs[0].bno = bno; write_disk_entry (siblock[indirs[0].offset], bno); record_poke (siblock, sblock->fs_bsize); @@ -697,7 +711,7 @@ poke_pages (memory_object_t obj, { for (poke = addr; poke < addr + len; poke += vm_page_size) *(volatile int *)poke = *(volatile int *)poke; - vm_deallocate (mach_task_self (), addr, len); + munmap ((caddr_t) addr, len); } start += len; } |