static int submit(int rw, pgoff_t page_off, void * page) { int error = 0; struct bio * bio; bio = bio_alloc(GFP_ATOMIC,1); if (!bio) return -ENOMEM; bio->bi_sector = page_off * (PAGE_SIZE >> 9); bio_get(bio); bio->bi_bdev = resume_bdev; bio->bi_end_io = end_io; if (bio_add_page(bio, virt_to_page(page), PAGE_SIZE, 0) < PAGE_SIZE) { printk("pmdisk: ERROR: adding page to bio at %ld\n",page_off); error = -EFAULT; goto Done; } if (rw == WRITE) bio_set_pages_dirty(bio); start_io(); submit_bio(rw | (1 << BIO_RW_SYNC), bio); wait_io(); Done: bio_put(bio); return error; }
int aos_poll(struct pollfd *fds, int nfds, int timeout) { fd_set rfds; int ret = VFS_SUCCESS; int nset = 0; struct poll_arg parg; if (init_parg(&parg) < 0) { return -1; } FD_ZERO(&rfds); ret = pre_poll(fds, nfds, &rfds, &parg); if (ret < 0) { goto check_poll; } ret = wait_io(ret, &rfds, &parg, timeout); if (ret >= 0) { int i; for (i = 0; i < nfds; i++) { struct pollfd *pfd = fds + i; if (FD_ISSET(pfd->fd, &rfds)) { pfd->revents |= POLLIN; } } nset += ret; } check_poll: nset += post_poll(fds, nfds); deinit_parg(&parg); return ret < 0 ? 0 : nset; }
int check_pop3(char *host) { int sockfd, s; struct sockaddr_in dest_addr; #ifdef USE_GETHOSTBYNAME struct hostent *hp; #endif char buf[1024]; char *tmp = NULL; int msg_count, box_size; memset(&dest_addr, 0, sizeof(struct sockaddr_in)); #ifdef USE_GETHOSTBYNAME if ((hp = gethostbyname(host)) == NULL) { return -1; } #endif sockfd = socket(AF_INET, SOCK_STREAM, 0); fcntl(sockfd, F_SETFL, O_NONBLOCK); dest_addr.sin_family = AF_INET; dest_addr.sin_port = htons(110); #ifdef USE_GETHOSTBYNAME dest_addr.sin_addr.s_addr = ((struct in_addr *)(hp->h_addr))->s_addr; #else dest_addr.sin_addr.s_addr = inet_addr(host); #endif /* this will usually return -1 on a non-blocking socket */ connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr)); /* wait for banner message */ if (wait_io(1, sockfd, 4, 0) == -1) { shutdown(sockfd, 2); close(sockfd); return 1; } s = read(sockfd, &buf, sizeof(buf)); if (s == -1) { return 1; } if (s > 0) { buf[s] = '\0'; } /* send user */ sprintf(buf, "USER %s\r\n", main_config->pop3->user); if (!(tmp = net_request(sockfd, buf))) { shutdown(sockfd, 2); close(sockfd); return 1; } if (strncmp("+OK", tmp, 3) != 0) { shutdown(sockfd, 2); close(sockfd); free(tmp); return 0; } free(tmp); /* send pass */ sprintf(buf, "PASS %s\r\n", main_config->pop3->pass); if (!(tmp = net_request(sockfd, buf))) { shutdown(sockfd, 2); close(sockfd); return 1; } if (strncmp("+OK", tmp, 3) != 0) { /* invalid password right here, we'll still say the pop3 is good =) --- good pop3 */ shutdown(sockfd, 2); close(sockfd); free(tmp); return 0; } free(tmp); /* send stat */ sprintf(buf, "STAT\r\n"); if (!(tmp = net_request(sockfd, buf))) { shutdown(sockfd, 2); close(sockfd); return 1; } s = sscanf(tmp, "%*s %d %d", &msg_count, &box_size); if (s == 2) { free(tmp); if (msg_count > 0) { /* delete a message */ sprintf(buf, "DELE 1\r\n"); if (!(tmp = net_request(sockfd, buf))) { shutdown(sockfd, 2); close(sockfd); return 1; } free(tmp); } } else { free(tmp); } /* send quit */ sprintf(buf, "QUIT\r\n"); if (!(tmp = net_request(sockfd, buf))) { shutdown(sockfd, 2); close(sockfd); return 1; } free(tmp); shutdown(sockfd, 2); close(sockfd); return 0; }
int check_imap(char *host) { int sockfd, s; struct sockaddr_in dest_addr; #ifdef USE_GETHOSTBYNAME struct hostent *hp; #endif char buf[1024]; char *tmp; memset(&dest_addr, 0, sizeof(struct sockaddr_in)); #ifdef USE_GETHOSTBYNAME if ((hp = gethostbyname(host)) == NULL) { return -1; } #endif sockfd = socket(AF_INET, SOCK_STREAM, 0); fcntl(sockfd, F_SETFL, O_NONBLOCK); dest_addr.sin_family = AF_INET; dest_addr.sin_port = htons(143); #ifdef USE_GETHOSTBYNAME dest_addr.sin_addr.s_addr = ((struct in_addr *)(hp->h_addr))->s_addr; #else dest_addr.sin_addr.s_addr = inet_addr(host); #endif /* this will usually return -1 on a non-blocking socket */ connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr)); /* wait for banner message */ if (wait_io(1, sockfd, 4, 0) == -1) { shutdown(sockfd, 2); close(sockfd); return 1; } s = read(sockfd, &buf, sizeof(buf)); if (s == -1) return 1; if (s > 0) { buf[s] = '\0'; } /* send user & pass */ sprintf(buf, "A00001 LOGIN %s %s\r\n", main_config->imap->user, main_config->imap->pass); if (!(tmp = net_request(sockfd, buf))) { shutdown(sockfd, 2); close(sockfd); return 0; } if (strncmp("A00001 OK", tmp, 9) != 0) { /* login failed, but service still up... */ shutdown(sockfd, 2); close(sockfd); free(tmp); return 0; } free(tmp); /* send list */ strcpy(buf, "A00002 LIST \"\" \"%%\"\r\n"); if (!(tmp = net_request(sockfd, buf))) { shutdown(sockfd, 2); close(sockfd); free(tmp); return 0; } free(tmp); shutdown(sockfd, 2); close(sockfd); return 0; }