FreeBSD/sbin/geom/class/virstor/geom_virstor.c
/* Clears metadata on given provider(s) IF it's owned by us */
Clears metadata on given provider(s) IF it's owned by us
Clears metadata on given provider ( s ) IF it ' s owned by us
static void
virstor_clear(struct gctl_req *req)
{
	const char *name;
	char param[32];
	unsigned i;
	int nargs, error;
	int fd;
	nargs = gctl_get_int(req, "nargs");
	if (nargs < 1) {
		gctl_error(req, "Too few arguments.");
		return;
	}
	for (i = 0; i < (unsigned)nargs; i++) {
		snprintf(param, sizeof(param), "arg%u", i);
		name = gctl_get_ascii(req, "%s", param);
		error = g_metadata_clear(name, G_VIRSTOR_MAGIC);
		if (error != 0) {
			fprintf(stderr, "Can't clear metadata on %s: %s "
			    "(do I own it?)\n", name, strerror(error));
			gctl_error(req,
			    "Not fully done (can't clear metadata).");
			continue;
		}
		if (strncmp(name, _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0)
			fd = open(name, O_RDWR);
		else {
			sprintf(param, "%s%s", _PATH_DEV, name);
			fd = open(param, O_RDWR);
		}
		if (fd < 0) {
			gctl_error(req, "Cannot clear header sector for %s",
			    name);
			continue;
		}
		if (verbose)
			printf("Metadata cleared on %s.\n", name);
	}
}
static void virstor_clear ( struct gctl_req * req ) { const char * name ; char param [ 32 ] ; unsigned i ; int nargs , error ; int fd ; nargs = gctl_get_int ( req , " " ) ; if ( nargs < 1 ) { gctl_error ( req , " " ) ; return ; } for ( i = 0 ; i < ( unsigned ) nargs ; i ++ ) { snprintf ( param , sizeof ( param ) , " " , i ) ; name = gctl_get_ascii ( req , " " , param ) ; error = g_metadata_clear ( name , G_VIRSTOR_MAGIC ) ; if ( error != 0 ) { fprintf ( stderr , " " " \n " , name , strerror ( error ) ) ; gctl_error ( req , " " ) ; continue ; } if ( strncmp ( name , _PATH_DEV , sizeof ( _PATH_DEV ) - 1 ) == 0 ) fd = open ( name , O_RDWR ) ; else { sprintf ( param , " " , _PATH_DEV , name ) ; fd = open ( param , O_RDWR ) ; } if ( fd < 0 ) { gctl_error ( req , " " , name ) ; continue ; } if ( verbose ) printf ( " \n " , name ) ; } }
Clears metadata on given provider(s) IF it's owned by us
Clears metadata on given provider ( s ) IF it ' s owned by us