/* 目录初始化,避免直接创建文件失败。 如果需要确保的是目录,则需要在路径后加上斜杠,否则最后一段视为文件名。 如:filename为/home/test/aaa.txt,则确保的是目录/home/test 如:filename为/home/mydir/,则确保的是目录/home/mydir */ int dir_exist_ensure(char *filename) { if(NULL==filename || strlen(filename)>128){ DEBUG("file name is NULL or too long\n"); return -1; } char tmp_dir[128]; snprintf(tmp_dir, sizeof(tmp_dir), "%s", filename); char *last_slash = strrchr(tmp_dir, '/'); if(NULL==last_slash) return 0; *last_slash = '\0'; if(0!=access(tmp_dir, F_OK)){ ERROROUT("dir %s is not exist\n", tmp_dir); if(0!=mkdir(tmp_dir, 0777)){ ERROROUT("create dir %s failed\n", tmp_dir); return -1; } else{ DEBUG("create dir %s success\n", tmp_dir); return 0; } } else{ DEBUG("dir %s is exist\n", tmp_dir); return 0; } }
/** * Open current file on an external viewer. * * @param bCustom TRUE to use one of the custom viewers, FALSE to use associated program. * @param bSecondary TRUE to use secondary viewer, FALSE to use primary viewer. Ignored if the bCustom is FALSE. */ void LaunchInViewer(BOOL bCustom, BOOL bSecondary) { if (bCustom) { if (!bSecondary && options.szBrowser[0] == _T('\0')) { MessageBox(hwnd, GetString(IDS_PRIMARY_VIEWER_MISSING), STR_METAPAD, MB_OK|MB_ICONEXCLAMATION); SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(ID_VIEW_OPTIONS, 0), 0); return; } //DBGOUT(options.szBrowser2, _T("run szBrowser2 value:")); if (bSecondary && options.szBrowser2[0] == _T('\0')) { MessageBox(hwnd, GetString(IDS_SECONDARY_VIEWER_MISSING), STR_METAPAD, MB_OK|MB_ICONEXCLAMATION); SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(ID_VIEW_OPTIONS, 0), 0); return; } } if (szFile[0] == _T('\0') || (bDirtyFile && options.nLaunchSave != 2)) { int res = IDYES; if (options.nLaunchSave == 0) { TCHAR szBuffer[MAXFN]; wsprintf(szBuffer, GetString(IDS_DIRTYFILE), szCaptionFile); res = MessageBox(hwnd, szBuffer, STR_METAPAD, MB_ICONEXCLAMATION | MB_YESNOCANCEL); } if (res == IDCANCEL) { return; } else if (res == IDYES) { if (!SaveCurrentFile()) { return; } } } if (szFile[0] != _T('\0')) { if (bCustom) { if (bSecondary) { LaunchSecondaryExternalViewer(); } else { LaunchPrimaryExternalViewer(); } } else { INT_PTR ret = (INT_PTR)ShellExecute(NULL, _T("open"), szFile, NULL, szDir, SW_SHOW); if (ret <= 32) { switch (ret) { case SE_ERR_NOASSOC: ERROROUT(GetString(IDS_NO_DEFAULT_VIEWER)); break; default: ERROROUT(GetString(IDS_DEFAULT_VIEWER_ERROR)); } } } } if (options.bLaunchClose) { DestroyWindow(hwnd); } }
/** Inserts the specified element into this priority queue. @param q a pointer to an instance of the priqueue_t data structure @param ptr a pointer to the data to be inserted into the priority queue @return The zero-based index where ptr is stored in the priority queue, where 0 indicates that ptr was stored at the front of the priority queue. */ int priqueue_offer(priqueue_t *q, void *ptr) { node_t* node_ptr = new_node(); insert_value_node(node_ptr,ptr); int i; if(q->size ==0) { q->head = node_ptr; q->size ++; return 0; } if(q->comp(node_ptr->obj,q->head->obj) < 0) { insert_next_node(node_ptr,q->head); q->head = node_ptr; q->size ++; return 0; } node_t* iterator = q->head; for (i = 0; i < q->size; ++i) { if(iterator->next == NULL || q->comp(node_ptr->obj,iterator->next->obj)<0) { insert_next_node(node_ptr,iterator->next); iterator->next = node_ptr; q->size ++; return i+1; } else iterator = iterator -> next; } ERROROUT("insert failed."); exit(1); return -1; }
void print_timestamp(int show_s_ms, int show_str) { struct timeval tv_now; time_t t; struct tm area; tzset(); /* tzset()*/ if(show_s_ms){ if(-1==gettimeofday(&tv_now, NULL)){ ERROROUT("gettimeofday failed\n"); } else printf("|s: %ld\t|ms: %ld\t|us:%ld\t", tv_now.tv_sec, (tv_now.tv_usec)/1000, (tv_now.tv_usec)); } if(show_str){ t = time(NULL); localtime_r(&t, &area); printf("|%s", asctime(&area)); } if(0==show_str) printf("\n"); return; }
int softdvb_init() { int ret = 0; Filter_param param; // xml 根pid unsigned short root_pid = root_channel_get(); int filter1 = alloc_filter(root_pid, 0); DEBUG("set dvb filter, pid=%d, fid=%d\n", root_pid, filter1); // 升级pid memset(¶m,0,sizeof(param)); param.filter[0] = 0xf0; param.mask[0] = 0xff; loader_dsc_fid=TC_alloc_filter(0x1ff0, ¶m, loader_des_section_handle, NULL, 0); DEBUG("set upgrade filter, pid=0x1ff0, fid=%d\n", loader_dsc_fid); // ca pid memset(¶m,0,sizeof(param)); param.filter[0] = 0x1; param.mask[0] = 0xff; int ca_dsc_fid=TC_alloc_filter(0x1, ¶m, ca_section_handle, NULL, 0); DEBUG("set ca filter, pid=0x1, fid=%d\n", ca_dsc_fid); #ifdef PUSH_LOCAL_TEST // prog/video unsigned short video_pid = 123; int filter5 = alloc_filter(video_pid, 1); DEBUG("set dvb filter3, pid=%d, fid=%d\n", video_pid, filter5); // prog/file unsigned short file_pid = 654; int filter4 = alloc_filter(file_pid, 1); DEBUG("set dvb filter3, pid=%d, fid=%d\n", file_pid, filter4); // prog/audio unsigned short audio_pid = 8123; int filter3 = alloc_filter(audio_pid, 1); DEBUG("set dvb filter3, pid=%d, fid=%d\n", audio_pid, filter3); #else if(-1==pid_init(1)){ DEBUG("allpid init faild\n"); return -1; } #endif tdt_time_sync_awake(); if(0==pthread_create(&pth_softdvb_id, NULL, softdvb_thread, NULL)){ //pthread_detach(pth_softdvb_id); DEBUG("create soft dvb thread success\n"); ret = 0; } else{ ERROROUT("create multicast receive thread failed\n"); ret = -1; } return ret; }
void* get_obj_node (node_t* node_ptr) { if(node_ptr==NULL) { ERROROUT("node is empty"); exit(1); } return node_ptr->obj; }
/** * Launch the secondary external viewer. */ static void LaunchSecondaryExternalViewer(void) { TCHAR szLaunch[MAXFN] = {_T('\0')}; lstrcat(szLaunch, options.szArgs2); lstrcat(szLaunch, _T(" \"")); lstrcat(szLaunch, szFile); lstrcat(szLaunch, _T("\"")); if (!ExecuteProgram(options.szBrowser2, szLaunch)) ERROROUT(GetString(IDS_SECONDARY_VIEWER_ERROR)); }
/** * Launch the primary external viewer. */ void LaunchPrimaryExternalViewer(void) { TCHAR szLaunch[MAXFN] = {_T('\0')}; lstrcat(szLaunch, options.szArgs); lstrcat(szLaunch, _T(" \"")); lstrcat(szLaunch, szFile); lstrcat(szLaunch, _T("\"")); if (!ExecuteProgram(options.szBrowser, szLaunch)) ERROROUT(GetString(IDS_PRIMARY_VIEWER_ERROR)); }
/** Returns the element at the specified position in this list, or NULL if the queue does not contain an index'th element. @param q a pointer to an instance of the priqueue_t data structure @param index position of retrieved element @return the index'th element in the queue @return NULL if the queue does not contain the index'th element */ void *priqueue_at(priqueue_t *q, int index) { if(index < 0) { ERROROUT("index should be positive."); return NULL; } if(index >= q->size) return NULL; if(index == 0) return q->head->obj; int i; node_t * iterator = q->head; for(i=1; i<= index; ++i) iterator = iterator -> next; return iterator -> obj; }
/* 此函数目前只能调用一次。 */ int multicast_add() { int ret = -1; // 创建接收线程 if(0==pthread_create(&pth_igmp_id, NULL, igmp_thread, NULL)){ //pthread_detach(pth_igmp_id); DEBUG("create multicast receive thread success\n"); ret = 0; } else{ ERROROUT("create multicast receive thread failed\n"); ret = -1; } return ret; }
/* 整个母盘初始化过程应当是独占的,避免在母盘初始化过程中由于插拔智能卡或插拔网线等导致逻辑混乱 return : 0: nomarl -1: failed 1: this is mother disc, perhaps reboot the system. */ int motherdisc_process() { char direct_uri[1024]; char new_uri_motherdisc_xml[1024]; char sqlite_cmd[1024]; int ret = 0; if(1==motherdisc_check()){ s_motherdisc_processing_status = 1; DEBUG("%s is exist, initialize disc starting...\n", MOTHERDISC_XML_URI); msg_send2_UI(MOTHER_DISC_INITIALIZE_START, NULL, 0); if(0==motherdisc_parse()){ DEBUG("parse mother disc finish\n"); sqlite3_snprintf(sizeof(sqlite_cmd),sqlite_cmd,"DELETE FROM Initialize;"); sqlite_execute(sqlite_cmd); sqlite3_snprintf(sizeof(sqlite_cmd),sqlite_cmd,"DELETE FROM ProductDesc;"); sqlite_execute(sqlite_cmd); ret = 0; } snprintf(direct_uri,sizeof(direct_uri),"%s/pushroot/%s", push_dir_get(),MOTHERDISC_XML_URI); snprintf(new_uri_motherdisc_xml,sizeof(new_uri_motherdisc_xml),"%s_PROCESSED__",direct_uri); if(0!=rename(direct_uri,new_uri_motherdisc_xml)){ ERROROUT("rename %s to %s failed\n", direct_uri, new_uri_motherdisc_xml); remove(direct_uri); } s_motherdisc_processing_status = 0; } else{ s_motherdisc_processing_status = 0; ret = -1; } return ret; }
/** Removes the specified index from the queue, moving later elements up a spot in the queue to fill the gap. @param q a pointer to an instance of the priqueue_t data structure @param index position of element to be removed @return the element removed from the queue @return NULL if the specified index does not exist */ void *priqueue_remove_at(priqueue_t *q, int index) { if(index < 0) { ERROROUT("index should be positive."); return NULL; } if(index >= q->size) return NULL; if(index == 0) return priqueue_poll(q); int i; node_t *iterator = q->head, *node_ptr; for(i=1; i<= index -1 ; ++i) iterator = iterator -> next; node_ptr = iterator -> next; iterator -> next = node_ptr -> next; q-> size --; return destroy_node(node_ptr); }
int igmp_recvbuf_init() { DEBUG("s_igmp_recvbuf_init_flag=%d\n", s_igmp_recvbuf_init_flag); if(0==s_igmp_recvbuf_init_flag){ if(p_buf){ DEBUG("free p_buf: %p\n", p_buf); free(p_buf); p_buf = NULL; } p_buf = (unsigned char *)malloc(MULTI_BUF_SIZE); if(NULL==p_buf){ ERROROUT("can not malloc space for p_buf\n"); return -1; } s_igmp_recvbuf_init_flag = 1; DEBUG("malloc %d for igmp receive buffer\n", MULTI_BUF_SIZE); } else{ DEBUG("have malloc igmp receive buffer already\n"); } return 0; }
struct resource * bus_alloc_resource(device_t dev, int type, int *rid, int d, int e, int f, int g) { switch (type) { case SYS_RES_IOPORT: { uint32 v = pci_read_config(dev, *rid, 4) & PCI_address_io_mask; INIT_DEBUGOUT2("bus_alloc_resource SYS_RES_IOPORT, reg 0x%x, adr %p\n", *rid, (void *)v); return (struct resource *) v; } case SYS_RES_MEMORY: { uint32 v = pci_read_config(dev, *rid, 4) & PCI_address_memory_32_mask; uint32 size = 128 * 1024; // XXX get size from BAR void *virt; INIT_DEBUGOUT2("bus_alloc_resource SYS_RES_MEMORY, reg 0x%x, adr %p\n", *rid, (void *)v); if (map_mem(&virt, (void *)v, size, 0, "SYS_RES_MEMORY") < 0) return 0; return (struct resource *) virt; } case SYS_RES_IRQ: { uint8 v = pci_read_config(dev, PCI_interrupt_line, 1); if (v == 0 || v == 0xff) { ERROROUT("bus_alloc_resource SYS_RES_IRQ: no irq"); return 0; } return (struct resource *)(int)v; } default: INIT_DEBUGOUT("bus_alloc_resource default!\n"); return 0; } }
static int nfs_statvfs(struct mount *mp, struct statvfs *sbp, struct ucred *cred) { struct vnode *vp; struct nfs_statfs *sfp; struct nfsmount *nmp = VFSTONFS(mp); thread_t td = curthread; int error = 0, retattr; struct nfsnode *np; struct nfsm_info info; info.mrep = NULL; info.v3 = (nmp->nm_flag & NFSMNT_NFSV3); lwkt_gettoken(&nmp->nm_token); #ifndef nolint sfp = NULL; #endif error = nfs_nget(mp, (nfsfh_t *)nmp->nm_fh, nmp->nm_fhsize, &np, NULL); if (error) { lwkt_reltoken(&nmp->nm_token); return (error); } vp = NFSTOV(np); /* ignore the passed cred */ cred = crget(); cred->cr_ngroups = 1; if (info.v3 && (nmp->nm_state & NFSSTA_GOTFSINFO) == 0) (void)nfs_fsinfo(nmp, vp, td); nfsstats.rpccnt[NFSPROC_FSSTAT]++; nfsm_reqhead(&info, vp, NFSPROC_FSSTAT, NFSX_FH(info.v3)); ERROROUT(nfsm_fhtom(&info, vp)); NEGKEEPOUT(nfsm_request(&info, vp, NFSPROC_FSSTAT, td, cred, &error)); if (info.v3) { ERROROUT(nfsm_postop_attr(&info, vp, &retattr, NFS_LATTR_NOSHRINK)); } if (error) { if (info.mrep != NULL) m_freem(info.mrep); goto nfsmout; } NULLOUT(sfp = nfsm_dissect(&info, NFSX_STATFS(info.v3))); sbp->f_flag = nmp->nm_flag; sbp->f_owner = nmp->nm_cred->cr_ruid; if (info.v3) { sbp->f_bsize = NFS_FABLKSIZE; sbp->f_frsize = NFS_FABLKSIZE; sbp->f_blocks = (fxdr_hyper(&sfp->sf_tbytes) / ((u_quad_t)NFS_FABLKSIZE)); sbp->f_bfree = (fxdr_hyper(&sfp->sf_fbytes) / ((u_quad_t)NFS_FABLKSIZE)); sbp->f_bavail = (fxdr_hyper(&sfp->sf_abytes) / ((u_quad_t)NFS_FABLKSIZE)); sbp->f_files = fxdr_hyper(&sfp->sf_tfiles); sbp->f_ffree = fxdr_hyper(&sfp->sf_ffiles); sbp->f_favail = fxdr_hyper(&sfp->sf_afiles); } else { sbp->f_bsize = fxdr_unsigned(int32_t, sfp->sf_bsize); sbp->f_blocks = fxdr_unsigned(int32_t, sfp->sf_blocks); sbp->f_bfree = fxdr_unsigned(int32_t, sfp->sf_bfree); sbp->f_bavail = fxdr_unsigned(int32_t, sfp->sf_bavail); sbp->f_files = 0; sbp->f_ffree = 0; sbp->f_favail = 0; } sbp->f_syncreads = 0; sbp->f_syncwrites = 0; sbp->f_asyncreads = 0; sbp->f_asyncwrites = 0; sbp->f_type = mp->mnt_vfc->vfc_typenum; m_freem(info.mrep); info.mrep = NULL; nfsmout: vput(vp); crfree(cred); lwkt_reltoken(&nmp->nm_token); return (error); }
status_t init_driver(void) { struct pci_info *item; int index; int cards; #ifdef DEBUG set_dprintf_enabled(true); load_driver_symbols("ipro1000"); #endif dprintf("ipro1000: " INFO "\n"); item = (pci_info *)malloc(sizeof(pci_info)); if (!item) return B_NO_MEMORY; if (get_module(B_PCI_MODULE_NAME, (module_info **)&gPci) < B_OK) { free(item); return B_ERROR; } for (cards = 0, index = 0; gPci->get_nth_pci_info(index++, item) == B_OK; ) { const char *info = identify_device(item); if (info) { char name[64]; sprintf(name, "net/ipro1000/%d", cards); dprintf("ipro1000: /dev/%s is a %s\n", name, info); gDevList[cards] = item; gDevNameList[cards] = strdup(name); gDevNameList[cards + 1] = NULL; cards++; item = (pci_info *)malloc(sizeof(pci_info)); if (!item) goto err_outofmem; if (cards == MAX_CARDS) break; } } free(item); if (!cards) goto err_cards; if (initialize_timer() != B_OK) { ERROROUT("timer init failed"); goto err_timer; } if (mempool_init(cards * 768) != B_OK) { ERROROUT("mempool init failed"); goto err_mempool; } return B_OK; err_mempool: terminate_timer(); err_timer: err_cards: err_outofmem: for (index = 0; index < cards; index++) { free(gDevList[index]); free(gDevNameList[index]); } put_module(B_PCI_MODULE_NAME); return B_ERROR; }
/* 功能:获取指定网卡的ip、状态、mac地址 输入:interface_name ——网卡名称,如:"eth0"、"lo" 输出: ip ——点分十进制的IP v4地址,如:"192.168.100.100" status ——状态,如:"UP"、"DOWN" mac ——MAC地址,以分号隔开的16进制表示,如:"00:0c:29:50:fc:f8" 返回:0——成功;其他——失败 */ int ifconfig_get(char *interface_name, char *ip, char *status, char *mac) { if(NULL==interface_name || (NULL==ip && NULL==status && NULL==mac)){ DEBUG("some params are invalid\n"); return -1; } #ifdef SOLARIS struct arpreq arp; #endif register int fd=0, interface_num=0, ret = 0; struct ifreq buf[MAXINTERFACES]; struct ifconf ifc; if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) >= 0) { DEBUG("create socket(%d) to read ifconfig infor\n", fd); ifc.ifc_len = sizeof(buf); ifc.ifc_buf = (caddr_t) buf; if (!ioctl (fd, SIOCGIFCONF, (char *) &ifc)) { //获取接口信息 interface_num = ifc.ifc_len / sizeof (struct ifreq); DEBUG("interface num is %d\n",interface_num); //根据接口信息循环获取设备IP和MAC地址 while (interface_num-- > 0) { //获取设备名称 DEBUG ("net device %d: %s\n", interface_num, buf[interface_num].ifr_name); if(strcmp(interface_name, buf[interface_num].ifr_name)){ continue; } ret = 0; //判断网卡类型 if (!(ioctl (fd, SIOCGIFFLAGS, (char *) &buf[interface_num]))) { if (buf[interface_num].ifr_flags & IFF_PROMISC) { DEBUG("the interface_num is PROMISC\n"); } } else { char str[256]; sprintf (str, "cpm: ioctl device %s", buf[interface_num].ifr_name); perror (str); ret = -1; break; } //判断网卡状态 if(NULL!=status) { if (buf[interface_num].ifr_flags & IFF_UP) { DEBUG("the interface_num status is UP\n"); strcpy(status, "UP"); } else { DEBUG("the interface_num status is DOWN\n"); strcpy(status, "DOWN"); } } //获取当前网卡的IP地址 if(NULL!=ip) { if (!(ioctl (fd, SIOCGIFADDR, (char *) &buf[interface_num]))) { strcpy(ip, (char *)inet_ntoa(((struct sockaddr_in*)(&buf[interface_num].ifr_addr))->sin_addr)); DEBUG ("IP address is: %s\n", ip); } else { char str[256]; sprintf (str, "cpm: ioctl device %s", buf[interface_num].ifr_name); perror (str); ret = -1; break; } } if(NULL!=mac) { #ifdef SOLARIS /* this section can't get Hardware Address,I don't know whether the reason is module driver*/ //获取MAC地址 arp.arp_pa.sa_family = AF_INET; arp.arp_ha.sa_family = AF_INET; ((struct sockaddr_in*)&arp.arp_pa)->sin_addr.s_addr=((struct sockaddr_in*)(&buf[interface_num].ifr_addr))->sin_addr.s_addr; if (!(ioctl (fd, SIOCGARP, (char *) &arp))) { puts ("HW address is:"); //以十六进制显示MAC地址 printf("%02x:%02x:%02x:%02x:%02x:%02x\n", (unsigned char)arp.arp_ha.sa_data[0], (unsigned char)arp.arp_ha.sa_data[1], (unsigned char)arp.arp_ha.sa_data[2], (unsigned char)arp.arp_ha.sa_data[3], (unsigned char)arp.arp_ha.sa_data[4], (unsigned char)arp.arp_ha.sa_data[5]); puts(""); puts(""); } #else #if 0 /*Get HW ADDRESS of the net card */ if (!(ioctl (fd, SIOCGENADDR, (char *) &buf[interface_num]))) { puts ("HW address is:"); printf("%02x:%02x:%02x:%02x:%02x:%02x\n", (unsigned char)buf[interface_num].ifr_enaddr[0], (unsigned char)buf[interface_num].ifr_enaddr[1], (unsigned char)buf[interface_num].ifr_enaddr[2], (unsigned char)buf[interface_num].ifr_enaddr[3], (unsigned char)buf[interface_num].ifr_enaddr[4], (unsigned char)buf[interface_num].ifr_enaddr[5]); puts(""); puts(""); } #endif if (!(ioctl (fd, SIOCGIFHWADDR, (char *) &buf[interface_num]))) { sprintf(mac, "%02x:%02x:%02x:%02x:%02x:%02x", (unsigned char)buf[interface_num].ifr_hwaddr.sa_data[0], (unsigned char)buf[interface_num].ifr_hwaddr.sa_data[1], (unsigned char)buf[interface_num].ifr_hwaddr.sa_data[2], (unsigned char)buf[interface_num].ifr_hwaddr.sa_data[3], (unsigned char)buf[interface_num].ifr_hwaddr.sa_data[4], (unsigned char)buf[interface_num].ifr_hwaddr.sa_data[5]); DEBUG("hardware address: %s\n", mac); } #endif else { char str[256]; sprintf (str, "cpm: ioctl device %s", buf[interface_num].ifr_name); perror (str); ret = -1; break; } } break; // 只完成一个有效循环即可。 } //while } else{ ERROROUT ("cpm: ioctl"); ret = -1; } close (fd); DEBUG("close fd(%d)\n", fd); } else{ ERROROUT ("cpm: socket"); ret = -1; } return ret; }
/* * nfs statfs call */ int nfs_statfs(struct mount *mp, struct statfs *sbp, struct ucred *cred) { struct vnode *vp; struct nfs_statfs *sfp; struct nfsmount *nmp = VFSTONFS(mp); thread_t td = curthread; int error = 0, retattr; struct nfsnode *np; u_quad_t tquad; struct nfsm_info info; info.mrep = NULL; info.v3 = (nmp->nm_flag & NFSMNT_NFSV3); lwkt_gettoken(&nmp->nm_token); #ifndef nolint sfp = NULL; #endif error = nfs_nget(mp, (nfsfh_t *)nmp->nm_fh, nmp->nm_fhsize, &np, NULL); if (error) { lwkt_reltoken(&nmp->nm_token); return (error); } vp = NFSTOV(np); /* ignore the passed cred */ cred = crget(); cred->cr_ngroups = 1; if (info.v3 && (nmp->nm_state & NFSSTA_GOTFSINFO) == 0) (void)nfs_fsinfo(nmp, vp, td); nfsstats.rpccnt[NFSPROC_FSSTAT]++; nfsm_reqhead(&info, vp, NFSPROC_FSSTAT, NFSX_FH(info.v3)); ERROROUT(nfsm_fhtom(&info, vp)); NEGKEEPOUT(nfsm_request(&info, vp, NFSPROC_FSSTAT, td, cred, &error)); if (info.v3) { ERROROUT(nfsm_postop_attr(&info, vp, &retattr, NFS_LATTR_NOSHRINK)); } if (error) { if (info.mrep != NULL) m_freem(info.mrep); goto nfsmout; } NULLOUT(sfp = nfsm_dissect(&info, NFSX_STATFS(info.v3))); sbp->f_flags = nmp->nm_flag; if (info.v3) { sbp->f_bsize = NFS_FABLKSIZE; tquad = fxdr_hyper(&sfp->sf_tbytes); sbp->f_blocks = (long)(tquad / ((u_quad_t)NFS_FABLKSIZE)); tquad = fxdr_hyper(&sfp->sf_fbytes); sbp->f_bfree = (long)(tquad / ((u_quad_t)NFS_FABLKSIZE)); tquad = fxdr_hyper(&sfp->sf_abytes); sbp->f_bavail = (long)(tquad / ((u_quad_t)NFS_FABLKSIZE)); sbp->f_files = (fxdr_unsigned(int32_t, sfp->sf_tfiles.nfsuquad[1]) & 0x7fffffff); sbp->f_ffree = (fxdr_unsigned(int32_t, sfp->sf_ffiles.nfsuquad[1]) & 0x7fffffff); } else { sbp->f_bsize = fxdr_unsigned(int32_t, sfp->sf_bsize); sbp->f_blocks = fxdr_unsigned(int32_t, sfp->sf_blocks); sbp->f_bfree = fxdr_unsigned(int32_t, sfp->sf_bfree); sbp->f_bavail = fxdr_unsigned(int32_t, sfp->sf_bavail); sbp->f_files = 0; sbp->f_ffree = 0; } /* * Some values are pre-set in mnt_stat. Note in particular f_iosize * cannot be changed once the filesystem is mounted as it is used * as the basis for BIOs. */ if (sbp != &mp->mnt_stat) { sbp->f_type = mp->mnt_vfc->vfc_typenum; bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN); sbp->f_iosize = mp->mnt_stat.f_iosize; } m_freem(info.mrep); info.mrep = NULL; nfsmout: vput(vp); crfree(cred); lwkt_reltoken(&nmp->nm_token); return (error); }
int setting_init(void) { if(1==s_settingInitFlag) return 0; FILE* fp; char tmp_buf[256]; int i=0; int j=0; char *p_value; settingDefault_set(); DEBUG("init settings with file %s\n", SETTING_BASE); fp = fopen(SETTING_BASE,"r"); if (NULL == fp) { ERROROUT("open file %s faild! use default setting\n", SETTING_BASE); return 0; } DEBUG("open file %s success\n", SETTING_BASE); memset(tmp_buf, 0, sizeof(tmp_buf)); while(NULL!=fgets(tmp_buf, sizeof(tmp_buf), fp)){ if('#'==tmp_buf[0]){ DEBUG("this line is ignored as explain\n"); continue; } DEBUG("read line: %s\n", tmp_buf); j = 0; for(i=0; i<strlen(tmp_buf); i++){ #if 0 if( (tmp_buf[i]>'0'&&tmp_buf[i]<'9') ||(tmp_buf[i]>'A'&&tmp_buf[i]<'Z') ||(tmp_buf[i]>'a'&&tmp_buf[i]<'z') ||'_'==tmp_buf[i] || '-'==tmp_buf[i] || '@'==tmp_buf[i] ) #else if( isgraph(tmp_buf[i]) ) //or check it between 33('!') and 126('~') #endif { if(j!=i) tmp_buf[j] = tmp_buf[i]; j++; } } tmp_buf[j] = '\0'; DEBUG("tmp_buf: %s\n", tmp_buf); if('#'==tmp_buf[0]){ DEBUG("ignore a line because of explain\n"); continue; } p_value = strchr(tmp_buf, '='); if(p_value){ *p_value = '\0'; p_value++; DEBUG("tmp_buf: %s, p_value=%s\n", tmp_buf, p_value); if(strlen(tmp_buf)>0 && strlen(p_value)>0){ if(0==strcmp(tmp_buf, "server_ip")) strncpy(s_server_ip, p_value, sizeof(s_server_ip)-1); else if(0==strcmp(tmp_buf, "server_port")) s_server_port = atoi(p_value); else if(0==strcmp(tmp_buf, "serial_num")) strncpy(s_serial_num, p_value, sizeof(s_serial_num)-1); else if(0==strcmp(tmp_buf, "version")) strncpy(s_version, p_value, sizeof(s_version)-1); #ifdef WORK_NORMAL_NOT_TEST #else else if(0==strcmp(tmp_buf, "test_cmdstr")){ memset(s_test_cmdstr, 0, sizeof(s_test_cmdstr)); strncpy(s_test_cmdstr, p_value, sizeof(s_test_cmdstr)-1); } #endif } } memset(tmp_buf, 0, sizeof(tmp_buf)); j = 0; } fclose(fp); DEBUG("init settings OK\n"); s_settingInitFlag = 1; return 0; }
/* * nfs version 3 fsinfo rpc call */ int nfs_fsinfo(struct nfsmount *nmp, struct vnode *vp, struct thread *td) { struct nfsv3_fsinfo *fsp; u_int32_t pref, max; int error = 0, retattr; u_int64_t maxfsize; struct nfsm_info info; info.v3 = 1; nfsstats.rpccnt[NFSPROC_FSINFO]++; nfsm_reqhead(&info, vp, NFSPROC_FSINFO, NFSX_FH(1)); ERROROUT(nfsm_fhtom(&info, vp)); NEGKEEPOUT(nfsm_request(&info, vp, NFSPROC_FSINFO, td, nfs_vpcred(vp, ND_READ), &error)); ERROROUT(nfsm_postop_attr(&info, vp, &retattr, NFS_LATTR_NOSHRINK)); if (error == 0) { NULLOUT(fsp = nfsm_dissect(&info, NFSX_V3FSINFO)); pref = fxdr_unsigned(u_int32_t, fsp->fs_wtpref); if (pref < nmp->nm_wsize && pref >= NFS_FABLKSIZE) nmp->nm_wsize = roundup2(pref, NFS_FABLKSIZE); max = fxdr_unsigned(u_int32_t, fsp->fs_wtmax); if (max < nmp->nm_wsize && max > 0) { nmp->nm_wsize = max & ~(NFS_FABLKSIZE - 1); if (nmp->nm_wsize == 0) nmp->nm_wsize = max; } pref = fxdr_unsigned(u_int32_t, fsp->fs_rtpref); if (pref < nmp->nm_rsize && pref >= NFS_FABLKSIZE) nmp->nm_rsize = roundup2(pref, NFS_FABLKSIZE); max = fxdr_unsigned(u_int32_t, fsp->fs_rtmax); if (max < nmp->nm_rsize && max > 0) { nmp->nm_rsize = max & ~(NFS_FABLKSIZE - 1); if (nmp->nm_rsize == 0) nmp->nm_rsize = max; } pref = fxdr_unsigned(u_int32_t, fsp->fs_dtpref); if (pref < nmp->nm_readdirsize && pref >= NFS_DIRBLKSIZ) nmp->nm_readdirsize = roundup2(pref, NFS_DIRBLKSIZ); if (max < nmp->nm_readdirsize && max > 0) { nmp->nm_readdirsize = max & ~(NFS_DIRBLKSIZ - 1); if (nmp->nm_readdirsize == 0) nmp->nm_readdirsize = max; } maxfsize = fxdr_hyper(&fsp->fs_maxfilesize); if (maxfsize > 0 && maxfsize < nmp->nm_maxfilesize) nmp->nm_maxfilesize = maxfsize; nmp->nm_state |= NFSSTA_GOTFSINFO; /* * Use the smaller of rsize/wsize for the biosize. */ if (nmp->nm_rsize < nmp->nm_wsize) nmp->nm_mountp->mnt_stat.f_iosize = nmp->nm_rsize; else nmp->nm_mountp->mnt_stat.f_iosize = nmp->nm_wsize; } m_freem(info.mrep); info.mrep = NULL; nfsmout: return (error); }
/* 功能: 程序开始时初始化各个模块,启动相关的线程,instruction线程用于处理具体指令,timing线程管理定时器 返回: 0——成功;-1——失败 */ int global_init() { int ret = -1; if(-1==dir_exist_ensure(WORKSPACE_SURFIX)) return -1; setting_init(); if(-1==dir_exist_ensure(FIFO_DIR)) return -1; if(-1==socket_init()){ DEBUG("socket module init failed\n"); return -1; } if(-1==sqlite_init()){ DEBUG("sqlite module init failed\n"); return -1; } if(-1==timing_init()){ DEBUG("timer module init failed\n"); return -1; } if(-1==equipment_init()){ DEBUG("equipment array init failed\n"); return -1; } if(-1==instruction_init()){ DEBUG("instruction module init failed\n"); return -1; } if(-1==serial_int()){ DEBUG("serial module init failed\n"); return -1; } // only for database testing //DEBUG("getGlobalPara(version)=%d\n", getGlobalPara("version")); //~~~~~~~~~~create thread~~~~~~~~~~// typedef void*(*format)(void *); ///define function pointer of "void*(name)(void*)" pthread_t l_socketlinkthread; /// the file description of thread #if 0 pthread_attr_t l_attrthread; ///the attribute of thread size_t l_stacksize=1048576*1; ///set thread stack size ///start thread. pthread_attr_init(&l_attrthread); ///initialize attribute pthread_attr_setscope(&l_attrthread,PTHREAD_SCOPE_SYSTEM); ///set attribute binding pthread_attr_setdetachstate(&l_attrthread,PTHREAD_CREATE_DETACHED); ///set attribute detached pthread_attr_setstacksize(&l_attrthread,l_stacksize); ret=pthread_create(&l_socketlinkthread,&l_attrthread,(format)socketHandler,NULL); #else /* use default attr */ ret = pthread_create(&l_socketlinkthread,NULL,(format)instruction_mainloop,NULL); #endif if(0!=ret) { ERROROUT("thread instruction_mainloop create failed!"); return -1; } pthread_t timing_thread_id; ret = pthread_create(&timing_thread_id, NULL, (void *)timing_mainloop, NULL); if(0!=ret){ ERROROUT("thread timing_mainloop create failed\n"); } return 0; }