#include <linux/blkdev.h>
#include <linux/completion.h>
#include <linux/dcache.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/fcntl.h>
#include <linux/file.h>
#include <linux/fs.h>
#include <linux/kstrtox.h>
#include <linux/kthread.h>
#include <linux/sched/signal.h>
#include <linux/limits.h>
#include <linux/pagemap.h>
#include <linux/rwsem.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/string.h>
#include <linux/freezer.h>
#include <linux/module.h>
#include <linux/uaccess.h>
#include <linux/unaligned.h>
#include <linux/usb/ch9.h>
#include <linux/usb/gadget.h>
#include <linux/usb/composite.h>
#include <linux/nospec.h>
#include "configfs.h"
#define FSG_DRIVER_DESC …
#define FSG_DRIVER_VERSION …
static const char fsg_string_interface[] = …;
#include "storage_common.h"
#include "f_mass_storage.h"
static struct usb_string fsg_strings[] = …;
static struct usb_gadget_strings fsg_stringtab = …;
static struct usb_gadget_strings *fsg_strings_array[] = …;
struct fsg_dev;
struct fsg_common;
struct fsg_common { … };
struct fsg_dev { … };
static inline int __fsg_is_set(struct fsg_common *common,
const char *func, unsigned line)
{ … }
#define fsg_is_set(common) …
static inline struct fsg_dev *fsg_from_func(struct usb_function *f)
{ … }
static int exception_in_progress(struct fsg_common *common)
{ … }
static void set_bulk_out_req_length(struct fsg_common *common,
struct fsg_buffhd *bh, unsigned int length)
{ … }
static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep)
{ … }
static void __raise_exception(struct fsg_common *common, enum fsg_state new_state,
void *arg)
{ … }
static void raise_exception(struct fsg_common *common, enum fsg_state new_state)
{ … }
static int ep0_queue(struct fsg_common *common)
{ … }
static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req)
{ … }
static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req)
{ … }
static int _fsg_common_get_max_lun(struct fsg_common *common)
{ … }
static int fsg_setup(struct usb_function *f,
const struct usb_ctrlrequest *ctrl)
{ … }
static int start_transfer(struct fsg_dev *fsg, struct usb_ep *ep,
struct usb_request *req)
{ … }
static bool start_in_transfer(struct fsg_common *common, struct fsg_buffhd *bh)
{ … }
static bool start_out_transfer(struct fsg_common *common, struct fsg_buffhd *bh)
{ … }
static int sleep_thread(struct fsg_common *common, bool can_freeze,
struct fsg_buffhd *bh)
{ … }
static int do_read(struct fsg_common *common)
{ … }
static int do_write(struct fsg_common *common)
{ … }
static int do_synchronize_cache(struct fsg_common *common)
{ … }
static void invalidate_sub(struct fsg_lun *curlun)
{ … }
static int do_verify(struct fsg_common *common)
{ … }
static int do_inquiry(struct fsg_common *common, struct fsg_buffhd *bh)
{ … }
static int do_request_sense(struct fsg_common *common, struct fsg_buffhd *bh)
{ … }
static int do_read_capacity(struct fsg_common *common, struct fsg_buffhd *bh)
{ … }
static int do_read_capacity_16(struct fsg_common *common, struct fsg_buffhd *bh)
{ … }
static int do_read_header(struct fsg_common *common, struct fsg_buffhd *bh)
{ … }
static int do_read_toc(struct fsg_common *common, struct fsg_buffhd *bh)
{ … }
static int do_mode_sense(struct fsg_common *common, struct fsg_buffhd *bh)
{ … }
static int do_start_stop(struct fsg_common *common)
{ … }
static int do_prevent_allow(struct fsg_common *common)
{ … }
static int do_read_format_capacities(struct fsg_common *common,
struct fsg_buffhd *bh)
{ … }
static int do_mode_select(struct fsg_common *common, struct fsg_buffhd *bh)
{ … }
static int halt_bulk_in_endpoint(struct fsg_dev *fsg)
{ … }
static int wedge_bulk_in_endpoint(struct fsg_dev *fsg)
{ … }
static int throw_away_data(struct fsg_common *common)
{ … }
static int finish_reply(struct fsg_common *common)
{ … }
static void send_status(struct fsg_common *common)
{ … }
static int check_command(struct fsg_common *common, int cmnd_size,
enum data_direction data_dir, unsigned int mask,
int needs_medium, const char *name)
{ … }
static int check_command_size_in_blocks(struct fsg_common *common,
int cmnd_size, enum data_direction data_dir,
unsigned int mask, int needs_medium, const char *name)
{ … }
static int do_scsi_command(struct fsg_common *common)
{ … }
static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
{ … }
static int get_next_command(struct fsg_common *common)
{ … }
static int alloc_request(struct fsg_common *common, struct usb_ep *ep,
struct usb_request **preq)
{ … }
static int do_set_interface(struct fsg_common *common, struct fsg_dev *new_fsg)
{ … }
static int fsg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
{ … }
static void fsg_disable(struct usb_function *f)
{ … }
static void handle_exception(struct fsg_common *common)
{ … }
static int fsg_main_thread(void *common_)
{ … }
static ssize_t ro_show(struct device *dev, struct device_attribute *attr, char *buf)
{ … }
static ssize_t nofua_show(struct device *dev, struct device_attribute *attr,
char *buf)
{ … }
static ssize_t file_show(struct device *dev, struct device_attribute *attr,
char *buf)
{ … }
static ssize_t ro_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{ … }
static ssize_t nofua_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{ … }
static ssize_t file_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{ … }
static ssize_t forced_eject_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{ … }
static DEVICE_ATTR_RW(nofua);
static DEVICE_ATTR_WO(forced_eject);
static DEVICE_ATTR_RW(ro);
static DEVICE_ATTR_RW(file);
static void fsg_lun_release(struct device *dev)
{ … }
static struct fsg_common *fsg_common_setup(struct fsg_common *common)
{ … }
void fsg_common_set_sysfs(struct fsg_common *common, bool sysfs)
{ … }
EXPORT_SYMBOL_GPL(…);
static void _fsg_common_free_buffers(struct fsg_buffhd *buffhds, unsigned n)
{ … }
int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n)
{ … }
EXPORT_SYMBOL_GPL(…);
void fsg_common_remove_lun(struct fsg_lun *lun)
{ … }
EXPORT_SYMBOL_GPL(…);
static void _fsg_common_remove_luns(struct fsg_common *common, int n)
{ … }
void fsg_common_remove_luns(struct fsg_common *common)
{ … }
EXPORT_SYMBOL_GPL(…);
void fsg_common_free_buffers(struct fsg_common *common)
{ … }
EXPORT_SYMBOL_GPL(…);
int fsg_common_set_cdev(struct fsg_common *common,
struct usb_composite_dev *cdev, bool can_stall)
{ … }
EXPORT_SYMBOL_GPL(…);
static struct attribute *fsg_lun_dev_attrs[] = …;
static umode_t fsg_lun_dev_is_visible(struct kobject *kobj,
struct attribute *attr, int idx)
{ … }
static const struct attribute_group fsg_lun_dev_group = …;
static const struct attribute_group *fsg_lun_dev_groups[] = …;
int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg,
unsigned int id, const char *name,
const char **name_pfx)
{ … }
EXPORT_SYMBOL_GPL(…);
int fsg_common_create_luns(struct fsg_common *common, struct fsg_config *cfg)
{ … }
EXPORT_SYMBOL_GPL(…);
void fsg_common_set_inquiry_string(struct fsg_common *common, const char *vn,
const char *pn)
{ … }
EXPORT_SYMBOL_GPL(…);
static void fsg_common_release(struct fsg_common *common)
{ … }
static int fsg_bind(struct usb_configuration *c, struct usb_function *f)
{ … }
static void fsg_unbind(struct usb_configuration *c, struct usb_function *f)
{ … }
static inline struct fsg_lun_opts *to_fsg_lun_opts(struct config_item *item)
{ … }
static inline struct fsg_opts *to_fsg_opts(struct config_item *item)
{ … }
static void fsg_lun_attr_release(struct config_item *item)
{ … }
static struct configfs_item_operations fsg_lun_item_ops = …;
static ssize_t fsg_lun_opts_file_show(struct config_item *item, char *page)
{ … }
static ssize_t fsg_lun_opts_file_store(struct config_item *item,
const char *page, size_t len)
{ … }
CONFIGFS_ATTR(…);
static ssize_t fsg_lun_opts_ro_show(struct config_item *item, char *page)
{ … }
static ssize_t fsg_lun_opts_ro_store(struct config_item *item,
const char *page, size_t len)
{ … }
CONFIGFS_ATTR(…);
static ssize_t fsg_lun_opts_removable_show(struct config_item *item,
char *page)
{ … }
static ssize_t fsg_lun_opts_removable_store(struct config_item *item,
const char *page, size_t len)
{ … }
CONFIGFS_ATTR(…);
static ssize_t fsg_lun_opts_cdrom_show(struct config_item *item, char *page)
{ … }
static ssize_t fsg_lun_opts_cdrom_store(struct config_item *item,
const char *page, size_t len)
{ … }
CONFIGFS_ATTR(…);
static ssize_t fsg_lun_opts_nofua_show(struct config_item *item, char *page)
{ … }
static ssize_t fsg_lun_opts_nofua_store(struct config_item *item,
const char *page, size_t len)
{ … }
CONFIGFS_ATTR(…);
static ssize_t fsg_lun_opts_inquiry_string_show(struct config_item *item,
char *page)
{ … }
static ssize_t fsg_lun_opts_inquiry_string_store(struct config_item *item,
const char *page, size_t len)
{ … }
CONFIGFS_ATTR(…);
static ssize_t fsg_lun_opts_forced_eject_store(struct config_item *item,
const char *page, size_t len)
{ … }
CONFIGFS_ATTR_WO(…);
static struct configfs_attribute *fsg_lun_attrs[] = …;
static const struct config_item_type fsg_lun_type = …;
static struct config_group *fsg_lun_make(struct config_group *group,
const char *name)
{ … }
static void fsg_lun_drop(struct config_group *group, struct config_item *item)
{ … }
static void fsg_attr_release(struct config_item *item)
{ … }
static struct configfs_item_operations fsg_item_ops = …;
static ssize_t fsg_opts_stall_show(struct config_item *item, char *page)
{ … }
static ssize_t fsg_opts_stall_store(struct config_item *item, const char *page,
size_t len)
{ … }
CONFIGFS_ATTR(…);
#ifdef CONFIG_USB_GADGET_DEBUG_FILES
static ssize_t fsg_opts_num_buffers_show(struct config_item *item, char *page)
{ … }
static ssize_t fsg_opts_num_buffers_store(struct config_item *item,
const char *page, size_t len)
{ … }
CONFIGFS_ATTR(…);
#endif
static struct configfs_attribute *fsg_attrs[] = …;
static struct configfs_group_operations fsg_group_ops = …;
static const struct config_item_type fsg_func_type = …;
static void fsg_free_inst(struct usb_function_instance *fi)
{ … }
static struct usb_function_instance *fsg_alloc_inst(void)
{ … }
static void fsg_free(struct usb_function *f)
{ … }
static struct usb_function *fsg_alloc(struct usb_function_instance *fi)
{ … }
DECLARE_USB_FUNCTION_INIT(mass_storage, fsg_alloc_inst, fsg_alloc);
MODULE_DESCRIPTION(…) …;
MODULE_LICENSE(…) …;
MODULE_AUTHOR(…) …;
void fsg_config_from_params(struct fsg_config *cfg,
const struct fsg_module_parameters *params,
unsigned int fsg_num_buffers)
{ … }
EXPORT_SYMBOL_GPL(…);