Re: [PATCH] Provide a common block device size utility for Solaris & Linux

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Dec 02, 2008 at 06:25:39PM -0800, john.levon@xxxxxxx wrote:
> @@ -257,6 +259,18 @@ def xml_escape(str):
>      str = str.replace("<", "&lt;")
>      str = str.replace(">", "&gt;")
>      return str
> + 
> +def blkdev_size(path):
> +    if platform.system() == 'SunOS':
> +        return os.stat(path)[stat.ST_SIZE]
> +    else:
> +        dummy, msg = commands.getstatusoutput('fdisk -s %s' % path)
> +        # check
> +        if msg.isdigit() == False:
> +            lines = msg.splitlines()
> +            # retry eg. for the GPT disk
> +            msg = lines[len(lines)-1]
> +        return (int(msg) * 1024)


ACK, to the general idea of adding a common routine. The original Linux
impl was kind of crazy. We could get a single portable impl for all
OS by using seek(), which is how libvirt does it in its storage code.

       fd = os.open(path, O_RDONLY)
       size = os.lseek(fd, 0, SEEK_END);
       os.close(fd)
       return size


Danie
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/et-mgmt-tools

[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux