Anti-nuisance lawsuit warning: The purpose of these notes is to remind me, Zoegond, of stuff or to help me work stuff out. They may contain mistakes.

Quick

  • ($a, $b....) = unpack("A2A7...", $packed)
  • push( array, list )

Wednesday, June 29, 2011

STL vectors and iterators

vector::end() (like end() for containers generally) returns an iterator, not an element, and it refers to the end+1 position, not the last element position.

Tuesday, June 28, 2011

C++ since 1996

Ongoing notes about how C++ has changed since I last used it.

Namespaces


'using' for namespaces, can specify a whole namespace or just one name from it. Don't have to use using, can use explicit scope prefixes eg

std::string s;

(NB with mingw 'using std' will cause loads of errors with eg '#include vector'. The scope prefix way works fine though. May be some fix for this involving editing stl_user_config.h)

Executable size


If you do use any of the standard libraries, be prepared for a gigantic executable. 100K for declaring a 'string', 125K if you want to assign it too, 500K to print it out via iostream. In a way though this is a good thing as it's effectively offering you a higher level language - if you want a small executable you can still write C++, just not use any standard includes. stdio.h still works if you need it and the executable size is still only 20K for a minimal example.

(NB the huge executable thing is not there under Linux, the minimal executable is about 7K whichever way you do it).

(Further NB that even under Windows most of the hugeness is due to iostream. Using cstdio (ie stdio.h) instead cuts that 500K down to 130K.)


No finally


C++ has no finally in its exception handling. If you need to release a resource, make its pointer a public member of a local class (local classes are allowed, apparently) and have the class's destructor free the resource. Eg

class Allocs {
public: char *stem;
~Allocs() { delete stem; }
};
Allocs m;

Saturday, June 25, 2011

Dual boot Ubuntu and Windows 7 - how did I do it?

I've now got the dual-booting installation of Ubuntu 11.04 and Windows 7 that I wanted, but I'm buggered if I know how I managed it.

The steps I took were:

1. Made a Ubuntu live USB with unetbootin which I used to test hardware compatibility. The persistence feature on the USB didn't work, in fact it led to hangs every time I tried it, but Ubuntu itself worked fine.

2. Used Windows disc management to make two new partitions on the HD, a 40G one for Ubuntu and an 8G one for swap.

3. Made a Ubuntu installation USB with unetbootin and installed Ubuntu to the partition I'd made. I specifically didn't use the option to alter the boot setup at all because my experience with Windows XP and Linux was that doing this buggers up the Windows boot mechanism and it has to be fixed using a Windows tool.

4. Made a Super Grub Disc USB using unetbootin and tried to boot the HD Ubuntu with it. This didn't work, because as I found out later, Ubuntu uses Grub2 not 'Legacy' Grub.

5. Tried to make a Super Grub2 Disc USB with unetbootin. Although I got a boot menu off this it wouldn't work at all. As I found out later, unetbootin can't make SG2 USBs.

6. Made an SG2 USB with Windows dd. This worked perfectly, detecting Ubuntu and Windows 7. Booted into Ubuntu from it, all good.

7. Restarted the notebook intending to boot Windows and use bcdedit to put Ubuntu onto the Windows boot menu. But I got a Ubuntu-branded Grub2 menu - presumably Ubuntu had put that there when I installed it on the HD. (I'm sure I ran Windows at least once after that installation, though, and I didn't get the menu then).

8. Booted Ubuntu from this menu, worked fine. Restarted and booted Windows from this menu, worked fine. Have run both several times since with no problems.

So I'm pleased, but perplexed.

Wednesday, June 22, 2011

Windows dd for Super Grub2 Disk live usb

I wanted to create a live usb for Super Grub2 Disc, and unetbootin currently won't do that properly.

So I got hold of Windows dd and used that.

First did

dd --list

to find which device name the USB stick had (in this case \\?\Device\Harddisk1\Partition0). Then

dd --filter=removable --progress --size bs=32k if=c:\super_grub_disk_hybrid-1.98s1.iso of=\\?\Device\Harddisk1\Partition0

to write the image to the stick. It booted fine and I was able to locate and boot the Ubuntu installation I'd lost on my HD.

(I used bs=32k because the iso is very small - 1.4M - and I wanted to see some evidence that it was being written. You'd use bs=1M or larger to write a full-size CD iso.)


(Updated to say: --filter-removable is a safety precaution. It restricts writing only to discs which dd believes to be removeable. Sometimes dd --list will report a disc as removeable, but dd --filter-removable will refuse to write to it, thinking it isn't removeable. In such cases, try omitting the --filter-removable switch, but of course you should make sure you do actually have the right output target.)

Linux

Linux dd may not have any of the -- or - options - try eg
sudo dd status=progress bs=1M if=/U/com/packages/lubunto18.04.iso of=/dev/sdd
noting particularly that you specify a drive (/dev/sdd) here, not a partition (/dev/sdd1).)

I read that sync is no use afterwards, the equivalent is eg
blockdev --flushbufs /dev/sdd

Thursday, June 16, 2011

Ubuntu persistence

Persistence on live USB keeps going wrong and leading to stalled boots - boot can always be achieved by removing 'persistent' from boot params.

Can use a second live USB with Puppy Linux to read the first USB and check the casper-rw file (can't do it from live Ubuntu as casper-rw is mounted). NB that in this case we're using a path to a file, not a device name, as the first argument to mount because the filesystem we're mounting is inside a file.

mkdir /mnt/cas
mount /mnt/sdb1/casper-rw /mnt/cas -o loop

(the /mnt/sdb1 bit may be different according to where Puppy has mounted the USB)

We can now ls /mnt/cas to see the files inside casper-rw. And we can also check the filesystem:

fsck -y /mnt/sdb1/casper-rw

(after a stalled boot this will find and fix lots of errors)

Boot with 'persistent' will now work again - though persistence still won't work!

SYSLINUX

SYSLINUX is a Linux boot loader, syslinux.exe is an install program which puts SYSLINUX onto a disc, making it bootable. (Bit like sys a: on DOS). LDLINUX.SYS is also created in root.

SYSLINUX expects a kernel file called LINUX in the disc's root directory. You can change the expected name but not the location.

SYSLINUX can read a syslinux.cfg file from root, /syslinux or /boot/syslinux on the disc. It tries all those locations.

The parameters after an APPEND in the .cfg file are linux kernel parameters.

When unetbootin creates a live USB, what it actually does is install SYSLINUX on the disc, and generate an appropriate .cfg file.

AutoIt3 run command

When running single commands as described under Running Scripts, don't use the double single quotes in the example. Use double double quotes.

"c:\program files\autoit3\autoit3.exe" /autoit3executeline "msgbox(0,""test"",""Testing"")"

Live USBs

Having once created a live USB, if you then write additional files onto it other than by using the application it boots, you may be overwriting parts of the drive that the application is using for persistence. So best not to.

The particular example is creating a Ubuntu live USB and then copying extra files onto the drive from Windows.

Wednesday, June 1, 2011

caspol makes .NET work

CasPol -m -ag 1.2 -url file://xxx2/xxxshare$/xx/src/cs/* FullTrust

NB caspol.exe must not be on a mapped drive, or you'll get "ERROR: Insufficient rights to obtain policy level"

Followers

Blog Archive