The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/device/dk_label.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /* 
    2  * Mach Operating System
    3  * Copyright (c) 1993,1991,1990 Carnegie Mellon University
    4  * All Rights Reserved.
    5  * 
    6  * Permission to use, copy, modify and distribute this software and its
    7  * documentation is hereby granted, provided that both the copyright
    8  * notice and this permission notice appear in all copies of the
    9  * software, derivative works or modified versions, and any portions
   10  * thereof, and that both notices appear in supporting documentation.
   11  * 
   12  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
   13  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
   14  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
   15  * 
   16  * Carnegie Mellon requests users of this software to return to
   17  * 
   18  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
   19  *  School of Computer Science
   20  *  Carnegie Mellon University
   21  *  Pittsburgh PA 15213-3890
   22  * 
   23  * any improvements or extensions that they make and grant Carnegie Mellon
   24  * the rights to redistribute these changes.
   25  */
   26 /*
   27  * HISTORY
   28  * $Log:        dk_label.c,v $
   29  * Revision 2.3  93/11/17  16:32:17  dbg
   30  *      ANSI-fied.
   31  *      [93/10/07            dbg]
   32  * 
   33  * Revision 2.2  93/08/10  15:45:43  mrt
   34  *      Taken from rz_disk.c -- generic label code.
   35  *      [93/08/10            rvb]
   36  * 
   37  */
   38 /*
   39  *      File: rz_disk.c
   40  *      Author: Alessandro Forin, Carnegie Mellon University
   41  *      Date:   10/90
   42  *
   43  */
   44 
   45 #include <sys/types.h>
   46 #include <sys/ioctl.h>
   47 #include <device/device_types.h>
   48 #include <device/disk_status.h>
   49 #include <kern/kern_io.h>
   50 
   51 /* Checksum a disk label */
   52 unsigned int
   53 dkcksum(
   54         struct disklabel *lp)
   55 {
   56         register unsigned short *start, *end, sum = 0;
   57 
   58         start = (unsigned short *)lp;
   59         end = (unsigned short *)&lp->d_partitions[lp->d_npartitions];
   60         while (start < end) sum ^= *start++;
   61         return sum;
   62 }
   63 
   64 /* Perform some checks and then copy a disk label */
   65 io_return_t
   66 setdisklabel(
   67         struct disklabel *lp,
   68         struct disklabel *nlp)
   69 {
   70         if (nlp->d_magic != DISKMAGIC || nlp->d_magic2 != DISKMAGIC ||
   71             (dkcksum(nlp) != 0))
   72                 return D_INVALID_OPERATION;
   73         *lp = *nlp;
   74         return D_SUCCESS;
   75 }
   76 
   77 void
   78 dkgetlabel(
   79         struct disklabel *lp,
   80         int             flavor,
   81         int *           data,           /* pointer to OUT array */
   82         natural_t       *count)         /* OUT */
   83 {
   84 
   85         switch (flavor) {
   86         /* get */
   87         case DIOCGDINFO:
   88                 *(struct disklabel *)data = *lp;
   89                 *count = sizeof(struct disklabel)/sizeof(int);
   90                 break;
   91         case DIOCGDINFO - (0x10<<16):
   92                 *(struct disklabel *)data = *lp;
   93                 *count = sizeof(struct disklabel)/sizeof(int) - 4;
   94                 break;
   95         }
   96 }
   97 
   98 void print_bsd_label(
   99         struct disklabel        *lp,
  100         const char              *str)
  101 {
  102         int i;
  103 
  104         printf("%s sectors %d, tracks %d, cylinders %d\n",
  105                 str, lp->d_nsectors, lp->d_ntracks, lp->d_ncylinders);
  106         printf("%s secpercyl %d, secperunit %d, npartitions %d\n",
  107                 str, lp->d_secpercyl, lp->d_secperunit, lp->d_npartitions);
  108 
  109         for (i = 0; i < lp->d_npartitions; i++) {
  110                 printf("%s    %c: size = %d, offset = %d\n",
  111                         str, 'a'+i,
  112                         lp->d_partitions[i].p_size,
  113                         lp->d_partitions[i].p_offset);
  114         }
  115 }

Cache object: f496c2ceaf7d064d98aea6d431a75e6f


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.