示例#1
0
 def Start(self):
   if "/opt" in self.args.path_list[0]:
     mnt = rdf_client.UnixVolume(mount_point="/opt")
     self.SendReply(rdf_client.Volume(unixvolume=mnt, bytes_per_sector=4096,
                                      sectors_per_allocation_unit=1,
                                      actual_available_allocation_units=10,
                                      total_allocation_units=100))
   else:
     mnt = rdf_client.UnixVolume(mount_point="/var")
     self.SendReply(rdf_client.Volume(unixvolume=mnt, bytes_per_sector=1,
                                      sectors_per_allocation_unit=1,
                                      actual_available_allocation_units=784165,
                                      total_allocation_units=78416500))
示例#2
0
    def Run(self, args):
        if platform.system() == "Windows":
            raise RuntimeError("os.statvfs not available on Windows")

        for path in args.path_list:

            try:
                fd = vfs.VFSOpen(rdf_paths.PathSpec(path=path,
                                                    pathtype=args.pathtype),
                                 progress_callback=self.Progress)
                st = fd.StatFS()
                mount_point = fd.GetMountPoint()
            except (IOError, OSError) as e:
                self.SetStatus(rdf_flows.GrrStatus.ReturnedStatus.IOERROR, e)
                continue

            unix = rdf_client.UnixVolume(mount_point=mount_point)

            # On linux pre 2.6 kernels don't have frsize, so we fall back to bsize.
            # The actual_available_allocation_units attribute is set to blocks
            # available to the unprivileged user, root may have some additional
            # reserved space.
            self.SendReply(
                rdf_client.Volume(
                    bytes_per_sector=(st.f_frsize or st.f_bsize),
                    sectors_per_allocation_unit=1,
                    total_allocation_units=st.f_blocks,
                    actual_available_allocation_units=st.f_bavail,
                    unixvolume=unix))
示例#3
0
class UnixVolumeClientMock(ActionMock):
  """A mock of client filesystem volumes."""
  unix_local = rdf_client.UnixVolume(mount_point="/usr")
  unix_home = rdf_client.UnixVolume(mount_point="/")
  path_results = [
      rdf_client.Volume(
          unixvolume=unix_local, bytes_per_sector=4096,
          sectors_per_allocation_unit=1, actual_available_allocation_units=50,
          total_allocation_units=100),
      rdf_client.Volume(
          unixvolume=unix_home, bytes_per_sector=4096,
          sectors_per_allocation_unit=1,
          actual_available_allocation_units=10,
          total_allocation_units=100)]

  def StatFS(self, _):
    return self.path_results