• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *		plugin.h : define interface for plugin development
3  *
4  * Copyright (c) 2015-2021 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 "layout.h"
34 #include "inode.h"
35 #include "dir.h"
36 
37 struct fuse_file_info;
38 struct stat;
39 
40 	/*
41 	 *	The plugin operations currently defined.
42 	 * These functions should return a non-negative value when they
43 	 * succeed, or a negative errno value when they fail.
44 	 * They must not close or free their arguments.
45 	 * The file system must be left in a consistent state after
46 	 * each individual call.
47 	 * If an operation is not defined, an EOPNOTSUPP error is
48 	 * returned to caller.
49 	 */
50 typedef struct plugin_operations {
51 	/*
52 	 *	Set the attributes st_size, st_blocks and st_mode
53 	 * into a struct stat. The returned st_mode must at least
54 	 * define the file type. Depending on the permissions options
55 	 * used for mounting, the umask will be applied to the returned
56 	 * permissions, or the permissions will be changed according
57 	 * to the ACL set on the file.
58 	 */
59 	int (*getattr)(ntfs_inode *ni, const REPARSE_POINT *reparse,
60 			struct stat *stbuf);
61 
62 	/*
63 	 *	Open a file for reading or writing
64 	 * The field fi->flags indicates the kind of opening.
65 	 * The field fi->fh may be used to store some information which
66 	 * will be available to subsequent reads and writes. When used
67 	 * this field must be non-null.
68 	 * The returned value is zero for success and a negative errno
69 	 * value for failure.
70 	 */
71 	int (*open)(ntfs_inode *ni, const REPARSE_POINT *reparse,
72 			struct fuse_file_info *fi);
73 
74 	/*
75 	 *	Release an open file or directory
76 	 * This is only called if fi->fh has been set to a non-null
77 	 * value while opening. It may be used to free some context
78 	 * specific to the open file or directory
79 	 * The returned value is zero for success or a negative errno
80 	 * value for failure.
81 	 */
82 	int (*release)(ntfs_inode *ni, const REPARSE_POINT *reparse,
83 			struct fuse_file_info *fi);
84 
85 	/*
86 	 *	Read from an open file
87 	 * The returned value is the count of bytes which were read
88 	 * or a negative errno value for failure.
89 	 * If the returned value is positive, the access time stamp
90 	 * will be updated after the call.
91 	 */
92 	int (*read)(ntfs_inode *ni, const REPARSE_POINT *reparse,
93 			char *buf, size_t size,
94 			off_t offset, struct fuse_file_info *fi);
95 
96 	/*
97 	 *	Write to an open file
98 	 * The file system must be left consistent after each write call,
99 	 * the file itself must be at least deletable if the application
100 	 * writing to it is killed for some reason.
101 	 * The returned value is the count of bytes which were written
102 	 * or a negative errno value for failure.
103 	 * If the returned value is positive, the modified time stamp
104 	 * will be updated after the call.
105 	 */
106 	int (*write)(ntfs_inode *ni, const REPARSE_POINT *reparse,
107 			const char *buf, size_t size,
108 			off_t offset, struct fuse_file_info *fi);
109 
110 	/*
111 	 *	Get a symbolic link
112 	 * The symbolic link must be returned in an allocated buffer,
113 	 * encoded in a zero terminated multibyte string compatible
114 	 * with the locale mount option.
115 	 * The returned value is zero for success or a negative errno
116 	 * value for failure.
117 	 */
118 	int (*readlink)(ntfs_inode *ni, const REPARSE_POINT *reparse,
119 			char **pbuf);
120 
121 	/*
122 	 *	Truncate a file (shorten or append zeroes)
123 	 * The returned value is zero for success or a negative errno
124 	 * value for failure.
125 	 * If the returned value is zero, the modified time stamp
126 	 * will be updated after the call.
127 	 */
128 	int (*truncate)(ntfs_inode *ni, const REPARSE_POINT *reparse,
129 			off_t size);
130 	/*
131 	 *	Open a directory
132 	 * The field fi->flags indicates the kind of opening.
133 	 * The field fi->fh may be used to store some information which
134 	 * will be available to subsequent readdir(). When used
135 	 * this field must be non-null and freed in release().
136 	 * The returned value is zero for success and a negative errno
137 	 * value for failure.
138 	 */
139 	int (*opendir)(ntfs_inode *ni, const REPARSE_POINT *reparse,
140 			struct fuse_file_info *fi);
141 
142 	/*
143 	 *	Get entries from a directory
144 	 *
145 	 * Use the filldir() function with fillctx argument to return
146 	 * the directory entries.
147 	 * Names "." and ".." are expected to be returned.
148 	 * The returned value is zero for success and a negative errno
149 	 * value for failure.
150 	 */
151 	int (*readdir)(ntfs_inode *ni, const REPARSE_POINT *reparse,
152 			s64 *pos, void *fillctx, ntfs_filldir_t filldir,
153 			struct fuse_file_info *fi);
154 	/*
155 	 *	Create a new file of any type
156 	 *
157 	 * The returned value is a pointer to the inode created, or
158 	 * NULL if failed, with errno telling why.
159 	 */
160 	ntfs_inode *(*create)(ntfs_inode *dir_ni, const REPARSE_POINT *reparse,
161 			le32 securid, ntfschar *name, int name_len,
162 			mode_t type);
163 	/*
164 	 *	Link a new name to a file or directory
165 	 * Linking a directory is needed for renaming a directory
166 	 * The returned value is zero for success or a negative errno
167 	 * value for failure.
168 	 * If the returned value is zero, the modified time stamp
169 	 * will be updated after the call.
170 	 */
171 	int (*link)(ntfs_inode *dir_ni, const REPARSE_POINT *reparse,
172 			ntfs_inode *ni, ntfschar *name, int name_len);
173 	/*
174 	 *	Unlink a name from a directory
175 	 * The argument pathname may be NULL
176 	 * The returned value is zero for success or a negative errno
177 	 * value for failure.
178 	 */
179 	int (*unlink)(ntfs_inode *dir_ni, const REPARSE_POINT *reparse,
180 			const char *pathname,
181 			ntfs_inode *ni, ntfschar *name, int name_len);
182 } plugin_operations_t;
183 
184 
185 /*
186  *		Plugin initialization routine
187  *	Returns the entry table if successful, otherwise returns NULL
188  *	and sets errno (e.g. to EINVAL if the tag is not supported by
189  *	the plugin.)
190  */
191 typedef const struct plugin_operations *(*plugin_init_t)(le32 tag);
192 const struct plugin_operations *init(le32 tag);
193 
194 #endif /* _NTFS_PLUGIN_H */
195