p_generic.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1999-2001 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* p_generic.c :
* This file contains the functions for pcmcia memory card plug-in
* for libsm.so.g
*/
#include <stdio.h>
#include <unistd.h>
#include <locale.h>
#include <string.h>
#include "../../../library/common/l_defines.h"
/*
* These defines are from the PCMCIA memory driver driver
* header files (pcramio.h/pcramvar.h) and they are in
* the Platform Specific (PS) train.
*/
#ifndef PCRAM_PROBESIZE
#endif
/* FORMAT PATTERNS */
#define PATTERN_1 0x55;
#define PATTERN_2 0xaa;
#define PATTERN_3 0xff;
#define PATTERN_4 0x00;
static void
my_perror(char *err_string)
{
int error_no;
if (errno == 0)
return;
perror("");
}
_m_version_no(void)
{
return (SM_PCMEM_VERSION_1);
}
{
if (ctype == DKC_PCMCIA_MEM) {
if (mtype == 0)
return (0);
}
return (-1);
}
{
DPRINTF("Null Handle\n");
return (-1);
}
"Signature expected=0x%x, found=0x%x\n",
return (-1);
}
PERROR("DKIOCSTATE failed");
return (-1);
}
if (state != DKIO_INSERTED) {
DPRINTF("No media.\n");
return (0);
}
/*
* Card doesn't have a CIS. So, ask driver to probe
* card size info
*/
int save_errno;
save_errno = errno;
size information"));
errno = save_errno;
if (!errno)
return (-1);
}
}
return (0);
}
/* ARGSUSED0 */
{
DPRINTF("Null Handle\n");
return (-1);
}
"Signature expected=0x%x, found=0x%x\n",
return (-1);
}
if (vendor_name == NULL) {
if (!errno)
return (-1);
}
if (product_name == NULL) {
if (!errno)
return (-1);
}
if (fw_version == NULL) {
if (!errno)
return (-1);
}
vendor_name[0] = 0;
product_name[0] = 0;
fw_version[0] = 0;
return (0);
}
{
/* Check for valid handle */
DPRINTF("Null Handle\n");
return (-1);
}
DPRINTF("Invalid signature in handle.\n");
return (-1);
}
return (0);
}
/* ARGSUSED1 */
{
int32_t i, j;
char wrpat;
char wrbuf[512];
char rdbuf[512];
/* Check for valid handle */
DPRINTF("Null Handle\n");
return (-1);
}
"Signature expected=0x%x, found=0x%x\n",
return (-1);
}
PERROR("DKIOCSTATE failed");
return (-1);
}
if (state != DKIO_INSERTED) {
gettext("No media.\n"));
return (-1);
}
/*
* Card doesn't have a CIS. So, ask driver to probe
* card size info
*/
PERROR("Unable to get card size information");
return (-1);
}
}
/* PCMCIA memory default sector size */
/*
* First try to format only 512 bytes with four different
* patterns.
*/
for (i = 0; i < 4; ++i) {
switch (i) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
}
if (!errno)
PERROR("seek to blk 0 failed");
return (-1);
}
if (!errno)
PERROR("Format Write failed");
return (-1);
}
if (!errno)
PERROR("seek to blk 0 failed");
return (-1);
}
if (!errno)
PERROR("Format Read failed");
return (-1);
}
gettext("Format Compare Error"));
return (-1);
}
}
/*
* Then format the whole memory card with patterns
* 0xff and 0x00 to erase the card.
*/
for (i = 0; i < 2; ++i) {
if (i == 0) {
} else {
}
if (!errno)
PERROR("seek to blk 0 failed");
return (-1);
}
for (j = 0; j < (card_size/512); ++j) {
if (!errno)
PERROR("Format Write failed");
return (-1);
}
}
/*
* do a verify
*/
if (!errno)
PERROR("seek to blk 0 failed");
return (-1);
}
for (j = 0; j < (card_size/512); ++j) {
if (!errno)
PERROR("Format Read failed");
return (-1);
}
gettext("Format Compare Error"));
return (-1);
}
}
}
return (0);
}
{
int32_t i, j;
char wrpat;
char wrbuf[512];
char rdbuf[512];
DPRINTF("Null Handle\n");
return (-1);
}
"Signature expected=0x%x, found=0x%x\n",
return (-1);
}
/*
* Using DKIOCSTATE ioctl()
* to replace FDGETCHANGE ioctl()
* start out with state=DKIO_NONE
*/
PERROR("DKIOCSTATE failed");
return (-1);
}
if (state != DKIO_INSERTED) {
gettext("No media\n"));
return (-1);
}
/*
* Card doesn't have a CIS. So, ask driver to probe
* card size info
*/
PERROR("Unable to get card size information");
return (-1);
}
}
/* PCMCIA memory default sector size */
/*
* If first track is being formatted, first try to format
* only 512 bytes with four different patterns.
*/
for (i = 0; i < 4; ++i) {
switch (i) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
}
if (!errno)
PERROR("seek to blk 0 failed");
return (-1);
}
if (!errno)
PERROR("Format Write failed");
return (-1);
}
if (!errno)
PERROR("seek to blk 0 failed");
return (-1);
}
if (!errno)
PERROR("Format Read failed");
return (-1);
}
gettext("Format Compare Error"));
return (-1);
}
}
}
/*
* Then format the whole memory card with patterns
* 0xff and 0x00 to erase the card.
*/
for (i = 0; i < 2; ++i) {
if (i == 0) {
} else {
}
if (!errno)
PERROR("seek to blk 0 failed");
return (-1);
}
j++) {
if (!errno)
PERROR("Format Write failed");
return (-1);
}
}
/*
* do a verify
*/
if (!errno)
PERROR("seek to blk 0 failed");
return (-1);
}
++j) {
if (!errno)
PERROR("Format Read failed");
return (-1);
}
gettext("Format Compare Error"));
return (-1);
}
}
}
return (0);
}