42
|
1 |
--- source3/modules/vfs_samfs.c 2010-07-07 10:22:33.756895700 -0700
|
|
2 |
+++ source3/modules/vfs_samfs.c 2010-07-07 07:13:55.603441200 -0700
|
|
3 |
@@ -0,0 +1,172 @@
|
|
4 |
+/*
|
|
5 |
+ * Support for offline files with Sun SAM-QFS
|
|
6 |
+ *
|
|
7 |
+ * Copyright (C) Dirk Nitschke, 2009
|
|
8 |
+ *
|
|
9 |
+ * Modified by Jiri Sasek, 2010
|
|
10 |
+ * To conform the samba-vfs api
|
|
11 |
+ *
|
|
12 |
+ * This program is free software; you can redistribute it and/or modify
|
|
13 |
+ * it under the terms of the GNU General Public License as published by
|
|
14 |
+ * the Free Software Foundation; either version 3 of the License, or
|
|
15 |
+ * (at your option) any later version.
|
|
16 |
+ *
|
|
17 |
+ * This program is distributed in the hope that it will be useful,
|
|
18 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20 |
+ * GNU General Public License for more details.
|
|
21 |
+ *
|
|
22 |
+ * You should have received a copy of the GNU General Public License
|
|
23 |
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
24 |
+ *
|
|
25 |
+ */
|
|
26 |
+
|
|
27 |
+#include "includes.h"
|
|
28 |
+/*
|
|
29 |
+ * Include files for Sun SAM-QFS
|
|
30 |
+ *
|
|
31 |
+ */
|
|
32 |
+#include "sam-stat.h"
|
|
33 |
+#include "sam-lib.h"
|
|
34 |
+
|
|
35 |
+#undef DBGC_CLASS
|
|
36 |
+#define DBGC_CLASS DBGC_VFS
|
|
37 |
+
|
|
38 |
+#define SAMFS_MODULE_NAME "samfs"
|
|
39 |
+
|
|
40 |
+NTSTATUS vfs_samfs_init(void);
|
|
41 |
+
|
|
42 |
+/*
|
|
43 |
+ * samfs_is_offline()
|
|
44 |
+ * check if the local file is offline in the sense of SAM-QFS
|
|
45 |
+ *
|
|
46 |
+ * A segmented file is offline if the file's index inode is
|
|
47 |
+ * offline or at least one of it's segments is offline.
|
|
48 |
+ *
|
|
49 |
+ * See sam_stat(3) and sam_segment_stat(3) for details.
|
|
50 |
+ *
|
|
51 |
+ * If something goes wrong we assume that the file is offline.
|
|
52 |
+ */
|
|
53 |
+static bool samfs_is_offline(struct vfs_handle_struct *handle, const char *path, SMB_STRUCT_STAT *sbuf)
|
|
54 |
+{
|
|
55 |
+ struct sam_stat file_info;
|
|
56 |
+ struct sam_stat *seg_info_ptr;
|
|
57 |
+ bool offline;
|
|
58 |
+ int number_of_segments;
|
|
59 |
+ int result;
|
|
60 |
+ int i;
|
|
61 |
+
|
|
62 |
+ offline = false;
|
|
63 |
+ if (ISDOT(path) || ISDOTDOT(path)) {
|
|
64 |
+ return false;
|
|
65 |
+ }
|
|
66 |
+
|
|
67 |
+ /*
|
|
68 |
+ * Initialize file_info to be all zero bits
|
|
69 |
+ */
|
|
70 |
+ memset((void *)&file_info, 0, sizeof(struct sam_stat));
|
|
71 |
+
|
|
72 |
+ /*
|
|
73 |
+ * Stat the file using the regular sam_stat function
|
|
74 |
+ */
|
|
75 |
+ result = sam_stat(path, &file_info, sizeof(struct sam_stat));
|
|
76 |
+
|
|
77 |
+ if (result != 0) {
|
|
78 |
+ DEBUG(10,("samfs_is_offline: cannot sam_stat %s, %s\nAssuming file is offline.\n", \
|
|
79 |
+ path, strerror(errno)));
|
|
80 |
+ return true;
|
|
81 |
+ }
|
|
82 |
+
|
|
83 |
+ /*
|
|
84 |
+ * Check if file is offline
|
|
85 |
+ */
|
|
86 |
+ if (SS_ISOFFLINE(file_info.attr)) {
|
|
87 |
+ DEBUG(10,("samfs_is_offline: file %s is offline.\n", path));
|
|
88 |
+ return true;
|
|
89 |
+ }
|
|
90 |
+
|
|
91 |
+ /*
|
|
92 |
+ * Check for segmented file
|
|
93 |
+ */
|
|
94 |
+ if (SS_ISSEGMENT_F(file_info.attr)) {
|
|
95 |
+ number_of_segments = NUM_SEGS(&file_info);
|
|
96 |
+ seg_info_ptr = (struct sam_stat *)malloc(number_of_segments *
|
|
97 |
+ sizeof(struct sam_stat));
|
|
98 |
+ if (seg_info_ptr != NULL) {
|
|
99 |
+ /*
|
|
100 |
+ * Initialize seg_info_ptr to be all zero bits
|
|
101 |
+ */
|
|
102 |
+ memset((void *)seg_info_ptr, 0, number_of_segments *
|
|
103 |
+ sizeof(struct sam_stat));
|
|
104 |
+ /*
|
|
105 |
+ * Stat all segments
|
|
106 |
+ */
|
|
107 |
+ result = sam_segment_stat(path, seg_info_ptr,
|
|
108 |
+ number_of_segments * sizeof(struct sam_stat));
|
|
109 |
+ if (result != 0) {
|
|
110 |
+ DEBUG(10,("samfs_is_offline: cannot sam_segment_stat %s, %s\nAssuming file is offline.\n", \
|
|
111 |
+ path, strerror(errno)));
|
|
112 |
+ offline = true;
|
|
113 |
+ }
|
|
114 |
+ /*
|
|
115 |
+ * Loop over segments until we have checked all segments
|
|
116 |
+ * or found one which is offline.
|
|
117 |
+ */
|
|
118 |
+ i = 0;
|
|
119 |
+ while (!offline && (i < number_of_segments)) {
|
|
120 |
+ if (SS_ISOFFLINE(seg_info_ptr[i].attr)) {
|
|
121 |
+ DEBUG(10,("samfs_is_offline: file %s has offline segment %d\n", \
|
|
122 |
+ path, i+1));
|
|
123 |
+ offline = true;
|
|
124 |
+ }
|
|
125 |
+ i++;
|
|
126 |
+ }
|
|
127 |
+ SAFE_FREE(seg_info_ptr);
|
|
128 |
+ } else {
|
|
129 |
+ DEBUG(10,("samfs_is_offline: cannot malloc for segment stat info %s\nAssuming file is offline.\n", \
|
|
130 |
+ path));
|
|
131 |
+ offline = true;
|
|
132 |
+ }
|
|
133 |
+
|
|
134 |
+ }
|
|
135 |
+ return offline;
|
|
136 |
+}
|
|
137 |
+
|
|
138 |
+/*
|
|
139 |
+ * release a file-command to SAM-stagger
|
|
140 |
+ */
|
|
141 |
+extern int sam_release(const char *path, const char *command);
|
|
142 |
+
|
|
143 |
+/*
|
|
144 |
+ * samfs_set_offline()
|
|
145 |
+ *
|
|
146 |
+ * Release the local file in the sense of SAM-QFS.
|
|
147 |
+ * See sam_release(3) for details.
|
|
148 |
+ *
|
|
149 |
+ */
|
|
150 |
+static int samfs_set_offline(struct vfs_handle_struct *handle, const char *path)
|
|
151 |
+{
|
|
152 |
+ int result;
|
|
153 |
+
|
|
154 |
+ result = sam_release(path, "i");
|
|
155 |
+ if (result != 0) {
|
|
156 |
+ DEBUG(10,("samfs_set_offline: sam_release %s returned %s\n", \
|
|
157 |
+ path, strerror(errno)));
|
|
158 |
+ return -1;
|
|
159 |
+ }
|
|
160 |
+ return 0;
|
|
161 |
+}
|
|
162 |
+
|
|
163 |
+/* VFS operations structure */
|
|
164 |
+
|
|
165 |
+static struct vfs_fn_pointers samfs_fns = {
|
|
166 |
+ .is_offline = samfs_is_offline,
|
|
167 |
+ .set_offline = samfs_set_offline
|
|
168 |
+};
|
|
169 |
+
|
|
170 |
+NTSTATUS vfs_samfs_init(void);
|
|
171 |
+NTSTATUS vfs_samfs_init(void)
|
|
172 |
+{
|
|
173 |
+ return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, SAMFS_MODULE_NAME,
|
|
174 |
+ &samfs_fns);
|
|
175 |
+}
|