rem: int n_scsi_units = 0;
add: int n_scsi_units;
context: linux_scan (gboolean recorder_only){	char **device_str, **devices;	char **cdrom_info;	struct scsi_unit *scsi_units;	struct cdrom_unit *cdroms;	char *p, *t;	int n_cdroms, maj, min, i, j;	int n_scsi_units = 0;	int fd;	GList *cdroms_list;	gboolean have_devfs = FALSE;	/* devfs creates and populates the /dev/cdroms directory when its mounted	 * the 'old style names' are matched with devfs names below.	 * The cdroms.device string gets cleaned up again in cdrom_get_name()	 * we need the oldstyle name to get device->display_name for ide.	 */	if (g_file_test ("/dev/cdroms", G_FILE_TEST_IS_DIR)) {		have_devfs = TRUE;	}		cdrom_info = read_lines ("/proc/sys/dev/cdrom/info");	if (cdrom_info == NULL || cdrom_info[0] == NULL || cdrom_info[1] == NULL) {		g_warning ("Couldn't read /proc/sys/dev/cdrom/info");		return NULL;	}	if (!g_str_has_prefix (cdrom_info[2], "drive name:\t")) {		return NULL;	}	p = cdrom_info[2] + strlen ("drive name:\t");	while (*p == '\t') {		p++;	}	n_cdroms = count_strings (p);	cdroms = g_new0 (struct cdrom_unit, n_cdroms);	for (j = 0; j < n_cdroms; j++) {		t = strchr (p, '\t');		if (t != NULL) {			*t = 0;		}		cdroms[j].device = get_cd_device_file (p);		if (t != NULL) {			p = t + 1;		}	}	/* we only have to check the first char, since only ide or scsi 		 * devices are listed in /proc/sys/dev/cdrom/info. It will always	 * be 'h' or 's'	 */	for (i = 0; i < n_cdroms; i++) {		if (cdroms[i].device[0] == 's') {			n_scsi_units++;		}	}	if (n_scsi_units > 0) {		/* open /dev/sg0 to force loading of the sg module if not loaded yet */		fd = open ("/dev/sg0", O_RDONLY);		if (fd != -1) {			close (fd);		}				devices = read_lines ("/proc/scsi/sg/devices");		device_str = read_lines ("/proc/scsi/sg/device_strs");		if (device_str == NULL) {			g_warning ("Can't read /proc/scsi/sg/device_strs");			g_strfreev (devices);			return NULL;		}				scsi_units = g_new0 (struct scsi_unit, n_scsi_units);		get_scsi_units (device_str, devices, scsi_units);		g_strfreev (device_str);		g_strfreev (devices);	} else {		scsi_units = NULL;	}		for (i = 3; cdrom_info[i] != NULL; i++) {		if (g_str_has_prefix (cdrom_info[i], "Can write CD-R:")) {			p = cdrom_info[i] + strlen ("Can write CD-R:");			while (*p == '\t') {				p++;			}			for (j = 0; j < n_cdroms; j++) {				cdroms[j].can_write_cdr = *p++ == '1';				/* Skip tab */				p++;			}		}		if (g_str_has_prefix (cdrom_info[i], "Can write CD-RW:")) {			p = cdrom_info[i] + strlen ("Can write CD-RW:");			while (*p == '\t') {				p++;			}			for (j = 0; j < n_cdroms; j++) {				cdroms[j].can_write_cdrw = *p++ == '1';				/* Skip tab */				p++;			}		}		if (g_str_has_prefix (cdrom_info[i], "Can write DVD-R:")) {			p = cdrom_info[i] + strlen ("Can write DVD-R:");			while (*p == '\t') {				p++;			}			for (j = 0; j < n_cdroms; j++) {				cdroms[j].can_write_dvdr = *p++ == '1';				/* Skip tab */				p++;			}		}		if (g_str_has_prefix (cdrom_info[i], "Can write DVD-RAM:")) {			p = cdrom_info[i] + strlen ("Can write DVD-RAM:");			while (*p == '\t') {				p++;			}			for (j = 0; j < n_cdroms; j++) {				cdroms[j].can_write_dvdram = *p++ == '1';				/* Skip tab */				p++;			}		}		if (g_str_has_prefix (cdrom_info[i], "Can read DVD:")) {			p = cdrom_info[i] + strlen ("Can read DVD:");			while (*p == '\t') {				p++;			}			for (j = 0; j < n_cdroms; j++) {				cdroms[j].can_read_dvd = *p++ == '1';				/* Skip tab */				p++;			}		}		if (g_str_has_prefix (cdrom_info[i], "drive speed:")) {			p = cdrom_info[i] + strlen ("drive speed:");			while (*p == '\t') {				p++;			}			for (j = 0; j < n_cdroms; j++) {  				cdroms[j].speed = atoi (p);				/* Skip tab */				p++;			}		}	}	g_strfreev (cdrom_info);	/* get kernel major.minor version */	(FILE *) fd = fopen("/proc/sys/kernel/osrelease", "r");	if ((FILE *) fd == NULL || fscanf((FILE *) fd, "%d.%d", &maj, &min) != 2) {		g_warning("Could not get kernel version.");		maj = min = 0;	}	fclose((FILE *) fd);		cdroms_list = NULL;	for (i = n_cdroms - 1, j = 0; i >= 0; i--, j++) {		if ((cdroms[i].can_write_cdr ||		    cdroms[i].can_write_cdrw ||		    cdroms[i].can_write_dvdr ||		    cdroms[i].can_write_dvdram) &&			(cdroms[i].device[0] == 's' ||			(maj > 2) || (maj == 2 && min >= 5))) {			if (have_devfs) {				cdroms[i].device = g_strdup_printf("%s cdroms/cdrom%d",						cdroms[i].device,  j);			}			cdroms_list = add_linux_cd_recorder (cdroms_list,					&cdroms[i], scsi_units, n_scsi_units);		} else if (!recorder_only) {			if (have_devfs) {				cdroms[i].device = g_strdup_printf("%s cdroms/cdrom%d",						cdroms[i].device,  j);			}			cdroms_list = add_linux_cd_drive (cdroms_list,					&cdroms[i], scsi_units, n_scsi_units);		}	}	g_free (scsi_units);	g_free (cdroms);	return cdroms_list;}