USBIP C library 0.7.0
Virtual USB devices & host drivers over USB/IP
Loading...
Searching...
No Matches
mtp_opts Struct Reference

MTP configuration: device identity + one or more storage backends. More...

#include <classes/mtp.h>

Data Fields

int read_only
 Nonzero -> reject host writes/deletes/edits.
 
const char * name
 Model / device friendly name.
 
const char * manufacturer
 DeviceInfo Manufacturer (may be NULL)
 
const char * serial
 32 hex chars (NULL -> a built-in default)
 
int winusb
 Nonzero -> advertise the Microsoft OS "MTP" Compatible ID.
 
int n_stores
 Number of storages exposed (entries used in stores)
 
void * stores [MTP_MAX_STORAGES]
 Per-storage backend contexts (e.g.
 
void(* listdir )(void *store, const char *path, mtp_emit emit, void *ctx)
 List a directory: call emit once per entry it contains.
 
int(* get_info )(void *store, const char *path, int *is_dir, uint64_t *size, uint32_t *mtime)
 Stat one object.
 
int(* read )(void *store, const char *path, long off, uint8_t *buf, int want)
 Read from a file.
 
int(* write )(void *store, const char *path, const uint8_t *data, int len)
 Create or overwrite a file with the given contents (whole-file write).
 
int(* make_dir )(void *store, const char *path)
 Create a directory.
 
int(* remove )(void *store, const char *path)
 Delete a file or empty directory.
 
int(* rename )(void *store, const char *path, const char *newpath)
 Rename or move an object.
 
int(* pwrite )(void *store, const char *path, long off, const uint8_t *data, int len)
 Partial in-place write (Android edit extension; may be NULL).
 
int(* truncate )(void *store, const char *path, uint64_t size)
 Truncate a file to a new length (Android edit extension; may be NULL).
 
void(* disk_usage )(void *store, uint64_t *total, uint64_t *freeb)
 Report the storage's capacity.
 
const char *(* description )(void *store)
 Storage label shown to the host (may be NULL).
 
void(* on_event )(void *user, const char *text)
 Human-readable log hook for MTP activity (may be NULL).
 
void * user
 Opaque pointer passed to on_event.
 

Detailed Description

MTP configuration: device identity + one or more storage backends.

The class implements the MTP protocol and object model but performs no filesystem access - every storage operation is delegated to the callbacks below. Each callback's first argument is the per-storage context (one of stores[]). Paths are relative and "/"-separated; the empty string "" is that storage's root. Unless noted, the int callbacks return 0 on success and a negative value on failure.

Field Documentation

◆ read_only

int mtp_opts::read_only

Nonzero -> reject host writes/deletes/edits.

◆ name

const char* mtp_opts::name

Model / device friendly name.

◆ manufacturer

const char* mtp_opts::manufacturer

DeviceInfo Manufacturer (may be NULL)

◆ serial

const char* mtp_opts::serial

32 hex chars (NULL -> a built-in default)

◆ winusb

int mtp_opts::winusb

Nonzero -> advertise the Microsoft OS "MTP" Compatible ID.

◆ n_stores

int mtp_opts::n_stores

Number of storages exposed (entries used in stores)

◆ stores

void* mtp_opts::stores[MTP_MAX_STORAGES]

Per-storage backend contexts (e.g.

a directory root)

◆ listdir

void(* mtp_opts::listdir) (void *store, const char *path, mtp_emit emit, void *ctx)

List a directory: call emit once per entry it contains.

Parameters
storethe per-storage context.
pathdirectory path ("" = storage root).
emitsink for entry names (see mtp_emit).
ctxopaque pointer to pass back to emit.

◆ get_info

int(* mtp_opts::get_info) (void *store, const char *path, int *is_dir, uint64_t *size, uint32_t *mtime)

Stat one object.

Parameters
storethe per-storage context.
pathobject path.
[out]is_dirset non-zero for a directory, 0 for a file.
[out]sizeset to the file size in bytes.
[out]mtimeset to the modification time (Unix epoch seconds).
Returns
0 if the object exists, < 0 if it is missing.

◆ read

int(* mtp_opts::read) (void *store, const char *path, long off, uint8_t *buf, int want)

Read from a file.

Parameters
storethe per-storage context.
pathfile path.
offbyte offset to read from.
bufdestination buffer.
wantmaximum number of bytes to read.
Returns
bytes read (0 at end of file), or < 0 on error.

◆ write

int(* mtp_opts::write) (void *store, const char *path, const uint8_t *data, int len)

Create or overwrite a file with the given contents (whole-file write).

Parameters
storethe per-storage context.
pathfile path.
datathe file contents.
lennumber of bytes in data.
Returns
0 on success, < 0 on error.

◆ make_dir

int(* mtp_opts::make_dir) (void *store, const char *path)

Create a directory.

Parameters
storethe per-storage context.
pathdirectory path to create.
Returns
0 on success, < 0 on error.

◆ remove

int(* mtp_opts::remove) (void *store, const char *path)

Delete a file or empty directory.

Parameters
storethe per-storage context.
pathobject path to remove.
Returns
0 on success, < 0 on error.

◆ rename

int(* mtp_opts::rename) (void *store, const char *path, const char *newpath)

Rename or move an object.

Parameters
storethe per-storage context.
pathexisting object path.
newpathnew path.
Returns
0 on success, < 0 on error.

◆ pwrite

int(* mtp_opts::pwrite) (void *store, const char *path, long off, const uint8_t *data, int len)

Partial in-place write (Android edit extension; may be NULL).

Parameters
storethe per-storage context.
pathfile path.
offbyte offset to write at.
datathe bytes to write.
lennumber of bytes in data.
Returns
0 on success, < 0 on error.

◆ truncate

int(* mtp_opts::truncate) (void *store, const char *path, uint64_t size)

Truncate a file to a new length (Android edit extension; may be NULL).

Parameters
storethe per-storage context.
pathfile path.
sizenew length in bytes.
Returns
0 on success, < 0 on error.

◆ disk_usage

void(* mtp_opts::disk_usage) (void *store, uint64_t *total, uint64_t *freeb)

Report the storage's capacity.

Parameters
storethe per-storage context.
[out]totalset to total bytes.
[out]freebset to free bytes.

◆ description

const char *(* mtp_opts::description) (void *store)

Storage label shown to the host (may be NULL).

Parameters
storethe per-storage context.
Returns
a NUL-terminated label, or NULL for a built-in default.

◆ on_event

void(* mtp_opts::on_event) (void *user, const char *text)

Human-readable log hook for MTP activity (may be NULL).

Parameters
userthe user pointer.
texta NUL-terminated description.

◆ user

void* mtp_opts::user

Opaque pointer passed to on_event.


The documentation for this struct was generated from the following file: