Example #1
0
/*
 * Finds and mounts an existing Rocks Partition, if one exists.
 * Returns 0 on success, 1 otherwise. Mounts to a well-known dir.
 */
static int
getRocksPartition()
{
	int	rc=1;
	int	major, minor, blocks;
	char	dev[32];
	char	*diskdevice;
	char	*line;
	char	*contents;

	contents = getPartitions();

	diskdevice = NULL;

	/*
	 * eat the first two lines
	 *
	 * there is a two line header on the output of
	 * /proc/partitions -- toss those lines, then do
	 * the work
	 */
	line = contents;
	line = strstr(line, "\n") + 1;

	while (1) {
		line = strstr(line, "\n");
		if (!line)
			break;
		line += 1;
		if (!strlen(line))
			continue;

		sscanf(line, "%d %d %d %32s", &major, &minor, &blocks, dev);

		if (!diskdevice || 
			strncmp(dev, diskdevice, strlen(diskdevice))) {
			/* A disk device name, like hda */
			diskdevice = dev;
			logMessage(INFO, "ROCKS:found disk device %s", dev);
			rc = bootable(diskdevice, major, minor);
			if (!rc) {
				/* Restart the parse */
				free(contents);
				return getRocksPartition();
			}
		}

		else if (!strncmp(dev, diskdevice, strlen(diskdevice))) {
			/* A disk partition name, like hda1 */
			logMessage(INFO, "ROCKS:found partition %s", dev);
			rc = mountRocksDisk(dev, major, minor);
			if (!rc)
				break;		/* Success */
		}
	}
	free(contents);
	return rc;
}
Example #2
0
File: rarpd.c Project: OPSF/uClinux
struct rarp_map *rarp_lookup(int ifindex, int hatype,
			     int halen, unsigned char *lladdr)
{
	struct rarp_map *r;

	for (r=rarp_db; r; r=r->next) {
		if (r->arp_type != hatype && r->arp_type != -1)
			continue;
		if (r->lladdr_len != halen)
			continue;
		if (r->ifindex != ifindex && r->ifindex != 0)
			continue;
		if (memcmp(r->lladdr, lladdr, halen) == 0)
			break;
	}

	if (r == NULL) {
		if (hatype == ARPHRD_ETHER && halen == 6) {
			struct ifaddr *ifa;
			struct hostent *hp;
			char ename[256];
			static struct rarp_map emap = {
				NULL,
				0,
				ARPHRD_ETHER,
				6,
			};

			if (ether_ntohost(ename, lladdr) != 0 ||
			    (hp = gethostbyname(ename)) == NULL) {
				if (verbose)
					syslog(LOG_INFO, "not found in /etc/ethers");
				return NULL;
			}
			if (hp->h_addrtype != AF_INET) {
				syslog(LOG_ERR, "no IP address");
				return NULL;
			}
			ifa = select_ipaddr(ifindex, &emap.ipaddr, (__u32 **)hp->h_addr_list);
			if (ifa) {
				memcpy(emap.lladdr, lladdr, 6);
				if (only_ethers || bootable(emap.ipaddr))
					return &emap;
				if (verbose)
					syslog(LOG_INFO, "not bootable");
			}
		}
	}
	return r;
}