From 2fa1a664f3ea4dd50a15404282542c6d529bd830 Mon Sep 17 00:00:00 2001 From: Alex Hornung Date: Mon, 27 Feb 2012 12:52:08 +0000 Subject: [PATCH] disklabel - add new freedisklabel op * The freedisklabel op is simply used to free the disklabel stored in a disklabel_t (in a diskslice). * It deallocates the memory and sets the pointer to NULL. --- sys/kern/subr_disklabel32.c | 10 +++++++++- sys/kern/subr_disklabel64.c | 10 +++++++++- sys/sys/disklabel.h | 2 ++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/sys/kern/subr_disklabel32.c b/sys/kern/subr_disklabel32.c index 02b8eba1f8..93e045fea4 100644 --- a/sys/kern/subr_disklabel32.c +++ b/sys/kern/subr_disklabel32.c @@ -159,6 +159,13 @@ l32_getnumparts(disklabel_t lp) return(lp.lab32->d_npartitions); } +static void +l32_freedisklabel(disklabel_t *lpp) +{ + kfree((*lpp).lab32, M_DEVBUF); + (*lpp).lab32 = NULL; +} + /* * Attempt to read a disk label from a device. * @@ -626,6 +633,7 @@ struct disklabel_ops disklabel32_ops = { .op_getpartbounds = l32_getpartbounds, .op_loadpartinfo = l32_loadpartinfo, .op_getnumparts = l32_getnumparts, - .op_makevirginlabel = l32_makevirginlabel + .op_makevirginlabel = l32_makevirginlabel, + .op_freedisklabel = l32_freedisklabel }; diff --git a/sys/kern/subr_disklabel64.c b/sys/kern/subr_disklabel64.c index b3f4b8ecb9..8bf14f5ef7 100644 --- a/sys/kern/subr_disklabel64.c +++ b/sys/kern/subr_disklabel64.c @@ -112,6 +112,13 @@ l64_getnumparts(disklabel_t lp) return(lp.lab64->d_npartitions); } +static void +l64_freedisklabel(disklabel_t *lpp) +{ + kfree((*lpp).lab64, M_DEVBUF); + (*lpp).lab64 = NULL; +} + /* * Attempt to read a disk label from a device. 64 bit disklabels are * sector-agnostic and begin at offset 0 on the device. 64 bit disklabels @@ -503,6 +510,7 @@ struct disklabel_ops disklabel64_ops = { .op_getpartbounds = l64_getpartbounds, .op_loadpartinfo = l64_loadpartinfo, .op_getnumparts = l64_getnumparts, - .op_makevirginlabel = l64_makevirginlabel + .op_makevirginlabel = l64_makevirginlabel, + .op_freedisklabel = l64_freedisklabel }; diff --git a/sys/sys/disklabel.h b/sys/sys/disklabel.h index 089f562847..608165a53b 100644 --- a/sys/sys/disklabel.h +++ b/sys/sys/disklabel.h @@ -89,6 +89,8 @@ struct disklabel_ops { void (*op_makevirginlabel) (disklabel_t, struct diskslices *, struct diskslice *, struct disk_info *); + void (*op_freedisklabel) + (disklabel_t *); }; typedef struct disklabel_ops *disklabel_ops_t; -- 2.41.0