xref: /haiku/src/add-ons/kernel/file_systems/ntfs/libntfs/plugin.h (revision 1deede7388b04dbeec5af85cae7164735ea9e70d)
1 /*
2  *		plugin.h : define interface for plugin development
3  *
4  * Copyright (c) 2015 Jean-Pierre Andre
5  *
6  */
7 
8 /*
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program (in the main directory of the NTFS-3G
21  * distribution in the file COPYING); if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23  */
24 
25 /*
26  *	This file defines the interface to ntfs-3g plugins which
27  *	add support for processing some type of reparse points.
28  */
29 
30 #ifndef _NTFS_PLUGIN_H
31 #define _NTFS_PLUGIN_H
32 
33 #include "inode.h"
34 #include "layout.h"
35 
36 struct fuse_file_info;
37 struct stat;
38 
39 	/*
40 	 *	The plugin operations currently defined.
41 	 * These functions should return a non-negative value when they
42 	 * succeed, or a negative errno value when they fail.
43 	 * They must not close or free their arguments.
44 	 * The file system must be left in a consistent state after
45 	 * each individual call.
46 	 * If an operation is not defined, an EOPNOTSUPP error is
47 	 * returned to caller.
48 	 */
49 typedef struct plugin_operations {
50 	/*
51 	 *	Set the attributes st_size, st_blocks and st_mode
52 	 * into a struct stat. The returned st_mode must at least
53 	 * define the file type. Depending on the permissions options
54 	 * used for mounting, the umask will be applied to the returned
55 	 * permissions, or the permissions will be changed according
56 	 * to the ACL set on the file.
57 	 */
58 	int (*getattr)(ntfs_inode *ni, const REPARSE_POINT *reparse,
59 			struct stat *stbuf);
60 
61 	/*
62 	 *	Open a file for reading or writing
63 	 * The field fi->flags indicates the kind of opening.
64 	 * The field fi->fh may be used to store some information which
65 	 * will be available to subsequent reads and writes. When used
66 	 * this field must be non-null.
67 	 * The returned value is zero for success and a negative errno
68 	 * value for failure.
69 	 */
70 	int (*open)(ntfs_inode *ni, const REPARSE_POINT *reparse,
71 			struct fuse_file_info *fi);
72 
73 	/*
74 	 *	Release an open file
75 	 * This is only called if fi->fh has been set to a non-null
76 	 * value while opening. It may be used to free some context
77 	 * specific to the open file.
78 	 * The returned value is zero for success or a negative errno
79 	 * value for failure.
80 	 */
81 	int (*release)(ntfs_inode *ni, const REPARSE_POINT *reparse,
82 			struct fuse_file_info *fi);
83 
84 	/*
85 	 *	Read from an open file
86 	 * The returned value is the count of bytes which were read
87 	 * or a negative errno value for failure.
88 	 * If the returned value is positive, the access time stamp
89 	 * will be updated after the call.
90 	 */
91 	int (*read)(ntfs_inode *ni, const REPARSE_POINT *reparse,
92 			char *buf, size_t size,
93 			off_t offset, struct fuse_file_info *fi);
94 
95 	/*
96 	 *	Write to an open file
97 	 * The file system must be left consistent after each write call,
98 	 * the file itself must be at least deletable if the application
99 	 * writing to it is killed for some reason.
100 	 * The returned value is the count of bytes which were written
101 	 * or a negative errno value for failure.
102 	 * If the returned value is positive, the modified time stamp
103 	 * will be updated after the call.
104 	 */
105 	int (*write)(ntfs_inode *ni, const REPARSE_POINT *reparse,
106 			const char *buf, size_t size,
107 			off_t offset, struct fuse_file_info *fi);
108 
109 	/*
110 	 *	Get a symbolic link
111 	 * The symbolic link must be returned in an allocated buffer,
112 	 * encoded in a zero terminated multibyte string compatible
113 	 * which the locale mount option.
114 	 * The returned value is zero for success or a negative errno
115 	 * value for failure.
116 	 */
117 	int (*readlink)(ntfs_inode *ni, const REPARSE_POINT *reparse,
118 			char **pbuf);
119 
120 	/*
121 	 *	Truncate a file (shorten or append zeroes)
122 	 * The returned value is zero for success or a negative errno
123 	 * value for failure.
124 	 * If the returned value is zero, the modified time stamp
125 	 * will be updated after the call.
126 	 */
127 	int (*truncate)(ntfs_inode *ni, const REPARSE_POINT *reparse,
128 			off_t size);
129 } plugin_operations_t;
130 
131 
132 /*
133  *		Plugin initialization routine
134  *	Returns the entry table if successful, otherwise returns NULL
135  *	and sets errno (e.g. to EINVAL if the tag is not supported by
136  *	the plugin.)
137  */
138 typedef const struct plugin_operations *(*plugin_init_t)(le32 tag);
139 const struct plugin_operations *init(le32 tag);
140 
141 #endif /* _NTFS_PLUGIN_H */
142