/* * Handle an I/O request. */ static void operar_sector(struct sbd_device *dev, unsigned long offset, unsigned long nbytes, char *buffer, int op) { int len; struct sckReq pack; if ((offset + nbytes) > dev->size) { printk (KERN_NOTICE "sbd: Overflow de escritura (%ld %ld)\n", offset, nbytes); return; } pack.op = op; pack.offset = offset; pack.nbytes = nbytes; printk (KERN_NOTICE "sbd: Operacion: %d - Off: %ld - Size: %ld\n", op, offset, nbytes); if (op) { // ESCRITURA. payload = kmalloc(sizeof(struct sckReq) + nbytes, GFP_KERNEL); memcpy(payload, &pack, sizeof(struct sckReq)); memcpy(payload + sizeof(struct sckReq), buffer, nbytes); len = send_sync_buf(clientsocket, payload, sizeof(struct sckReq) + nbytes, 0); len = recv_sync_buf(clientsocket, (void*)&pack, sizeof(struct sckReq), 0); if (pack.op == 2) { printk (KERN_NOTICE "sbd: Grabe correctamente %ld bytes\n", nbytes); } kfree(payload); } else { // LECTURA. len = send_sync_buf(clientsocket, (void*)&pack, sizeof(struct sckReq), 0); len = recv_sync_buf(clientsocket, buffer, nbytes, 0); printk (KERN_NOTICE "sbd: Lei correctamente %ld bytes\n", nbytes); } }
static void send_reply(struct socket *sock, char *str) { send_sync_buf(sock, str, strlen(str), MSG_DONTWAIT); }
void send_string(struct socket *sock, char *str) { send_sync_buf(sock, (void*)str, strlen(str), 0); }