Skip to content

Commit 52e8c29

Browse files
authored
Merge pull request #4 from grupoudea/feature/rotacion
Feature/rotacion
2 parents 3a23364 + b651881 commit 52e8c29

File tree

8 files changed

+180
-96
lines changed

8 files changed

+180
-96
lines changed

kernel-data-structure-lab1/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ gcc -o clientBridge clientBridge.c
3737

3838
gcc -o clientBridge clientBridge.c utilsClientBridge.c
3939

40+
gcc -o clientBridge clientBridge.c utilsClientBridge.c moduleImplement/bridgeLink.c moduleImplement/bridgeIO.c
41+
4042
```
4143

4244
### Up module

kernel-data-structure-lab1/bridgeOwn.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ static long bridge_ioctl(struct file *f, unsigned int cmd, unsigned long arg){
8989
printk(KERN_INFO "Stack succesfully created\n");
9090
break;
9191
case BRIDGE_W_S:
92-
printk(KERN_INFO "Creando");
92+
printk(KERN_INFO "Creating\n");
9393
raw_copy_from_user(message, (char *)arg, 100);
9494
add_element_to_stack(message);
9595
printk(KERN_INFO "Element succesfully added to the stack\n");
9696
break;
9797
case BRIDGE_R_S:
98-
printk(KERN_INFO "Leyendo");
99-
tmp_element = list_last_entry(&stack, struct string_node, list);
100-
list_del(&(tmp_element->list));
98+
printk(KERN_INFO "Reading\n");
99+
tmp_element = list_first_entry(&stack, struct string_node, list);
100+
list_del(&(tmp_element->list));
101101
raw_copy_to_user((char *)arg, tmp_element->message, 100);
102102
kfree(tmp_element);
103103
break;

kernel-data-structure-lab1/clientBridge.c

Lines changed: 4 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -3,86 +3,14 @@
33
#include <fcntl.h>
44
#include <unistd.h>
55
#include <string.h>
6-
#include <sys/ioctl.h>
76
#include <stdlib.h>
8-
#include "clientBridge.h"
7+
#include "moduleImplement/bridgeLink.h"
98
#include "constants.h"
109
#include "utilsClientBridge.h"
1110

1211
char** argsv;
1312
int argsc;
1413

15-
void write_message(int fd, unsigned long command, char * message){
16-
if (ioctl(fd, command, message) == -1){
17-
perror("Write message error at ioctl");
18-
}
19-
}
20-
21-
void read_message(int fd, unsigned long command, char * message){
22-
if(ioctl(fd, command, message) == -1){
23-
perror("Read message error at ioctl");
24-
}else{
25-
printf("Copy the messsage from the kernel\n");
26-
}
27-
}
28-
29-
void read_message_param(int fd, unsigned long command, int * value){
30-
if(ioctl(fd, command, value) == -1){
31-
perror("Read message param error at ioctl");
32-
}else{
33-
printf("Copy the messsage from the kernel\n");
34-
}
35-
}
36-
37-
void write_int(int fd, unsigned long command, int * value){
38-
if (ioctl(fd, command, value) == -1){
39-
perror("Write int error at ioctl");
40-
}
41-
}
42-
43-
void read_int(int fd, unsigned long command, int * value){
44-
if(ioctl(fd, command, value) == -1){
45-
perror("Read int error at ioctl");
46-
}else{
47-
printf("Copy the int from the kernel\n");
48-
}
49-
}
50-
51-
int send_empty_command(int fd, unsigned long command){
52-
int result = ioctl(fd, command);
53-
if( result == -1){
54-
perror("Send command error at ioctl");
55-
}else{
56-
printf("Command OK to the kernel\n");
57-
}
58-
return result;
59-
}
60-
61-
void write_several_messages(int fd){
62-
write_message(fd, BRIDGE_W_S, "Message 1");
63-
write_message(fd, BRIDGE_W_S, "Message 2");
64-
write_message(fd, BRIDGE_W_S, "Message 3");
65-
}
66-
67-
void read_all_messages(int fd){
68-
char message[100];
69-
while( send_empty_command(fd, BRIDGE_STATE_S) > 0){
70-
read_message(fd, BRIDGE_R_S, message);
71-
printf("Message: %s\n", message);
72-
}
73-
}
74-
75-
int callModule(){
76-
const char *file_name = "/dev/bridgeOwn"; //used by ioctl
77-
int fd;
78-
79-
fd = open(file_name, O_RDWR);
80-
if (fd == -1){
81-
perror("Bridge ioctl file open");
82-
return 2;
83-
}
84-
}
85-
8614
void usageMenu(){
8715
printf("uso: clientBridge [--help] \n");
8816
printf("\n");
@@ -109,26 +37,19 @@ char* getPathFile(){
10937
return pathfile;
11038
}
11139

112-
void validarSimetria(int fd,char **file,int numOfLines){
113-
char test[100];
114-
ioctl(fd, BRIDGE_W_S, "Hola este es un mensaje a la pila \n");
115-
ioctl(fd, BRIDGE_R_S, test);
116-
printf("%s\n",test);
117-
}
118-
11940
void chooseOption(char* option){
12041

121-
int fd = callModule();
12242
char* pathfile = getPathFile();
12343
int numOfLines = 0;
12444
char **linesArray = readFile(pathfile,&numOfLines);
12545

12646
if(strcmp(ORDEN_INVERSO, option) == 0){
47+
ordenInverso(linesArray, numOfLines);
12748

12849
}else if(strcmp(RANDOM, option) == 0){
12950

13051
}else if(strcmp(VALIDAR_SIMETRIA, option) == 0){
131-
validarSimetria(fd,linesArray,numOfLines);
52+
validarSimetria(linesArray, numOfLines);
13253

13354
}else if(strcmp(COLA_PRIORIDAD, option) == 0){
13455

@@ -139,7 +60,7 @@ void chooseOption(char* option){
13960
}else if(strcmp(CONCATENAR, option) == 0){
14061

14162
}else if(strcmp(ROTACION, option) == 0){
142-
63+
rotateToRight(5);
14364
}else if(strcmp(LIMPIAR_LISTA, option) == 0){
14465

14566
}else if(strcmp(MAYOR, option) == 0){
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
hola hola hola
2-
mundo
3-
como
4-
van
5-
bien
6-
o
7-
nooooooooooooooooooooo
8-
mundo
9-
nuevo
1+
one
2+
two
3+
three
4+
four
5+
five
6+
six
7+
seven
8+
eight
9+
nine
10+
ten
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include <sys/ioctl.h>
2+
#include <stdio.h>
3+
#include "bridgeIO.h"
4+
5+
void write_message(int fd, unsigned long command, char * message){
6+
if (ioctl(fd, command, message) == -1){
7+
perror("Write message error at ioctl");
8+
}
9+
}
10+
11+
void read_message(int fd, unsigned long command, char * message){
12+
if(ioctl(fd, command, message) == -1){
13+
perror("Read message error at ioctl");
14+
}else{
15+
printf("Copy the messsage from the kernel\n");
16+
}
17+
}
18+
19+
void read_message_param(int fd, unsigned long command, int * value){
20+
if(ioctl(fd, command, value) == -1){
21+
perror("Read message param error at ioctl");
22+
}else{
23+
printf("Copy the messsage from the kernel\n");
24+
}
25+
}
26+
27+
void write_int(int fd, unsigned long command, int * value){
28+
if (ioctl(fd, command, value) == -1){
29+
perror("Write int error at ioctl");
30+
}
31+
}
32+
33+
void read_int(int fd, unsigned long command, int * value){
34+
if(ioctl(fd, command, value) == -1){
35+
perror("Read int error at ioctl");
36+
}else{
37+
printf("Copy the int from the kernel\n");
38+
}
39+
}
40+
41+
int send_empty_command(int fd, unsigned long command){
42+
int result = ioctl(fd, command);
43+
if( result == -1){
44+
perror("Send command error at ioctl");
45+
}else{
46+
printf("Command OK to the kernel\n");
47+
}
48+
return result;
49+
}
50+
51+
void write_several_messages(int fd){
52+
write_message(fd, BRIDGE_W_S, "Message 1");
53+
write_message(fd, BRIDGE_W_S, "Message 2");
54+
write_message(fd, BRIDGE_W_S, "Message 3");
55+
}
56+
57+
void read_all_messages(int fd){
58+
char message[100];
59+
while( send_empty_command(fd, BRIDGE_STATE_S) > 0){
60+
read_message(fd, BRIDGE_R_S, message);
61+
printf("Message: %s\n", message);
62+
}
63+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#ifndef CLIENT_BRIDGE_H
2+
#define CLIENT_BRIDGE_H
3+
#include <linux/ioctl.h>
4+
5+
// cmd ‘BRIDGE_DATA_VAR’ to send a message to the module
6+
7+
#define BRIDGE_CREATE_Q _IO('p', 1) //Create a queue
8+
#define BRIDGE_W_HIGH_PRIOR_Q _IOW('p', 2, char *)
9+
#define BRIDGE_W_MIDDLE_PRIOR_Q _IOW('p', 3, char *)
10+
#define BRIDGE_W_LOW_PRIOR_Q _IOW('p', 4, char *)
11+
#define BRIDGE_R_HIGH_PRIOR_Q _IOR('p', 5, char *)
12+
#define BRIDGE_R_MIDDLE_PRIOR_Q _IOR('p', 6, char *)
13+
#define BRIDGE_R_LOW_PRIOR_Q _IOR('p', 7, char *)
14+
#define BRIDGE_STATE_Q _IO('p', 8)
15+
#define BRIDGE_DESTROY_Q _IO('p', 9)
16+
17+
#define BRIDGE_CREATE_S _IO('p', 10) //Create a stack
18+
#define BRIDGE_W_S _IOW('p', 11, char *)
19+
#define BRIDGE_R_S _IOR('p', 12, char *)
20+
#define BRIDGE_STATE_S _IO('p', 13)
21+
#define BRIDGE_DESTROY_S _IO('p', 14)
22+
23+
#define BRIDGE_CREATE_L _IO('p', 15) //Create a list
24+
#define BRIDGE_W_L _IOW('p', 16, char *)
25+
#define BRIDGE_R_L _IOR('p', 17, char *)
26+
#define BRIDGE_INVERT_L _IO('p', 18)
27+
#define BRIDGE_ROTATE_L _IOW('p', 19, int *)
28+
#define BRIDGE_CLEAN_L _IO('p', 20)
29+
#define BRIDGE_GREATER_VAL_L _IOR('p', 21, char *)
30+
#define BRIDGE_END_L _IO('p', 22)
31+
#define BRIDGE_CONCAT_L _IO('p', 23)
32+
#define BRIDGE_STATE_L _IO('p', 24)
33+
#define BRIDGE_DESTROY_L _IO('p', 25)
34+
35+
#endif
36+
37+
38+
void write_message(int fd, unsigned long command, char * message);
39+
void read_message(int fd, unsigned long command, char * message);
40+
void read_message_param(int fd, unsigned long command, int * value);
41+
42+
void write_int(int fd, unsigned long command, int * value);
43+
void read_int(int fd, unsigned long command, int * value);
44+
45+
int send_empty_command(int fd, unsigned long command);
46+
void write_several_messages(int fd);
47+
void read_all_messages(int fd);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <stdio.h>
2+
#include <sys/ioctl.h>
3+
#include <fcntl.h>
4+
#include "bridgeIO.h"
5+
#include "bridgeLink.h"
6+
7+
int callModule(){
8+
const char *file_name = "/dev/bridgeOwn"; //used by ioctl
9+
int fd;
10+
11+
fd = open(file_name, O_RDWR);
12+
if (fd == -1){
13+
perror("Bridge ioctl file open");
14+
return 2;
15+
}
16+
}
17+
18+
void validarSimetria(char **file,int numOfLines){
19+
char test[100];
20+
int fd = callModule();
21+
ioctl(fd, BRIDGE_W_S, "Hola este es un mensaje a la pila \n");
22+
ioctl(fd, BRIDGE_R_S, test);
23+
printf("%s\n",test);
24+
}
25+
26+
void ordenInverso(char** arrayLines, int numOfLines){
27+
printf("\n###### Lineas del archivo orden original ######\n");
28+
int fd = callModule();
29+
for (int i = 0; i < numOfLines; i++){
30+
printf("%s",arrayLines[i]);
31+
write_message(fd, BRIDGE_W_S, arrayLines[i]);
32+
}
33+
char test[100];
34+
printf("\n###### Lineas del archivo orden inverso ######\n");
35+
for (int i = 0; i < numOfLines; i++){
36+
write_message(fd, BRIDGE_R_S, test);
37+
printf("%s",test);
38+
}
39+
}
40+
41+
void rotateToRight(int numberRotations){
42+
int fd = callModule();
43+
write_message(fd, BRIDGE_ROTATE_L, "a");
44+
}
45+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
void validarSimetria(char** file, int numOfLines);
2+
3+
void ordenInverso(char** file, int numOfLines);
4+
5+
void rotateToRight(int numberRotations);

0 commit comments

Comments
 (0)