Skip to content

Commit a91635d

Browse files
authored
Merge pull request #12 from grupoudea/develop
Develop
2 parents cc91b67 + ef6b2f3 commit a91635d

File tree

17 files changed

+173
-19
lines changed

17 files changed

+173
-19
lines changed

kernel-data-structure-lab1/README.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,43 @@ Esta práctica también nos permitirá aprender a utilizar ciertas funciones que
1919

2020
## Commands
2121

22+
### Other way to compile module bridgeOwn and clientBridge
23+
24+
firstly, go to the folder /**kernel-data-structure-lab1** inside the project, run the command **sudo ./scripts/run_it_run**, this command will create symbolic links or just links to access in an easier way to commands like: bridge_load, bridge_reset also to clientBridge executable easier.
25+
26+
Now, if you want execute clientBridge you just to write:
27+
28+
```sh
29+
sudo clientBridge
30+
```
31+
32+
Here, command list:
33+
34+
```sh
35+
sudo bridge_status
36+
```
37+
=> show if the module is on.
38+
```sh
39+
sudo bridge_load
40+
```
41+
=> load the module.
42+
```sh
43+
sudo bridge_reset
44+
```
45+
=> reset the module, but before, unload the module, it execute the make command and finally load the module again.
46+
```sh
47+
sudo bridge_syslog_clean
48+
```
49+
=> clean the syslog in /var/log/syslog. Don't worry it will make a backup.
50+
51+
```sh
52+
sudo compile_client
53+
```
54+
=> compile the clientBridge from **kernel-data-structure-lab1** only. It will replace with Makefile in future versions.
55+
56+
Note: Some of these commands work just if you are in the **kernel-data-structure-lab1** path in his terminal or console.
57+
58+
2259

2360
### To compile module bridgeOwn
2461

@@ -33,9 +70,6 @@ make
3370
### To compile client
3471

3572
```sh
36-
gcc -o clientBridge clientBridge.c
37-
38-
gcc -o clientBridge clientBridge.c utilsClientBridge.c
3973

4074
gcc -o clientBridge clientBridge.c utilsClientBridge.c moduleImplement/bridgeLink.c moduleImplement/bridgeIO.c
4175

kernel-data-structure-lab1/bridgeOwn.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static long bridge_ioctl(struct file *f, unsigned int cmd, unsigned long arg){
118118
break;
119119
case BRIDGE_W_L:
120120
raw_copy_from_user(message, (char *)arg, 100);
121-
printk(KERN_INFO "AGREGANDO ELEMENTO A LA LISTA STACK: message = %s\n", message);
121+
//printk(KERN_INFO "AGREGANDO ELEMENTO A LA LISTA STACK: message = %s\n", message);
122122
add_element_to_stack(message, &stack);
123123
break;
124124
case BRIDGE_R_L:
@@ -172,6 +172,26 @@ static long bridge_ioctl(struct file *f, unsigned int cmd, unsigned long arg){
172172
case BRIDGE_STATE_L:
173173
printk(KERN_INFO "message %s\n", "bla23");
174174
break;
175+
case BRIDGE_RANDOM_L:
176+
printk(KERN_INFO "------------ BRIDGE_RANDOM_L REVOLVER LA LISTA \n");
177+
long numberRandom;
178+
raw_copy_from_user(message, (char* )arg, 20);
179+
kstrtol(message, 10, &numberRandom);
180+
printk(KERN_INFO "message BRIDGE_RANDOM_L numberRandom = %d\n", numberRandom);
181+
printk(KERN_INFO "------------------------------------------------------------------\n\n");
182+
int iteratorRandom = 0;
183+
184+
struct string_node *tmp_element;
185+
struct list_head *watch, *next;
186+
list_for_each_safe(watch, next, &stack){
187+
tmp_element = list_entry(watch, struct string_node, list);
188+
if(numberRandom>0 && iteratorRandom == numberRandom){
189+
list_swap(watch, watch->next);
190+
break;
191+
}
192+
iteratorRandom++;
193+
}
194+
break;
175195
case BRIDGE_DESTROY_L:
176196
printk(KERN_INFO "message %s\n", "bla24");
177197
}

kernel-data-structure-lab1/bridgeOwn.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#define BRIDGE_CONCAT_L _IO('p', 23)
3737
#define BRIDGE_STATE_L _IO('p', 24)
3838
#define BRIDGE_DESTROY_L _IO('p', 25)
39+
#define BRIDGE_RANDOM_L _IO('p', 26)
40+
3941

4042
#include <linux/list.h>
4143

kernel-data-structure-lab1/bridge_reset

Lines changed: 0 additions & 7 deletions
This file was deleted.

kernel-data-structure-lab1/clientBridge.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ void chooseOption(char* option){
6666
ordenInverso(linesArray, numOfLines);
6767

6868
}else if(strcmp(RANDOM, option) == 0){
69+
randomLines(linesArray, numOfLines, pathfile);
6970

7071
}else if(strcmp(VALIDAR_SIMETRIA, option) == 0){
71-
validarSimetria(linesArray, numOfLines);
72+
validarSimetria(linesArray, numOfLines);
7273

7374
}else if(strcmp(COLA_PRIORIDAD, option) == 0){
7475

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ void write_message(int fd, unsigned long command, char * message){
88
}
99
}
1010

11+
void write_message_array(int fd, unsigned long command, char** message){
12+
if (ioctl(fd, command, message) == -1){
13+
perror("Write message error at ioctl");
14+
}
15+
}
16+
1117
void read_message(int fd, unsigned long command, char * message){
1218
if(ioctl(fd, command, message) == -1){
1319
perror("Read message error at ioctl");
@@ -54,10 +60,10 @@ void write_several_messages(int fd){
5460
write_message(fd, BRIDGE_W_S, "Message 3");
5561
}
5662

57-
void read_all_messages(int fd){
63+
void read_all_messages(int fd, unsigned long command){
5864
char message[100];
5965
while( send_empty_command(fd, BRIDGE_STATE_S) > 0){
60-
read_message(fd, BRIDGE_R_S, message);
66+
read_message(fd, command, message);
6167
printf("Message: %s\n", message);
6268
}
6369
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#define BRIDGE_CONCAT_L _IO('p', 23)
3232
#define BRIDGE_STATE_L _IO('p', 24)
3333
#define BRIDGE_DESTROY_L _IO('p', 25)
34+
#define BRIDGE_RANDOM_L _IO('p', 26)
35+
3436

3537
#endif
3638

@@ -44,4 +46,4 @@ void read_int(int fd, unsigned long command, int * value);
4446

4547
int send_empty_command(int fd, unsigned long command);
4648
void write_several_messages(int fd);
47-
void read_all_messages(int fd);
49+
void read_all_messages(int fd, unsigned long command);

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include <stdio.h>
22
#include <sys/ioctl.h>
33
#include <fcntl.h>
4+
#include <stdlib.h>
5+
#include <time.h>
46
#include "bridgeIO.h"
57
#include "bridgeLink.h"
68
#include "../constants.h"
@@ -39,6 +41,42 @@ void ordenInverso(char** arrayLines, int numOfLines){
3941
}
4042
}
4143

44+
int randomNumber(int maxNumber, int seed){
45+
int time1 = time(NULL)-((seed+1)*RAND_MAX);
46+
srand(time1);// numero aleatorio entre 0 y maxNumber
47+
int numberGenerate = (rand() % maxNumber);
48+
return numberGenerate;
49+
}
50+
51+
52+
void randomLines(char** arrayLines, const int numOfLines, char* fileName){
53+
int fd = callModule();
54+
55+
for (int i = 0; i < numOfLines; i++){
56+
write_message(fd, BRIDGE_W_L, arrayLines[i]);
57+
}
58+
59+
if(numOfLines>=2){
60+
int maxRandom = numOfLines;
61+
if(numOfLines==2){
62+
maxRandom = 2;
63+
}
64+
for (int i = 0; i < maxRandom; i++){
65+
int randomNumberInt = randomNumber(maxRandom,(i));
66+
char randomNumberChar[20];
67+
sprintf(randomNumberChar, "%d", randomNumberInt);
68+
write_message(fd, BRIDGE_RANDOM_L, randomNumberChar);
69+
}
70+
}
71+
72+
char fileLine[MAX_LENGTH_CHAR_BRIDGE];
73+
for (int i = 0; i < numOfLines; i++){
74+
write_message(fd, BRIDGE_R_L, fileLine);
75+
printf("Random Lines: %s\n",fileLine);
76+
}
77+
78+
}
79+
4280
void rotateToRight(char* numberRotations, char** arrayLines, int numOfLines){
4381
printf("ROTAR A LA DERECHA\n\n");
4482
int fd = callModule();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ void ordenInverso(char** file, int numOfLines);
44

55
void rotateToRight(char* numberRotations, char** arrayLines, int numOfLines);
66

7-
void randomLines(char* pathFile);
7+
void randomLines(char** arrayLines, int numOfLines, char* fileName);
88

99
void concatTwoLists(char** firstList, int numFirstList, char** secondList, int numSecondList);
1010

11-
void cleanList(char** arrayLines, int numOfLines);
11+
void cleanList(char** arrayLines, int numOfLines);

kernel-data-structure-lab1/bridge_load renamed to kernel-data-structure-lab1/scripts/bridge_load

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ group="sudo"
88
echo " Loading module from Load Script"
99
# invoke insmod with all arguments we got
1010
# and use a pathname, as insmod doesn't look in . by default
11-
/sbin/insmod ./$module.ko $* || exit 1
11+
/sbin/insmod ../$module.ko $* || exit 1
1212

1313
# retrieve major number
1414
major=$(awk "\$2==\"$module\" {print \$1}" /proc/devices)

0 commit comments

Comments
 (0)