From 8dfa44bc875da2b7646fe30da494acbe01ef23aa Mon Sep 17 00:00:00 2001 From: maxv Date: Mon, 29 Dec 2014 17:17:54 +0000 Subject: [PATCH] Small cleanup: - KNF - malloc + memset -> malloc(|M_ZERO) - no need to check data == NULL --- sys/fs/hfs/hfs_vfsops.c | 104 +++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 60 deletions(-) diff --git a/sys/fs/hfs/hfs_vfsops.c b/sys/fs/hfs/hfs_vfsops.c index 2781c892c8b6..696e4f092adf 100644 --- a/sys/fs/hfs/hfs_vfsops.c +++ b/sys/fs/hfs/hfs_vfsops.c @@ -1,4 +1,4 @@ -/* $NetBSD: hfs_vfsops.c,v 1.32 2014/08/10 08:53:22 hannken Exp $ */ +/* $NetBSD: hfs_vfsops.c,v 1.33 2014/12/29 17:17:54 maxv Exp $ */ /*- * Copyright (c) 2005, 2007 The NetBSD Foundation, Inc. @@ -99,7 +99,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: hfs_vfsops.c,v 1.32 2014/08/10 08:53:22 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: hfs_vfsops.c,v 1.33 2014/12/29 17:17:54 maxv Exp $"); #ifdef _KERNEL_OPT #include "opt_compat_netbsd.h" @@ -174,13 +174,12 @@ struct vfsops hfs_vfsops = { }; static const struct genfs_ops hfs_genfsops = { - .gop_size = genfs_size, + .gop_size = genfs_size, }; static int hfs_modcmd(modcmd_t cmd, void *arg) { - switch (cmd) { case MODULE_CMD_INIT: return vfs_attach(&hfs_vfsops); @@ -207,10 +206,10 @@ hfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len) if (*data_len < sizeof *args) return EINVAL; -#ifdef HFS_DEBUG +#ifdef HFS_DEBUG printf("vfsop = hfs_mount()\n"); #endif /* HFS_DEBUG */ - + if (mp->mnt_flag & MNT_GETARGS) { hmp = VFSTOHFS(mp); if (hmp == NULL) @@ -220,9 +219,6 @@ hfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len) return 0; } - if (data == NULL) - return EINVAL; - /* FIXME: For development ONLY - disallow remounting for now */ #if 0 update = mp->mnt_flag & MNT_UPDATE; @@ -239,7 +235,7 @@ hfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len) NSM_FOLLOW_NOEMULROOT, &devvp); if (error != 0) return error; - + if (!update) { /* * Be sure this is a valid block device @@ -269,7 +265,6 @@ hfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len) } } - /* * If mount by non-root, then verify that user has necessary * permissions on the device. @@ -302,14 +297,14 @@ hfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len) if ((error = hfs_mountfs(devvp, mp, l, args->fspec)) != 0) goto error; - + error = set_statvfs_info(path, UIO_USERSPACE, args->fspec, UIO_USERSPACE, mp->mnt_op->vfs_name, mp, l); #ifdef HFS_DEBUG if(!update) { char* volname; - + hmp = VFSTOHFS(mp); volname = malloc(hmp->hm_vol.name.length + 1, M_TEMP, M_WAITOK); if (volname == NULL) @@ -324,9 +319,9 @@ hfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len) } } #endif /* HFS_DEBUG */ - + return error; - + error: vrele(devvp); return error; @@ -335,8 +330,7 @@ error: int hfs_start(struct mount *mp, int flags) { - -#ifdef HFS_DEBUG +#ifdef HFS_DEBUG printf("vfsop = hfs_start()\n"); #endif /* HFS_DEBUG */ @@ -353,20 +347,18 @@ hfs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l, struct hfsmount *hmp; kauth_cred_t cred; int error; - + cred = l ? l->l_cred : NOCRED; error = 0; hmp = NULL; /* Create mounted volume structure. */ - hmp = (struct hfsmount*)malloc(sizeof(struct hfsmount), - M_HFSMNT, M_WAITOK); + hmp = malloc(sizeof(struct hfsmount), M_HFSMNT, M_WAITOK|M_ZERO); if (hmp == NULL) { error = ENOMEM; goto error; } - memset(hmp, 0, sizeof(struct hfsmount)); - + mp->mnt_data = hmp; mp->mnt_flag |= MNT_LOCAL; vfs_getnewfsid(mp); @@ -374,12 +366,12 @@ hfs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l, hmp->hm_mountp = mp; hmp->hm_dev = devvp->v_rdev; hmp->hm_devvp = devvp; - + /* * Use libhfs to open the volume and read the volume header and other * useful information. */ - + hfslib_init_cbargs(&cbargs); argsopen.cred = argsread.cred = cred; argsopen.l = argsread.l = l; @@ -390,7 +382,7 @@ hfs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l, if ((error = hfslib_open_volume(devpath, mp->mnt_flag & MNT_RDONLY, &hmp->hm_vol, &cbargs)) != 0) goto error; - + /* Make sure this is not a journaled volume whose journal is dirty. */ if (!hfslib_is_journal_clean(&hmp->hm_vol)) { printf("volume journal is dirty; not mounting\n"); @@ -399,16 +391,15 @@ hfs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l, } mp->mnt_fs_bshift = 0; - while ((1 << mp->mnt_fs_bshift) < hmp->hm_vol.vh.block_size) + while ((1 << mp->mnt_fs_bshift) < hmp->hm_vol.vh.block_size) mp->mnt_fs_bshift++; mp->mnt_dev_bshift = DEV_BSHIFT; return 0; - + error: if (hmp != NULL) free(hmp, M_HFSMNT); - return error; } @@ -420,17 +411,17 @@ hfs_unmount(struct mount *mp, int mntflags) struct hfsmount* hmp; int error; int flags; - -#ifdef HFS_DEBUG + +#ifdef HFS_DEBUG printf("vfsop = hfs_unmount()\n"); #endif /* HFS_DEBUG */ hmp = VFSTOHFS(mp); - + flags = 0; if (mntflags & MNT_FORCE) flags |= FORCECLOSE; - + if ((error = vflush(mp, NULLVP, flags)) != 0) return error; @@ -438,13 +429,13 @@ hfs_unmount(struct mount *mp, int mntflags) argsclose.l = curlwp; cbargs.closevol = (void*)&argsclose; hfslib_close_volume(&hmp->hm_vol, &cbargs); - + vrele(hmp->hm_devvp); free(hmp, M_HFSMNT); mp->mnt_data = NULL; mp->mnt_flag &= ~MNT_LOCAL; - + return error; } @@ -454,14 +445,14 @@ hfs_root(struct mount *mp, struct vnode **vpp) struct vnode *nvp; int error; -#ifdef HFS_DEBUG +#ifdef HFS_DEBUG printf("vfsop = hfs_root()\n"); #endif /* HFS_DEBUG */ - + if ((error = VFS_VGET(mp, HFS_CNID_ROOT_FOLDER, &nvp)) != 0) return error; *vpp = nvp; - + return 0; } @@ -469,13 +460,13 @@ int hfs_statvfs(struct mount *mp, struct statvfs *sbp) { hfs_volume_header_t *vh; - -#ifdef HFS_DEBUG + +#ifdef HFS_DEBUG printf("vfsop = hfs_statvfs()\n"); #endif /* HFS_DEBUG */ vh = &VFSTOHFS(mp)->hm_vol.vh; - + sbp->f_bsize = vh->block_size; sbp->f_frsize = sbp->f_bsize; sbp->f_iosize = 4096;/* mac os x uses a 4 kb io size, so do the same */ @@ -486,15 +477,14 @@ hfs_statvfs(struct mount *mp, struct statvfs *sbp) sbp->f_files = vh->file_count; /* total files */ sbp->f_ffree = (1<<31) - vh->file_count; /* free file nodes */ copy_statvfs_info(sbp, mp); - + return 0; } int hfs_sync(struct mount *mp, int waitfor, kauth_cred_t cred) { - -#ifdef HFS_DEBUG +#ifdef HFS_DEBUG printf("vfsop = hfs_sync()\n"); #endif /* HFS_DEBUG */ @@ -550,7 +540,7 @@ hfs_loadvnode(struct mount *mp, struct vnode *vp, hfs_catalog_key_t cat_key; /* the search key used to find this file on disk */ dev_t dev; -#ifdef HFS_DEBUG +#ifdef HFS_DEBUG printf("vfsop = hfs_loadvnode()\n"); #endif /* HFS_DEBUG */ @@ -574,13 +564,13 @@ hfs_loadvnode(struct mount *mp, struct vnode *vp, * Read catalog record from disk. */ hfslib_init_cbargs(&cbargs); - + if (hfslib_find_catalog_record_with_cnid(&hmp->hm_vol, hfskey.hnk_cnid, &rec, &cat_key, &cbargs) != 0) { pool_put(&hfs_node_pool, hnode); return EBADF; } - + memcpy(&hnode->h_rec, &rec, sizeof(hnode->h_rec)); hnode->h_parent = cat_key.parent_cnid; @@ -594,7 +584,7 @@ hfs_loadvnode(struct mount *mp, struct vnode *vp, vp->v_tag = VT_HFS; vp->v_op = hfs_vnodeop_p; - vp->v_vflag |= VV_LOCKSWORK; + vp->v_vflag |= VV_LOCKSWORK; vp->v_data = hnode; genfs_node_init(vp, &hfs_genfsops); @@ -603,7 +593,7 @@ hfs_loadvnode(struct mount *mp, struct vnode *vp, */ hfs_vinit(mp, hfs_specop_p, hfs_fifoop_p, &vp); - hnode->h_devvp = hmp->hm_devvp; + hnode->h_devvp = hmp->hm_devvp; vref(hnode->h_devvp); /* Increment the ref count to the volume's device. */ /* Make sure UVM has allocated enough memory. (?) */ @@ -626,7 +616,7 @@ int hfs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp) { -#ifdef HFS_DEBUG +#ifdef HFS_DEBUG printf("vfsop = hfs_fhtovp()\n"); #endif /* HFS_DEBUG */ @@ -636,8 +626,7 @@ hfs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp) int hfs_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size) { - -#ifdef HFS_DEBUG +#ifdef HFS_DEBUG printf("vfsop = hfs_vptofh()\n"); #endif /* HFS_DEBUG */ @@ -649,7 +638,7 @@ hfs_init(void) { hfs_callbacks callbacks; -#ifdef HFS_DEBUG +#ifdef HFS_DEBUG printf("vfsop = hfs_init()\n"); #endif /* HFS_DEBUG */ @@ -671,8 +660,7 @@ hfs_init(void) void hfs_reinit(void) { - -#ifdef HFS_DEBUG +#ifdef HFS_DEBUG printf("vfsop = hfs_reinit()\n"); #endif /* HFS_DEBUG */ @@ -682,23 +670,19 @@ hfs_reinit(void) void hfs_done(void) { - -#ifdef HFS_DEBUG +#ifdef HFS_DEBUG printf("vfsop = hfs_done()\n"); #endif /* HFS_DEBUG */ malloc_type_detach(M_HFSMNT); - pool_destroy(&hfs_node_pool); - hfslib_done(); } int hfs_mountroot(void) { - -#ifdef HFS_DEBUG +#ifdef HFS_DEBUG printf("vfsop = hfs_mountroot()\n"); #endif /* HFS_DEBUG */