ev3duder  0.3.0
EV3 Downloader/Uploader
mkdir.c
Go to the documentation of this file.
1 
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <errno.h>
11 
12 #include "ev3_io.h"
13 
14 #include "defs.h"
15 #include "packets.h"
16 #include "error.h"
17 #include "funcs.h"
18 
29 int mkdir(const char *path)
30 {
31  int res;
32  size_t path_sz = strlen(path) + 1;
33  CREATE_DIR *mk = packet_alloc(CREATE_DIR, path_sz);
34  memcpy(mk->path, path, path_sz);
35 
36  res = ev3_write(handle, (u8 *)mk, mk->packetLen + PREFIX_SIZE);
37  if (res < 0) {
38  errmsg = "Unable to write CREATE_DIR.";
39  return ERR_COMM;
40  }
41  fputs("Checking reply: \n", stderr);
42  CREATE_DIR_REPLY mkrep;
43 
44  res = ev3_read_timeout(handle, (u8 *)&mkrep, sizeof mkrep, TIMEOUT);
45  if (res <= 0)
46  {
47  errmsg = "Unable to read CREATE_DIR_REPLY";
48  return ERR_COMM;
49  }
50 
51  if (mkrep.type == VM_ERROR)
52  {
53  errno = mkrep.ret;
54  fputs("Operation failed.\nlast_reply=", stderr);
55  print_bytes(&mkrep, mkrep.packetLen);
56 
57 
58  errmsg = "`CREATE_DIR` was denied.";
59  return ERR_VM;
60  }
61 
62  errmsg = "`CREATE_DIR` was successful.";
63  return ERR_UNK;
64 }
65 
EV3_COMMAND_FIELDS u8 path[]
Definition: packets.h:233
EXTERN void * handle
Definition: ev3_io.h:17
Definition: error.h:20
Error enumerations and decriptions.
#define print_bytes(buf, len)
Definition: defs.h:34
create directory
Definition: packets.h:228
#define packet_alloc(type, extra)
Definition: packets.h:328
EXTERN int(* ev3_read_timeout)(void *, u8 *, size_t, int milliseconds)
Definition: ev3_io.h:14
#define TIMEOUT
Definition: defs.h:46
packed structs for the packets.
base packet for SYSTEM REPLIES
Definition: packets.h:72
Definition: error.h:20
uint8_t u8
Definition: defs.h:9
Definition: error.h:20
Definition: error.h:22
EXTERN const char * errmsg
global variable for last error message
Definition: error.h:25
contains declarations for ev3 commands
EXTERN int(* ev3_write)(void *, const u8 *, size_t)
Definition: ev3_io.h:13
int mkdir(const char *path)
creates directory structures relative to /home/root/lms2012/prjs/sys/
Definition: mkdir.c:29
#define PREFIX_SIZE
Definition: packets.h:54