Skip to content

New file_io messages #183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 70 additions & 21 deletions c/include/libsbp/file_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,75 @@
#include "common.h"


/** Read file from the file system (host <=> device)
/** Read file from the file system (host => device)
*
* The file read message reads a certain length (up to 255 bytes)
* from a given offset into a file, and returns the data in a
* MSG_FILEIO_READ message where the message length field indicates
* how many bytes were succesfully read. If the message is invalid,
* a followup MSG_PRINT message will print "Invalid fileio read
* message".
* MSG_FILEIO_READ_RESPONSE message where the message length field
* indicates how many bytes were succesfully read. If the message is
* invalid, a followup MSG_PRINT message will print "Invalid fileio
* read message".
*/
#define SBP_MSG_FILEIO_READ 0x00A8
#define SBP_MSG_FILEIO_READ_REQUEST 0x00A8
typedef struct __attribute__((packed)) {
u32 offset; /**< File offset [bytes] */
u8 chunk_size; /**< Chunk size to read [bytes] */
char filename[20]; /**< Name of the file to read from (NULL padded) */
} msg_fileio_read_t;
} msg_fileio_read_request_t;


/** File read from the file system (host <= device)
*
* The file read message reads a certain length (up to 255 bytes)
* from a given offset into a file, and returns the data in a
* message where the message length field indicates how many bytes
* were succesfully read.
*/
#define SBP_MSG_FILEIO_READ_RESPONSE 0x00A3
typedef struct __attribute__((packed)) {
u32 offset; /**< File offset [bytes] */
u8 chunk_size; /**< Chunk size read [bytes] */
char filename[20]; /**< Name of the file read from (NULL padded) */
u8 contents[0]; /**< Contents of read file */
} msg_fileio_read_response_t;


/** List files in a directory (host <=> device)
/** List files in a directory (host => device)
*
* The read directory message lists the files in a directory on the
* device's onboard flash file system. The offset parameter can be
* used to skip the first n elements of the file list. Returns a
* MSG_FILEIO_READ_DIR message containing the directory listings as
* a NULL delimited list. The listing is chunked over multiple SBP
* packets and the end of the list is identified by an entry
* containing just the character 0xFF. If message is invalid, a
* MSG_FILEIO_READ_DIR_RESPONSE message containing the directory
* listings as a NULL delimited list. The listing is chunked over
* multiple SBP packets and the end of the list is identified by an
* entry containing just the character 0xFF. If message is invalid, a
* followup MSG_PRINT message will print "Invalid fileio read
* message".
*/
#define SBP_MSG_FILEIO_READ_DIR 0x00A9
#define SBP_MSG_FILEIO_READ_DIR_REQUEST 0x00A9
typedef struct __attribute__((packed)) {
u32 offset; /**< The offset to skip the first n elements of the file list
*/
char dirname[20]; /**< Name of the directory to list (NULL padded) */
} msg_fileio_read_dir_t;
} msg_fileio_read_dir_request_t;


/** Files listed in a directory (host <= device)
*
* The read directory message lists the files in a directory on the
* device's onboard flash file system. The offset parameter can be
* used to skip the first n elements of the file list. Message contains
* the directory listings as a NULL delimited list. The listing is
* chunked over multiple SBP packets and the end of the list is
* identified by an entry containing just the character 0xFF.
*/
#define SBP_MSG_FILEIO_READ_DIR_RESPONSE 0x00AA
typedef struct __attribute__((packed)) {
u32 offset; /**< The offset to skip the first n elements of the file list
*/
char dirname[20]; /**< Name of the directory to list (NULL padded) */
u8 contents[0]; /**< Contents of read directory */
} msg_fileio_read_dir_response_t;


/** Delete a file from the file system (host => device)
Expand All @@ -78,26 +112,41 @@ typedef struct __attribute__((packed)) {
* message is invalid, a followup MSG_PRINT message will print
* "Invalid fileio remove message".
*/
#define SBP_MSG_FILEIO_REMOVE 0x00AC
#define SBP_MSG_FILEIO_REMOVE 0x00AC
typedef struct __attribute__((packed)) {
char filename[20]; /**< Name of the file to delete (NULL padded) */
} msg_fileio_remove_t;


/** Write to file (host <=> device)
/** Write to file (host => device)
*
* The file write message writes a certain length (up to 255 bytes)
* of data to a file at a given offset. Returns a copy of the
* original MSG_FILEIO_WRITE message to check integrity of the
* write. If message is invalid, a followup MSG_PRINT message will
* print "Invalid fileio write message".
* original MSG_FILEIO_WRITE_RESPONSE message to check integrity of
* the write. If message is invalid, a followup MSG_PRINT message
* will print "Invalid fileio write message".
*/
#define SBP_MSG_FILEIO_WRITE_REQUEST 0x00AD
typedef struct __attribute__((packed)) {
char filename[20]; /**< Name of the file to write to (NULL padded) */
u32 offset; /**< Offset into the file at which to start writing in bytes [bytes] */
u8 data[0]; /**< Variable-length array of data to write */
} msg_fileio_write_request_t;


/** File written to (host <= device)
*
* The file write message writes a certain length (up to 255 bytes)
* of data to a file at a given offset. The message is a copy of the
* original MSG_FILEIO_WRITE_REQUEST message to check integrity of the
* write.
*/
#define SBP_MSG_FILEIO_WRITE 0x00AD
#define SBP_MSG_FILEIO_WRITE_RESPONSE 0x00AB
typedef struct __attribute__((packed)) {
char filename[20]; /**< Name of the file to write to (NULL padded) */
u32 offset; /**< Offset into the file at which to start writing in bytes [bytes] */
u8 data[0]; /**< Variable-length array of data to write */
} msg_fileio_write_t;
} msg_fileio_write_response_t;


/** \} */
Expand Down
4 changes: 2 additions & 2 deletions c/include/libsbp/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
/** Protocol major version. */
#define SBP_MAJOR_VERSION 0
/** Protocol minor version. */
#define SBP_MINOR_VERSION 45
#define SBP_MINOR_VERSION 47

/** \} */


#endif /* LIBSBP_VERSION_H */
#endif /* LIBSBP_VERSION_H */
Loading