Size of a partition

classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|

Size of a partition

Rainer Stratmann
How to get the total size of an unmounted partition in Linux?

For example "/dev/sdb1"
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Size of a partition

Bart-48
On 12/18/14, Rainer Stratmann <[hidden email]> wrote:

> How to get the total size of an unmounted partition in Linux?

Can you use the info at
http://serverfault.com/questions/190685/whats-the-best-way-to-get-info-about-currently-unmounted-drives
?

Just googled you question ;-)

You can run these commands and parse the output.

Bart
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Size of a partition

Rainer Stratmann
 On Thursday 18 December 2014 22:49:08 you wrote:
> On 12/18/14, Rainer Stratmann <[hidden email]> wrote:
> > How to get the total size of an unmounted partition in Linux?
>
> Can you use the info at
> http://serverfault.com/questions/190685/whats-the-best-way-to-get-info-abou
> t-currently-unmounted-drives ?
>
> Just googled you question ;-)

Thanks, it is may interesting.
Better would be a syscall.
 
> You can run these commands and parse the output.
>
> Bart
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal 
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Size of a partition

Sven Barth-2

Am 19.12.2014 13:54 schrieb "Rainer Stratmann" <[hidden email]>:
>
>  On Thursday 18 December 2014 22:49:08 you wrote:
> > On 12/18/14, Rainer Stratmann <[hidden email]> wrote:
> > > How to get the total size of an unmounted partition in Linux?
> >
> > Can you use the info at
> > http://serverfault.com/questions/190685/whats-the-best-way-to-get-info-abou
> > t-currently-unmounted-drives ?
> >
> > Just googled you question ;-)
>
> Thanks, it is may interesting.
> Better would be a syscall.

You'll likely need to check for IOCTL values you can then pass to an opened partition node per FpIoctl. I don't know them though, so I can't help you there...

Regards,
Sven


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Size of a partition

Mark Morgan Lloyd-5
In reply to this post by Rainer Stratmann
Rainer Stratmann wrote:

>  On Thursday 18 December 2014 22:49:08 you wrote:
>> On 12/18/14, Rainer Stratmann <[hidden email]> wrote:
>>> How to get the total size of an unmounted partition in Linux?
>> Can you use the info at
>> http://serverfault.com/questions/190685/whats-the-best-way-to-get-info-abou
>> t-currently-unmounted-drives ?
>>
>> Just googled you question ;-)
>
> Thanks, it is may interesting.
> Better would be a syscall.

I think this is a question that doesn't have a straightforward answer.
For example, you refer to an "unmounted partition", but partitions
aren't mounted: filesystems are mounted, and without knowing the type of
filesystem you don't know how much overhead is associated.

The canonical program that looks at partition sizes is fdisk, and
painful experience has taught me that different fdisk implementations
can return different results. Sometimes the differences are subtle,
sometimes not.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Size of a partition

David W Noon-2
In reply to this post by Rainer Stratmann
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Fri, 19 Dec 2014 13:53:23 +0100, Rainer Stratmann
([hidden email]) wrote about "Re: [fpc-pascal] Size of a
partition" (in <[hidden email]>):

> On Thursday 18 December 2014 22:49:08 you wrote:
>> On 12/18/14, Rainer Stratmann <[hidden email]>
>> wrote:
>>> How to get the total size of an unmounted partition in Linux?
>>
>> Can you use the info at
>> http://serverfault.com/questions/190685/whats-the-best-way-to-get-info-abou
>>
>>
t-currently-unmounted-drives ?
>>
>> Just googled you question ;-)
>
> Thanks, it is may interesting.

Probably not, actually. ... :-)

> Better would be a syscall.

This stuff is all in sysfs.  Attached is some code that can get you
started on a more sensible path.

HTH.
- --
Regards,

Dave  [RLU #314465]
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
[hidden email] (David W Noon)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iEYEARECAAYFAlSUhuoACgkQogYgcI4W/5TVigCeO9dvGFzl9f555Gdami7BhFmn
G6AAn2JvBzYT2jHijewMohXpAW/mjXxH
=xRzJ
-----END PGP SIGNATURE-----

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

VolumeUtils.zip (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

What's wrong with this simple test program

Ralf Quint
I have been trying to use tStringList in a larger project of mine, but
this just keeps bombing out with a exception.
I have been able to reproduce the problem with this very simple test
program:

program project1;

USES Classes;

Var T : tStringList;
     S : String;
begin
   S := 'Test';
   T.Create;
// T.Clear;
   T.Add (S);
   T.Free;
end.

It will throw the exception at each and every instruction using T after
the T.Create statement.

The project is a simple command line program, tested both with Lazarus
1.2.6 and the included default install of FPC 2.6.4 on either Windows
8.1/64 or Windows 10/32...



---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: What's wrong with this simple test program

Joost van der Sluis
On 12/19/2014 09:48 PM, Ralf Quint wrote:

> I have been trying to use tStringList in a larger project of mine, but
> this just keeps bombing out with a exception.
> I have been able to reproduce the problem with this very simple test
> program:
>
> program project1;
>
> USES Classes;
>
> Var T : tStringList;
>      S : String;
> begin
>    S := 'Test';
>    T.Create;
> // T.Clear;
>    T.Add (S);
>    T.Free;
> end.

You're mixing old TP-style objects with classes.

T := TStringList.Create is the correct syntax.

Regards,

Joost.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: What's wrong with this simple test program

Michael Van Ham
In reply to this post by Ralf Quint

On Fri, Dec 19, 2014, 12:49 Ralf Quint <[hidden email]> wrote:

I have been trying to use tStringList in a larger project of mine, but
this just keeps bombing out with a exception.
I have been able to reproduce the problem with this very simple test
program:

program project1;

USES Classes;

Var T : tStringList;
     S : String;
begin
   S := 'Test';
   T.Create;
// T.Clear;
   T.Add (S);
   T.Free;
end.

It will throw the exception at each and every instruction using T after
the T.Create statement.

The project is a simple command line program, tested both with Lazarus
1.2.6 and the included default install of FPC 2.6.4 on either Windows
8.1/64 or Windows 10/32...

---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Try this,


T := tstringlist.create;


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: What's wrong with this simple test program

Ralf Quint
In reply to this post by Joost van der Sluis
On 12/19/2014 12:53 PM, Joost van der Sluis wrote:

> On 12/19/2014 09:48 PM, Ralf Quint wrote:
>> I have been trying to use tStringList in a larger project of mine, but
>> this just keeps bombing out with a exception.
>> I have been able to reproduce the problem with this very simple test
>> program:
>>
>> program project1;
>>
>> USES Classes;
>>
>> Var T : tStringList;
>>      S : String;
>> begin
>>    S := 'Test';
>>    T.Create;
>> // T.Clear;
>>    T.Add (S);
>>    T.Free;
>> end.
>
> You're mixing old TP-style objects with classes.
>
> T := TStringList.Create is the correct syntax.
Well, then why is the compiler building this just fine without even
throwing an error?!?!?
As mentioned, I do not get the error at the .Create call, but at
anything after that...
I do not have a working Delphi system at hand right now, but I am sure
that this would have compiled and worked on anything up to Delphi 2006
just fine.

I will change this and see if this makes a difference, thanks

Ralf

---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Size of a partition

Rainer Stratmann
In reply to this post by David W Noon-2
Hi Dave!

that's exactly what I was searching for.
Thanks a lot.

One question is left:

Where can I read the blocksize. Normally it is 512 bytes. But there are
(newer) devices where there is a different blocksize. Also a CD has a different
blocksize as far I know.


 On Friday 19 December 2014 21:13:30 you wrote:

> On Fri, 19 Dec 2014 13:53:23 +0100, Rainer Stratmann
> ([hidden email]) wrote about "Re: [fpc-pascal] Size of a
>
> partition" (in <[hidden email]>):
> > On Thursday 18 December 2014 22:49:08 you wrote:
> >> On 12/18/14, Rainer Stratmann <[hidden email]>
> >>
> >> wrote:
> >>> How to get the total size of an unmounted partition in Linux?
> >>
> >> Can you use the info at
> >> http://serverfault.com/questions/190685/whats-the-best-way-to-get-info-a
> >> bou
>
> t-currently-unmounted-drives ?
>
> >> Just googled you question ;-)
> >
> > Thanks, it is may interesting.
>
> Probably not, actually. ... :-)
>
> > Better would be a syscall.
>
> This stuff is all in sysfs.  Attached is some code that can get you
> started on a more sensible path.
>
> HTH.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Size of a partition

Rainer Stratmann
 On Saturday 20 December 2014 00:00:35 you wrote:
> Hi Dave!
>
> that's exactly what I was searching for.
> Thanks a lot.
>
> One question is left:
>
> Where can I read the blocksize.

/sys/block/sda/queue/hw_sector_size

logical_block_size
physical_block_size

and so on

> Normally it is 512 bytes. But there are
> (newer) devices where there is a different blocksize. Also a CD has a
> different blocksize as far I know.
>
>  On Friday 19 December 2014 21:13:30 you wrote:
> > On Fri, 19 Dec 2014 13:53:23 +0100, Rainer Stratmann
> > ([hidden email]) wrote about "Re: [fpc-pascal] Size of a
> >
> > partition" (in <[hidden email]>):
> > > On Thursday 18 December 2014 22:49:08 you wrote:
> > >> On 12/18/14, Rainer Stratmann <[hidden email]>
> > >>
> > >> wrote:
> > >>> How to get the total size of an unmounted partition in Linux?
> > >>
> > >> Can you use the info at
> > >> http://serverfault.com/questions/190685/whats-the-best-way-to-get-info
> > >> -a bou
> >
> > t-currently-unmounted-drives ?
> >
> > >> Just googled you question ;-)
> > >
> > > Thanks, it is may interesting.
> >
> > Probably not, actually. ... :-)
> >
> > > Better would be a syscall.
> >
> > This stuff is all in sysfs.  Attached is some code that can get you
> > started on a more sensible path.
> >
> > HTH.
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal 
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Size of a partition

David W Noon-2
In reply to this post by Rainer Stratmann
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sat, 20 Dec 2014 00:00:35 +0100, Rainer Stratmann
([hidden email]) wrote about "Re: [fpc-pascal] Size of a
partition" (in <[hidden email]>):

> Hi Dave!
>
> that's exactly what I was searching for. Thanks a lot.

You're welcome.

> One question is left:
>
> Where can I read the blocksize. Normally it is 512 bytes. But there
> are (newer) devices where there is a different blocksize. Also a CD
> has a different blocksize as far I know.

There are 2 functions in the unit to do that:
get_physical_sector_size() and get_logical_sector_size().

If the disk's sector size is 512 bytes they will give the same answer.
 Likewise, for a CD or DVD they will give the same answer of 2048 bytes.

If a disk has a physical sector size of 4096 bytes, it is up to the
SATA/SAS driver to publish a logical sector size of either 4096 or
512.  I think this configuration is determined when you partition the
drive, where using GPT sets it to 4096 and using DOS-style partition
reverts it to 512 bytes, but this is just my guess -- I don't have a
large disk on which to test.
- --
Regards,

Dave  [RLU #314465]
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
[hidden email] (David W Noon)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iEYEARECAAYFAlSUscQACgkQogYgcI4W/5To2wCfeUNNrWY1Gl7KK/HRvLdzUfWs
aZ8An2jp7kBJcJkGkdSmLP/C4DxZ35SU
=zCW3
-----END PGP SIGNATURE-----
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: What's wrong with this simple test program

Sven Barth-2
In reply to this post by Ralf Quint

Am 19.12.2014 21:58 schrieb "Ralf Quint" <[hidden email]>:
>
> On 12/19/2014 12:53 PM, Joost van der Sluis wrote:
>>
>> On 12/19/2014 09:48 PM, Ralf Quint wrote:
>>>
>>> I have been trying to use tStringList in a larger project of mine, but
>>> this just keeps bombing out with a exception.
>>> I have been able to reproduce the problem with this very simple test
>>> program:
>>>
>>> program project1;
>>>
>>> USES Classes;
>>>
>>> Var T : tStringList;
>>>      S : String;
>>> begin
>>>    S := 'Test';
>>>    T.Create;
>>> // T.Clear;
>>>    T.Add (S);
>>>    T.Free;
>>> end.
>>
>>
>> You're mixing old TP-style objects with classes.
>>
>> T := TStringList.Create is the correct syntax.
>
> Well, then why is the compiler building this just fine without even throwing an error?!?!?

Because Create is a legal method call as well. You can call a constructor like a normal method on an existing instance.

> As mentioned, I do not get the error at the .Create call, but at anything after that...
> I do not have a working Delphi system at hand right now, but I am sure that this would have compiled and worked on anything up to Delphi 2006 just fine.

Delphi will compile this (like FPC does), but it will fail at runtime. Trust me here, I did the mistake a few times myself when I thought about too many other things.

Regards,
Sven


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Size of a partition

Sven Barth-2
In reply to this post by Rainer Stratmann

Am 20.12.2014 00:01 schrieb "Rainer Stratmann" <[hidden email]>:
>
> Hi Dave!
>
> that's exactly what I was searching for.
> Thanks a lot.
>
> One question is left:
>
> Where can I read the blocksize. Normally it is 512 bytes. But there are
> (newer) devices where there is a different blocksize. Also a CD has a different
> blocksize as far I know.

Please note that there are drives that internally have 4kB, but emulate 512B ones. On SATA ports you can determine this, but if you connect them using some USB adapter you might not be able to detect this. Depending on what you plan to do thus is important (e.g. copying large amount of data would be better done in 4kB blocks or multiples of that).

Regards,
Sven


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: What's wrong with this simple test program

etrusco
In reply to this post by Sven Barth-2


>
> Delphi will compile this (like FPC does), but it will fail at runtime. Trust me here, I did the mistake a few times myself when I thought about too many other things.
>
> Regards,
> Sven
>

Yes and this is just sad.
Is there a reasonable case for not disallowing call of constructor as method outside constructors (of the class itself)?

Best regards,
Flávio


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal