<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-2" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
<div class="moz-text-plain" wrap="true" graphical-quote="true"
 style="font-family: -moz-fixed; font-size: 13px;" lang="x-central-euro">
<pre wrap="">Ok, diky. Zkusim to nejak rozbehat.

LP.


------------------------------

Posilam par odkazu a fragmentu kodu ktery urcite po par upravach i
zkompilujete, snad to pomuze.
Abyste si neprepsal disk ktery nechcete prepsat, je vhodne napr. pri
otevreni zkontrolovat velikost
oteviraneho disku a zakazat pristup na "velke disky", nebo zkontrolovat zda
jsou na nejakem sektoru,
nebo sektorech zapsana urcita identifikacni data, ktera si zvolite.

#include "stdafx.h"
#include "AlarmRead.h"
#include "AlarmReadDlg.h"
#include "winioctl.h"
#include &lt;stdlib.h&gt;
#include &lt;io.h&gt;
#include "stdafx.h"
#include "windows.h"
#include &lt;direct.h&gt;

unsigned char read_sd (unsigned char *buf, unsigned long sector) {
  DWORD res;

  res = SetFilePointer(
  dh,          // handle of file
  sector*512,  // number of bytes to move file pointer
  NULL,        // pointer to high-order DWORD of distance to move
  FILE_BEGIN   // how to move
  );

  if ((res==0xFFFFFFFF)||(res!=sector*512))
   return (0);

  if (!ReadFile(
       dh,                          // handle of file to read
       buf,                         // pointer to buffer that receives data
       512,                         // number of bytes to read
       &amp;res,                        // pointer to number of bytes read
       NULL                         // pointer to structure for data
  ))
      return (0);

  if (res!=512) return (0);

  return (1);
}


unsigned char read_block_sd (unsigned char *buf, unsigned long sector,
unsigned long size)
{
  DWORD res;

  res = SetFilePointer(
  dh,          // handle of file
  sector*512,  // number of bytes to move file pointer
  NULL,        // pointer to high-order DWORD of distance to move
  FILE_BEGIN   // how to move
  );

  if ((res==0xFFFFFFFF)||(res!=sector*512))
   return (0);

  if (!ReadFile(
       dh,                          // handle of file to read
       buf,                         // pointer to buffer that receives data
       (size+1)*512,                        // number of bytes to read
       &amp;res,                        // pointer to number of bytes read
       NULL                         // pointer to structure for data
  ))
      return (0);

  if (res!=(size+1)*512) return (0);

  return (1);
}


unsigned char write_sd (unsigned char *buf, unsigned long sector, unsigned
long size) {
  DWORD res;

  res = SetFilePointer(
  dh,          // handle of file
  sector*512,  // number of bytes to move file pointer
  NULL,        // pointer to high-order DWORD of distance to move
  FILE_BEGIN   // how to move
  );

  if ((res==0xFFFFFFFF)||(res!=sector*512))
   return (0);

  if (!WriteFile(
       dh,                          // handle of file to write
       buf,                         // pointer to buffer that receives data
       size*512,                    // number of bytes to write
       &amp;res,                        // pointer to number of bytes writed
       NULL                         // pointer to structure for data
  ))
      return (0);

  if (res!=size*512) return (0);

  return (1);
}


bool get_drive_size (unsigned long *ds) {
  DISK_GEOMETRY dg;
  DWORD br;

  if (!DeviceIoControl(
  dh,                            // handle to device of interest
  IOCTL_DISK_GET_DRIVE_GEOMETRY, // dwIoControlCode, control code of
operation to perform
  NULL,                          // lpInBuffer is not used; must be NULL
  0,                             // nInBufferSize is not used; must be zero
  &amp;dg,                           // pointer to output buffer
  sizeof(dg),                    // size, in bytes, of lpOutBuffer
  &amp;br,                           // pointer to variable to receive output
byte count
  NULL                           // pointer to OVERLAPPED structure for
asynchronous operation
  )) return (false);

  if (dg.BytesPerSector!=512) return (false);


*ds=/*(dg.BytesPerSector)**/(dg.SectorsPerTrack)*(dg.TracksPerCylinder)*(dg.
Cylinders.LowPart);
  *ds=*ds-1;


  return (true);
}

char drivet[]="\\\\.\\PHYSICALDRIVEX";
char selected_drive;

bool open_disc (unsigned char fmode) {
 DWORD dw, le;

 drivet[17]=selected_drive+'0';
 if (fmode==0)
 {
     dh = CreateFile(
      drivet,                            // pointer to name of the file
      GENERIC_READ,                      // access mode
      FILE_SHARE_READ|FILE_SHARE_WRITE,  // share mode
      NULL,                              // pointer to security attributes
      OPEN_EXISTING,                     // how to create
      0,                                 // file attributes
      NULL                               // handle to file with attributes
to copy
     );
 }
 else
 {
     dh = CreateFile(
      drivet,                            // pointer to name of the file
      GENERIC_READ|GENERIC_WRITE,        // access mode
      FILE_SHARE_READ|FILE_SHARE_WRITE,  // share mode
      NULL,                              // pointer to security attributes
      OPEN_EXISTING,                     // how to create
      0,                                 // file attributes
      NULL                               // handle to file with attributes
to copy
     );
 }

 if (dh==INVALID_HANDLE_VALUE) {
  le=GetLastError ();
  return (false);
 }

 dw = GetFileType (dh);
 if (dw!=FILE_TYPE_DISK) {
  CloseHandle (dh);
  return (false);
    }


    if (!get_drive_size (&amp;sd_tot_size)) {
  CloseHandle (dh);
  return (false);
    }

 return (true);
}

</pre>
<blockquote type="cite">
  <pre wrap=""><span class="moz-txt-citetags">&gt;</span>Jestli by to nevadilo, tak bych byl za kousek kodu rad <span
 class="moz-smiley-s1"><span> :) </span></span>.
<span class="moz-txt-citetags">&gt;</span>Tou vetou jsem chtel rict ze casto se CreateFile pouziva pro pristup na
<span class="moz-txt-citetags">&gt;</span>disk, ale ne primo RAW, ale souborovy zapis v ramci filesystemu.
  </pre>
</blockquote>
<pre wrap=""><!---->
</pre>
<blockquote type="cite">
  <pre wrap=""><span class="moz-txt-citetags">&gt;</span>Zatim me nenapada co pouzit jako "pointer to name of the file" (/*???*/)
<span class="moz-txt-citetags">&gt;</span>, je to hned prvni parametr funkce createfile. Mluvim o pripadu kdy chci
<span class="moz-txt-citetags">&gt;</span>pristup na USB ctecku karet. Abych treba omylem nehrabnul na pevny disk
<span class="moz-txt-citetags">&gt;</span>a pak by byl problem na svete.
  </pre>
</blockquote>
<pre wrap=""><!---->
</pre>
<blockquote type="cite">
  <pre wrap=""><span class="moz-txt-citetags">&gt;</span>hDevice = CreateFile( /*???*/ , GENERIC_READ | GENERIC_WRITE,
<span class="moz-txt-citetags">&gt;</span>FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0,
<span class="moz-txt-citetags">&gt;</span>NULL);
  </pre>
</blockquote>
<pre wrap=""><!---->
</pre>
<blockquote type="cite">
  <pre wrap=""><span class="moz-txt-citetags">&gt;</span>Kdyz jsme u toho, podobny pristup by sel pouzit i na seriovy a LPT port?
  </pre>
</blockquote>
<pre wrap=""><!---->
<a class="moz-txt-link-freetext"
 href="http://forum.builder.cz/read.php?123,1555971,1557011#msg-1557011">http://forum.builder.cz/read.php?123,1555971,1557011#msg-1557011</a>
<a class="moz-txt-link-freetext"
 href="http://forum.builder.cz/read.php?23,1472592,1477895#msg-1477895">http://forum.builder.cz/read.php?23,1472592,1477895#msg-1477895</a>
<a class="moz-txt-link-freetext"
 href="http://forum.builder.cz/read.php?23,1447448,1448208#msg-1448208">http://forum.builder.cz/read.php?23,1447448,1448208#msg-1448208</a>

J.Ber

</pre>
<blockquote type="cite">
  <pre wrap=""><span class="moz-txt-citetags">&gt;</span>DeviceIOControl je spis na nastavovani nejakych specifickych vlastnosti.
<span class="moz-txt-citetags">&gt;</span>Ano pomoci funkci (CreateFile, ReadFile, WriteFile, CloseHandle)
<span class="moz-txt-citetags">&gt;</span>zapise/prectete
<span class="moz-txt-citetags">&gt;</span>raw data do/z jakehokoliv sektroru.
  </pre>
</blockquote>
<pre wrap=""><!---->
</pre>
<blockquote type="cite">
  <pre wrap=""><span class="moz-txt-citetags">&gt;</span>Nevim co si predstavit pod touto vetou ?:
<span class="moz-txt-citetags">&gt;</span>"mel jsem za to ze v pripade disku se pouziva session pres FAT nebo NTFS"
  </pre>
</blockquote>
<pre wrap=""><!---->
</pre>
<blockquote type="cite">
  <pre wrap=""><span class="moz-txt-citetags">&gt;</span>Kdyz to bude nutny, tak muzu poslat i kus
<span class="moz-txt-citetags">&gt;</span>kodu na ukazku, ale fakt to neni veda.
  </pre>
</blockquote>
<pre wrap=""><!---->
</pre>
<blockquote type="cite">
  <pre wrap=""><span class="moz-txt-citetags">&gt;</span>J.Ber
  </pre>
</blockquote>
<pre wrap=""><!---->

_______________________________________________
HW-list mailing list  -  sponsored by <a
 class="moz-txt-link-abbreviated" href="http://www.HW.cz">www.HW.cz</a>
<a class="moz-txt-link-abbreviated" href="mailto:Hw-list@list.hw.cz">Hw-list@list.hw.cz</a>
<a class="moz-txt-link-freetext"
 href="http://list.hw.cz/mailman/listinfo/hw-list">http://list.hw.cz/mailman/listinfo/hw-list</a>



</pre>
</div>
</body>
</html>