FreeBSD/sys/kern/subr_devstat.c
/*
 * Take a malloced and zeroed devstat structure given to us, fill it in 
 * and add it to the queue of devices.  
 */
Take a malloced and zeroed devstat structure given to us, fill it in
and add it to the queue of devices.
Take a malloced and zeroed devstat structure given to us fill it in and add it to the queue of devices .
static void
devstat_add_entry(struct devstat *ds, const void *dev_name, 
		  int unit_number, uint32_t block_size,
		  devstat_support_flags flags,
		  devstat_type_flags device_type,
		  devstat_priority priority)
{
	struct devstatlist *devstat_head;
	struct devstat *ds_tmp;
	mtx_assert(&devstat_mutex, MA_OWNED);
	devstat_num_devs++;
	devstat_head = &device_statq;
	if (devstat_num_devs == 1)
		STAILQ_INSERT_TAIL(devstat_head, ds, dev_links);
	else {
		STAILQ_FOREACH(ds_tmp, devstat_head, dev_links) {
			struct devstat *ds_next;
			ds_next = STAILQ_NEXT(ds_tmp, dev_links);
			if ((priority <= ds_tmp->priority)
			 && ((ds_next == NULL)
			   || (priority > ds_next->priority))) {
				STAILQ_INSERT_AFTER(devstat_head, ds_tmp, ds,
						    dev_links);
				break;
			} else if (priority > ds_tmp->priority) {
				if (ds_tmp == STAILQ_FIRST(devstat_head)) {
					STAILQ_INSERT_HEAD(devstat_head,
							   ds, dev_links);
					break;
				} else {
					STAILQ_INSERT_TAIL(devstat_head,
							   ds, dev_links);
					printf("devstat_add_entry: HELP! "
					       "sorting problem detected "
					       "for name %p unit %d\n",
					       dev_name, unit_number);
					break;
				}
			}
		}
	}
	ds->device_number = devstat_current_devnumber++;
	ds->unit_number = unit_number;
	strlcpy(ds->device_name, dev_name, DEVSTAT_NAME_LEN);
	ds->block_size = block_size;
	ds->flags = flags;
	ds->device_type = device_type;
	ds->priority = priority;
	binuptime(&ds->creation_time);
	devstat_generation++;
}
static void devstat_add_entry ( struct devstat * ds , const void * dev_name , int unit_number , uint32_t block_size , devstat_support_flags flags , devstat_type_flags device_type , devstat_priority priority ) { struct devstatlist * devstat_head ; struct devstat * ds_tmp ; mtx_assert ( & devstat_mutex , MA_OWNED ) ; devstat_num_devs ++ ; devstat_head = & device_statq ; if ( devstat_num_devs == 1 ) STAILQ_INSERT_TAIL ( devstat_head , ds , dev_links ) ; else { STAILQ_FOREACH ( ds_tmp , devstat_head , dev_links ) { struct devstat * ds_next ; ds_next = STAILQ_NEXT ( ds_tmp , dev_links ) ; if ( ( priority <= ds_tmp -> priority ) && ( ( ds_next == NULL ) || ( priority > ds_next -> priority ) ) ) { STAILQ_INSERT_AFTER ( devstat_head , ds_tmp , ds , dev_links ) ; break ; } else if ( priority > ds_tmp -> priority ) { if ( ds_tmp == STAILQ_FIRST ( devstat_head ) ) { STAILQ_INSERT_HEAD ( devstat_head , ds , dev_links ) ; break ; } else { STAILQ_INSERT_TAIL ( devstat_head , ds , dev_links ) ; printf ( " " " " " \n " , dev_name , unit_number ) ; break ; } } } } ds -> device_number = devstat_current_devnumber ++ ; ds -> unit_number = unit_number ; strlcpy ( ds -> device_name , dev_name , DEVSTAT_NAME_LEN ) ; ds -> block_size = block_size ; ds -> flags = flags ; ds -> device_type = device_type ; ds -> priority = priority ; binuptime ( & ds -> creation_time ) ; devstat_generation ++ ; }
Take a malloced and zeroed devstat structure given to us, fill it in
 and add it to the queue of devices.
Take a malloced and zeroed devstat structure given to us fill it in and add it to the queue of devices .
/*
	 * Priority sort.  Each driver passes in its priority when it adds
	 * its devstat entry.  Drivers are sorted first by priority, and
	 * then by probe order.
	 * 
	 * For the first device, we just insert it, since the priority
	 * doesn't really matter yet.  Subsequent devices are inserted into
	 * the list using the order outlined above.
	 */ /*
			 * If we find a break between higher and lower
			 * priority items, and if this item fits in the
			 * break, insert it.  This also applies if the
			 * "lower priority item" is the end of the list.
			 */ /*
				 * If this is the case, we should be able
				 * to insert ourselves at the head of the
				 * list.  If we can't, something is wrong.
				 */