2001-11-10 16:22:20 +03:00
|
|
|
/* $NetBSD: msdosfs_denode.c,v 1.53 2001/11/10 13:26:45 lukem Exp $ */
|
1994-06-29 10:29:24 +04:00
|
|
|
|
1994-07-19 01:38:08 +04:00
|
|
|
/*-
|
1997-10-17 15:23:29 +04:00
|
|
|
* Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
|
|
|
|
* Copyright (C) 1994, 1995, 1997 TooLs GmbH.
|
1994-07-19 01:38:08 +04:00
|
|
|
* All rights reserved.
|
1994-08-21 22:43:49 +04:00
|
|
|
* Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
|
1994-07-19 01:38:08 +04:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by TooLs GmbH.
|
|
|
|
* 4. The name of TooLs GmbH may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
1993-08-13 15:35:13 +04:00
|
|
|
/*
|
|
|
|
* Written by Paul Popelka (paulp@uts.amdahl.com)
|
1997-11-17 18:36:17 +03:00
|
|
|
*
|
1993-08-13 15:35:13 +04:00
|
|
|
* You can do anything you want with this software, just don't say you wrote
|
1994-07-19 01:38:08 +04:00
|
|
|
* it, and don't remove this notice.
|
1997-11-17 18:36:17 +03:00
|
|
|
*
|
1993-08-13 15:35:13 +04:00
|
|
|
* This software is provided "as is".
|
1997-11-17 18:36:17 +03:00
|
|
|
*
|
1994-07-19 01:38:08 +04:00
|
|
|
* The author supplies this software to be publicly redistributed on the
|
1993-08-13 15:35:13 +04:00
|
|
|
* understanding that the author is not responsible for the correct
|
|
|
|
* functioning of this software in any circumstances and is not liable for
|
|
|
|
* any damages caused by this software.
|
1997-11-17 18:36:17 +03:00
|
|
|
*
|
1993-08-13 15:35:13 +04:00
|
|
|
* October 1992
|
|
|
|
*/
|
|
|
|
|
2001-11-10 16:22:20 +03:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__KERNEL_RCSID(0, "$NetBSD: msdosfs_denode.c,v 1.53 2001/11/10 13:26:45 lukem Exp $");
|
|
|
|
|
1993-12-18 03:50:51 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mount.h>
|
1994-07-17 01:32:06 +04:00
|
|
|
#include <sys/malloc.h>
|
1998-09-01 08:04:10 +04:00
|
|
|
#include <sys/pool.h>
|
1993-12-18 03:50:51 +03:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/kernel.h> /* defines "time" */
|
1995-10-15 18:34:19 +03:00
|
|
|
#include <sys/dirent.h>
|
1996-02-09 22:13:39 +03:00
|
|
|
#include <sys/namei.h>
|
|
|
|
|
1998-02-05 10:59:28 +03:00
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
|
1993-12-18 03:50:51 +03:00
|
|
|
#include <msdosfs/bpb.h>
|
|
|
|
#include <msdosfs/msdosfsmount.h>
|
|
|
|
#include <msdosfs/direntry.h>
|
|
|
|
#include <msdosfs/denode.h>
|
|
|
|
#include <msdosfs/fat.h>
|
1993-08-13 15:35:13 +04:00
|
|
|
|
2001-09-15 20:12:54 +04:00
|
|
|
LIST_HEAD(ihashhead, denode) *dehashtbl;
|
1994-07-17 01:32:06 +04:00
|
|
|
u_long dehash; /* size of hash table - 1 */
|
2001-09-15 20:12:54 +04:00
|
|
|
#define DEHASH(dev, dcl, doff) \
|
|
|
|
(((dev) + (dcl) + (doff) / sizeof(struct direntry)) & dehash)
|
1993-08-13 15:35:13 +04:00
|
|
|
|
1998-05-20 05:45:15 +04:00
|
|
|
struct simplelock msdosfs_ihash_slock;
|
1998-03-01 05:20:01 +03:00
|
|
|
|
1998-09-01 08:04:10 +04:00
|
|
|
struct pool msdosfs_denode_pool;
|
|
|
|
|
2001-02-07 15:40:43 +03:00
|
|
|
extern int prtactive;
|
|
|
|
|
a whole bunch of changes to improve performance and robustness under load:
- remove special treatment of pager_map mappings in pmaps. this is
required now, since I've removed the globals that expose the address range.
pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's
no longer any need to special-case it.
- eliminate struct uvm_vnode by moving its fields into struct vnode.
- rewrite the pageout path. the pager is now responsible for handling the
high-level requests instead of only getting control after a bunch of work
has already been done on its behalf. this will allow us to UBCify LFS,
which needs tighter control over its pages than other filesystems do.
writing a page to disk no longer requires making it read-only, which
allows us to write wired pages without causing all kinds of havoc.
- use a new PG_PAGEOUT flag to indicate that a page should be freed
on behalf of the pagedaemon when it's unlocked. this flag is very similar
to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the
pageout fails due to eg. an indirect-block buffer being locked.
this allows us to remove the "version" field from struct vm_page,
and together with shrinking "loan_count" from 32 bits to 16,
struct vm_page is now 4 bytes smaller.
- no longer use PG_RELEASED for swap-backed pages. if the page is busy
because it's being paged out, we can't release the swap slot to be
reallocated until that write is complete, but unlike with vnodes we
don't keep a count of in-progress writes so there's no good way to
know when the write is done. instead, when we need to free a busy
swap-backed page, just sleep until we can get it busy ourselves.
- implement a fast-path for extending writes which allows us to avoid
zeroing new pages. this substantially reduces cpu usage.
- encapsulate the data used by the genfs code in a struct genfs_node,
which must be the first element of the filesystem-specific vnode data
for filesystems which use genfs_{get,put}pages().
- eliminate many of the UVM pagerops, since they aren't needed anymore
now that the pager "put" operation is a higher-level operation.
- enhance the genfs code to allow NFS to use the genfs_{get,put}pages
instead of a modified copy.
- clean up struct vnode by removing all the fields that used to be used by
the vfs_cluster.c code (which we don't use anymore with UBC).
- remove kmem_object and mb_object since they were useless.
instead of allocating pages to these objects, we now just allocate
pages with no object. such pages are mapped in the kernel until they
are freed, so we can use the mapping to find the page to free it.
this allows us to remove splvm() protection in several places.
The sum of all these changes improves write throughput on my
decstation 5000/200 to within 1% of the rate of NetBSD 1.5
and reduces the elapsed time for "make release" of a NetBSD 1.5
source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
|
|
|
struct genfs_ops msdosfs_genfsops = {
|
|
|
|
genfs_size,
|
|
|
|
msdosfs_gop_alloc,
|
|
|
|
genfs_gop_write,
|
|
|
|
};
|
|
|
|
|
1996-02-09 22:13:39 +03:00
|
|
|
static struct denode *msdosfs_hashget __P((dev_t, u_long, u_long));
|
|
|
|
static void msdosfs_hashins __P((struct denode *));
|
|
|
|
static void msdosfs_hashrem __P((struct denode *));
|
|
|
|
|
|
|
|
void
|
1993-08-13 15:35:13 +04:00
|
|
|
msdosfs_init()
|
|
|
|
{
|
2001-09-15 20:12:54 +04:00
|
|
|
dehashtbl = hashinit(desiredvnodes / 2, HASH_LIST, M_MSDOSFSMNT,
|
2000-11-08 17:28:12 +03:00
|
|
|
M_WAITOK, &dehash);
|
1998-05-20 05:45:15 +04:00
|
|
|
simple_lock_init(&msdosfs_ihash_slock);
|
1998-09-01 08:04:10 +04:00
|
|
|
pool_init(&msdosfs_denode_pool, sizeof(struct denode), 0, 0, 0,
|
|
|
|
"msdosnopl", 0, pool_page_alloc_nointr, pool_page_free_nointr,
|
|
|
|
M_MSDOSFSNODE);
|
1994-07-17 01:32:06 +04:00
|
|
|
}
|
1993-08-13 15:35:13 +04:00
|
|
|
|
2001-09-15 20:12:54 +04:00
|
|
|
/*
|
|
|
|
* Reinitialize inode hash table.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
msdosfs_reinit()
|
|
|
|
{
|
|
|
|
struct denode *dep;
|
|
|
|
struct ihashhead *oldhash, *hash;
|
|
|
|
u_long oldmask, mask, val;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
hash = hashinit(desiredvnodes / 2, HASH_LIST, M_MSDOSFSMNT, M_WAITOK,
|
|
|
|
&mask);
|
|
|
|
|
|
|
|
simple_lock(&msdosfs_ihash_slock);
|
|
|
|
oldhash = dehashtbl;
|
|
|
|
oldmask = dehash;
|
|
|
|
dehashtbl = hash;
|
|
|
|
dehash = mask;
|
|
|
|
for (i = 0; i <= oldmask; i++) {
|
|
|
|
while ((dep = LIST_FIRST(&oldhash[i])) != NULL) {
|
|
|
|
LIST_REMOVE(dep, de_hash);
|
|
|
|
val = DEHASH(dep->de_dev, dep->de_dirclust,
|
|
|
|
dep->de_diroffset);
|
|
|
|
LIST_INSERT_HEAD(&hash[val], dep, de_hash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
simple_unlock(&msdosfs_ihash_slock);
|
|
|
|
hashdone(oldhash, M_MSDOSFSMNT);
|
|
|
|
}
|
|
|
|
|
2000-03-16 21:08:17 +03:00
|
|
|
void
|
|
|
|
msdosfs_done()
|
|
|
|
{
|
|
|
|
hashdone(dehashtbl, M_MSDOSFSMNT);
|
|
|
|
pool_destroy(&msdosfs_denode_pool);
|
|
|
|
}
|
|
|
|
|
1994-07-17 01:32:06 +04:00
|
|
|
static struct denode *
|
|
|
|
msdosfs_hashget(dev, dirclust, diroff)
|
|
|
|
dev_t dev;
|
|
|
|
u_long dirclust;
|
|
|
|
u_long diroff;
|
|
|
|
{
|
|
|
|
struct denode *dep;
|
1998-03-01 05:20:01 +03:00
|
|
|
struct vnode *vp;
|
|
|
|
|
|
|
|
loop:
|
|
|
|
simple_lock(&msdosfs_ihash_slock);
|
2001-09-15 20:12:54 +04:00
|
|
|
LIST_FOREACH(dep, &dehashtbl[DEHASH(dev, dirclust, diroff)], de_hash) {
|
1998-03-01 05:20:01 +03:00
|
|
|
if (dirclust == dep->de_dirclust &&
|
|
|
|
diroff == dep->de_diroffset &&
|
|
|
|
dev == dep->de_dev &&
|
|
|
|
dep->de_refcnt != 0) {
|
|
|
|
vp = DETOV(dep);
|
|
|
|
simple_lock(&vp->v_interlock);
|
1998-04-20 20:48:05 +04:00
|
|
|
simple_unlock(&msdosfs_ihash_slock);
|
1998-03-01 05:20:01 +03:00
|
|
|
if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK))
|
|
|
|
goto loop;
|
|
|
|
return (dep);
|
1994-07-17 01:32:06 +04:00
|
|
|
}
|
1998-03-01 05:20:01 +03:00
|
|
|
}
|
2000-02-26 20:25:17 +03:00
|
|
|
simple_unlock(&msdosfs_ihash_slock);
|
1998-03-01 05:20:01 +03:00
|
|
|
return (NULL);
|
1994-07-17 01:32:06 +04:00
|
|
|
}
|
1993-08-13 15:35:13 +04:00
|
|
|
|
1994-07-17 01:32:06 +04:00
|
|
|
static void
|
|
|
|
msdosfs_hashins(dep)
|
|
|
|
struct denode *dep;
|
|
|
|
{
|
2001-09-15 20:12:54 +04:00
|
|
|
struct ihashhead *depp;
|
|
|
|
int val;
|
1997-11-17 18:36:17 +03:00
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
simple_lock(&msdosfs_ihash_slock);
|
2001-09-15 20:12:54 +04:00
|
|
|
val = DEHASH(dep->de_dev, dep->de_dirclust, dep->de_diroffset);
|
|
|
|
depp = &dehashtbl[val];
|
|
|
|
LIST_INSERT_HEAD(depp, dep, de_hash);
|
1998-03-01 05:20:01 +03:00
|
|
|
simple_unlock(&msdosfs_ihash_slock);
|
1994-07-17 01:32:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
msdosfs_hashrem(dep)
|
|
|
|
struct denode *dep;
|
|
|
|
{
|
1998-03-01 05:20:01 +03:00
|
|
|
simple_lock(&msdosfs_ihash_slock);
|
2001-09-15 20:12:54 +04:00
|
|
|
LIST_REMOVE(dep, de_hash);
|
1998-03-01 05:20:01 +03:00
|
|
|
simple_unlock(&msdosfs_ihash_slock);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-11-17 18:36:17 +03:00
|
|
|
* If deget() succeeds it returns with the gotten denode locked().
|
1994-07-17 01:32:06 +04:00
|
|
|
*
|
|
|
|
* pmp - address of msdosfsmount structure of the filesystem containing
|
|
|
|
* the denode of interest. The pm_dev field and the address of
|
1997-11-17 18:36:17 +03:00
|
|
|
* the msdosfsmount structure are used.
|
1994-07-17 01:32:06 +04:00
|
|
|
* dirclust - which cluster bp contains, if dirclust is 0 (root directory)
|
|
|
|
* diroffset is relative to the beginning of the root directory,
|
1997-11-17 18:36:17 +03:00
|
|
|
* otherwise it is cluster relative.
|
|
|
|
* diroffset - offset past begin of cluster of denode we want
|
1994-07-17 01:32:06 +04:00
|
|
|
* depp - returns the address of the gotten denode.
|
1993-08-13 15:35:13 +04:00
|
|
|
*/
|
|
|
|
int
|
1995-11-05 21:47:48 +03:00
|
|
|
deget(pmp, dirclust, diroffset, depp)
|
1993-08-13 15:35:13 +04:00
|
|
|
struct msdosfsmount *pmp; /* so we know the maj/min number */
|
|
|
|
u_long dirclust; /* cluster this dir entry came from */
|
|
|
|
u_long diroffset; /* index of entry within the cluster */
|
|
|
|
struct denode **depp; /* returns the addr of the gotten denode */
|
|
|
|
{
|
|
|
|
int error;
|
1996-02-09 22:13:39 +03:00
|
|
|
extern int (**msdosfs_vnodeop_p) __P((void *));
|
1995-11-05 21:47:48 +03:00
|
|
|
struct direntry *direntptr;
|
1993-08-13 15:35:13 +04:00
|
|
|
struct denode *ldep;
|
|
|
|
struct vnode *nvp;
|
|
|
|
struct buf *bp;
|
|
|
|
|
1994-07-19 01:38:08 +04:00
|
|
|
#ifdef MSDOSFS_DEBUG
|
1997-11-17 18:36:17 +03:00
|
|
|
printf("deget(pmp %p, dirclust %lu, diroffset %lx, depp %p)\n",
|
1996-10-11 02:46:11 +04:00
|
|
|
pmp, dirclust, diroffset, depp);
|
1994-07-19 01:38:08 +04:00
|
|
|
#endif
|
1993-08-13 15:35:13 +04:00
|
|
|
|
1997-10-17 15:23:29 +04:00
|
|
|
/*
|
|
|
|
* On FAT32 filesystems, root is a (more or less) normal
|
|
|
|
* directory
|
|
|
|
*/
|
|
|
|
if (FAT32(pmp) && dirclust == MSDOSFSROOT)
|
|
|
|
dirclust = pmp->pm_rootdirblk;
|
|
|
|
|
1993-08-13 15:35:13 +04:00
|
|
|
/*
|
|
|
|
* See if the denode is in the denode cache. Use the location of
|
|
|
|
* the directory entry to compute the hash value. For subdir use
|
1997-10-17 15:23:29 +04:00
|
|
|
* address of "." entry. For root dir (if not FAT32) use cluster
|
|
|
|
* MSDOSFSROOT, offset MSDOSFSROOT_OFS
|
1997-11-17 18:36:17 +03:00
|
|
|
*
|
1993-08-13 15:35:13 +04:00
|
|
|
* NOTE: The check for de_refcnt > 0 below insures the denode being
|
|
|
|
* examined does not represent an unlinked but still open file.
|
|
|
|
* These files are not to be accessible even when the directory
|
|
|
|
* entry that represented the file happens to be reused while the
|
|
|
|
* deleted file is still open.
|
|
|
|
*/
|
1996-02-09 22:13:39 +03:00
|
|
|
ldep = msdosfs_hashget(pmp->pm_dev, dirclust, diroffset);
|
|
|
|
if (ldep) {
|
1993-08-13 15:35:13 +04:00
|
|
|
*depp = ldep;
|
1994-09-28 14:31:23 +03:00
|
|
|
return (0);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Directory entry was not in cache, have to create a vnode and
|
|
|
|
* copy it from the passed disk buffer.
|
|
|
|
*/
|
|
|
|
/* getnewvnode() does a VREF() on the vnode */
|
1996-02-09 22:13:39 +03:00
|
|
|
error = getnewvnode(VT_MSDOSFS, pmp->pm_mountp,
|
|
|
|
msdosfs_vnodeop_p, &nvp);
|
|
|
|
if (error) {
|
1993-08-13 15:35:13 +04:00
|
|
|
*depp = 0;
|
1994-09-28 14:31:23 +03:00
|
|
|
return (error);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
1998-09-01 08:04:10 +04:00
|
|
|
ldep = pool_get(&msdosfs_denode_pool, PR_WAITOK);
|
a whole bunch of changes to improve performance and robustness under load:
- remove special treatment of pager_map mappings in pmaps. this is
required now, since I've removed the globals that expose the address range.
pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's
no longer any need to special-case it.
- eliminate struct uvm_vnode by moving its fields into struct vnode.
- rewrite the pageout path. the pager is now responsible for handling the
high-level requests instead of only getting control after a bunch of work
has already been done on its behalf. this will allow us to UBCify LFS,
which needs tighter control over its pages than other filesystems do.
writing a page to disk no longer requires making it read-only, which
allows us to write wired pages without causing all kinds of havoc.
- use a new PG_PAGEOUT flag to indicate that a page should be freed
on behalf of the pagedaemon when it's unlocked. this flag is very similar
to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the
pageout fails due to eg. an indirect-block buffer being locked.
this allows us to remove the "version" field from struct vm_page,
and together with shrinking "loan_count" from 32 bits to 16,
struct vm_page is now 4 bytes smaller.
- no longer use PG_RELEASED for swap-backed pages. if the page is busy
because it's being paged out, we can't release the swap slot to be
reallocated until that write is complete, but unlike with vnodes we
don't keep a count of in-progress writes so there's no good way to
know when the write is done. instead, when we need to free a busy
swap-backed page, just sleep until we can get it busy ourselves.
- implement a fast-path for extending writes which allows us to avoid
zeroing new pages. this substantially reduces cpu usage.
- encapsulate the data used by the genfs code in a struct genfs_node,
which must be the first element of the filesystem-specific vnode data
for filesystems which use genfs_{get,put}pages().
- eliminate many of the UVM pagerops, since they aren't needed anymore
now that the pager "put" operation is a higher-level operation.
- enhance the genfs code to allow NFS to use the genfs_{get,put}pages
instead of a modified copy.
- clean up struct vnode by removing all the fields that used to be used by
the vfs_cluster.c code (which we don't use anymore with UBC).
- remove kmem_object and mb_object since they were useless.
instead of allocating pages to these objects, we now just allocate
pages with no object. such pages are mapped in the kernel until they
are freed, so we can use the mapping to find the page to free it.
this allows us to remove splvm() protection in several places.
The sum of all these changes improves write throughput on my
decstation 5000/200 to within 1% of the rate of NetBSD 1.5
and reduces the elapsed time for "make release" of a NetBSD 1.5
source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
|
|
|
memset(ldep, 0, sizeof *ldep);
|
1994-07-17 01:32:06 +04:00
|
|
|
nvp->v_data = ldep;
|
1993-08-13 15:35:13 +04:00
|
|
|
ldep->de_vnode = nvp;
|
|
|
|
ldep->de_flag = 0;
|
|
|
|
ldep->de_devvp = 0;
|
|
|
|
ldep->de_lockf = 0;
|
1994-09-28 14:31:23 +03:00
|
|
|
ldep->de_dev = pmp->pm_dev;
|
1994-07-17 01:32:06 +04:00
|
|
|
ldep->de_dirclust = dirclust;
|
|
|
|
ldep->de_diroffset = diroffset;
|
1993-08-13 15:35:13 +04:00
|
|
|
fc_purge(ldep, 0); /* init the fat cache for this denode */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Insert the denode into the hash queue and lock the denode so it
|
|
|
|
* can't be accessed until we've read it in and have done what we
|
|
|
|
* need to it.
|
|
|
|
*/
|
1998-03-01 05:20:01 +03:00
|
|
|
vn_lock(nvp, LK_EXCLUSIVE | LK_RETRY);
|
1994-07-17 01:32:06 +04:00
|
|
|
msdosfs_hashins(ldep);
|
1993-08-13 15:35:13 +04:00
|
|
|
|
1997-10-17 15:23:29 +04:00
|
|
|
ldep->de_pmp = pmp;
|
|
|
|
ldep->de_devvp = pmp->pm_devvp;
|
|
|
|
ldep->de_refcnt = 1;
|
1993-08-13 15:35:13 +04:00
|
|
|
/*
|
|
|
|
* Copy the directory entry into the denode area of the vnode.
|
|
|
|
*/
|
1997-10-17 15:23:29 +04:00
|
|
|
if ((dirclust == MSDOSFSROOT
|
|
|
|
|| (FAT32(pmp) && dirclust == pmp->pm_rootdirblk))
|
|
|
|
&& diroffset == MSDOSFSROOT_OFS) {
|
1993-08-13 15:35:13 +04:00
|
|
|
/*
|
|
|
|
* Directory entry for the root directory. There isn't one,
|
|
|
|
* so we manufacture one. We should probably rummage
|
|
|
|
* through the root directory and find a label entry (if it
|
|
|
|
* exists), and then use the time and date from that entry
|
|
|
|
* as the time and date for the root denode.
|
|
|
|
*/
|
1997-10-17 15:23:29 +04:00
|
|
|
nvp->v_flag |= VROOT; /* should be further down XXX */
|
|
|
|
|
1993-08-13 15:35:13 +04:00
|
|
|
ldep->de_Attributes = ATTR_DIRECTORY;
|
1997-10-17 15:23:29 +04:00
|
|
|
if (FAT32(pmp))
|
|
|
|
ldep->de_StartCluster = pmp->pm_rootdirblk;
|
|
|
|
/* de_FileSize will be filled in further down */
|
|
|
|
else {
|
|
|
|
ldep->de_StartCluster = MSDOSFSROOT;
|
|
|
|
ldep->de_FileSize = pmp->pm_rootdirsize * pmp->pm_BytesPerSec;
|
|
|
|
}
|
1993-08-13 15:35:13 +04:00
|
|
|
/*
|
|
|
|
* fill in time and date so that dos2unixtime() doesn't
|
|
|
|
* spit up when called from msdosfs_getattr() with root
|
|
|
|
* denode
|
|
|
|
*/
|
1997-10-17 15:23:29 +04:00
|
|
|
ldep->de_CHun = 0;
|
1995-11-29 18:08:32 +03:00
|
|
|
ldep->de_CTime = 0x0000; /* 00:00:00 */
|
|
|
|
ldep->de_CDate = (0 << DD_YEAR_SHIFT) | (1 << DD_MONTH_SHIFT)
|
1994-03-03 03:51:30 +03:00
|
|
|
| (1 << DD_DAY_SHIFT);
|
1993-08-13 15:35:13 +04:00
|
|
|
/* Jan 1, 1980 */
|
1995-11-29 18:08:32 +03:00
|
|
|
ldep->de_ADate = ldep->de_CDate;
|
|
|
|
ldep->de_MTime = ldep->de_CTime;
|
|
|
|
ldep->de_MDate = ldep->de_CDate;
|
1993-08-13 15:35:13 +04:00
|
|
|
/* leave the other fields as garbage */
|
1994-07-17 01:32:06 +04:00
|
|
|
} else {
|
1996-02-09 22:13:39 +03:00
|
|
|
error = readep(pmp, dirclust, diroffset, &bp, &direntptr);
|
|
|
|
if (error)
|
1995-11-05 21:47:48 +03:00
|
|
|
return (error);
|
1994-03-03 03:51:30 +03:00
|
|
|
DE_INTERNALIZE(ldep, direntptr);
|
1995-11-05 21:47:48 +03:00
|
|
|
brelse(bp);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill in a few fields of the vnode and finish filling in the
|
|
|
|
* denode. Then return the address of the found denode.
|
|
|
|
*/
|
|
|
|
if (ldep->de_Attributes & ATTR_DIRECTORY) {
|
|
|
|
/*
|
|
|
|
* Since DOS directory entries that describe directories
|
|
|
|
* have 0 in the filesize field, we take this opportunity
|
|
|
|
* to find out the length of the directory and plug it into
|
|
|
|
* the denode structure.
|
|
|
|
*/
|
|
|
|
u_long size;
|
|
|
|
|
|
|
|
nvp->v_type = VDIR;
|
1997-10-17 15:23:29 +04:00
|
|
|
if (ldep->de_StartCluster != MSDOSFSROOT) {
|
2000-03-27 21:40:26 +04:00
|
|
|
error = pcbmap(ldep, CLUST_END, 0, &size, 0);
|
1993-08-13 15:35:13 +04:00
|
|
|
if (error == E2BIG) {
|
1995-10-15 18:34:19 +03:00
|
|
|
ldep->de_FileSize = de_cn2off(pmp, size);
|
1993-08-13 15:35:13 +04:00
|
|
|
error = 0;
|
1994-07-17 01:32:06 +04:00
|
|
|
} else
|
1996-10-13 08:10:34 +04:00
|
|
|
printf("deget(): pcbmap returned %d\n", error);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
1994-07-17 01:32:06 +04:00
|
|
|
} else
|
1993-08-13 15:35:13 +04:00
|
|
|
nvp->v_type = VREG;
|
a whole bunch of changes to improve performance and robustness under load:
- remove special treatment of pager_map mappings in pmaps. this is
required now, since I've removed the globals that expose the address range.
pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's
no longer any need to special-case it.
- eliminate struct uvm_vnode by moving its fields into struct vnode.
- rewrite the pageout path. the pager is now responsible for handling the
high-level requests instead of only getting control after a bunch of work
has already been done on its behalf. this will allow us to UBCify LFS,
which needs tighter control over its pages than other filesystems do.
writing a page to disk no longer requires making it read-only, which
allows us to write wired pages without causing all kinds of havoc.
- use a new PG_PAGEOUT flag to indicate that a page should be freed
on behalf of the pagedaemon when it's unlocked. this flag is very similar
to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the
pageout fails due to eg. an indirect-block buffer being locked.
this allows us to remove the "version" field from struct vm_page,
and together with shrinking "loan_count" from 32 bits to 16,
struct vm_page is now 4 bytes smaller.
- no longer use PG_RELEASED for swap-backed pages. if the page is busy
because it's being paged out, we can't release the swap slot to be
reallocated until that write is complete, but unlike with vnodes we
don't keep a count of in-progress writes so there's no good way to
know when the write is done. instead, when we need to free a busy
swap-backed page, just sleep until we can get it busy ourselves.
- implement a fast-path for extending writes which allows us to avoid
zeroing new pages. this substantially reduces cpu usage.
- encapsulate the data used by the genfs code in a struct genfs_node,
which must be the first element of the filesystem-specific vnode data
for filesystems which use genfs_{get,put}pages().
- eliminate many of the UVM pagerops, since they aren't needed anymore
now that the pager "put" operation is a higher-level operation.
- enhance the genfs code to allow NFS to use the genfs_{get,put}pages
instead of a modified copy.
- clean up struct vnode by removing all the fields that used to be used by
the vfs_cluster.c code (which we don't use anymore with UBC).
- remove kmem_object and mb_object since they were useless.
instead of allocating pages to these objects, we now just allocate
pages with no object. such pages are mapped in the kernel until they
are freed, so we can use the mapping to find the page to free it.
this allows us to remove splvm() protection in several places.
The sum of all these changes improves write throughput on my
decstation 5000/200 to within 1% of the rate of NetBSD 1.5
and reduces the elapsed time for "make release" of a NetBSD 1.5
source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
|
|
|
genfs_node_init(nvp, &msdosfs_genfsops);
|
1993-08-13 15:35:13 +04:00
|
|
|
VREF(ldep->de_devvp);
|
|
|
|
*depp = ldep;
|
a whole bunch of changes to improve performance and robustness under load:
- remove special treatment of pager_map mappings in pmaps. this is
required now, since I've removed the globals that expose the address range.
pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's
no longer any need to special-case it.
- eliminate struct uvm_vnode by moving its fields into struct vnode.
- rewrite the pageout path. the pager is now responsible for handling the
high-level requests instead of only getting control after a bunch of work
has already been done on its behalf. this will allow us to UBCify LFS,
which needs tighter control over its pages than other filesystems do.
writing a page to disk no longer requires making it read-only, which
allows us to write wired pages without causing all kinds of havoc.
- use a new PG_PAGEOUT flag to indicate that a page should be freed
on behalf of the pagedaemon when it's unlocked. this flag is very similar
to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the
pageout fails due to eg. an indirect-block buffer being locked.
this allows us to remove the "version" field from struct vm_page,
and together with shrinking "loan_count" from 32 bits to 16,
struct vm_page is now 4 bytes smaller.
- no longer use PG_RELEASED for swap-backed pages. if the page is busy
because it's being paged out, we can't release the swap slot to be
reallocated until that write is complete, but unlike with vnodes we
don't keep a count of in-progress writes so there's no good way to
know when the write is done. instead, when we need to free a busy
swap-backed page, just sleep until we can get it busy ourselves.
- implement a fast-path for extending writes which allows us to avoid
zeroing new pages. this substantially reduces cpu usage.
- encapsulate the data used by the genfs code in a struct genfs_node,
which must be the first element of the filesystem-specific vnode data
for filesystems which use genfs_{get,put}pages().
- eliminate many of the UVM pagerops, since they aren't needed anymore
now that the pager "put" operation is a higher-level operation.
- enhance the genfs code to allow NFS to use the genfs_{get,put}pages
instead of a modified copy.
- clean up struct vnode by removing all the fields that used to be used by
the vfs_cluster.c code (which we don't use anymore with UBC).
- remove kmem_object and mb_object since they were useless.
instead of allocating pages to these objects, we now just allocate
pages with no object. such pages are mapped in the kernel until they
are freed, so we can use the mapping to find the page to free it.
this allows us to remove splvm() protection in several places.
The sum of all these changes improves write throughput on my
decstation 5000/200 to within 1% of the rate of NetBSD 1.5
and reduces the elapsed time for "make release" of a NetBSD 1.5
source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
|
|
|
nvp->v_size = ldep->de_FileSize;
|
1994-09-28 14:31:23 +03:00
|
|
|
return (0);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1995-06-02 19:33:22 +04:00
|
|
|
deupdat(dep, waitfor)
|
1993-08-13 15:35:13 +04:00
|
|
|
struct denode *dep;
|
|
|
|
int waitfor;
|
|
|
|
{
|
1995-09-09 23:38:00 +04:00
|
|
|
|
2000-05-14 03:43:06 +04:00
|
|
|
return (VOP_UPDATE(DETOV(dep), NULL, NULL, waitfor ? UPDATE_WAIT : 0));
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Truncate the file described by dep to the length specified by length.
|
|
|
|
*/
|
|
|
|
int
|
1994-07-17 01:32:06 +04:00
|
|
|
detrunc(dep, length, flags, cred, p)
|
1993-08-13 15:35:13 +04:00
|
|
|
struct denode *dep;
|
|
|
|
u_long length;
|
|
|
|
int flags;
|
1994-07-17 01:32:06 +04:00
|
|
|
struct ucred *cred;
|
|
|
|
struct proc *p;
|
1993-08-13 15:35:13 +04:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
int allerror;
|
|
|
|
u_long eofentry;
|
|
|
|
u_long chaintofree;
|
2000-05-28 08:13:56 +04:00
|
|
|
daddr_t bn, lastblock;
|
1993-08-13 15:35:13 +04:00
|
|
|
int boff;
|
|
|
|
int isadir = dep->de_Attributes & ATTR_DIRECTORY;
|
|
|
|
struct buf *bp;
|
|
|
|
struct msdosfsmount *pmp = dep->de_pmp;
|
|
|
|
|
1994-07-19 01:38:08 +04:00
|
|
|
#ifdef MSDOSFS_DEBUG
|
1997-11-17 18:36:17 +03:00
|
|
|
printf("detrunc(): file %s, length %lu, flags %x\n", dep->de_Name, length, flags);
|
1994-07-19 01:38:08 +04:00
|
|
|
#endif
|
1993-08-13 15:35:13 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Disallow attempts to truncate the root directory since it is of
|
|
|
|
* fixed size. That's just the way dos filesystems are. We use
|
|
|
|
* the VROOT bit in the vnode because checking for the directory
|
|
|
|
* bit and a startcluster of 0 in the denode is not adequate to
|
|
|
|
* recognize the root directory at this point in a file or
|
|
|
|
* directory's life.
|
|
|
|
*/
|
1997-10-17 15:23:29 +04:00
|
|
|
if ((DETOV(dep)->v_flag & VROOT) && !FAT32(pmp)) {
|
1996-10-13 08:10:34 +04:00
|
|
|
printf("detrunc(): can't truncate root directory, clust %ld, offset %ld\n",
|
1993-08-13 15:35:13 +04:00
|
|
|
dep->de_dirclust, dep->de_diroffset);
|
1994-09-28 14:31:23 +03:00
|
|
|
return (EINVAL);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
|
|
|
|
1998-02-05 10:59:28 +03:00
|
|
|
uvm_vnp_setsize(DETOV(dep), length);
|
1993-08-13 15:35:13 +04:00
|
|
|
|
1994-07-19 01:38:08 +04:00
|
|
|
if (dep->de_FileSize < length)
|
1994-09-28 14:31:23 +03:00
|
|
|
return (deextend(dep, length, cred));
|
2000-05-28 08:13:56 +04:00
|
|
|
lastblock = de_clcount(pmp, length) - 1;
|
1993-08-13 15:35:13 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the desired length is 0 then remember the starting cluster of
|
|
|
|
* the file and set the StartCluster field in the directory entry
|
|
|
|
* to 0. If the desired length is not zero, then get the number of
|
|
|
|
* the last cluster in the shortened file. Then get the number of
|
|
|
|
* the first cluster in the part of the file that is to be freed.
|
|
|
|
* Then set the next cluster pointer in the last cluster of the
|
|
|
|
* file to CLUST_EOFE.
|
|
|
|
*/
|
|
|
|
if (length == 0) {
|
|
|
|
chaintofree = dep->de_StartCluster;
|
|
|
|
dep->de_StartCluster = 0;
|
|
|
|
eofentry = ~0;
|
1994-07-17 01:32:06 +04:00
|
|
|
} else {
|
2000-05-28 08:13:56 +04:00
|
|
|
error = pcbmap(dep, lastblock, 0, &eofentry, 0);
|
1996-02-09 22:13:39 +03:00
|
|
|
if (error) {
|
1994-07-19 01:38:08 +04:00
|
|
|
#ifdef MSDOSFS_DEBUG
|
1996-10-13 08:10:34 +04:00
|
|
|
printf("detrunc(): pcbmap fails %d\n", error);
|
1994-07-19 01:38:08 +04:00
|
|
|
#endif
|
1994-09-28 14:31:23 +03:00
|
|
|
return (error);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-28 08:13:56 +04:00
|
|
|
fc_purge(dep, lastblock + 1);
|
1993-08-13 15:35:13 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the new length is not a multiple of the cluster size then we
|
|
|
|
* must zero the tail end of the new last cluster in case it
|
|
|
|
* becomes part of the file again because of a seek.
|
|
|
|
*/
|
|
|
|
if ((boff = length & pmp->pm_crbomask) != 0) {
|
|
|
|
if (isadir) {
|
|
|
|
bn = cntobn(pmp, eofentry);
|
|
|
|
error = bread(pmp->pm_devvp, bn, pmp->pm_bpcluster,
|
|
|
|
NOCRED, &bp);
|
1994-07-17 01:32:06 +04:00
|
|
|
} else {
|
1994-07-19 01:38:08 +04:00
|
|
|
bn = de_blk(pmp, length);
|
1993-08-13 15:35:13 +04:00
|
|
|
error = bread(DETOV(dep), bn, pmp->pm_bpcluster,
|
|
|
|
NOCRED, &bp);
|
|
|
|
}
|
|
|
|
if (error) {
|
1995-10-15 18:34:19 +03:00
|
|
|
brelse(bp);
|
1994-07-19 01:38:08 +04:00
|
|
|
#ifdef MSDOSFS_DEBUG
|
1996-10-13 08:10:34 +04:00
|
|
|
printf("detrunc(): bread fails %d\n", error);
|
1994-07-19 01:38:08 +04:00
|
|
|
#endif
|
1994-09-28 14:31:23 +03:00
|
|
|
return (error);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
2000-11-27 11:39:39 +03:00
|
|
|
|
1993-08-13 15:35:13 +04:00
|
|
|
/*
|
|
|
|
* is this the right place for it?
|
|
|
|
*/
|
1998-08-10 00:51:08 +04:00
|
|
|
memset(bp->b_data + boff, 0, pmp->pm_bpcluster - boff);
|
1993-08-13 15:35:13 +04:00
|
|
|
if (flags & IO_SYNC)
|
|
|
|
bwrite(bp);
|
|
|
|
else
|
|
|
|
bdwrite(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write out the updated directory entry. Even if the update fails
|
|
|
|
* we free the trailing clusters.
|
|
|
|
*/
|
|
|
|
dep->de_FileSize = length;
|
1995-09-09 23:38:00 +04:00
|
|
|
if (!isadir)
|
|
|
|
dep->de_flag |= DE_UPDATE|DE_MODIFIED;
|
2000-05-28 08:13:56 +04:00
|
|
|
vtruncbuf(DETOV(dep), lastblock + 1, 0, 0);
|
1995-06-02 19:33:22 +04:00
|
|
|
allerror = deupdat(dep, 1);
|
1994-07-19 01:38:08 +04:00
|
|
|
#ifdef MSDOSFS_DEBUG
|
1997-11-17 18:36:17 +03:00
|
|
|
printf("detrunc(): allerror %d, eofentry %lu\n",
|
1994-07-17 01:32:06 +04:00
|
|
|
allerror, eofentry);
|
1994-07-19 01:38:08 +04:00
|
|
|
#endif
|
1993-08-13 15:35:13 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we need to break the cluster chain for the file then do it
|
|
|
|
* now.
|
|
|
|
*/
|
|
|
|
if (eofentry != ~0) {
|
1996-02-09 22:13:39 +03:00
|
|
|
error = fatentry(FAT_GET_AND_SET, pmp, eofentry,
|
|
|
|
&chaintofree, CLUST_EOFE);
|
|
|
|
if (error) {
|
1994-07-19 01:38:08 +04:00
|
|
|
#ifdef MSDOSFS_DEBUG
|
1996-10-13 08:10:34 +04:00
|
|
|
printf("detrunc(): fatentry errors %d\n", error);
|
1994-07-19 01:38:08 +04:00
|
|
|
#endif
|
1994-09-28 14:31:23 +03:00
|
|
|
return (error);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
1995-10-15 18:34:19 +03:00
|
|
|
fc_setcache(dep, FC_LASTFC, de_cluster(pmp, length - 1),
|
1994-07-17 01:32:06 +04:00
|
|
|
eofentry);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now free the clusters removed from the file because of the
|
|
|
|
* truncation.
|
|
|
|
*/
|
2000-05-13 10:04:41 +04:00
|
|
|
if (chaintofree != 0 && !MSDOSFSEOF(chaintofree, pmp->pm_fatmask))
|
1993-08-13 15:35:13 +04:00
|
|
|
freeclusterchain(pmp, chaintofree);
|
|
|
|
|
1994-09-28 14:31:23 +03:00
|
|
|
return (allerror);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
|
|
|
|
1994-07-17 01:32:06 +04:00
|
|
|
/*
|
|
|
|
* Extend the file described by dep to length specified by length.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
deextend(dep, length, cred)
|
|
|
|
struct denode *dep;
|
1994-09-28 14:31:23 +03:00
|
|
|
u_long length;
|
1994-07-17 01:32:06 +04:00
|
|
|
struct ucred *cred;
|
|
|
|
{
|
|
|
|
struct msdosfsmount *pmp = dep->de_pmp;
|
2001-01-01 03:25:41 +03:00
|
|
|
u_long count, osize;
|
1994-07-17 01:32:06 +04:00
|
|
|
int error;
|
1997-11-17 18:36:17 +03:00
|
|
|
|
1994-07-17 01:32:06 +04:00
|
|
|
/*
|
|
|
|
* The root of a DOS filesystem cannot be extended.
|
|
|
|
*/
|
1997-10-17 15:23:29 +04:00
|
|
|
if ((DETOV(dep)->v_flag & VROOT) && !FAT32(pmp))
|
1994-09-28 14:31:23 +03:00
|
|
|
return (EINVAL);
|
1994-07-17 01:32:06 +04:00
|
|
|
|
|
|
|
/*
|
1995-11-29 18:08:32 +03:00
|
|
|
* Directories cannot be extended.
|
1994-07-17 01:32:06 +04:00
|
|
|
*/
|
1995-11-29 18:08:32 +03:00
|
|
|
if (dep->de_Attributes & ATTR_DIRECTORY)
|
|
|
|
return (EISDIR);
|
1994-07-17 01:32:06 +04:00
|
|
|
|
|
|
|
if (length <= dep->de_FileSize)
|
|
|
|
panic("deextend: file too large");
|
1997-11-17 18:36:17 +03:00
|
|
|
|
1994-07-17 01:32:06 +04:00
|
|
|
/*
|
1994-07-19 01:38:08 +04:00
|
|
|
* Compute the number of clusters to allocate.
|
1994-07-17 01:32:06 +04:00
|
|
|
*/
|
1994-07-19 01:38:08 +04:00
|
|
|
count = de_clcount(pmp, length) - de_clcount(pmp, dep->de_FileSize);
|
|
|
|
if (count > 0) {
|
|
|
|
if (count > pmp->pm_freeclustercount)
|
1994-09-28 14:31:23 +03:00
|
|
|
return (ENOSPC);
|
1996-02-09 22:13:39 +03:00
|
|
|
error = extendfile(dep, count, NULL, NULL, DE_CLEAR);
|
|
|
|
if (error) {
|
1994-07-19 01:38:08 +04:00
|
|
|
/* truncate the added clusters away again */
|
|
|
|
(void) detrunc(dep, dep->de_FileSize, 0, cred, NULL);
|
1994-09-28 14:31:23 +03:00
|
|
|
return (error);
|
1994-07-19 01:38:08 +04:00
|
|
|
}
|
1994-07-17 01:32:06 +04:00
|
|
|
}
|
1997-11-17 18:36:17 +03:00
|
|
|
|
2001-01-01 03:25:41 +03:00
|
|
|
osize = dep->de_FileSize;
|
1994-07-17 01:32:06 +04:00
|
|
|
dep->de_FileSize = length;
|
2001-01-01 03:25:41 +03:00
|
|
|
uvm_vnp_setsize(DETOV(dep), (voff_t)dep->de_FileSize);
|
1995-06-02 19:33:22 +04:00
|
|
|
dep->de_flag |= DE_UPDATE|DE_MODIFIED;
|
2001-01-01 03:25:41 +03:00
|
|
|
uvm_vnp_zerorange(DETOV(dep), (off_t)osize,
|
|
|
|
(size_t)(dep->de_FileSize - osize));
|
1995-06-02 19:33:22 +04:00
|
|
|
return (deupdat(dep, 1));
|
1994-07-17 01:32:06 +04:00
|
|
|
}
|
|
|
|
|
1993-08-13 15:35:13 +04:00
|
|
|
/*
|
|
|
|
* Move a denode to its correct hash queue after the file it represents has
|
|
|
|
* been moved to a new directory.
|
|
|
|
*/
|
1994-09-28 14:31:23 +03:00
|
|
|
void
|
1993-08-13 15:35:13 +04:00
|
|
|
reinsert(dep)
|
|
|
|
struct denode *dep;
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Fix up the denode cache. If the denode is for a directory,
|
|
|
|
* there is nothing to do since the hash is based on the starting
|
|
|
|
* cluster of the directory file and that hasn't changed. If for a
|
|
|
|
* file the hash is based on the location of the directory entry,
|
|
|
|
* so we must remove it from the cache and re-enter it with the
|
|
|
|
* hash based on the new location of the directory entry.
|
|
|
|
*/
|
1994-09-28 14:31:23 +03:00
|
|
|
if (dep->de_Attributes & ATTR_DIRECTORY)
|
|
|
|
return;
|
|
|
|
msdosfs_hashrem(dep);
|
|
|
|
msdosfs_hashins(dep);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1996-02-09 22:13:39 +03:00
|
|
|
msdosfs_reclaim(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1994-07-17 01:32:06 +04:00
|
|
|
struct vop_reclaim_args /* {
|
|
|
|
struct vnode *a_vp;
|
1996-02-09 22:13:39 +03:00
|
|
|
} */ *ap = v;
|
1994-07-17 01:32:06 +04:00
|
|
|
struct vnode *vp = ap->a_vp;
|
1993-08-13 15:35:13 +04:00
|
|
|
struct denode *dep = VTODE(vp);
|
1997-11-17 18:36:17 +03:00
|
|
|
|
1994-07-19 01:38:08 +04:00
|
|
|
#ifdef MSDOSFS_DEBUG
|
1997-11-17 00:47:27 +03:00
|
|
|
printf("msdosfs_reclaim(): dep %p, file %s, refcnt %ld\n",
|
1993-08-13 15:35:13 +04:00
|
|
|
dep, dep->de_Name, dep->de_refcnt);
|
1994-07-19 01:38:08 +04:00
|
|
|
#endif
|
1993-08-13 15:35:13 +04:00
|
|
|
|
1994-07-17 01:32:06 +04:00
|
|
|
if (prtactive && vp->v_usecount != 0)
|
1993-08-13 15:35:13 +04:00
|
|
|
vprint("msdosfs_reclaim(): pushing active", vp);
|
|
|
|
/*
|
1994-09-28 14:31:23 +03:00
|
|
|
* Remove the denode from its hash chain.
|
1993-08-13 15:35:13 +04:00
|
|
|
*/
|
1994-07-17 01:32:06 +04:00
|
|
|
msdosfs_hashrem(dep);
|
1993-08-13 15:35:13 +04:00
|
|
|
/*
|
1994-09-28 14:31:23 +03:00
|
|
|
* Purge old data structures associated with the denode.
|
1993-08-13 15:35:13 +04:00
|
|
|
*/
|
1994-09-28 14:31:23 +03:00
|
|
|
cache_purge(vp);
|
1993-08-13 15:35:13 +04:00
|
|
|
if (dep->de_devvp) {
|
|
|
|
vrele(dep->de_devvp);
|
|
|
|
dep->de_devvp = 0;
|
|
|
|
}
|
1994-09-28 14:31:23 +03:00
|
|
|
#if 0 /* XXX */
|
1993-08-13 15:35:13 +04:00
|
|
|
dep->de_flag = 0;
|
1994-09-28 14:31:23 +03:00
|
|
|
#endif
|
1998-09-01 08:04:10 +04:00
|
|
|
pool_put(&msdosfs_denode_pool, dep);
|
1994-07-17 01:32:06 +04:00
|
|
|
vp->v_data = NULL;
|
1994-09-28 14:31:23 +03:00
|
|
|
return (0);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1996-02-09 22:13:39 +03:00
|
|
|
msdosfs_inactive(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1994-07-17 01:32:06 +04:00
|
|
|
struct vop_inactive_args /* {
|
|
|
|
struct vnode *a_vp;
|
1998-03-01 05:20:01 +03:00
|
|
|
struct proc *a_p;
|
1996-02-09 22:13:39 +03:00
|
|
|
} */ *ap = v;
|
1998-03-01 05:20:01 +03:00
|
|
|
struct proc *p = ap->a_p;
|
1994-07-17 01:32:06 +04:00
|
|
|
struct vnode *vp = ap->a_vp;
|
1993-08-13 15:35:13 +04:00
|
|
|
struct denode *dep = VTODE(vp);
|
1998-03-01 05:20:01 +03:00
|
|
|
int error = 0;
|
1997-11-17 18:36:17 +03:00
|
|
|
|
1994-07-19 01:38:08 +04:00
|
|
|
#ifdef MSDOSFS_DEBUG
|
1997-11-17 00:47:27 +03:00
|
|
|
printf("msdosfs_inactive(): dep %p, de_Name[0] %x\n", dep, dep->de_Name[0]);
|
1994-07-19 01:38:08 +04:00
|
|
|
#endif
|
1993-08-13 15:35:13 +04:00
|
|
|
|
1994-07-17 01:32:06 +04:00
|
|
|
if (prtactive && vp->v_usecount != 0)
|
1993-08-13 15:35:13 +04:00
|
|
|
vprint("msdosfs_inactive(): pushing active", vp);
|
|
|
|
|
|
|
|
/*
|
1994-09-28 14:31:23 +03:00
|
|
|
* Get rid of denodes related to stale file handles.
|
1993-08-13 15:35:13 +04:00
|
|
|
*/
|
1998-03-01 05:20:01 +03:00
|
|
|
if (dep->de_Name[0] == SLOT_DELETED)
|
|
|
|
goto out;
|
1993-08-13 15:35:13 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the file has been deleted and it is on a read/write
|
|
|
|
* filesystem, then truncate the file, and mark the directory slot
|
1994-07-17 01:32:06 +04:00
|
|
|
* as empty. (This may not be necessary for the dos filesystem.)
|
1993-08-13 15:35:13 +04:00
|
|
|
*/
|
1994-07-19 01:38:08 +04:00
|
|
|
#ifdef MSDOSFS_DEBUG
|
2000-02-01 16:55:23 +03:00
|
|
|
printf("msdosfs_inactive(): dep %p, refcnt %ld, mntflag %x %s",
|
|
|
|
dep, dep->de_refcnt, vp->v_mount->mnt_flag,
|
|
|
|
(vp->v_mount->mnt_flag & MNT_RDONLY) ? "MNT_RDONLY" : "");
|
1994-07-19 01:38:08 +04:00
|
|
|
#endif
|
1995-10-15 18:34:19 +03:00
|
|
|
if (dep->de_refcnt <= 0 && (vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
|
2001-02-18 23:17:04 +03:00
|
|
|
if (dep->de_FileSize != 0) {
|
|
|
|
error = detrunc(dep, (u_long)0, 0, NOCRED, NULL);
|
|
|
|
}
|
1995-10-15 18:34:19 +03:00
|
|
|
dep->de_Name[0] = SLOT_DELETED;
|
|
|
|
}
|
1995-06-02 19:33:22 +04:00
|
|
|
deupdat(dep, 0);
|
1998-03-01 05:20:01 +03:00
|
|
|
out:
|
|
|
|
VOP_UNLOCK(vp, 0);
|
1993-08-13 15:35:13 +04:00
|
|
|
/*
|
1994-09-28 14:31:23 +03:00
|
|
|
* If we are done with the denode, reclaim it
|
|
|
|
* so that it can be reused immediately.
|
1993-08-13 15:35:13 +04:00
|
|
|
*/
|
1994-07-19 01:38:08 +04:00
|
|
|
#ifdef MSDOSFS_DEBUG
|
2000-02-01 13:33:18 +03:00
|
|
|
printf("msdosfs_inactive(): v_usecount %ld, de_Name[0] %x\n",
|
|
|
|
vp->v_usecount, dep->de_Name[0]);
|
1994-07-19 01:38:08 +04:00
|
|
|
#endif
|
1998-03-01 05:20:01 +03:00
|
|
|
if (dep->de_Name[0] == SLOT_DELETED)
|
|
|
|
vrecycle(vp, (struct simplelock *)0, p);
|
1994-09-28 14:31:23 +03:00
|
|
|
return (error);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
a whole bunch of changes to improve performance and robustness under load:
- remove special treatment of pager_map mappings in pmaps. this is
required now, since I've removed the globals that expose the address range.
pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's
no longer any need to special-case it.
- eliminate struct uvm_vnode by moving its fields into struct vnode.
- rewrite the pageout path. the pager is now responsible for handling the
high-level requests instead of only getting control after a bunch of work
has already been done on its behalf. this will allow us to UBCify LFS,
which needs tighter control over its pages than other filesystems do.
writing a page to disk no longer requires making it read-only, which
allows us to write wired pages without causing all kinds of havoc.
- use a new PG_PAGEOUT flag to indicate that a page should be freed
on behalf of the pagedaemon when it's unlocked. this flag is very similar
to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the
pageout fails due to eg. an indirect-block buffer being locked.
this allows us to remove the "version" field from struct vm_page,
and together with shrinking "loan_count" from 32 bits to 16,
struct vm_page is now 4 bytes smaller.
- no longer use PG_RELEASED for swap-backed pages. if the page is busy
because it's being paged out, we can't release the swap slot to be
reallocated until that write is complete, but unlike with vnodes we
don't keep a count of in-progress writes so there's no good way to
know when the write is done. instead, when we need to free a busy
swap-backed page, just sleep until we can get it busy ourselves.
- implement a fast-path for extending writes which allows us to avoid
zeroing new pages. this substantially reduces cpu usage.
- encapsulate the data used by the genfs code in a struct genfs_node,
which must be the first element of the filesystem-specific vnode data
for filesystems which use genfs_{get,put}pages().
- eliminate many of the UVM pagerops, since they aren't needed anymore
now that the pager "put" operation is a higher-level operation.
- enhance the genfs code to allow NFS to use the genfs_{get,put}pages
instead of a modified copy.
- clean up struct vnode by removing all the fields that used to be used by
the vfs_cluster.c code (which we don't use anymore with UBC).
- remove kmem_object and mb_object since they were useless.
instead of allocating pages to these objects, we now just allocate
pages with no object. such pages are mapped in the kernel until they
are freed, so we can use the mapping to find the page to free it.
this allows us to remove splvm() protection in several places.
The sum of all these changes improves write throughput on my
decstation 5000/200 to within 1% of the rate of NetBSD 1.5
and reduces the elapsed time for "make release" of a NetBSD 1.5
source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
|
|
|
|
|
|
|
int
|
|
|
|
msdosfs_gop_alloc(struct vnode *vp, off_t off, off_t len, int flags,
|
|
|
|
struct ucred *cred)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|