gerrit安装配置及过程中遇到的问题

(文章来源: http://blog.csdn.net/ljchlx/article/details/22277311)


小注解:

本文所使用的关于apache的配置设置是基于apache2.2的,因此部分设置与apache 2.3/2.4稍有不同.

例如:

          Order deny,allow
          Allow from all
就应该改为

          Require all granted

 进一步详细的请查看apache说明文档。

系统配置环境
Gerrit 是一个基于 Web 的代码评审和项目管理的工具,面向基于 Git 版本控制系统的项目。因此需要Apache、Mysql、GIT等相关软件的支持 系统配置: 新装的UBANTU LINUX系统请先更新自己的系统软件包 $sudo apt-get dist-upgrade
$sudo adduser project
以新用户身份操作 $sudo su - project
$sudo apt-get install  git-core apache2.2-bin apache2.2-common apache2-utils apache2-mpm-worker

安装Gerrit



1.创建一个以项目名称命名的新用户,以project为例(如以创建可省)
$sudo adduser project

以新用户身份操作

$sudo su - project

 
 
2.创建安装目录,以项目名命令。(建议直接拷贝使用其它项目的gerrit安装目录) $mkdir -p gerrit_reviewsite

3.下载gerrit

 http://code.google.com/p/gerrit/downloads/list?can=1&q=&colspec=Filename+Summary+Uploaded+ReleaseDate+Size+DownloadCount

  
  
4.安装并配置初始化gerrit
 java -jar gerrit-2.6.1.war init -d ~/gerrit_reviewsite/

reate '/home/gerrit2/review-site' [Y/n]?

*** Git Repositories
***

Location of Git repositories [git]:

*** SQL Database
***

Database server type [H2/?]:   //改成MYSQL或者使用H2

*** User Authentication
***

Authentication method [OPENID/?]: HTTP   //注意这个不要按回车跳过去了,否则不是HTTP认证,是需要用google的OPENID
Get username from custom HTTP header [y/N]? :
SSO logout URL : 

*** Email Delivery
***

SMTP server hostname [localhost]: smtp.126.com   //自己改成自己的邮箱smtp
SMTP server port [(default)]: 25
SMTP encryption [NONE/?]: 
SMTP username [?]: xxxxxxxx@126.com             //自己改成自己的邮箱
yourname@xxxxx.com's password : xxxxxxx
confirm password : xxxxxxx

*** Container Process
***

Run as [project]:
Java runtime [/usr/lib/jvm/java-6-sun-1.6.0.24/jre]:
Copy gerrit.war to /home/gerrit2/review-site/bin/gerrit.war [Y/n]?
Copying gerrit.war to /home/gerrit2/review-site/bin/gerrit.war

*** SSH Daemon
***

Listen on address [*]:
Listen on port [29418]:       //如果同一个用户下建多个gerrit,请不用都公用29418这个端口号 如39418 49418

Gerrit Code Review is not shipped with Bouncy Castle Crypto v144
  If available, Gerrit can take advantage of features
  in the library, but will also function without it.
Download and install it now [Y/n]?     
//这里如果选择了y,则gerrit服务器上的fingerprint会有两个,否则则只有一个
Downloading http://www.bouncycastle.org/download/bcprov-jdk16-144.jar ... OKChecksum bcprov-jdk16-144.jar OKGenerating SSH host key ... rsa... dsa... done*** HTTP Daemon*** Behind reverse proxy [y/N]? y
//使用反向代理的话必须选择y来配置,默认是N

Proxy uses SSL (https://) [y/N]? n
Subdirectory on proxy server   [/]: /project/     //可以选择直接跳过,那样你的gerrit最后的URL是http://192.168.11.73:80
Listen on address              [*]: 
Listen on port                 [8081]:          //切记,此端口号一定不要和apache2占用相同的端口号,多个gerrit可以8082 8083 8084                                                			//否则就会Starting Gerrit Code Review:Failed
Canonical URL                  [http://*/]:http://192.168.11.73/project/    //上一步Subdirectory on proxy server 跳过不填则是http://192.168.11.73:80  (80为你将要在apache 给gerrit设置的端口)
Initialized /home/gerrit2/review-siteExecuting 
/home/gerrit2/review-site/bin/gerrit.sh start
Starting Gerrit Code Review: OK
=========================================QA=======================================================================================
Q:Configuration ErrorCheck the HTTP server's authentication settings.The HTTP server did not provide the username in the Authorizationheader when it forwarded the request to Gerrit Code Review.If the HTTP server is Apache HTTPd, check the proxy configurationincludes an authorization directive with the proper location, ensuringit ends with '/':
In error_log:ERROR com.google.gerrit.httpd.auth.container.HttpLoginServlet : Unableto authenticate user by Authorization request header.  Check containeror server configuration.
A:You cannot run these on the same port. Your Apache NameVirtualHostshould be on a different port than the internal Jetty web sever thatGerrit is using.
即gerrit和apache2占用相同的端口号
例如:

cat review_site_project/etc/gerrit.config:

[httpd]       listenUrl = http://x.x.x.x:8081/

cat /etc/apache2/apache2.conf :

NameVirtualHost x.x.x.x:8081

<VirtualHost x.x.x.x:8081>

apache2和gerrit都使用了8081,肯定有一个启动不来的,一般是gerrit
5. 启动gerrit时失败,查看gerrit_reviewsite/log/error_log中的错误信息如下:
[2016-07-29 02:56:56,387] [main] WARN  com.google.gerrit.sshd.SshDaemon : Disabling cipher aes192-cbc: Illegal key size; try installing unlimited cryptography extension
[2016-07-29 02:56:56,388] [main] WARN  com.google.gerrit.sshd.SshDaemon : Disabling cipher aes256-cbc: Illegal key size; try installing unlimited cryptography extension
[2016-07-29 02:56:56,390] [main] WARN  com.google.gerrit.sshd.SshDaemon : Disabling cipher aes256-ctr: Illegal key size; try installing unlimited cryptography extension
[2016-07-29 02:56:56,393] [main] WARN  com.google.gerrit.sshd.SshDaemon : Disabling cipher arcfour256: Illegal key size or default parameters; try installing unlimited cryptography extension
[2016-07-29 02:56:56,425] [main] WARN  com.google.gerrit.server.config.GitwebCgiConfig : gitweb not installed (no /usr/lib/cgi-bin/gitweb.cgi found)
[2016-07-29 02:56:56,882] [main] INFO  org.eclipse.jetty.util.log : Logging initialized @14808ms
[2016-07-29 02:56:56,950] [main] INFO  com.google.gerrit.server.git.LocalDiskRepositoryManager : Defaulting core.streamFileThreshold to 45m
[2016-07-29 02:56:56,999] [main] ERROR com.google.gerrit.pgm.Daemon : Unable to start daemon
com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) Schema not yet initialized.  Run init to initialize the schema:
$ java -jar gerrit.war init -d /home/watasianata/gerrit_review

1 error
        at com.google.gerrit.server.schema.SchemaVersionCheck.start(SchemaVersionCheck.java:56)
        at com.google.gerrit.lifecycle.LifecycleManager.start(LifecycleManager.java:74)
        at com.google.gerrit.pgm.Daemon.start(Daemon.java:302)
        at com.google.gerrit.pgm.Daemon.run(Daemon.java:203)
        at com.google.gerrit.pgm.util.AbstractProgram.main(AbstractProgram.java:64)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at com.google.gerrit.launcher.GerritLauncher.invokeProgram(GerritLauncher.java:159)
        at com.google.gerrit.launcher.GerritLauncher.mainImpl(GerritLauncher.java:100)
        at com.google.gerrit.launcher.GerritLauncher.main(GerritLauncher.java:56)
        at Main.main(Main.java:25)
1)原因1,google搜素到有如下可能,就是我们在新的gerrit的gerrit.config中增加了如下索引的配置
 [index]
        type = LUCENE

而我们的系统中,并未安装Lucene,因此参照网上的例子安装下Lucene(http://keping.me/ubuntu%E4%B8%8Blucene%E7%8E%AF%E5%A2%83%E6%90%AD%E9%85%8D/)。


2)Lucene安装完毕了,试一下,发现仍然报上述错误。

万般无奈之下,只能按照提示重新跑了一遍

java -jar gerrit.war init -d /home/watasianata/gerrit_review

逐个参数检查,终于发现原来是在安装Lucene时,将原本jkd1.7的环境改为了jdk1.8,而gerrit却仍然采用了jdk1.7的配置,能不出错吗?

赶紧将
        user = watasianata
        javaHome = /usr/local/devtools/jdk1.8.0_45/jre

改好。

再次试,这次仍然出错:

[2016-07-29 03:24:10,152] [main] INFO  com.google.gerrit.server.plugins.PluginLoader : Loaded plugin reviewnotes, version v2.12.3
[2016-07-29 03:24:10,214] [main] INFO  com.google.gerrit.server.plugins.PluginLoader : Loaded plugin singleusergroup, version v2.12.3
[2016-07-29 03:24:10,216] [main] ERROR com.google.gerrit.pgm.Daemon : Unable to start daemon
com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) No index versions ready; run Reindex

1 error
        at com.google.gerrit.lucene.LuceneVersionManager.start(LuceneVersionManager.java:124)
        at com.google.gerrit.lifecycle.LifecycleManager.start(LifecycleManager.java:74)
        at com.google.gerrit.pgm.Daemon.start(Daemon.java:302)
        at com.google.gerrit.pgm.Daemon.run(Daemon.java:203)
        at com.google.gerrit.pgm.util.AbstractProgram.main(AbstractProgram.java:64)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at com.google.gerrit.launcher.GerritLauncher.invokeProgram(GerritLauncher.java:159)
        at com.google.gerrit.launcher.GerritLauncher.mainImpl(GerritLauncher.java:100)
        at com.google.gerrit.launcher.GerritLauncher.main(GerritLauncher.java:56)
        at Main.main(Main.java:25)

这次的信息明确多了,直接重新reindex一次,

java -jar ~/tool/gerrit-2.12.3.war reindex

好啦!

5.按下面内容修改gerrit_reviewsite/etc/gerrit.conf 及GERRIT的配置文件

[gerrit]
        basePath = git  //指定被gerrit管理的所有git库存放位置,即review_site_project/git/
        canonicalWebUrl = http://42.62.42.75:8090/project    

//指定web访问gerrit的网址//填自己的ip和端口号,勿完全抄

[database]
        type = h2          //指定gerrit所默认数据库类型,可以选用mysql
        database = db/ReviewDB    
[auth]
        type = HTTP    //指定浏览器登录gerrit时的认证方式
[sendemail]
        enable = true
        smtpServer = smtp.126.com
        smtpServerPort = 25
        smtpUser = xxxxxxxxxxxx@126.com
        smtpPass = xxxxxxxx
        sslVerify = false
        from = CodeReview<xxxxxxxx@126.com>

[container]
        user = gerritserver            //指定gerrit所在机器的用户身份与上文创建的用户对应一致
        javaHome = /usr/lib/jvm/jdk7/jre           //系统本身自带
[sshd]
        listenAddress = *:29418          //指定sshd服务监听的端口号
[httpd]
        listenUrl = http://*:8081/project            //指定http代理地址
[cache]
        directory = cache      //缓存位置



配置Apache


$sudo apt-get install  apache2.2-bin apache2.2-common apache2-utils apache2-mpm-worker

1.创建编辑apache配置文件,添加如下内容(下面以Ubuntu系统为例请注意不同操作系统apache配置文件的区别)也可配置 apache2.conf httpd.conf,我们这里配置的是/etc/apache2/sites-available/gerrit

$sudo vi /etc/apache2/sites-available/defalt   

<VirtualHost 192.168.134.59:8090>
    ServerName 192.168.134.59

    ProxyRequests Off
    ProxyVia Off
    ProxyPreserveHost On

    <Proxy *>
          Order deny,allow
          Allow from all
    </Proxy>

    <Location "/project/login/">
      AuthType Basic
      AuthName "Gerrit Code Review"
      AuthBasicProvider file
      AuthUserFile ../../../etc/apache2/passwords

//指定http登录认证的的paassword文件所在位置,放哪都行,根据后来 sudo htpasswd -cb  /etc/apache2/passwords admin pwxxx 来定。

      Require valid-user
    </Location>


    AllowEncodedSlashes On
    RedirectMatch  ^/project$                /project/
    ProxyPass /project/ http://127.0.0.1:8081/project/
    ProxyPassReverse /project/ http://127.0.0.1:8081/project/
</VirtualHost>


保存退出
$cd /etc/apache2/sites-enabled/
$sudo ln ../sites-available/gerrit .

2.创建passwd文件,添加gerrit登录用户,-c参数为创建,仅限第一次添加用户时使用
$sudo htpasswd -cb  /etc/apache2/passwords admin passwordxxx

第二次添加其他用户时,不要加-c了:
$sudo htpasswd -b  /etc/apache2/passwords test test


3继续配置apache2
   
   
$sudo vi /etc/apache2/http.conf //在文件中加入以下内容
ServerName localhost


$cd /etc/apache2/mods-enabled
$sudo ln -s /etc/apache2/mods-available/proxy.conf proxy.conf 
$sudo ln -s /etc/apache2/mods-available/proxy.load proxy.load 
$sudo ln -s /etc/apache2/mods-available/proxy_http.load proxy_http.load
配置apache2的监听端口:
/etc/apache2$sudo vi ports.conf 
NameVirtualHost *:80
Listen 80
Listen 8080    //不要给gerrit!
Listen 8000    //不要给gerrit!
添加apache2的tcp端口号,切记不要把gerrit的,即
Listen on port                 [8081]: 不要输入上面配置给apache2的端口号,切记!!!
可以用sudo netstat -lnp | grep 80   查看相关80的所有端口使用情况
否则gerrit 起不来的
搭建多个gerrit 时Listen on port                 [8081]:可以用8082 8083 8084 等

 

Apache2 配置安装 FQA:

Q:启动apache报错

Syntax error on line 300 of /etc/apache2/apache2.conf:Invalid command 'ProxyPass', perhaps misspelled or defined by a module not included in the server configuration   ...fail!
A:配置了反向代理,但是没有打开module,执行下面操作
cd /etc/apache2/mods-enabled
ln -s /etc/apache2/mods-available/proxy.conf proxy.conf 
ln -s /etc/apache2/mods-available/proxy.load proxy.load 
 ln -s /etc/apache2/mods-available/proxy_http.load proxy_http.load
Q:启动Apache报错
No apache MPM package installed
A:安装apache2-mpm-worker软件包
$sudo apt-get install apache2-mpm-worker
Q:启动Apache报错
 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
A:修改/etc/apache2/http.conf文件,在文件中加入以下内容
ServerName localhost
 
Q:(13)Permission denied: make_sock: could not bind to address 0.0.0.0:80

A:需要用ROOT用户执行   直接 sudo  /etc/init.d/apache2 restart  就OK了    

启动服务

1.启动apache
sudo /etc/init.d/apache2 restart 
2.启动gerrit服务
$review_site_project/bin/gerrit.sh start 

登录gerrit

在浏览器地址栏中输入

192.168.11.73/project/    

注:Subdirectory on proxy server [/]:选择直接跳过  则192.168.11.73:80

在显示的登录框中输入用户名/密码,

即之前配置passwords 

$sudo htpasswd -cb  /etc/apache2/passwords admin passwordxx
admin
passwordxx

Note: 请注意第一个登入的用户,Gerrit会自动将其定义为管理员

3. 接入企业内部域账号
    <Location "/project/login">
      AuthType Basic
      AuthName "Gerrit Code Review"
      AuthBasicProvider ldap
      AuthzLDAPAuthoritative off
      AuthLDAPURL "ldap://192.168.xx.x:xxx/OU=xxxxx,OU=_BJKS(xxx),DC=xxxxx,DC=cn?sAMAccountName?sub?(objectClass=user)"
      AuthLDAPBindDN xxxx@kingsoft.cn
      AuthLDAPBindPassword xxxx
      Require valid-user
    </Location>






[编辑本段]Turbo C2.0    介绍      Turbo C2.0不仅是一个快捷、高效的编译程序,同时还有一个易学、易用的集成开发环境。使用Turbo C2.0无需独立地编辑、编译和连接程序,就能建立并运行C语言程序。因为这些功能都组合在Turbo 2.0的集成开发环境内,并且可以通过一个简单的主屏幕使用这些功能。    基本配置要求   Turbo C 2.0可运行于IBM-PC系列微机,包括XT,AT及IBM 兼容机。此时要求DOS2.0或更高版本支持,并至少需要448K的RAM,可在任何彩、单色80列监视器上运行。支持数学协处理器芯片,也可进行浮点仿真,这将加快程序的执行。 [编辑本段]Turbo C 2.0的主要文件的简单介绍   INSTALL.EXE 安装程序文件   TC.EXE 集成编译   TCINST.EXE 集成开发环境的配置设置程序   TCHELP.TCH 帮助文件   THELP.COM 读取TCHELP.TCH的驻留程序README 关于Turbo C的信息文件   TCCONFIG.EXE 配置文件转换程序MAKE.EXE   项目管理工具TCC.EXE   命令行编译TLINK.EXE   Turbo C系列连接器TLIB.EXE   Turbo C系列库管理工具C0?.OBJ 不   同模式启动代码C?.LIB   不同模式运行库GRAPHICS.LIB   图形库EMU.LIB   8087仿真库FP87.LIB 8087库   *.H Turbo C头文件   *.BGI 不同显示器图形驱动程序   *.C Turbo C例行程序(源文件)   其中:上面的?分别为:T Tiny(微型模式)S Small(小模式)C Compact(紧凑模式)M Medium(中型模式)L Large(大模式)H Huge(巨大模式)    Turbo C++ 3.0   “Turbo C++ 3.0”软件是Borland公司在1992年推出的强大的——C语言程序设计与C++面向对象程序设计 的集成开发工具。它只需要修改一个设置选项,就能够在同一个IDE集成开发环境下设计和编译以标准 C 和 C++ 语法设计的程序文件。 [编辑本段]C 语言   C语言起始于1968年发表的CPL语言,它的许多重要思想都来自于Martin Richards在1969年研制的BCPL语言,以及以BCPL语言为基础的与Ken Thompson在1970年研制的B语言。Ken Thompson用B语言写了第一个UNIX操作系统。M.M.Ritchie1972年在B语言的基础上研制了C语言,并用C语言写成了第一个在PDP-11计算机上研制的UNIX操作系统。1977年出现了独立于极其的C语言编译文本《看移植C语言编译程序》,从而大大简化了把C语言编译程序移植到新环境中所做的工作,这本身也就使UNIX的日益广泛使用,C语言也迅速得到推广。   1983年美国国家标准化协会(ANSI)根据C语言问世以来的各种版本,对C语言的发展和扩充制定了新的标准,成为ANSI C。1987年ANSI又公布了新标准————87ANSI C。   目前在微型计算机上使用的有Microsoft C、Quick C、Turbo C等多种版本。这些不同的C语言版本,基本部分是相同的,但是在有关规定上有略有差异。   C 语言发展如此迅速, 而且成为最受欢迎的语言之一, 主要因为它具有强大的功能。许多著名的系统软件, 如DBASE Ⅲ PLUS、DBASE Ⅳ 都是由C 语言编写的。用C 语言加上一些汇编语言子程序, 就更能显示C 语言的优势了,象PC- DOS ,WORDSTAR等就是用这种方法编写的。归纳起来C 语言具有下列特点:   1. C是中级语言   它把高级语言的基本结构和语句与低级语言的实用性结合起来。C 语言可以象汇编语言一样对位、字节和地址进行操作, 而这三者是计算机最基本的工作单元。   2. C是结构式语言   结构式语言的显著特点是代码及数据的分隔化, 即程序的各个部分除了必要的信息交流外彼此独立。这种结构化方式可使程序层次清晰, 便于使用、维护以及调试。C 语言是以函数形式提供给用户的, 这些函数可方便的调用, 并具有多种循环、条件语句控制程序流向, 从而使程序完全结构化。   3. C语言功能齐全   C 语言具有各种各样的数据类型, 并引入了指针概念, 可使程序效率更高。另外C 语言也具有强大的图形功能, 支持多种显示器和驱动器。而且计算功能、逻辑判断功能也比较强大, 可以实现决策目的。   4. C语言适用范围大   C 语言还有一个突出的优点就是适合于多种操作系统, 如DOS、UNIX,也适用于多种机型。   C语言的优点很多,但是也存在一些缺点,如运算优先级太多,运算能力方面不像其它高级语言那样强,语法定义不严格等。但是这些都不能阻止C语言成为一门广受欢迎的计算机编程语言
Turbo C2.0 介绍   Turbo C2.0不仅是一个快捷、高效的编译程序,同时还有一个易学、易用的集成开发环境。使用Turbo C2.0无需独立地编辑、编译和连接程序,就能建立并运行C语言程序。因为这些功能都组合在Turbo 2.0的集成开发环境内,并且可以通过一个简单的主屏幕使用这些功能。 基本配置要求   Turbo C 2.0可运行于IBM-PC系列微机,包括XT,AT及IBM 兼容机。此时要求DOS2.0或更高版本支持,并至少需要448K的RAM,可在任何彩、单色80列监视器上运行。支持数学协处理器芯片,也可进行浮点仿真,这将加快程序的执行。 主要文件的简单介绍   INSTALL.EXE 安装程序文件   TC.EXE 集成编译   TCINST.EXE 集成开发环境的配置设置程序   TCHELP.TCH 帮助文件   THELP.COM 读取TCHELP.TCH的驻留程序README 关于Turbo C的信息文件   TCCONFIG.EXE 配置文件转换程序MAKE.EXE   项目管理工具TCC.EXE   命令行编译TLINK.EXE   Turbo C系列连接器TLIB.EXE   Turbo C系列库管理工具C0?.OBJ 不   同模式启动代码C?.LIB   不同模式运行库GRAPHICS.LIB   图形库EMU.LIB   8087仿真库FP87.LIB 8087库   *.H Turbo C头文件   *.BGI 不同显示器图形驱动程序   *.C Turbo C例行程序(源文件)   其中:上面的?分别为:T Tiny(微型模式)S Small(小模式)C Compact(紧凑模式)M Medium(中型模式)L Large(大模式)H Huge(巨大模式)
### 回答1: 在 TURBO C 2.0 中,您可以使用 biosdisk() 函数来格式化软盘。 下面是一段代码示例: ``` #include <stdio.h> #include <dos.h> int main() { // 定义扇区的大小 unsigned int sector_size[3] = {512, 512, 1024}; // 定义填充字节 unsigned char fill_char[3] = {0xF6, 0xF6, 0x48}; // 格式化磁道 700 的前三个扇区 for (int i = 0; i < 3; i++) { int result = biosdisk(2, 0, 70, 0, i + 1, 1, sector_size[i], fill_char[i]); if (result != 0) { printf("格式化扇区 %d 失败,返回码: %d\n", i + 1, result); } } return 0; } ``` 请注意,在使用 biosdisk() 函数之前,需要包含 dos.h 头文件。 希望这能帮到您! ### 回答2使用TURBO C 2.0语言,可以通过以下代码格式化软盘的70磁道0面,并分别格式化3个扇区,大小分别为512字节、512字节和1024字节。其中,前两个扇区使用F6填充,第三个扇区使用48填充。 ```c #include<stdlib.h> #include<stdio.h> #include<dos.h> void formatFloppyDisk(){ union REGS regs; regs.h.ah = 0x0;// To format a floppy disk, we set AH=0 regs.h.dl = 0;// Drive number (0=A, 1=B, etc.) regs.x.cx = 0;// Track number to format regs.h.dh = 0;// Head number regs.h.al = 0;// Sector size (0=default, 1=512 bytes, 2=1024 bytes, 3=2048 bytes etc.) int FILL_BYTE = 0;// The byte value to fill the sectors with during formatting int NUM_SECTORS = 3;// Number of sectors to format // To format 70th track 0th head regs.x.ax = 0x1301; // 0x13 = Reset disk system, 01H = Reset only specified drive int86(0x13, &regs, &regs); // BIOS interrupt to reset disk system for (int i=0; i<NUM_SECTORS; i++){ regs.x.ax = 0x3101; // 0x31 = Write Format, 01H = Format only current track regs.x.bx = 0x0001; // 0x00 = Drive A:, 01H = Head 1, 0 = Generate ID Field depending on the disk in the drive 1 = Keep the ID Field all zeros regs.x.cx = 0x0170; // Track number=70(0-79 range) regs.h.dh = 0x00; // Head number=0 or 1 regs.h.al = 0x02; // Control byte=always zero regs.x.dx = i+1; // Sector number starting from 1 regs.x.si = 0x0000; // segment and offset of read/write buffer regs.x.di = 0x0000; // segment and offset of result if(i == 2){ FILL_BYTE = 0x48; // Fill the third sector with 48 regs.x.ax = 0x3102; // 0x31 = Write Format, 02H = Format sequential tracks immediately following the one being formatted }else{ FILL_BYTE = 0xF6; // Fill the first two sectors with F6 } regs.h.ah = FILL_BYTE; // Fill the sector with specified byte int86(0x13, &regs, &regs); // BIOS interrupt to format the specified sector } } int main(){ formatFloppyDisk(); return 0; } ``` 上述代码使用了INT 0x13,即BIOS中断服务例程,来执行软盘格式化操作。通过设置寄存器的不同参数,可以指定要格式化的磁道、面、扇区大小和填充字节。在这个例子中,我们格式化了软盘70磁道0面的3个扇区,前两个扇区使用F6填充,第三个扇区使用48填充。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值