I Want To Make A Utility Like The Old DOS Command "rdisk" In C++.
The Things I Want It To Be Able To Do Are:
WIN: Be Able To Specify The Drive Letter (Like rdisk's /:Z)
UNIX: Be Able To Specify The Mount Point (/mnt/rdisk or /media/somthing, etc)
BOTH: Make A RamDisk Of A Specified Size (Default To Be 50 MB)
WIN: Make It The FAT16 Filesystem (And Check To See If ITs Too Big For That, If It Is Make It FAT32)
UNIX: Make It The Extended 2 Filesystm (Again If Too Big [dought it] Ext3)
BOTH: I Can Do This One, Put A File Called "WARNING(.txt)" In The RamDisk Saying That On Shutdown All RamDIsk Files Will Be Dleted.
BOTH:Have Most The Code Be Actual C++/C/Obj-C++ (Can Do!) And Only Rely On system() for mounting (I Even Want To DO THe Formating Of FAT/Ext2 From Within My Program If Possibel
Things I Know How To Do:
Load A Binary File Into A Vector
PLain File IO
.c_str()
All The Basic (if,do,logicl gates,cout,etc)
THings I Don't:
String Formating
REserve A Large Space In RAM
Most Pointer Related Things (Know How To Sort Of Use Heap)

Like I Said I Don't Want To Lean On system() Or External Libs Too Much.
I Want To Work From The Core (Making A Rdisk And Putting A filesystem On It, even if using system) And Then Work Up.
I Also Want It Explained.
Windows 7 (64-Bit), Windows XP (32-Bit), Ubuntu 11.10 (64-Bit), If Possible, MINIX 3. All Using GCC/MinGW
Sorry About The Strange Capitlazation (THe) My Shift Key Hates Me And For Sounding Demanding, Just Want To get To The Point...
Thanks In Advance.

In order to get things working, you're probably going to have to find a way to hook in to the kernel on all operating systems in order for it to believe you have an actual ramdisk device. (In UNIX stle systems, you may be able to just connect to a /dev/ device, and read the inputs/outputs from there, to make it look like there is an actual disk).

To get started, I'd bulid some kind of core layer, and use a malloc call to allocate enough ram for your ramdisk, but rather than formatting it, assuming your driver/program is going to be running the whole time that can handle memory and such.

From there, you're going to have to look in to the OS dependant ways of creating device drivers that can register themselves and create the fake device you want, from where the OS will be able to deal with it as a standard device, like a thumbdrive, mounting it where you want it to be.

Umm...
Like I Said: rdisk, set it up in a way where my program does not have to run.
Second: Never Mind About The Formating, Now Fine With system For That.
Third: Where's malloc? I think it was In curses.h but...
Let's Start With Unix/Linux.

The problem with that is your program will have to run if you want to manage the ramdisk yourself, otherwise you're just creating a wrapper over the functions in the OS Kernel that would do it normally for itself, that is the easier way to approach this problem, don't worry about the memory yourself, but rather use the underlying OS to do it.

malloc s a c call, (available in c++ thorugh stdlib.h) that grabs a whole chunk of memory, however note that as you're doing this in user mode rather than as a part of the kernel if you grab too much, it may be cached to disk unless you take special precautions, eliminating the whole point of making a ramdisk. But if you just write a program to wrap around Linux's normal ramdisk function (look for information on /dev/shm) then it will work as expected.

Here is a tutorial for what you will need to write a driver for the linux kernel for a block device (assuming you want to implement your own ramdisk).

If you'd rather just build a wrapper of sorts, you can look in to the way it is done using these functions (the kernel calls) and implement it yourself that way:

mkdir -p /tmp/ram
sudo mount -t tmpfs -o size=512M tmpfs /tmp/ram/

Sure I Could Just Write IT To Go Around The Linux Function.
I Dont Want To Do The "mke2fs /dev/ram 8126" Thing.
Could You Explain How To Do That? And Does THat Example Stay IN Ram? I Don't Want The RAMdisk to Get Sent To Swap.

If you're going to write around OS functions, I'd check the source out here: ftp://ftp.kernel.org/pub/linux/utils/util-linux/

You could also try reading the system man pages.
mount(2), umount(2), fstab(5), umount(8), swapon(8), nfs(5), xfs(5), e2label(8), xfs_admin(8), mountd(8), nfsd(8), mke2fs(8), tune2fs(8), losetup(8)

Now I'll do both for unix, in different implementations.
Now about Win7 (I'm admin, wont run into those problems).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.