diff options
author | Joel Sing <jsing@cvs.openbsd.org> | 2010-04-28 12:54:05 +0000 |
---|---|---|
committer | Joel Sing <jsing@cvs.openbsd.org> | 2010-04-28 12:54:05 +0000 |
commit | f156e3090c57b75564be37a99589e69a496b57fb (patch) | |
tree | 26db5420b9bf692fcc2a9079c9fef87c5b2ce8a2 /sys | |
parent | e1444f47e96572dde869de535273df00110efa0b (diff) |
When setting a disklabel automatically generate a new UID if it does not
already have one.
ok krw@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/subr_disk.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c index 0d462c86ec5..8c66be4bcb0 100644 --- a/sys/kern/subr_disk.c +++ b/sys/kern/subr_disk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_disk.c,v 1.101 2010/04/25 06:15:17 deraadt Exp $ */ +/* $OpenBSD: subr_disk.c,v 1.102 2010/04/28 12:54:04 jsing Exp $ */ /* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */ /* @@ -608,8 +608,10 @@ notfat: int setdisklabel(struct disklabel *olp, struct disklabel *nlp, u_int openmask) { - int i; struct partition *opp, *npp; + struct disk *dk = NULL; + u_int64_t uid; + int i; /* sanity clause */ if (nlp->d_secpercyl == 0 || nlp->d_secsize == 0 || @@ -648,6 +650,19 @@ setdisklabel(struct disklabel *olp, struct disklabel *nlp, u_int openmask) npp->p_cpg = opp->p_cpg; } } + + /* Generate a UID if the disklabel does not already have one. */ + uid = 0; + if (bcmp(nlp->d_uid, &uid, sizeof(nlp->d_uid)) == 0) { + do { + arc4random_buf(nlp->d_uid, sizeof(nlp->d_uid)); + TAILQ_FOREACH(dk, &disklist, dk_link) + if (dk->dk_label && bcmp(dk->dk_label->d_uid, + nlp->d_uid, sizeof(nlp->d_uid)) == 0) + break; + } while (dk != NULL); + } + nlp->d_checksum = 0; nlp->d_checksum = dkcksum(nlp); *olp = *nlp; |