From 14c9669847f16225ecd8967d977ffad240a620ca Mon Sep 17 00:00:00 2001 From: maxv Date: Fri, 20 Feb 2015 17:08:13 +0000 Subject: [PATCH] Cosmetic changes: - add a ffs-like ntfs_superblock_validate function - remove unused includes - fix some comments - KNF No functional change. --- sys/fs/ntfs/ntfs_compr.c | 34 ++++++++++----------------- sys/fs/ntfs/ntfs_conv.c | 15 ++---------- sys/fs/ntfs/ntfs_ihash.c | 5 ++-- sys/fs/ntfs/ntfs_subr.c | 14 ++++++------ sys/fs/ntfs/ntfs_vfsops.c | 48 ++++++++++++++++++++++----------------- 5 files changed, 50 insertions(+), 66 deletions(-) diff --git a/sys/fs/ntfs/ntfs_compr.c b/sys/fs/ntfs/ntfs_compr.c index 1b87ca5955c8..90aeff4426c5 100644 --- a/sys/fs/ntfs/ntfs_compr.c +++ b/sys/fs/ntfs/ntfs_compr.c @@ -1,4 +1,4 @@ -/* $NetBSD: ntfs_compr.c,v 1.5 2009/03/18 16:00:21 cegger Exp $ */ +/* $NetBSD: ntfs_compr.c,v 1.6 2015/02/20 17:08:13 maxv Exp $ */ /*- * Copyright (c) 1998, 1999 Semen Ustimenko @@ -29,36 +29,29 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ntfs_compr.c,v 1.5 2009/03/18 16:00:21 cegger Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ntfs_compr.c,v 1.6 2015/02/20 17:08:13 maxv Exp $"); #include #include #include -#include #include #include #include -#include -#include #include -#include - #include #include #define GET_UINT16(addr) (*((u_int16_t *)(addr))) int -ntfs_uncompblock( - u_int8_t * dbuf, - u_int8_t * cbuf) +ntfs_uncompblock(u_int8_t *dbuf, u_int8_t *cbuf) { - u_int32_t ctag; - int len, dshift, lmask; - int blen, boff; - int i, j; - int pos, cpos; + u_int32_t ctag; + int len, dshift, lmask; + int blen, boff; + int i, j; + int pos, cpos; len = GET_UINT16(cbuf) & 0xFFF; dprintf(("ntfs_uncompblock: block length: %d + 3, 0x%x,0x%04x\n", @@ -101,14 +94,11 @@ ntfs_uncompblock( } int -ntfs_uncompunit( - struct ntfsmount * ntmp, - u_int8_t * uup, - u_int8_t * cup) +ntfs_uncompunit(struct ntfsmount *ntmp, u_int8_t *uup, u_int8_t *cup) { - int i; - int off = 0; - int new; + int i; + int off = 0; + int new; for (i = 0; i * NTFS_COMPBLOCK_SIZE < ntfs_cntob(NTFS_COMPUNIT_CL); i++) { new = ntfs_uncompblock(uup + i * NTFS_COMPBLOCK_SIZE, cup + off); diff --git a/sys/fs/ntfs/ntfs_conv.c b/sys/fs/ntfs/ntfs_conv.c index 645919095503..1f253a3e9cf1 100644 --- a/sys/fs/ntfs/ntfs_conv.c +++ b/sys/fs/ntfs/ntfs_conv.c @@ -1,4 +1,4 @@ -/* $NetBSD: ntfs_conv.c,v 1.9 2008/04/28 20:24:02 martin Exp $ */ +/* $NetBSD: ntfs_conv.c,v 1.10 2015/02/20 17:08:13 maxv Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -31,29 +31,18 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ntfs_conv.c,v 1.9 2008/04/28 20:24:02 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ntfs_conv.c,v 1.10 2015/02/20 17:08:13 maxv Exp $"); #include #include #include -#include #include -#include #include -#include -#include #include -#include - -#include #include -#include #include -#include #include -#include -#include /* UTF-8 encoding stuff */ #include diff --git a/sys/fs/ntfs/ntfs_ihash.c b/sys/fs/ntfs/ntfs_ihash.c index 4c05235cb35b..e62d7519cfce 100644 --- a/sys/fs/ntfs/ntfs_ihash.c +++ b/sys/fs/ntfs/ntfs_ihash.c @@ -1,4 +1,4 @@ -/* $NetBSD: ntfs_ihash.c,v 1.10 2012/01/27 19:48:40 para Exp $ */ +/* $NetBSD: ntfs_ihash.c,v 1.11 2015/02/20 17:08:13 maxv Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1991, 1993, 1995 @@ -33,14 +33,13 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ntfs_ihash.c,v 1.10 2012/01/27 19:48:40 para Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ntfs_ihash.c,v 1.11 2015/02/20 17:08:13 maxv Exp $"); #include #include #include #include #include -#include #include #include diff --git a/sys/fs/ntfs/ntfs_subr.c b/sys/fs/ntfs/ntfs_subr.c index cb94b01ba0c7..b4911d6ff720 100644 --- a/sys/fs/ntfs/ntfs_subr.c +++ b/sys/fs/ntfs/ntfs_subr.c @@ -1,4 +1,4 @@ -/* $NetBSD: ntfs_subr.c,v 1.59 2015/01/16 17:02:12 maxv Exp $ */ +/* $NetBSD: ntfs_subr.c,v 1.60 2015/02/20 17:08:13 maxv Exp $ */ /*- * Copyright (c) 1998, 1999 Semen Ustimenko (semenu@FreeBSD.org) @@ -29,7 +29,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ntfs_subr.c,v 1.59 2015/01/16 17:02:12 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ntfs_subr.c,v 1.60 2015/02/20 17:08:13 maxv Exp $"); #include #include @@ -1183,7 +1183,7 @@ ntfs_nttimetounix(u_int64_t nt) } /* - * This is one of write routine. + * This is one of the write routines. */ int ntfs_writeattr_plain(struct ntfsmount *ntmp, struct ntnode *ip, @@ -1231,7 +1231,7 @@ ntfs_writeattr_plain(struct ntfsmount *ntmp, struct ntnode *ip, } /* - * This is one of write routine. + * This is one of the write routines. * * ntnode should be locked. */ @@ -1333,7 +1333,7 @@ ntfs_writentvattr_plain(struct ntfsmount *ntmp, struct ntnode *ip, } /* - * This is one of read routines. + * This is one of the read routines. * * ntnode should be locked. */ @@ -1460,7 +1460,7 @@ ntfs_readntvattr_plain(struct ntfsmount *ntmp, struct ntnode *ip, } /* - * This is one of read routines. + * This is one of the read routines. */ int ntfs_readattr_plain(struct ntfsmount *ntmp, struct ntnode *ip, @@ -1508,7 +1508,7 @@ ntfs_readattr_plain(struct ntfsmount *ntmp, struct ntnode *ip, } /* - * This is one of read routines. + * This is one of the read routines. */ int ntfs_readattr(struct ntfsmount *ntmp, struct ntnode *ip, u_int32_t attrnum, diff --git a/sys/fs/ntfs/ntfs_vfsops.c b/sys/fs/ntfs/ntfs_vfsops.c index 55db423eda32..524e10ee1228 100644 --- a/sys/fs/ntfs/ntfs_vfsops.c +++ b/sys/fs/ntfs/ntfs_vfsops.c @@ -1,4 +1,4 @@ -/* $NetBSD: ntfs_vfsops.c,v 1.102 2015/01/06 11:03:09 hannken Exp $ */ +/* $NetBSD: ntfs_vfsops.c,v 1.103 2015/02/20 17:08:13 maxv Exp $ */ /*- * Copyright (c) 1998, 1999 Semen Ustimenko @@ -29,7 +29,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ntfs_vfsops.c,v 1.102 2015/01/06 11:03:09 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ntfs_vfsops.c,v 1.103 2015/02/20 17:08:13 maxv Exp $"); #include #include @@ -65,6 +65,7 @@ MALLOC_JUSTDEFINE(M_NTFSMNT, "NTFS mount", "NTFS mount structure"); MALLOC_JUSTDEFINE(M_NTFSNTNODE,"NTFS ntnode", "NTFS ntnode information"); MALLOC_JUSTDEFINE(M_NTFSDIR,"NTFS dir", "NTFS dir buffer"); +static int ntfs_superblock_validate(struct ntfsmount *); static int ntfs_mount(struct mount *, const char *, void *, size_t *); static int ntfs_root(struct mount *, struct vnode **); static int ntfs_start(struct mount *, int); @@ -291,6 +292,25 @@ fail: return (err); } +static int +ntfs_superblock_validate(struct ntfsmount *ntmp) +{ + /* Sanity checks. XXX: More checks are probably needed. */ + if (strncmp(ntmp->ntm_bootfile.bf_sysid, NTFS_BBID, NTFS_BBIDLEN)) { + dprintf(("ntfs_superblock_validate: invalid boot block\n")); + return EINVAL; + } + if (ntmp->ntm_bps == 0) { + dprintf(("ntfs_superblock_validate: invalid bytes per sector\n")); + return EINVAL; + } + if (ntmp->ntm_spc == 0) { + dprintf(("ntfs_superblock_validate: invalid sectors per cluster\n")); + return EINVAL; + } + return 0; +} + /* * Common code for mount and mountroot */ @@ -324,22 +344,8 @@ ntfs_mountfs(struct vnode *devvp, struct mount *mp, struct ntfs_args *argsp, str brelse(bp, 0); bp = NULL; - /* Sanity checks. XXX: More checks are probably needed. */ - if (strncmp(ntmp->ntm_bootfile.bf_sysid, NTFS_BBID, NTFS_BBIDLEN)) { - error = EINVAL; - dprintf(("ntfs_mountfs: invalid boot block\n")); + if ((error = ntfs_superblock_validate(ntmp))) goto out; - } - if (ntmp->ntm_bps == 0) { - error = EINVAL; - dprintf(("ntfs_mountfs: invalid bytes per sector\n")); - goto out; - } - if (ntmp->ntm_spc == 0) { - error = EINVAL; - dprintf(("ntfs_mountfs: invalid sectors per cluster\n")); - goto out; - } { int8_t cpr = ntmp->ntm_mftrecsz; @@ -349,10 +355,10 @@ ntfs_mountfs(struct vnode *devvp, struct mount *mp, struct ntfs_args *argsp, str ntmp->ntm_bpmftrec = (1 << (-cpr)) / ntmp->ntm_bps; } dprintf(("ntfs_mountfs(): bps: %d, spc: %d, media: %x, mftrecsz: %d (%d sects)\n", - ntmp->ntm_bps,ntmp->ntm_spc,ntmp->ntm_bootfile.bf_media, - ntmp->ntm_mftrecsz,ntmp->ntm_bpmftrec)); + ntmp->ntm_bps, ntmp->ntm_spc, ntmp->ntm_bootfile.bf_media, + ntmp->ntm_mftrecsz, ntmp->ntm_bpmftrec)); dprintf(("ntfs_mountfs(): mftcn: 0x%x|0x%x\n", - (u_int32_t)ntmp->ntm_mftcn,(u_int32_t)ntmp->ntm_mftmirrcn)); + (u_int32_t)ntmp->ntm_mftcn, (u_int32_t)ntmp->ntm_mftmirrcn)); ntmp->ntm_mountp = mp; ntmp->ntm_dev = dev; @@ -410,7 +416,7 @@ ntfs_mountfs(struct vnode *devvp, struct mount *mp, struct ntfs_args *argsp, str struct attrdef ad; /* Open $AttrDef */ - error = VFS_VGET(mp, NTFS_ATTRDEFINO, &vp ); + error = VFS_VGET(mp, NTFS_ATTRDEFINO, &vp); if (error) goto out1;