summaryrefslogtreecommitdiffstats
path: root/drivers/block/loop/loop_file_fmt.h
blob: 208c8f7cbc316410beb23d89886c18c3ca523e93 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* 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