『楼 主』:
关于dos启动盘中setramd.bat命令行的理解
使用 LLM 解释/回答一下
关于setramd.bat命令行的理解。不对之处,请大师指正!
@echo off
a:\findramd
::运行a盘中的findramd寻找虚拟盘。
if errorlevel 255 goto no_ramdrive
::如果执行findramd后,返回值是255,说明不存在虚拟盘,执行no_ramdrive显示虚拟盘不存在的信息。
if not errorlevel 3 goto no_ramdrive
::如果执行findramd后,返回值不是3(返回值为3时存在虚拟盘),说
明不存在虚拟盘,执行no_ramdrive显示虚拟盘不存在的信息。
goto do_shift
::如果以上两种情况不成立(表明有虚拟盘存在),则执行do_shift开始设置虚拟盘盘符。
:loop
::确定虚拟盘盘符。
if errorlevel %1 goto no_shift
::因为shift执行后,返回值是参数%1代表的值。如果参数%1代表的值能作为返回值返回,表明参数%1不为空,则执行no_shift给虚拟盘分配盘符。
:do_shift
::开始设置虚拟盘盘符。
set cdrom=%2
::设置字符串cdrom(光驱盘符。由mscdex /L:%cdrom%决定)对应参数%2。请注意:此时光驱分配到的盘符是由硬件决定的,还没有包括由ramdrive建立起来的虚拟盘。因为系统默认的盘符分配是:软驱(a)、软驱(b)、硬盘、光驱,所以,如果硬盘只有一个分区则硬盘(c)、光驱(d),如果硬盘有多个分区则光驱盘符顺推,如果没有硬盘则光驱(c)。当有虚拟盘时,虚拟盘被安排在硬盘和光驱之间,因此光驱盘符会向后退一位。
shift
::参数左移一位(即让参数%1和参数%2对应的盘符向前移一位)。
shift
::参数左移一位(即让参数%1和参数%2对应的盘符再向前移一位)。
if not %1*==* goto loop
::两次左移后,如果参数%1仍然不为空(即%1*==*不成立),说明虚拟盘存在,则执行loop确定虚拟盘盘符。
goto no_ramdrive
::两次左移后,如果参数%1为空(即%1*==*成立),说明虚拟盘不存在,则执行no_ramdrive显示虚拟盘不存在的信息。
:no_shift
::给虚拟盘分配盘符。
set ramd=%2
::让虚拟盘盘符取参数%2对应的盘符(也就是没有建立虚拟盘前光驱取得的盘符)。
goto success
::执行success显示虚拟盘建立成功的信息。
:no_ramdrive
::没有或无法建立虚拟盘(可以设置一些提示信息)
:success
::显示虚拟盘建立成功的信息
Understanding of the setramd.bat command line. If there are any mistakes, please correct them, masters!
@echo off
a:\findramd
:: Run findramd in drive a to find the virtual drive.
if errorlevel 255 goto no_ramdrive
:: If the return value of executing findramd is 255, it means there is no virtual drive. Then execute no_ramdrive to display the information that the virtual drive does not exist.
if not errorlevel 3 goto no_ramdrive
:: If the return value of executing findramd is not 3 (when the return value is 3, the virtual drive exists), it means there is no virtual drive. Then execute no_ramdrive to display the information that the virtual drive does not exist.
goto do_shift
:: If the above two situations do not hold (indicating that the virtual drive exists), then execute do_shift to start setting the drive letter of the virtual drive.
:loop
:: Determine the drive letter of the virtual drive.
if errorlevel %1 goto no_shift
:: Because after shift is executed, the return value is the value represented by parameter %1. If the value represented by parameter %1 can be returned as the return value, it means that parameter %1 is not empty. Then execute no_shift to assign a drive letter to the virtual drive.
:do_shift
:: Start setting the drive letter of the virtual drive.
set cdrom=%2
:: Set the string cdrom (the drive letter of the CD-ROM. Determined by mscdex /L:%cdrom%) corresponding to parameter %2. Please note: At this time, the drive letter assigned to the CD-ROM is determined by the hardware and does not include the virtual drive established by ramdrive. Because the default drive letter allocation of the system is: floppy drive (a), floppy drive (b), hard disk, CD-ROM. So, if there is only one partition on the hard disk, the hard disk (c), CD-ROM (d). If there are multiple partitions on the hard disk, the CD-ROM drive letter is pushed back. If there is no hard disk, the CD-ROM (c). When there is a virtual drive, the virtual drive is arranged between the hard disk and the CD-ROM, so the CD-ROM drive letter will be moved back by one position.
shift
:: Shift the parameters by one position to the left (that is, make the drive letters corresponding to parameters %1 and %2 move forward by one position).
shift
:: Shift the parameters by one position to the left (that is, make the drive letters corresponding to parameters %1 and %2 move forward by one position again).
if not %1*==* goto loop
:: After two left shifts, if parameter %1 is still not empty (that is, %1*==* is not established), it means the virtual drive exists. Then execute loop to determine the drive letter of the virtual drive.
goto no_ramdrive
:: After two left shifts, if parameter %1 is empty (that is, %1*==* is established), it means the virtual drive does not exist. Then execute no_ramdrive to display the information that the virtual drive does not exist.
:no_shift
:: Assign a drive letter to the virtual drive.
set ramd=%2
:: Let the drive letter of the virtual drive take the drive letter corresponding to parameter %2 (that is, the drive letter that the CD-ROM obtained before the virtual drive was established).
goto success
:: Execute success to display the information that the virtual drive is successfully established.
:no_ramdrive
:: No virtual drive exists or cannot be established (some prompt information can be set).
:success
:: Display the information that the virtual drive is successfully established
|