tbscript problems: newline, mount

User discussion and information resource forum for scripting of TeraByte products using script lanugages such as TBScript, VBScript, Batch Files, and more.
schmibble
Posts: 22
Joined: Sat Aug 25, 2012 4:45 am

tbscript problems: newline, mount

Post by schmibble »

I'm trying to run the following test snippet in the BIBM boot environment (from a BIBM bootable flash drive) and am hoping someone could tell me why I'm erroring out. I've combed through it several times, but as far as I can tell I'm following the TBOSDT manual p. 64 code, except I'm not trying to loop the snippet--I can't get that far. Right now I'm just trying to see if a single go will work with easily visible, hard-coded numbers for parameters, and can't even do that.

Actually there are two problems, one annoying but trivial, the other significant.

1: trivial issue
-----------------
The trivial problem is with the newline text feature in printl. It's giving me a newline down one line exactly onscreen where the previous one ends. So in the first printl() in the snippet...
"the HD number is " # vHD.num # ",^Nso the script should proceed to mount the drive",
...what the user sees onscreen is "the HD number is [X]," and then there is a newline, but it has a bunch of blank space all the way out to where the "[X]," is. Except of course the "[X]" is a line ABOVE the new line, so the real new line --the actual text--doesnt start just one line down but also doesn't appear until the blank space reaches a point corresponding to the ending comma of the previous line. Very odd, and makes the newline feature useless.

2: important issue
----------------------
I can live without newlines if necessary. More importantly, the first debug message--"the HD number is"--correctly reports the HD number as 0, so apparently getHDinfo() worked, but then Mount command won't execute. The error message I get is "Invalid parameter: vHD.num:". I have five physical disks attached to my system, by the way, and BIBM sees them correctly, so the problem is not that there's no disk to be found.

I can't see why I'm getting this message. If I run the plain command "mount 0: 0 1" out in TBOSDT, it works just fine, and that's exactly what I'm telling tbscript to do here--right?

sub main()

GetDrvLtrInfo()
vHD=GetHdInfo(0)
vPartitionNum=1

; THE SCRIPT EXECUTES THIS MESSAGE CORRECTLY (NEWLINE PROBLEM ASIDE, AT LEAST)...
printl("the HD number is " # vHD.num # ",^Nso the script should proceed to mount the drive.")

; ...THEN GOES INTO THE LOOP...
while vHD

; ...AND ERRORS OUT AT THIS LINE:
ext("mount vHD.num: vHD.num vHD.partition[vPartitionNum]")

vCheckpath=CHDIR(vHD.partition[vPartitionNum]#":\Windows\")

If vCheckpath=0
then vSyspath=GETCWD()
else ext("umount vHD.num:")
End if

printl (vSyspath now holds "#vSyspath#"^N--but if there was nothing at the end of the line above, the .partition[X] method^n didn't work to create a path.")
wend

end sub

The same problem seems to raise its head later at unmount; I get an "Unexpected 'ext'" error reported for line 20, which is the umount line. The script seems to error out at that point, since the final printl() does not get executed.

By the way, HD0/partition 1 should yield the path I'm looking for (the Windows system folder). if I code a different number into GetHDinfo(), e.g. 1, I still get the same "Invalid parameter: vHD.num:" error, but instead of "Unexpected 'ext'", the second error message tells me I don't have a proper End If. Can't make heads or tails of this.

By the way, as the rest of the code indicates, I want to end up checking the mounted drive for the [DRIVE]:\Windows directory and return that as a value to a variable, then keep the drive mounted for operations with that path, unmounting the drive only if it didn't contain the directory in question. If anyone can see yet other problems with this--i.e. with the CHDIR code, I'd love to know prior to undertaking yet more hours debugging.
TeraByte Support
Posts: 3598
Joined: Thu May 05, 2011 10:37 pm

Re: tbscript problems: newline, mount

Post by TeraByte Support »

You can use ^R^N (CR/LF) to fix the newline issue.

For the other, you have to be outside the quotes:

ext("mount " # vHD.num #": " # vHD.num # " " # vHD.partition[vPartitionNum])


"schmibble" wrote in message news:5249@public.scripting...

I'm trying to run the following test snippet in the BIBM boot environment
(from a BIBM bootable flash drive) and am hoping someone could tell me why
I'm erroring out. I've combed through it several times, but as far as I can
tell I'm following the TBOSDT manual p. 64 code, except I'm not trying to
loop the snippet--I can't get that far. Right now I'm just trying to see if
a single go will work with easily visible, hard-coded numbers for
parameters, and can't even do that.

Actually there are two problems, one annoying but trivial, the other
significant.

1: trivial issue
-----------------
The trivial problem is with the newline text feature in printl. It's giving
me a newline down one line exactly onscreen where the previous one ends. So
in the first printl() in the snippet...
"the HD number is " # vHD.num # ",^Nso the script should proceed to mount
the drive",
....what the user sees onscreen is "the HD number is [X]," and then there is
a newline, but it has a bunch of blank space all the way out to where the
"[X]," is. Except of course the "[X]" is a line ABOVE the new line, so the
real new line --the actual text--doesnt start just one line down but also
doesn't appear until the blank space reaches a point corresponding to the
ending comma of the previous line. Very odd, and makes the newline feature
useless.

2: important issue
----------------------
I can live without newlines if necessary. More importantly, the first debug
message--"the HD number is"--correctly reports the HD number as 0, so
apparently getHDinfo() worked, but then Mount command won't execute. The
error message I get is "Invalid parameter: vHD.num:". I have five physical
disks attached to my system, by the way, and BIBM sees them correctly, so
the problem is not that there's no disk to be found.

I can't see why I'm getting this message. If I run the plain command "mount
0: 0 1" out in TBOSDT, it works just fine, and that's exactly what I'm
telling tbscript to do here--right?

sub main()

GetDrvLtrInfo()
vHD=GetHdInfo(0)
vPartitionNum=1

; THE SCRIPT EXECUTES THIS MESSAGE CORRECTLY (NEWLINE PROBLEM ASIDE, AT
LEAST)...
printl("the HD number is " # vHD.num # ",^Nso the script should proceed to
mount the drive.")

; ...THEN GOES INTO THE LOOP...
while vHD

; ...AND ERRORS OUT AT THIS LINE:
ext("mount vHD.num: vHD.num vHD.partition[vPartitionNum]")

vCheckpath=CHDIR(vHD.partition[vPartitionNum]#":\Windows\")

If vCheckpath=0
then vSyspath=GETCWD()
else ext("umount vHD.num:")
End if

printl (vSyspath now holds "#vSyspath#"^N--but if there was nothing at the
end of the line above, the .partition[X] method^n didn't work to create a
path.")
wend

end sub

The same problem seems to raise its head later at unmount; I get an
"Unexpected 'ext'" error reported for line 20, which is the umount line.
The script seems to error out at that point, since the final printl() does
not get executed.

By the way, HD0/partition 1 should yield the path I'm looking for (the
Windows system folder). if I code a different number into GetHDinfo(), e.g.
1, I still get the same "Invalid parameter: vHD.num:" error, but instead of
"Unexpected 'ext'", the second error message tells me I don't have a proper
End If. Can't make heads or tails of this.

By the way, as the rest of the code indicates, I want to end up checking the
mounted drive for the [DRIVE]:\Windows directory and return that as a value
to a variable, then keep the drive mounted for operations with that path,
unmounting the drive only if it didn't contain the directory in question. If
anyone can see yet other problems with this--i.e. with the CHDIR code, I'd
love to know prior to undertaking yet more hours debugging.

Eric
Posts: 224
Joined: Mon Sep 05, 2011 6:53 pm
Location: France

Re: tbscript problems: newline, mount

Post by Eric »

When mounting the drive number, you should specify the number of the drive you want to mount, (and not use the "HD number") as number for the drive, and specify the id of the partition. Like this:
>
> res=ext("mount 0: " # vHD.num # " " # vHD.partition[vPartitionNum].id)

Then you can use the result as a condition to continue or not (means 0: as been mounted correctly):
> if res=0 then
> vCheckpath=CHDIR("0:\Windows\")
>
> If vCheckpath=0
> then vSyspath="0:\Windows"
> ExitLoop
> End if
> ext("umoumt 0:")
> end if

Also, if vCheckPath=0, you can add an ExitLoop to exit the loop (because you found the partition)..
Just keep in mind that 0: will then still be mounted. So don't
Your
Last edited by Eric on Fri Apr 12, 2013 8:25 am, edited 2 times in total.
Eric
Posts: 224
Joined: Mon Sep 05, 2011 6:53 pm
Location: France

Re: tbscript problems: newline, mount

Post by Eric »

Continue:
... so don't forget to unmont at the end.

You loop (while vHD) is infinite because vHD is never changed. You need to modify it, lile getting the info of the next drive, just before the wend:

vHD=GetHdInfo(vHD.num+1)
Eric
Posts: 224
Joined: Mon Sep 05, 2011 6:53 pm
Location: France

Re: tbscript problems: newline, mount

Post by Eric »

For the new line issue, you can also use two successive printl.
schmibble
Posts: 22
Joined: Sat Aug 25, 2012 4:45 am

Re: tbscript problems: newline, mount

Post by schmibble »

awesome thanks for the fast replies, eric. well it looks like your advice just stomps all over that newline bug (since bug it pretty clearly is). That's what a bug's fate should always be--SPLAT n' SQUISSSSH!

Coupla questions before I plough into the script again with your advice. You say...

> When mounting the drive number, you should specify the number
> of the drive you want to mount, (and not use the "HD number")
> as number for the drive, and specify the id of the partition. Like this:
>
> res=ext("mount 0: " # vHD.num # " " # vHD.partition[vPartitionNum].id)

well, the problem is that eventually this will all be enclosed be in a FOR loop inspired (very) loosely by the use of getHDinfo() in the terabyte shipping script restoreg.tbs Bbuildlist: goto label. so the number given to getHDinfo() in my example is hard-coded as 0, but eventually it'll be a var holding the FOR's increment, and it'll make vHD.num the same number as the increment. so I kind of hoped that as I mounted and checked each drive, I could just go along and use vhd.num to mount each drive in turn, e.g. mount 0: 0 1, then mount 1: 1 1, then mount 2: 2 1, then mount 3: 3 1, then mount 4: 4 1, then finally mount 5: 5 1.

But apparantly you're saying that ext("mount " # vHD.num #": " # vHD.num # " " # vHD.partition[vPartitionNum]) is not going to work that way for me.

However, the problem with your solution, ext("mount 0: " # vHD.num # " " # vHD.partition[vPartitionNum].id), is that I actually can't specify "mount 0:" , or for that matter I can't specify "mount 2:" or whatever--it's going to have to be "mount SomeHDNumbrVariable:", one way or another, and for simplicity's sake I'd like to keep the arbitray hard-disk IDs (the "mount x:" the same as the HDnum that can't be changed. That way there's never a question of what HD I'm dealing with at any particular time. Or am I simply barking up a wrong tree here?

And what does the little *.id do, twisting in the wind there at the tail end of the whole thing? I know the documentations says its the "ID of partition as used by TeraByte products", but what good does it to here in my script? Nothing in the documentation would have lead me to expect it to be relevant to what I've attempting.
Eric
Posts: 224
Joined: Mon Sep 05, 2011 6:53 pm
Location: France

Re: tbscript problems: newline, mount

Post by Eric »

For sure you can do what you are saying, and use vHD.num instead of 0:. I have misundestood your needs and wasn't aware of the other parts of the script. Sorry.
If vHD.num is allways a number lower than 9, then it's fine.

For the 2nd point, In the moumt command, you have to use the id of the partition. The value of the .partition[] attribute is 0 or 1 (false or true, not exists or exists). That's the .id that specify the exact address of the mount command. It's the identifier of the partition inside the disk.
schmibble
Posts: 22
Joined: Sat Aug 25, 2012 4:45 am

Re: tbscript problems: newline, mount

Post by schmibble »

Thanks very much for the replies. Light is beginning to dawn. However, before I can proceed further I need to understand more about the GetHDinfo partition[].id member/submember pair. Three specific questions this time around:

1. The documentation says that .partition[] is an "Array (1 based) of partition entries". (I assume that "1 based" simply means that the array begins at 1 rather than 0; please correct me if it means something else.) Given this, I want to extract the array index (the number of entries in the array) and use that number as the condition of a FOR subloop. Inside it, MOUNT would execute the exact number of iterations needed for all the partitions on the current drive and would need no other exit condition. E.g. something like this:

GetDrvLtrInfo()
vHD=GetHdInfo(vIncrmentFromOuterLoop)
vHowManyPartitions={{unknown method of retrieving the .partition[] array's index}}

FOR i = 1 to vHowManyPartitions
[MOUNT THE PARTITION & RUN PATH-CHECKING CODE]
NEXT

Unfortunately, however, the documentation fails to offer a method of getting the index of the array. But surely there's a way to do that. How?

2. Why is .ID necessary at all? If .partition[] is an array containing all the partition entries on a particular drive, then why can't you just use .partition[1], .partition[2], partition[3], etc.? That's the way (one-dimensional) arrays work in most other languages, and why my original snippet coded it as vHD.partition[vPartitionNum].

3. If...
a) tbscript won't allow you to specify the partitions on a drive via .partition[1], .partition[2], partition[3], etc., but instead requires .ID; and if...
b) .ID is a value returned by GetHDinfo--it's not a changing variable, and it will always be the same for a given partition; then...
c) presumably GetHDInfo() by default returns a *.partition[].ID default value of 1, the first partition on the disk. But then how can you get past partition 1 on a multiple-partition drive? In other words, what do you tell GetHDInfo to make it generate an .ID that will designate the second or third or fourth partition instead of the first? Or maybe my guesses at how .partition[].ID works are wrong--but the documentation doesn't give any details, so I'm forced to speculate.
Eric
Posts: 224
Joined: Mon Sep 05, 2011 6:53 pm
Location: France

Re: tbscript problems: newline, mount

Post by Eric »

You have some examples in the documentation.
The .partition[i] entry contains all the info of partition number i (in the order they appear in the disk, not in the MBR or EMBR). The value of the root .partition[i] is allways 1 or 0. The value of the member .id depends on the partition.

For example, if the 2nd partition in the disk is at the 4th position in the MBR, it will have:
- .partition[2] =1 (because it exists)
- .partition[2].mbrentry =3
- .partition[2].id =0x04 =4
- .partition[2].name = "its name"

For the loop, you would use a while-wend method (as shown in the doc):
i=1
while vHD.partition[i]=1
...
i=i+1
wend
Eric
Posts: 224
Joined: Mon Sep 05, 2011 6:53 pm
Location: France

Re: tbscript problems: newline, mount

Post by Eric »

In the scripts Terabyte is providing, you can find some examples of loops browsing through all the partitions of hard drives to search for Windows installation.
For example in the GetWindowsSelection() in osdtool.tbs (search for it, then for GetHdInfo()...)
Post Reply