Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/fs/sysvbfs handle file resizing.



details:   https://anonhg.NetBSD.org/src/rev/bd3553ceab6d
branches:  trunk
changeset: 778160:bd3553ceab6d
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Mar 18 02:40:55 2012 +0000

description:
handle file resizing.

diffstat:

 sys/fs/sysvbfs/bfs.c           |  20 ++++++++++++++++++--
 sys/fs/sysvbfs/bfs.h           |   7 +++++--
 sys/fs/sysvbfs/sysvbfs_vnops.c |  39 ++++++++++++++++++++++++++-------------
 3 files changed, 49 insertions(+), 17 deletions(-)

diffs (170 lines):

diff -r c9fda71a01c1 -r bd3553ceab6d sys/fs/sysvbfs/bfs.c
--- a/sys/fs/sysvbfs/bfs.c      Sun Mar 18 02:14:16 2012 +0000
+++ b/sys/fs/sysvbfs/bfs.c      Sun Mar 18 02:40:55 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bfs.c,v 1.13 2010/07/26 13:43:26 njoly Exp $   */
+/*     $NetBSD: bfs.c,v 1.14 2012/03/18 02:40:55 christos Exp $        */
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: bfs.c,v 1.13 2010/07/26 13:43:26 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bfs.c,v 1.14 2012/03/18 02:40:55 christos Exp $");
 #define        BFS_DEBUG
 
 #include <sys/param.h>
@@ -57,6 +57,7 @@
 #define        __FREE(a, s, t)         free(a)
 #endif
 #include <fs/sysvbfs/bfs.h>
+#include <fs/sysvbfs/sysvbfs.h>
 
 #ifdef BFS_DEBUG
 #define        DPRINTF(on, fmt, args...)       if (on) printf(fmt, ##args)
@@ -506,6 +507,21 @@
        return true;
 }
 
+void
+bfs_file_setsize(struct vnode *v, size_t size)
+{
+       struct sysvbfs_node *bnode = v->v_data;
+       struct bfs_inode *inode = bnode->inode;
+
+       bnode->size = size;
+       uvm_vnp_setsize(v, bnode->size);
+       inode->end_sector = bnode->data_block +
+           (ROUND_SECTOR(bnode->size) >> DEV_BSHIFT) - 1;
+       inode->eof_offset_byte = bnode->data_block * DEV_BSIZE +
+           bnode->size - 1;
+       bnode->update_mtime = true;
+}
+
 bool
 bfs_dirent_lookup_by_inode(const struct bfs *bfs, int inode,
     struct bfs_dirent **dirent)
diff -r c9fda71a01c1 -r bd3553ceab6d sys/fs/sysvbfs/bfs.h
--- a/sys/fs/sysvbfs/bfs.h      Sun Mar 18 02:14:16 2012 +0000
+++ b/sys/fs/sysvbfs/bfs.h      Sun Mar 18 02:40:55 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bfs.h,v 1.5 2008/04/28 20:24:02 martin Exp $   */
+/*     $NetBSD: bfs.h,v 1.6 2012/03/18 02:40:55 christos Exp $ */
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -142,6 +142,8 @@
        bool (*write_n)(void *, uint8_t *, daddr_t, int);
 };
 
+struct vnode;
+
 int bfs_init2(struct bfs **, int, struct sector_io_ops *, bool);
 void bfs_fini(struct bfs *);
 int bfs_file_read(const struct bfs *, const char *, void *, size_t, size_t *);
@@ -153,10 +155,11 @@
 bool bfs_file_lookup(const struct bfs *, const char *, int *, int *,
     size_t *);
 size_t bfs_file_size(const struct bfs_inode *);
+void bfs_file_setsize(struct vnode *, size_t);
+
 bool bfs_dump(const struct bfs *);
 
 /* filesystem ops */
-struct vnode;
 int sysvbfs_bfs_init(struct bfs **, struct vnode *);
 void sysvbfs_bfs_fini(struct bfs *);
 bool bfs_inode_lookup(const struct bfs *, ino_t, struct bfs_inode **);
diff -r c9fda71a01c1 -r bd3553ceab6d sys/fs/sysvbfs/sysvbfs_vnops.c
--- a/sys/fs/sysvbfs/sysvbfs_vnops.c    Sun Mar 18 02:14:16 2012 +0000
+++ b/sys/fs/sysvbfs/sysvbfs_vnops.c    Sun Mar 18 02:40:55 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sysvbfs_vnops.c,v 1.41 2012/03/13 18:40:50 elad Exp $  */
+/*     $NetBSD: sysvbfs_vnops.c,v 1.42 2012/03/18 02:40:55 christos Exp $      */
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysvbfs_vnops.c,v 1.41 2012/03/13 18:40:50 elad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysvbfs_vnops.c,v 1.42 2012/03/18 02:40:55 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -359,11 +359,28 @@
                attr->gid = gid;
        }
 
+       if (vap->va_size != VNOVAL)
+               switch (vp->v_type) {
+               case VDIR:
+                       return EISDIR;
+               case VCHR:
+               case VBLK:
+               case VFIFO:
+                       break;
+               case VREG:
+                       if (vp->v_mount->mnt_flag & MNT_RDONLY)
+                               return EROFS;
+                       bfs_file_setsize(vp, vap->va_size);
+                       break;
+               default:
+                       return EOPNOTSUPP;
+               }
+
        if (vap->va_mode != (mode_t)VNOVAL) {
                mode_t mode = vap->va_mode;
                error = kauth_authorize_vnode(cred, KAUTH_VNODE_WRITE_SECURITY,
-                   vp, NULL, genfs_can_chmod(vp->v_type, cred, attr->uid, attr->gid,
-                   mode));
+                   vp, NULL, genfs_can_chmod(vp->v_type, cred, attr->uid,
+                   attr->gid, mode));
                if (error)
                        return error;
                attr->mode = mode;
@@ -373,7 +390,8 @@
            (vap->va_mtime.tv_sec != VNOVAL) ||
            (vap->va_ctime.tv_sec != VNOVAL)) {
                error = kauth_authorize_vnode(cred, KAUTH_VNODE_WRITE_TIMES, vp,
-                   NULL, genfs_can_chtimes(vp, vap->va_vaflags, attr->uid, cred));
+                   NULL, genfs_can_chtimes(vp, vap->va_vaflags, attr->uid,
+                   cred));
                if (error)
                        return error;
 
@@ -444,7 +462,6 @@
        struct uio *uio = a->a_uio;
        int advice = IO_ADV_DECODE(a->a_ioflag);
        struct sysvbfs_node *bnode = v->v_data;
-       struct bfs_inode *inode = bnode->inode;
        bool extended = false;
        vsize_t sz;
        int err = 0;
@@ -459,8 +476,7 @@
                return 0;
 
        if (bnode->size < uio->uio_offset + uio->uio_resid) {
-               bnode->size = uio->uio_offset + uio->uio_resid;
-               uvm_vnp_setsize(v, bnode->size);
+               bfs_file_setsize(v, uio->uio_offset + uio->uio_resid);
                extended = true;
        }
 
@@ -472,11 +488,8 @@
                        break;
                DPRINTF("%s: write %ldbyte\n", __func__, sz);
        }
-       inode->end_sector = bnode->data_block +
-           (ROUND_SECTOR(bnode->size) >> DEV_BSHIFT) - 1;
-       inode->eof_offset_byte = bnode->data_block * DEV_BSIZE +
-           bnode->size - 1;
-       bnode->update_mtime = true;
+       if (err)
+               bfs_file_setsize(v, bnode->size - uio->uio_resid);
 
        VN_KNOTE(v, NOTE_WRITE | (extended ? NOTE_EXTEND : 0));
 



Home | Main Index | Thread Index | Old Index