OpenBSD原代码导读之sbin/fdisk.c

2009-05-13 06:47:37来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折


/*    $OpenBSD: fdisk.c,v 1.46 2006/11/09 00:01:10 deraadt Exp $    */
/*
* Copyright (c) 1997 Tobias Weingartner
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include err.h>
#include stdio.h>
#include stdlib.h>
#include string.h>
#include unistd.h>
#include paths.h>
#include sys/types.h>
#include sys/fcntl.h>
#include sys/disklabel.h>
#include "disk.h"
#include "user.h"
#define _PATH_MBR _PATH_BOOTDIR "mbr"
两个宏一起定义,呵呵,以前从来没有这样写过代码
static unsigned char builtin_mbr[] = {
#include "mbrcode.h"
};
这个地方的用法很生僻啊,把一个数组的内容放在一个文件mbrcode.h中,这样写的优点:
以后mbr的代码改了,只要修改mbrcode.h就可以了,不需要改c文件。同时这个mbrcode.h文件估计也是由程序自动生成的。
int    y_flag; 对应fdisk命令的-y参数,y参数的解释是do not ask question。这个变量程序中这个变量没有起作用,估计是为了兼容旧版本
usage这个函数打印fdisk命令的用法
static void
usage(void)
{
    extern char * __progname;
    fprintf(stderr, "usage: %s "
     "[-ieuy] [-c cylinders -h heads -s sectors] [-f mbrfile] device\n"
     "\t-i: initialize disk with virgin MBR\n"
     "\t-u: update MBR code, preserve partition table\n"
     "\t-e: edit MBRs on disk interactively\n"

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:OpenBSD Road

下一篇:freebsd上安装杀毒软件