summaryrefslogblamecommitdiffstats
path: root/drivers/block/loop/loop_file_fmt.h
blob: 208c8f7cbc316410beb23d89886c18c3ca523e93 (plain) (tree)
1
2
3
4
5
6
7





                                                    
                                                                    
























                                                                     
                                                    
 

                                                             
 


                                                         
                                



                                      



















                                                                   

                                                                 











                                                                   

                                                             
                          
                           















                                                                              

                                                           












                                                                


                                                                      

                                                             
                                                       

                                       
                                                          


                                                             
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * loop_file_fmt.h
 *
 * File format subsystem for the loop device module.
 *
 * Copyright (C) 2019 Manuel Bentele <development@manuel-bentele.de>
 */

#ifndef _LINUX_LOOP_FILE_FMT_H
#define _LINUX_LOOP_FILE_FMT_H

#include "loop_main.h"

struct loop_file_fmt;

/* data structure representing the file format subsystem interface */
struct loop_file_fmt_ops {
	int (*init) (struct loop_file_fmt *lo_fmt);
	void (*exit) (struct loop_file_fmt *lo_fmt);

	int (*read) (struct loop_file_fmt *lo_fmt,
		     struct request *rq);
	int (*write) (struct loop_file_fmt *lo_fmt,
		      struct request *rq);
	int (*read_aio) (struct loop_file_fmt *lo_fmt,
			 struct request *rq);
	int (*write_aio) (struct loop_file_fmt *lo_fmt,
			  struct request *rq);
	int (*discard) (struct loop_file_fmt *lo_fmt,
			struct request *rq);

	int (*flush) (struct loop_file_fmt *lo_fmt);

	loff_t (*sector_size) (struct loop_file_fmt *lo_fmt);
};

/* data structure for implementing file format drivers */
struct loop_file_fmt_driver {
	const char *name;
	const u32 file_fmt_type;
	struct loop_file_fmt_ops *ops;
	struct module *owner;
};

/*
 * states of the file format
 *
 * transitions:
 *                    loop_file_fmt_init(...)
 * ---> uninitialized ------------------------------> initialized
 *                    loop_file_fmt_exit(...)
 *      initialized   ------------------------------> uninitialized
 *                    loop_file_fmt_read(...)
 *      initialized   ------------------------------> initialized
 *                    loop_file_fmt_read_aio(...)
 *      initialized   ------------------------------> initialized
 *                    loop_file_fmt_write(...)
 *      initialized   ------------------------------> initialized
 *                    loop_file_fmt_write_aio(...)
 *      initialized   ------------------------------> initialized
 *                    loop_file_fmt_discard(...)
 *      initialized   ------------------------------> initialized
 *                    loop_file_fmt_flush(...)
 *      initialized   ------------------------------> initialized
 *                    loop_file_fmt_sector_size(...)
 *      initialized   ------------------------------> initialized
 *
 *                    loop_file_fmt_change(...)
 *    +-----------------------------------------------------------+
 *    |               exit(...)              init(...)            |
 *    | initialized   -------> uninitialized -------> initialized |
 *    +-----------------------------------------------------------+
 */
enum {
	file_fmt_uninitialized = 0,
	file_fmt_initialized
};

/* data structure for using with the file format subsystem */
struct loop_file_fmt {
	u32 file_fmt_type;
	int file_fmt_state;
	struct loop_device *lo;
	void *private_data;
};

/* subsystem functions for the driver implementation */
extern int loop_file_fmt_register_driver(struct loop_file_fmt_driver *drv);
extern void loop_file_fmt_unregister_driver(struct loop_file_fmt_driver *drv);

/* subsystem functions for subsystem usage */
extern struct loop_file_fmt *loop_file_fmt_alloc(void);
extern void loop_file_fmt_free(struct loop_file_fmt *lo_fmt);

extern int loop_file_fmt_set_lo(struct loop_file_fmt *lo_fmt,
				struct loop_device *lo);
extern struct loop_device *loop_file_fmt_get_lo(struct loop_file_fmt *lo_fmt);

extern int loop_file_fmt_init(struct loop_file_fmt *lo_fmt,
			      u32 file_fmt_type);
extern void loop_file_fmt_exit(struct loop_file_fmt *lo_fmt);

extern int loop_file_fmt_read(struct loop_file_fmt *lo_fmt,
			      struct request *rq);
extern int loop_file_fmt_read_aio(struct loop_file_fmt *lo_fmt,
				  struct request *rq);
extern int loop_file_fmt_write(struct loop_file_fmt *lo_fmt,
			       struct request *rq);
extern int loop_file_fmt_write_aio(struct loop_file_fmt *lo_fmt,
				   struct request *rq);
extern int loop_file_fmt_discard(struct loop_file_fmt *lo_fmt,
				 struct request *rq);

extern int loop_file_fmt_flush(struct loop_file_fmt *lo_fmt);

extern loff_t loop_file_fmt_sector_size(struct loop_file_fmt *lo_fmt);

extern int loop_file_fmt_change(struct loop_file_fmt *lo_fmt,
				u32 file_fmt_type_new);

/* helper functions of the subsystem */
extern ssize_t loop_file_fmt_print_type(u32 file_fmt_type,
					char *file_fmt_name);

#endif