Deleted Added
full compact
g_eli.c (160741) g_eli.c (161127)
1/*-
2 * Copyright (c) 2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/geom/eli/g_eli.c 160741 2006-07-27 11:52:12Z yar $");
28__FBSDID("$FreeBSD: head/sys/geom/eli/g_eli.c 161127 2006-08-09 18:11:14Z pjd $");
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/kernel.h>
33#include <sys/linker.h>
34#include <sys/module.h>
35#include <sys/lock.h>
36#include <sys/mutex.h>

--- 413 unchanged lines hidden (view full) ---

450{
451 struct g_eli_softc *sc;
452 struct g_geom *gp;
453
454 gp = pp->geom;
455 sc = gp->softc;
456
457 if (dw > 0) {
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/kernel.h>
33#include <sys/linker.h>
34#include <sys/module.h>
35#include <sys/lock.h>
36#include <sys/mutex.h>

--- 413 unchanged lines hidden (view full) ---

450{
451 struct g_eli_softc *sc;
452 struct g_geom *gp;
453
454 gp = pp->geom;
455 sc = gp->softc;
456
457 if (dw > 0) {
458 if (sc->sc_flags & G_ELI_FLAG_RO) {
459 /* Deny write attempts. */
460 return (EROFS);
461 }
458 /* Someone is opening us for write, we need to remember that. */
459 sc->sc_flags |= G_ELI_FLAG_WOPEN;
460 return (0);
461 }
462 /* Is this the last close? */
463 if (pp->acr + dr > 0 || pp->acw + dw > 0 || pp->ace + de > 0)
464 return (0);
465

--- 24 unchanged lines hidden (view full) ---

490
491 gp = g_new_geomf(mp, "%s%s", bpp->name, G_ELI_SUFFIX);
492 gp->softc = NULL; /* for a moment */
493
494 sc = malloc(sizeof(*sc), M_ELI, M_WAITOK | M_ZERO);
495 gp->start = g_eli_start;
496 /*
497 * Spoiling cannot happen actually, because we keep provider open for
462 /* Someone is opening us for write, we need to remember that. */
463 sc->sc_flags |= G_ELI_FLAG_WOPEN;
464 return (0);
465 }
466 /* Is this the last close? */
467 if (pp->acr + dr > 0 || pp->acw + dw > 0 || pp->ace + de > 0)
468 return (0);
469

--- 24 unchanged lines hidden (view full) ---

494
495 gp = g_new_geomf(mp, "%s%s", bpp->name, G_ELI_SUFFIX);
496 gp->softc = NULL; /* for a moment */
497
498 sc = malloc(sizeof(*sc), M_ELI, M_WAITOK | M_ZERO);
499 gp->start = g_eli_start;
500 /*
501 * Spoiling cannot happen actually, because we keep provider open for
498 * writing all the time.
502 * writing all the time or provider is read-only.
499 */
500 gp->spoiled = g_eli_orphan_spoil_assert;
501 gp->orphan = g_eli_orphan;
503 */
504 gp->spoiled = g_eli_orphan_spoil_assert;
505 gp->orphan = g_eli_orphan;
506 gp->dumpconf = g_eli_dumpconf;
502 /*
507 /*
503 * If detach-on-last-close feature is not enabled, we can simply use
504 * g_std_access().
508 * If detach-on-last-close feature is not enabled and we don't operate
509 * on read-only provider, we can simply use g_std_access().
505 */
510 */
506 if (md->md_flags & G_ELI_FLAG_WO_DETACH)
511 if (md->md_flags & (G_ELI_FLAG_WO_DETACH | G_ELI_FLAG_RO))
507 gp->access = g_eli_access;
508 else
509 gp->access = g_std_access;
512 gp->access = g_eli_access;
513 else
514 gp->access = g_std_access;
510 gp->dumpconf = g_eli_dumpconf;
511
512 sc->sc_crypto = G_ELI_CRYPTO_SW;
513 sc->sc_flags = md->md_flags;
514 sc->sc_ealgo = md->md_ealgo;
515 sc->sc_nkey = nkey;
516 /*
517 * Remember the keys in our softc structure.
518 */

--- 54 unchanged lines hidden (view full) ---

573 bpp->name, error);
574 }
575 goto failed;
576 }
577 /*
578 * Keep provider open all the time, so we can run critical tasks,
579 * like Master Keys deletion, without wondering if we can open
580 * provider or not.
515
516 sc->sc_crypto = G_ELI_CRYPTO_SW;
517 sc->sc_flags = md->md_flags;
518 sc->sc_ealgo = md->md_ealgo;
519 sc->sc_nkey = nkey;
520 /*
521 * Remember the keys in our softc structure.
522 */

--- 54 unchanged lines hidden (view full) ---

577 bpp->name, error);
578 }
579 goto failed;
580 }
581 /*
582 * Keep provider open all the time, so we can run critical tasks,
583 * like Master Keys deletion, without wondering if we can open
584 * provider or not.
585 * We don't open provider for writing only when user requested read-only
586 * access.
581 */
587 */
582 error = g_access(cp, 1, 1, 1);
588 if (sc->sc_flags & G_ELI_FLAG_RO)
589 error = g_access(cp, 1, 0, 1);
590 else
591 error = g_access(cp, 1, 1, 1);
583 if (error != 0) {
584 if (req != NULL) {
585 gctl_error(req, "Cannot access %s (error=%d).",
586 bpp->name, error);
587 } else {
588 G_ELI_DEBUG(1, "Cannot access %s (error=%d).",
589 bpp->name, error);
590 }

--- 401 unchanged lines hidden (view full) ---

992} while (0)
993 ADD_FLAG(G_ELI_FLAG_ONETIME, "ONETIME");
994 ADD_FLAG(G_ELI_FLAG_BOOT, "BOOT");
995 ADD_FLAG(G_ELI_FLAG_WO_DETACH, "W-DETACH");
996 ADD_FLAG(G_ELI_FLAG_RW_DETACH, "RW-DETACH");
997 ADD_FLAG(G_ELI_FLAG_AUTH, "AUTH");
998 ADD_FLAG(G_ELI_FLAG_WOPEN, "W-OPEN");
999 ADD_FLAG(G_ELI_FLAG_DESTROY, "DESTROY");
592 if (error != 0) {
593 if (req != NULL) {
594 gctl_error(req, "Cannot access %s (error=%d).",
595 bpp->name, error);
596 } else {
597 G_ELI_DEBUG(1, "Cannot access %s (error=%d).",
598 bpp->name, error);
599 }

--- 401 unchanged lines hidden (view full) ---

1001} while (0)
1002 ADD_FLAG(G_ELI_FLAG_ONETIME, "ONETIME");
1003 ADD_FLAG(G_ELI_FLAG_BOOT, "BOOT");
1004 ADD_FLAG(G_ELI_FLAG_WO_DETACH, "W-DETACH");
1005 ADD_FLAG(G_ELI_FLAG_RW_DETACH, "RW-DETACH");
1006 ADD_FLAG(G_ELI_FLAG_AUTH, "AUTH");
1007 ADD_FLAG(G_ELI_FLAG_WOPEN, "W-OPEN");
1008 ADD_FLAG(G_ELI_FLAG_DESTROY, "DESTROY");
1009 ADD_FLAG(G_ELI_FLAG_RO, "READ-ONLY");
1000#undef ADD_FLAG
1001 }
1002 sbuf_printf(sb, "</Flags>\n");
1003
1004 if (!(sc->sc_flags & G_ELI_FLAG_ONETIME)) {
1005 sbuf_printf(sb, "%s<UsedKey>%u</UsedKey>\n", indent,
1006 sc->sc_nkey);
1007 }

--- 26 unchanged lines hidden ---
1010#undef ADD_FLAG
1011 }
1012 sbuf_printf(sb, "</Flags>\n");
1013
1014 if (!(sc->sc_flags & G_ELI_FLAG_ONETIME)) {
1015 sbuf_printf(sb, "%s<UsedKey>%u</UsedKey>\n", indent,
1016 sc->sc_nkey);
1017 }

--- 26 unchanged lines hidden ---