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.2  93/08/10  15:45:43  mrt
   30  *      Taken from rz_disk.c -- generic label code.
   31  *      [93/08/10            rvb]
   32  * 
   33  */
   34 /*
   35  *      File: rz_disk.c
   36  *      Author: Alessandro Forin, Carnegie Mellon University
   37  *      Date:   10/90
   38  *
   39  */
   40 
   41 #include <sys/types.h>
   42 #include <sys/ioctl.h>
   43 #include <device/device_types.h>
   44 #include <device/disk_status.h>
   45 
   46 /* Checksum a disk label */
   47 unsigned
   48 dkcksum(lp)
   49         struct disklabel *lp;
   50 {
   51         register unsigned short *start, *end, sum = 0;
   52 
   53         start = (unsigned short *)lp;
   54         end = (unsigned short*)&lp->d_partitions[lp->d_npartitions];
   55         while (start < end) sum ^= *start++;
   56         return sum;
   57 }
   58 
   59 /* Perform some checks and then copy a disk label */
   60 setdisklabel(lp, nlp)
   61         struct disklabel *lp, *nlp;
   62 {
   63         if (nlp->d_magic != DISKMAGIC || nlp->d_magic2 != DISKMAGIC ||
   64             (dkcksum(nlp) != 0))
   65                 return D_INVALID_OPERATION;
   66         *lp = *nlp;
   67         return D_SUCCESS;
   68 }
   69 
   70 dkgetlabel(lp, flavor, data, count)
   71         struct disklabel *lp;
   72         int             flavor;
   73         int *           data;           /* pointer to OUT array */
   74         unsigned int    *count;         /* OUT */
   75 {
   76 
   77         switch (flavor) {
   78         /* get */
   79         case DIOCGDINFO:
   80                 *(struct disklabel *)data = *lp;
   81                 *count = sizeof(struct disklabel)/sizeof(int);
   82                 break;
   83         case DIOCGDINFO - (0x10<<16):
   84                 *(struct disklabel *)data = *lp;
   85                 *count = sizeof(struct disklabel)/sizeof(int) - 4;
   86                 break;
   87         }
   88 }
   89 
   90 print_bsd_label(lp, str)
   91 struct disklabel        *lp;
   92 char                    *str;
   93 {
   94 int i;
   95         printf("%s sectors %d, tracks %d, cylinders %d\n",
   96                 str, lp->d_nsectors, lp->d_ntracks, lp->d_ncylinders);
   97         printf("%s secpercyl %d, secperunit %d, npartitions %d\n",
   98                 str, lp->d_secpercyl, lp->d_secperunit, lp->d_npartitions);
   99 
  100         for (i = 0; i < lp->d_npartitions; i++) {
  101                 printf("%s    %c: size = %d, offset = %d\n",
  102                         str, 'a'+i,
  103                         lp->d_partitions[i].p_size,
  104                         lp->d_partitions[i].p_offset);
  105         }
  106 }

Cache object: 8999c0c4dc0dcfa100c704453e67fae1


[ 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.