⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 devices.c

📁 linux下自动mount各种即插即用设备的一个小程序源码 文件包含内容: /vold.h /vold.c /split.h /split.c /disktype-6/disktype.c
💻 C
字号:
#include "vold.h"#include <string.h>	/* strncpy */#include <stdlib.h>	/* free */scan_item* scan_list = NULL; /* list of devices to monitor. created from the config file */vold_mount* mount_list = NULL;/* frees a device list */void sdevice_free(scan_item* list) {	if(!list) return;		if(list->next)		sdevice_free(list->next);	if(list->device) free(list->device);	free(list);}/* creates a new device struct and fills in the data */scan_item* sdevice_new(char* device, int periodic) {	scan_item* tmp;		if(device == NULL) return NULL;		tmp = (scan_item*) malloc(sizeof(scan_item));	if(tmp == NULL) {		errormsg("Not enough memory to create new device_item");		return NULL;	}		tmp->status = VOLD_UNKNOWN;	tmp->periodic = periodic;	tmp->device = strdup(device);	tmp->next = NULL;			return tmp;}/* add a device struct to the device_list */void sdevice_add(scan_item* device) {    scan_item* tmp;    	if(device != NULL) {		if( sdevice_find(device->device) ) {			errormsg("device %s does already exist in the scan_list", device->device);			return;		}	}	    if(scan_list == NULL) {		scan_list = device;    } else {		tmp = scan_list;		while(tmp->next) tmp = tmp->next;			tmp->next = device;    }}/* finds device and returns a pointer to it. NULL if not found */scan_item* sdevice_find(char* device) {    scan_item* tmp = scan_list;    if(device == NULL) return NULL;        while(tmp) {		if(strncmp(tmp->device, device, MAX_STRLEN) == 0)	    	return tmp;		tmp = tmp->next;    }    return NULL;}void sdevice_list() {    scan_item* tmp = scan_list;    int i = 1;        logmsg("Registered devices:");    while(tmp) {	logmsg("%i: %s", i, tmp->device);	i++;	tmp = tmp->next;    }}/* vold mounts */void vmount_free(vold_mount* list) {	if(list == NULL) return;		if(list->next != NULL)		vmount_free(list->next);	if(list->device != NULL) free(list->device);	if(list->mountpoint != NULL) free(list->mountpoint);	if(list->fstype != NULL) free(list->fstype);	if(list->data != NULL) free(list->data);	if(list->volumename != NULL) free(list->volumename);	free(list);}vold_mount* vmount_new() {	vold_mount* tmp;			tmp = (vold_mount*) malloc(sizeof(vold_mount));	if(tmp == NULL) {		errormsg("Not enough memory to create new vold_mount struct");		return NULL;	}		memset(tmp, 0, sizeof(vold_mount));		return tmp;}void vmount_add(vold_mount* vm) {    vold_mount* tmp;        if(mount_list == NULL) {		mount_list = vm;    } else {		tmp = mount_list;		while(tmp->next) tmp = tmp->next;			tmp->next = vm;    }}void vmount_remove(vold_mount* vm) {	vold_mount* tmp = mount_list;		if(mount_list != NULL) {		while(tmp && tmp->next != vm) {			tmp = tmp->next;		}			if(tmp != NULL) {			/* vmount found in the list, now detach vmount */			tmp->next = vm->next;			vm->next = NULL;		}	}		/* this only works for one list (mount_list).. well, we only have one, why bother :-) */	vmount_free(vm);}vold_mount* vmount_find(char* device, uuid_t uuid, char* volumename) {	vold_mount* tmp = mount_list;		if(device != NULL) {		while(tmp) {			if(strncmp(tmp->device, device, MAX_STRLEN) == 0)				return tmp;			tmp = tmp->next;		}	}		tmp = mount_list;	if(uuid != NULL) {		while(tmp) {			if(uuid_compare(uuid, tmp->uuid) != 0) 				return tmp;			tmp = tmp->next;		}	}		tmp = mount_list;	if(volumename != NULL && strlen(volumename) > 0) {		while(tmp) {			if(strncmp(tmp->volumename, volumename, MAX_STRLEN) == 0)	 			return tmp;			tmp = tmp->next;		}    }    return NULL;}void vmount_list() {	vold_mount* tmp = mount_list;		logmsg("%-30s %-9s %-40s %-5s %-32s %s", "file system", "type", "options", "fixed", "Volume Name", "Mounted On");	while(tmp != NULL) {		logmsg("%-30s %-9s %-40s %-5s %-32s %s", tmp->device, tmp->fstype, tmp->data, tmp->fixed?"yes":"no", tmp->volumename, tmp->mountpoint);		tmp = tmp->next;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -