2 * Copyright (c) 1998,1999,2000
3 * Traakan, Inc., Los Altos, CA
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice unmodified, this list of conditions, and the following
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #include "ndmagents.h"
40 #ifndef NDMOS_OPTION_NO_DATA_AGENT
44 * Initialization and Cleanup
45 ****************************************************************
48 /* Initialize -- Set data structure to know value, ignore current value */
50 ndmda_fh_initialize (struct ndm_session *sess)
52 struct ndm_data_agent * da = &sess->data_acb;
53 struct ndmfhheap * fhh = &da->fhh;
55 ndmfhh_initialize (fhh);
60 /* Commission -- Get agent ready. Entire session has been initialize()d */
62 ndmda_fh_commission (struct ndm_session *sess)
64 struct ndm_data_agent * da = &sess->data_acb;
65 struct ndmfhheap * fhh = &da->fhh;
67 ndmfhh_commission (fhh, &da->fhh_buf, sizeof da->fhh_buf);
72 /* Decommission -- Discard agent */
74 ndmda_fh_decommission (struct ndm_session *sess)
79 /* Belay -- Cancel partially issued activation/start */
81 ndmda_fh_belay (struct ndm_session *sess)
90 * Semantic actions -- called from ndmda_XXX() butype formatters
91 ****************************************************************
95 ndmda_fh_add_file (struct ndm_session *sess,
96 ndmp9_file_stat *filestat, char *name)
98 struct ndm_data_agent * da = &sess->data_acb;
99 int nlen = strlen (name) + 1;
103 rc = ndmda_fh_prepare (sess, NDMP9VER, NDMP9_FH_ADD_FILE,
104 sizeof (ndmp9_file), 1, nlen);
106 if (rc != NDMFHH_RET_OK)
109 file9 = ndmfhh_add_entry (&da->fhh);
110 file9->fstat = *filestat;
111 file9->unix_path = ndmfhh_save_item (&da->fhh, name, nlen);
115 ndmda_fh_add_dir (struct ndm_session *sess,
116 unsigned long long dir_fileno, char *name, unsigned long long fileno)
118 struct ndm_data_agent * da = &sess->data_acb;
119 int nlen = strlen (name) + 1;
123 rc = ndmda_fh_prepare (sess, NDMP9VER, NDMP9_FH_ADD_DIR,
124 sizeof (ndmp9_dir), 1, nlen);
126 if (rc != NDMFHH_RET_OK)
129 dir9 = ndmfhh_add_entry (&da->fhh);
130 dir9->unix_name = ndmfhh_save_item (&da->fhh, name, nlen);
131 dir9->parent = dir_fileno;
136 ndmda_fh_add_node (struct ndm_session *sess, ndmp9_file_stat *filestat)
138 struct ndm_data_agent * da = &sess->data_acb;
142 rc = ndmda_fh_prepare (sess, NDMP9VER, NDMP9_FH_ADD_NODE,
143 sizeof (ndmp9_node), 1, 0);
145 if (rc != NDMFHH_RET_OK)
148 node9 = ndmfhh_add_entry (&da->fhh);
149 node9->fstat = *filestat;
156 * Helpers -- prepare/flush
157 ****************************************************************
161 ndmda_fh_prepare (struct ndm_session *sess,
162 int vers, int msg, int entry_size,
163 unsigned n_item, unsigned total_size_of_items)
165 struct ndm_data_agent * da = &sess->data_acb;
166 struct ndmfhheap * fhh = &da->fhh;
167 int fhtype = (vers<<16) + msg;
170 rc = ndmfhh_prepare (fhh, fhtype, entry_size,
171 n_item, total_size_of_items);
173 if (rc == NDMFHH_RET_OK)
174 return NDMFHH_RET_OK;
176 ndmda_fh_flush (sess);
178 rc = ndmfhh_prepare (fhh, fhtype, entry_size,
179 n_item, total_size_of_items);
185 ndmda_fh_flush (struct ndm_session *sess)
187 struct ndm_data_agent * da = &sess->data_acb;
188 struct ndmfhheap * fhh = &da->fhh;
194 rc = ndmfhh_get_table (fhh, &fhtype, &table, &n_entry);
195 if (rc == NDMFHH_RET_OK && n_entry > 0) {
196 struct ndmp_xa_buf xa;
197 struct ndmfhh_generic_table *request;
199 request = (void *) &xa.request.body;
200 NDMOS_MACRO_ZEROFILL (&xa);
202 xa.request.protocol_version = fhtype >> 16;
203 xa.request.header.message = fhtype & 0xFFFF;
205 request->table_len = n_entry;
206 request->table_val = table;
208 ndma_send_to_control (sess, &xa, sess->plumb.data);
214 #endif /* !NDMOS_OPTION_NO_DATA_AGENT */