473,382 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

sector writing on MMC ?

How can i write on specifyed sector on a multimedia card?
I must go round file system and write/read direct.
C# VS2003

Thanks
Kruno
Apr 18 '06 #1
12 9128
Hi,

You cannot do this using .net , that's for sure. you will have to p/invoke .
Even so I don't remember any win32 function that let you especify the sector
you want to write into.

How is your assembly? :)
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Krunoslav Ostrouska" <kr*****************@tele-haase.at> wrote in message
news:ex**************@TK2MSFTNGP05.phx.gbl...
How can i write on specifyed sector on a multimedia card?
I must go round file system and write/read direct.
C# VS2003

Thanks
Kruno

Apr 18 '06 #2

"Krunoslav Ostrouska" <kr*****************@tele-haase.at> wrote in message
news:ex**************@TK2MSFTNGP05.phx.gbl...
| How can i write on specifyed sector on a multimedia card?
| I must go round file system and write/read direct.
| C# VS2003
|
| Thanks
| Kruno
|
|
You don't have to go round the FS, you just have to open the physical device
using Win32's API
CreateFile through PInvoke. When successful CreateFile returns a file handle
which you can use to read/write to the device at the physical level using
the FileStream class.

A physical device looks like \\.\PhysicalDrive<n> (hard disks start with n =
0), you can also refer to a physical device by using it's mountpoint
"\\.\C:" or volume ID \\?\Volume{guid}\

Willy.

Apr 18 '06 #3
Willy Denoyette [MVP] wrote:

Hi Willy,
A physical device looks like \\.\PhysicalDrive<n> (hard disks start with n =
0), you can also refer to a physical device by using it's mountpoint
"\\.\C:" or volume ID \\?\Volume{guid}\


That looks interesting. What could I google for to learn more about
these paths? Do you know how they call such path identifiers? I couldn't
find much so far.

thanks,
Max
Apr 18 '06 #4

"Markus Stoeger" <sp******@gmx.at> wrote in message
news:Od**************@TK2MSFTNGP05.phx.gbl...
| Willy Denoyette [MVP] wrote:
|
| Hi Willy,
|
| > A physical device looks like \\.\PhysicalDrive<n> (hard disks start with
n =
| > 0), you can also refer to a physical device by using it's mountpoint
| > "\\.\C:" or volume ID \\?\Volume{guid}\
|
| That looks interesting. What could I google for to learn more about
| these paths? Do you know how they call such path identifiers? I couldn't
| find much so far.
|
| thanks,
| Max

The Platform SDK and the DDK documentation in MSDN contains all you need to
know about device paths volume names and mount points.
Start by looking into the 'CreateFile' API docs.
Volume id's can be shown by running the 'mountvol' command.
Disk drive and MMAC CD card devices are identified just like an HD.
Physical paths (Device ID) can be queries by System.Management and WMI
(Win32_PhysicalMedia and Win32_DiskDrice classes).

Willy.
Apr 18 '06 #5
Hello, Krunoslav!

KO> How can i write on specifyed sector on a multimedia card?
KO> I must go round file system and write/read direct.
KO> C# VS2003

You won't be able to do this directly from C#. However, P/Invoke to DeviceIoControl win32 function should help.
You can utize defragmentation API to write data to specific locations. Not sure if this approach will work for removable sotrage, but you can try.

Here is some info
( http://msdn.microsoft.com/library/de...ting_files.asp )
( http://msdn.microsoft.com/library/de...e_data_str.asp )

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Apr 19 '06 #6

"Vadym Stetsyak" <va*****@ukr.net> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
| Hello, Krunoslav!
|
| KO> How can i write on specifyed sector on a multimedia card?
| KO> I must go round file system and write/read direct.
| KO> C# VS2003
|
| You won't be able to do this directly from C#. However, P/Invoke to
DeviceIoControl win32 function should help.
Sure you can, see my previous reply. Before user mode applications can
operate at the device level you need an handle to the device , the caller
must get a handle by calling CreateFile using the physical path name or
volume name that identifies the device. This is the same wheter the device
is a HD or an SD card (SFF (Small Form Factor) storage devices) or any other
device in Windows.
A call to DeviceIoControl is only needed if you want to access specific SFF
functionality like locking/unlocking and password protect a SD card.


| You can utize defragmentation API to write data to specific locations. Not
sure if this approach will work for removable sotrage, but you can try.

What makes you think that using defragmentation API's would help?

Willy.
Apr 19 '06 #7
Hello, Willy!

WDM> What makes you think that using defragmentation API's would help?

Defrag API is not complete solution, however it can be used to achieve the goals that OP stated above:
he want to write data to specific sector, that is write directly. AFAIK to accomplish this ( direct write ) he has to write device driver.

Defrag API gives the ablity to put file to the specified place on the disk via DeviceIoControl(...FSCTL_MOVE_FILE...) flag.

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Apr 19 '06 #8
How can i write on specifyed sector on a multimedia card?
I must go round file system and write/read direct.
C# VS2003

Thanks all for the information.
I will try this.
I didn't expext to make it with framework. It would be great if it works.
I must do this sector writing for a microcontroller device that dosen't use
fat16.
Kruno
Apr 19 '06 #9
"Willy Denoyette [MVP]" <wi*************@telenet.be> schrieb im Newsbeitrag
news:u8**************@TK2MSFTNGP04.phx.gbl...
You don't have to go round the FS, you just have to open the physical device using Win32's API
CreateFile through PInvoke. When successful CreateFile returns a file handle which you can use to read/write to the device at the physical level using
the FileStream class.

A physical device looks like \\.\PhysicalDrive<n> (hard disks start with n = 0), you can also refer to a physical device by using it's mountpoint
"\\.\C:" or volume ID \\?\Volume{guid}\

Willy.


I must write FAT sectors to!
The device that use the MMC can't use FAT.
I think, i must go round the FS to do this.
Thanks
Apr 19 '06 #10
Vadym, Sorry but you got it wrong.
You don't have to write a device driver, there is one installed when you
have a SD (or MM device) installed, it comes with the OS, nor do you have to
call DeviceIoControl to read write or position the file pointer to a device.
As I said before, all you have to do is get a handle to the device by
calling CreateFile using PInvoke. The handle returned can then be used by
the framework FileStream class to read, write and seek the device, jst like
any other device in the system.
Herewith a sample that reads sector 0 of the first HD in the system.
Note that here I assume a sector length of 512 bytes, some devices may have
other sector sizes, so check the drive geometry before doing stupid things.
using System;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
using System.Security;
using System.Text;

[SuppressUnmanagedCodeSecurity]
class Tester
{
const int FILE_FLAG_NO_BUFFERING = unchecked((int)0x20000000);
const int FILE_FLAG_SEQUENTIAL_SCAN = unchecked((int)0x08000000);

[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Unicode)]
static extern SafeFileHandle CreateFile(String fileName,
int
desiredAccess,
System.IO.FileShare
shareMode,
IntPtr
securityAttrs,
System.IO.FileMode
creationDisposition,
int
flagsAndAttributes,
IntPtr
templateFile);
static void Main()
{
FileStream fs;
SafeFileHandle handle;
int blockSize = 512;
int flags = FILE_FLAG_NO_BUFFERING | FILE_FLAG_SEQUENTIAL_SCAN ;
/* Call the Windows CreateFile() API to open the file */
handle = CreateFile( "\\\\.\\PHYSICALDRIVE0",
(int)FileAccess.Read,
FileShare.None,
IntPtr.Zero,
FileMode.Open,
flags,
IntPtr.Zero);

if (!handle.IsInvalid)
{
fs = new FileStream(handle, FileAccess.Read, blockSize, false);
byte[] b = new byte[blockSize];
UTF8Encoding temp = new UTF8Encoding(true);
fs.Seek(0, SeekOrigin.Begin);
fs.Read(b,0,b.Length);
Console.WriteLine(temp.GetString(b));
}
else
Console.WriteLine("Failed to open device");
}
}
Willy.
"Vadym Stetsyak" <va*****@ukr.net> wrote in message
news:OL**************@TK2MSFTNGP05.phx.gbl...
| Hello, Willy!
|
| WDM> What makes you think that using defragmentation API's would help?
|
| Defrag API is not complete solution, however it can be used to achieve the
goals that OP stated above:
| he want to write data to specific sector, that is write directly. AFAIK
to accomplish this ( direct write ) he has to write device driver.
|
| Defrag API gives the ablity to put file to the specified place on the disk
via DeviceIoControl(...FSCTL_MOVE_FILE...) flag.
|
| --
| Regards, Vadym Stetsyak
| www: http://vadmyst.blogspot.com
Apr 19 '06 #11
Hello, Willy!

Aahh, yes, I completely forgot about this kind of names ( \\\\.\\PHYSICALDRIVE0 ) or AFAIR symbolic names.
My fault...

WDM> FileStream fs;
WDM> SafeFileHandle handle;
WDM> int blockSize = 512;
WDM> int flags = FILE_FLAG_NO_BUFFERING | FILE_FLAG_SEQUENTIAL_SCAN ;
WDM> /* Call the Windows CreateFile() API to open the file */
WDM> handle = CreateFile( "\\\\.\\PHYSICALDRIVE0",
WDM> (int)FileAccess.Read,
WDM> FileShare.None,
WDM> IntPtr.Zero,
WDM> FileMode.Open,
WDM> flags,
WDM> IntPtr.Zero);
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Apr 20 '06 #12

"Krunoslav Ostrouska" <kr*****************@tele-haase.at> schrieb im
Newsbeitrag news:Oe**************@TK2MSFTNGP05.phx.gbl...
How can i write on specifyed sector on a multimedia card?
I must go round file system and write/read direct.
C# VS2003

Thanks all for the information.
I will try this.
I didn't expext to make it with framework. It would be great if it works.
I must do this sector writing for a microcontroller device that dosen't

use fat16.
Kruno


I get it. CreateFile() was the solution(thanks Willy).
I work with framework 1.1, so i coudn't use Microsoft.Win32.SafeHandles
namespace. Also FileStream opening raises "Function not allowed" exception.
But, i read and write with Read/WriteFile APIs and it works fine.
Thanks all!
Kruno
Apr 20 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: dfg | last post by:
Can I write a boot sector using VB? Is there some built in library, or is it possible to make my own? Can I embed Assembly language? Getting ready to work with Visual Basic for the first...
18
by: shakeel-ur-rehman | last post by:
I am wrtiting programm in C++ to read/take complete image of the partiton. can any one let me know the internet resources and web sites having tutorials relating to this and tell any sequence ...
7
by: Claudio Grondi | last post by:
Googling for keywords like "direct access sector harddrive Python module Windows" seems to give no useful results. Any hints(best if cross-platform)? Claudio
5
by: Sumana | last post by:
Hi All, We developed our project on VC++.Net console application to create image of disk and to write the image We are having problem with reading and writing the sector beyond 6GB Disk or...
3
by: Scott Bell | last post by:
Hello all, What is the equivalent in the .NET Framework for accessing a device at the block/sector level such as one would when using CreateFile on a device like "\\.\D:"? Attempting to create...
1
by: temir_gal | last post by:
Good evening! I can't read the sector's from floppy in Win98 OS. My application is 32-capacity and that's why I can't use interrupts. At the same time HANDLE hFile1 = CreateFile( "\\\\.\\A:",...
5
by: Jordi Maycas | last post by:
Could I do something like this with .net 2005? PROGRAM WriteBootSector; VAR DiskSectorsPerTrack, DiskTracksPerHead, DiskHeads : WORD; FUNCTION WriteSector(Sector : WORD; Buffer : POINTER) :...
3
by: aditigupta | last post by:
hi actually i m using absread to read a particular sector but when i write it i m getting some special characters instead of actual data....... i m writing the data by this command for...
1
by: CurtisW | last post by:
I have a bad sector on my NTFS HD. I know the sector number range from Spinrite. How do I find out the filename or directory it is storing? This is a cd storage drive with no OS. I can copy...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.