Skip to content

Commit cc91b67

Browse files
authored
Merge pull request #8 from grupoudea/develop
Develop
2 parents 9ba026e + 2bfbb7a commit cc91b67

File tree

7 files changed

+143
-58
lines changed

7 files changed

+143
-58
lines changed

kernel-data-structure-lab1/bridgeOwn.c

Lines changed: 74 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,26 @@ MODULE_AUTHOR("Jheisson Argiro Lopez Restrepo");
2525
MODULE_LICENSE("Dual BSD/GPL");
2626

2727
LIST_HEAD(stack);
28+
LIST_HEAD(linkedList);
29+
LIST_HEAD(linkedListConcat);
2830

29-
static void add_element_to_stack(char *node_element_msg){
31+
static void add_element_to_stack(char *node_element_msg, struct list_head* head){
3032
struct string_node *tmp_element;
3133
tmp_element = kmalloc(sizeof(struct string_node), GFP_KERNEL);
3234
strcpy(tmp_element->message, node_element_msg);
3335
INIT_LIST_HEAD(&tmp_element->list);
34-
list_add(&(tmp_element->list), &stack);
36+
list_add(&(tmp_element->list), head);
3537
}
3638

3739
void mylist_exit(void){
38-
struct string_node *tmp_element;
40+
struct string_node *tmp_element;
3941
struct list_head *watch, *next;
4042
list_for_each_safe(watch, next, &stack){
41-
tmp_element = list_entry(watch, struct string_node, list);
42-
list_del(&(tmp_element->list));
43+
tmp_element = list_entry(watch, struct string_node, list);
44+
list_del(&(tmp_element->list));
4345
kfree(tmp_element);
44-
}
45-
//kfree(&stack);
46+
}
47+
//kfree(&stack);
4648
}
4749

4850
struct bridge_dev *bridge_devices; /* allocated in bridge_init_module */
@@ -55,12 +57,12 @@ static long bridge_ioctl(struct file *f, unsigned int cmd, unsigned long arg){
5557
printk("llego al kernel");
5658
switch(cmd){
5759
case BRIDGE_CREATE_Q:
58-
printk(KERN_INFO "message %s\n", "bla");
60+
printk(KERN_INFO "message %s\n", "bla");
5961
//Return a posituve value indicating the state of the queue
6062
return_value = 1;
6163
break;
6264
case BRIDGE_W_HIGH_PRIOR_Q:
63-
raw_copy_from_user(message, (char *)arg, 100);
65+
raw_copy_from_user(message, (char *)arg, 100);
6466
printk(KERN_INFO "message %s\n", message);
6567
break;
6668
case BRIDGE_W_MIDDLE_PRIOR_Q:
@@ -70,29 +72,28 @@ static long bridge_ioctl(struct file *f, unsigned int cmd, unsigned long arg){
7072
printk(KERN_INFO "message %s\n", "bla2");
7173
break;
7274
case BRIDGE_R_HIGH_PRIOR_Q:
73-
printk(KERN_INFO "message %s\n", "bla3");
75+
printk(KERN_INFO "message %s\n", "bla3");
7476
break;
7577
case BRIDGE_R_MIDDLE_PRIOR_Q:
76-
printk(KERN_INFO "message %s\n", "bla4");
78+
printk(KERN_INFO "message %s\n", "bla4");
7779
break;
7880
case BRIDGE_R_LOW_PRIOR_Q:
79-
printk(KERN_INFO "message %s\n", "bla5");
81+
printk(KERN_INFO "message %s\n", "bla5");
8082
break;
8183
case BRIDGE_STATE_Q:
82-
printk(KERN_INFO "message %s\n", "bla6");
84+
printk(KERN_INFO "message %s\n", "bla6");
8385
break;
8486
case BRIDGE_DESTROY_Q:
85-
printk(KERN_INFO "message %s\n", "bla7");
87+
printk(KERN_INFO "message %s\n", "bla7");
8688
break;
87-
8889
case BRIDGE_CREATE_S:
8990
printk(KERN_INFO "Stack succesfully created\n");
9091
break;
9192
case BRIDGE_W_S:
92-
printk(KERN_INFO "Creating\n");
93-
raw_copy_from_user(message, (char *)arg, 100);
94-
add_element_to_stack(message);
95-
printk(KERN_INFO "Element succesfully added to the stack\n");
93+
printk(KERN_INFO "Creating\n");
94+
raw_copy_from_user(message, (char *)arg, 100);
95+
add_element_to_stack(message, &stack);
96+
printk(KERN_INFO "Element succesfully added to the stack\n");
9697
break;
9798
case BRIDGE_R_S:
9899
printk(KERN_INFO "Reading\n");
@@ -102,51 +103,77 @@ static long bridge_ioctl(struct file *f, unsigned int cmd, unsigned long arg){
102103
kfree(tmp_element);
103104
break;
104105
case BRIDGE_STATE_S:
105-
if(list_empty(&stack) != 0){
106-
return_value = 0;
106+
if(list_empty(&stack) != 0){
107+
return_value = 0;
107108
}else{
108-
return_value = 1;
109+
return_value = 1;
109110
}
110111
printk(KERN_INFO "Stack state succesfully sended!!!\n");
111112
break;
112113
case BRIDGE_DESTROY_S:
113-
printk(KERN_INFO "message %s\n", "bla12");
114+
printk(KERN_INFO "message %s\n", "bla12");
114115
break;
115-
116116
case BRIDGE_CREATE_L:
117-
printk(KERN_INFO "message %s\n", "bla13");
118-
break;
117+
printk(KERN_INFO "message %s\n", "bla13");
118+
break;
119119
case BRIDGE_W_L:
120-
printk(KERN_INFO "message %s\n", "bla14");
121-
break;
120+
raw_copy_from_user(message, (char *)arg, 100);
121+
printk(KERN_INFO "AGREGANDO ELEMENTO A LA LISTA STACK: message = %s\n", message);
122+
add_element_to_stack(message, &stack);
123+
break;
122124
case BRIDGE_R_L:
123-
printk(KERN_INFO "message %s\n", "bla15");
124-
break;
125+
/*ESTO RECORRE TODOS LOS REGISTROS DE LA LISTA STACK
126+
struct string_node *tmp_element;
127+
struct list_head *watch, *next;
128+
list_for_each_safe(watch, next, &stack){
129+
tmp_element = list_entry(watch, struct string_node, list);
130+
char* valor = tmp_element->message;
131+
printk(KERN_INFO "VALOR = %s\n", valor);
132+
}*/
133+
tmp_element = list_last_entry(&stack, struct string_node, list);
134+
list_del(&(tmp_element->list));
135+
raw_copy_to_user((char *)arg, tmp_element->message, 100);
136+
kfree(tmp_element);
137+
break;
125138
case BRIDGE_INVERT_L:
126-
printk(KERN_INFO "message %s\n", "bla16");
127-
break;
139+
printk(KERN_INFO "message %s\n", "bla16");
140+
break;
128141
case BRIDGE_ROTATE_L:
129-
get_user(data, (int *)arg);
130-
printk(KERN_INFO "message %d\n", data);
131-
break;
142+
printk(KERN_INFO "------------ BRIDGE_ROTATE_L ROTAR LA LISTA \n");
143+
raw_copy_from_user(message, (char*)arg, 100);
144+
long numberRotations;
145+
kstrtol(message, 10, &numberRotations);
146+
printk(KERN_INFO "message BRIDGE_ROTATE_L numberRotations = %d\n", numberRotations);
147+
printk(KERN_INFO "------------------------------------------------------------------\n\n");
148+
int i = 0;
149+
while (i < numberRotations){
150+
struct list_head *head = &stack;
151+
struct list_head *first;
152+
if (!list_empty(head)) {
153+
first = head->next;
154+
list_move_tail(first, head);
155+
}
156+
i++;
157+
}
158+
break;
132159
case BRIDGE_CLEAN_L:
133-
printk(KERN_INFO "message %s\n", "bla18");
134-
break;
160+
printk(KERN_INFO "message BRIDGE_CLEAN_L %s\n", "bla18");
161+
break;
135162
case BRIDGE_GREATER_VAL_L:
136-
//strcpy((char *)arg, "MensajePrueba");
137-
printk(KERN_INFO "message %s\n", "bla19");
138-
break;
163+
//strcpy((char *)arg, "MensajePrueba");
164+
printk(KERN_INFO "message %s\n", "bla19");
165+
break;
139166
case BRIDGE_END_L:
140-
printk(KERN_INFO "message %s\n", "bla21");
141-
break;
167+
printk(KERN_INFO "message %s\n", "bla21");
168+
break;
142169
case BRIDGE_CONCAT_L:
143-
printk(KERN_INFO "message %s\n", "bla22");
144-
break;
170+
printk(KERN_INFO "message BRIDGE_CONCAT_L %s\n", "bla22");
171+
break;
145172
case BRIDGE_STATE_L:
146-
printk(KERN_INFO "message %s\n", "bla23");
147-
break;
173+
printk(KERN_INFO "message %s\n", "bla23");
174+
break;
148175
case BRIDGE_DESTROY_L:
149-
printk(KERN_INFO "message %s\n", "bla24");
176+
printk(KERN_INFO "message %s\n", "bla24");
150177
}
151178
return return_value;
152179
}

kernel-data-structure-lab1/clientBridge.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ char* getPathFile(){
3737
return pathfile;
3838
}
3939

40+
char* getNumberRotations(){
41+
if(argsc > 3){
42+
return argsv[3];
43+
}else{
44+
killClientBridge("Debe digitar la cantidad de rotaciones");
45+
}
46+
}
47+
48+
char* getPathFileSecond(){
49+
char* pathfile = "/uk";
50+
if(argsc > 3){
51+
pathfile = argsv[3];
52+
}else{
53+
usageMenu();
54+
killClientBridge("no se ha encontrado el segundo pathfile");
55+
}
56+
return pathfile;
57+
}
58+
4059
void chooseOption(char* option){
4160

4261
char* pathfile = getPathFile();
@@ -58,11 +77,15 @@ void chooseOption(char* option){
5877
}else if(strcmp(INVERTIR, option) == 0){
5978

6079
}else if(strcmp(CONCATENAR, option) == 0){
61-
80+
char* secondPathfile = getPathFileSecond();
81+
int numOfLinesToConcat = 0;
82+
char** linesArrayToConcat = readFile(secondPathfile, &numOfLinesToConcat);
83+
concatTwoLists(linesArray, numOfLines, linesArrayToConcat, numOfLinesToConcat);
6284
}else if(strcmp(ROTACION, option) == 0){
63-
rotateToRight(5);
85+
char* numberRotations = getNumberRotations();
86+
rotateToRight(numberRotations, linesArray, numOfLines);
6487
}else if(strcmp(LIMPIAR_LISTA, option) == 0){
65-
88+
cleanList(linesArray, numOfLines);
6689
}else if(strcmp(MAYOR, option) == 0){
6790

6891
}else{

kernel-data-structure-lab1/constants.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
#define CONCATENAR "--concatenar"
88
#define ROTACION "--rotacion"
99
#define LIMPIAR_LISTA "--limpiar-lista"
10-
#define MAYOR "--mayor"
10+
#define MAYOR "--mayor"
11+
#define MAX_LENGTH_CHAR_BRIDGE 100
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
aaa
2+
bbb
3+
ccc
4+
ddd
5+
eee
6+
fff
7+
ggg

kernel-data-structure-lab1/moduleImplement/bridgeLink.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <fcntl.h>
44
#include "bridgeIO.h"
55
#include "bridgeLink.h"
6+
#include "../constants.h"
67

78
int callModule(){
89
const char *file_name = "/dev/bridgeOwn"; //used by ioctl
@@ -16,7 +17,7 @@ int callModule(){
1617
}
1718

1819
void validarSimetria(char **file,int numOfLines){
19-
char test[100];
20+
char test[MAX_LENGTH_CHAR_BRIDGE];
2021
int fd = callModule();
2122
ioctl(fd, BRIDGE_W_S, "Hola este es un mensaje a la pila \n");
2223
ioctl(fd, BRIDGE_R_S, test);
@@ -30,16 +31,38 @@ void ordenInverso(char** arrayLines, int numOfLines){
3031
printf("%s",arrayLines[i]);
3132
write_message(fd, BRIDGE_W_S, arrayLines[i]);
3233
}
33-
char fileLine[100];
34+
char fileLine[MAX_LENGTH_CHAR_BRIDGE];
3435
printf("\n###### Lineas del archivo orden inverso ######\n");
3536
for (int i = 0; i < numOfLines; i++){
3637
write_message(fd, BRIDGE_R_S, fileLine);
3738
printf("%s",fileLine);
3839
}
3940
}
4041

41-
void rotateToRight(int numberRotations){
42+
void rotateToRight(char* numberRotations, char** arrayLines, int numOfLines){
43+
printf("ROTAR A LA DERECHA\n\n");
4244
int fd = callModule();
43-
write_message(fd, BRIDGE_ROTATE_L, "a");
45+
printf("Number of rotations = %s \n\n", numberRotations);
46+
for (int i = 0; i < numOfLines; i++){
47+
printf("%s", arrayLines[i]);
48+
write_message(fd, BRIDGE_W_L, arrayLines[i]);
49+
}
50+
printf("\n\n LISTA ROTADA A LA DERECHA \n\n");
51+
char valor[MAX_LENGTH_CHAR_BRIDGE];
52+
write_message(fd, BRIDGE_ROTATE_L, numberRotations);
53+
for (int i = 0; i < numOfLines; i++){
54+
write_message(fd, BRIDGE_R_L, valor);
55+
printf("%s \n", valor);
56+
}
4457
}
4558

59+
void concatTwoLists(char** firstList, int numFirstList, char** secondList, int numSecondList){
60+
int fd = callModule();
61+
char** lists[2] = {firstList, secondList};
62+
write_message(fd, BRIDGE_CONCAT_L, "");
63+
}
64+
65+
void cleanList(char** arrayLines, int numOfLines){
66+
int fd = callModule();
67+
write_message(fd, BRIDGE_CLEAN_L, "");
68+
}

kernel-data-structure-lab1/moduleImplement/bridgeLink.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ void validarSimetria(char** file, int numOfLines);
22

33
void ordenInverso(char** file, int numOfLines);
44

5-
void rotateToRight(int numberRotations);
5+
void rotateToRight(char* numberRotations, char** arrayLines, int numOfLines);
66

7-
void randomLines(char* pathFile);
7+
void randomLines(char* pathFile);
8+
9+
void concatTwoLists(char** firstList, int numFirstList, char** secondList, int numSecondList);
10+
11+
void cleanList(char** arrayLines, int numOfLines);

kernel-data-structure-lab1/utilsClientBridge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ int validateString(char* string){
1212
}
1313

1414
void killClientBridge(char* message){
15-
printf("ERROR: %s n\n", message);
15+
printf("ERROR: %s \n\n", message);
1616
exit(-1);
1717
}
1818

0 commit comments

Comments
 (0)