[linux-minidisc] Building himdformat against libscg on MacOSX
Hi,
after several nervous breakdowns, I finally managed to build
himdformat on MacOS against libscg as included in cdrtools.
Eventually, it only took a few hacks to get it compile. I didn't test
the functionality yet (due to lack of hardware right now). So, here's
what I did:
1) Install cdrtools from Macports:
port install cdrtools
2) Apply the supplied patch "0001-cdrtools-darwin-xconfig.patch" to
/opt/local/include/schily/xconfig.h.
3) Create a symbolic link to CoreFoundation dynamic linker library in
the current directory (see [1]):
ln -s /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation libcorefoundation.dylib
4) Compile himdformat.c with:
gcc -D__DARWIN_X86_CC32 -I/opt/local/include -L/opt/local/lib -L. -lcorefoundation -lIOKit -lschily -lscg -o himdformat_scg himdformat_scg.c
5) himdformat runs on MacOS:
minimac2:~ zedv$ ./himdformat_scg
Please specify the path to the scsi device
minimac2:~ zedv$
I'm attaching the libscg version of himdformat as well as the
necessary patch.
Adrian
[1] http://sites.google.com/site/pengjungwu/install-ns2-31-on-osx
--- /opt/local/include/schily/xconfig.h~ 2010-05-06 14:05:09.000000000 +0200
+++ /opt/local/include/schily/xconfig.h 2010-05-07 21:07:49.000000000 +0200
@@ -129,6 +129,11 @@
#define __JS_ARCH_CONF_INCL
#endif
+#ifdef __DARWIN_X86_GCC32
+#include <schily/i386-darwin-cc/xconfig.h>
+#define __JS_ARCH_CONF_INCL
+#endif
+
#ifndef __JS_ARCH_CONF_INCL
#error unconfigured architecture
#endif
/*
* himdformat command using libscg
* use devicename on linux (/dev/sgX) or driveletter on windows (without ":")
*/
#include <stdio.h>
#include <string.h>
#include <schily/schily.h>
#include <scg/scgcmd.h>
#include <scg/scsitransp.h>
#define SONY_SPECIFIC_COMMAND 0xC2
#define HIMD_FORMAT 3
#define MAX_DEVICE_LEN 256
#define SCSI_TIMEOUT 20
int main(int argc, char ** argv)
{
SCSI * scgp = NULL;
char command[12];
int err = 0;
int ret;
char dev[MAX_DEVICE_LEN];
char errstr[80];
char cmdname[] = "himd_format";
struct scg_cmd * scmd;
if(argc < 2)
{
fputs("Please specify the path to the scsi device\n",stderr);
return -1;
}
memset(dev, 0, MAX_DEVICE_LEN);
memcpy(dev, argv[1], sizeof(argv[1]));
// open scsi driver
scgp = scg_open(dev, errstr, sizeof(errstr), 0, NULL);
if(!scgp)
{
fputs("Cannot open scsi driver", stderr);
return -2;
}
if(scgp->addr.scsibus == -2 && scgp->addr.target == -2) // scsi device not found, search by devicename
{ // this is nessessary on windows when driveletter is used
ret = scg__open(scgp, dev);
if(!ret)
{
fprintf(stderr, "Cannot open SCSI device for %d\n", dev);
err = -3;
goto clean;
}
}
scg_settimeout(scgp, SCSI_TIMEOUT);
scgp->cmdname = cmdname;
// preparing scsi command
scmd = scgp->scmd;
memset(scmd, 0, sizeof(struct scg_cmd));
scmd->addr = (caddr_t)0;
scmd->size = 0;
scmd->cdb_len = sizeof(command);
scmd->sense_len = CCS_SENSE_LEN;
scmd->flags = SCG_DISRE_ENA;
memset(command, 0, 12);
command[0] = SONY_SPECIFIC_COMMAND;
command[4] = HIMD_FORMAT;
memcpy(scmd->cdb.cmd_cdb, command, 12);
// sending command
if(scg_cmd(scgp) < 0)
{
fputs("cannot send scsi command", stderr);
err = -4;
goto clean;
}
else
fprintf(stderr, "scsi command successfully sent");
clean:
scg__close(scgp);
return err;
}