| 1 | /* |
|---|
| 2 | * (C) 2001 Clemson University and The University of Chicago |
|---|
| 3 | * |
|---|
| 4 | * See COPYING in top-level directory. |
|---|
| 5 | */ |
|---|
| 6 | |
|---|
| 7 | #include <time.h> |
|---|
| 8 | #ifndef WIN32 |
|---|
| 9 | #include <sys/time.h> |
|---|
| 10 | #endif |
|---|
| 11 | #include <stdio.h> |
|---|
| 12 | #include <string.h> |
|---|
| 13 | #include <stdlib.h> |
|---|
| 14 | |
|---|
| 15 | #include "client.h" |
|---|
| 16 | #include "pvfs2-util.h" |
|---|
| 17 | |
|---|
| 18 | void gen_rand_str( |
|---|
| 19 | int len, |
|---|
| 20 | char **gen_str); |
|---|
| 21 | |
|---|
| 22 | int main( |
|---|
| 23 | int argc, |
|---|
| 24 | char **argv) |
|---|
| 25 | { |
|---|
| 26 | PVFS_sysresp_lookup resp_look; |
|---|
| 27 | PVFS_sysresp_lookup *resp_lk = NULL; |
|---|
| 28 | PVFS_sysresp_readdir *resp_readdir = NULL; |
|---|
| 29 | #if 0 |
|---|
| 30 | PVFS_sysreq_getattr *req_gattr = NULL; |
|---|
| 31 | PVFS_sysresp_getattr *resp_gattr = NULL; |
|---|
| 32 | PVFS_sysreq_setattr *req_sattr = NULL; |
|---|
| 33 | PVFS_sysreq_mkdir *req_mkdir = NULL; |
|---|
| 34 | PVFS_sysresp_mkdir *resp_mkdir = NULL; |
|---|
| 35 | PVFS_sysreq_rmdir *req_rmdir = NULL; |
|---|
| 36 | PVFS_sysreq_statfs *req_statfs = NULL; |
|---|
| 37 | PVFS_sysresp_statfs *resp_statfs = NULL; |
|---|
| 38 | #endif |
|---|
| 39 | PVFS_sysresp_create *resp_create = NULL; |
|---|
| 40 | char *filename; |
|---|
| 41 | //char dirname[256] = "/parl/fshorte/sysint/home"; |
|---|
| 42 | int ret = -1, i = 0; |
|---|
| 43 | PVFS_fs_id fs_id; |
|---|
| 44 | char *name = "/"; |
|---|
| 45 | PVFS_credentials credentials; |
|---|
| 46 | char *entry_name; |
|---|
| 47 | PVFS_object_ref parent_refn; |
|---|
| 48 | PVFS_sys_attr attr; |
|---|
| 49 | PVFS_object_ref pinode_refn; |
|---|
| 50 | PVFS_ds_position token; |
|---|
| 51 | int pvfs_dirent_incount, |
|---|
| 52 | pvfs_dirent_outcount; |
|---|
| 53 | |
|---|
| 54 | PVFS_handle lk_handle; |
|---|
| 55 | PVFS_handle lk_fsid; |
|---|
| 56 | |
|---|
| 57 | gen_rand_str(10, &filename); |
|---|
| 58 | |
|---|
| 59 | printf("creating a file named %s\n", filename); |
|---|
| 60 | |
|---|
| 61 | ret = PVFS_util_init_defaults(); |
|---|
| 62 | if (ret < 0) |
|---|
| 63 | { |
|---|
| 64 | PVFS_perror("PVFS_util_init_defaults", ret); |
|---|
| 65 | return (-1); |
|---|
| 66 | } |
|---|
| 67 | ret = PVFS_util_get_default_fsid(&fs_id); |
|---|
| 68 | if (ret < 0) |
|---|
| 69 | { |
|---|
| 70 | PVFS_perror("PVFS_util_get_default_fsid", ret); |
|---|
| 71 | return (-1); |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | printf("SYSTEM INTERFACE INITIALIZED\n"); |
|---|
| 75 | |
|---|
| 76 | /* lookup the root handle */ |
|---|
| 77 | printf("looking up the root handle for fsid = %d\n", fs_id); |
|---|
| 78 | ret = PVFS_sys_lookup(fs_id, name, &credentials, |
|---|
| 79 | &resp_look, PVFS2_LOOKUP_LINK_NO_FOLLOW, NULL); |
|---|
| 80 | if (ret < 0) |
|---|
| 81 | { |
|---|
| 82 | printf("Lookup failed with errcode = %d\n", ret); |
|---|
| 83 | return (-1); |
|---|
| 84 | } |
|---|
| 85 | // print the handle |
|---|
| 86 | printf("--lookup--\n"); |
|---|
| 87 | printf("ROOT Handle:%ld\n", (long int) resp_look.ref.handle); |
|---|
| 88 | |
|---|
| 89 | /* test create */ |
|---|
| 90 | resp_create = (PVFS_sysresp_create *) malloc(sizeof(PVFS_sysresp_create)); |
|---|
| 91 | if (!resp_create) |
|---|
| 92 | { |
|---|
| 93 | printf("Error in malloc\n"); |
|---|
| 94 | return (-1); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | // Fill in the create info |
|---|
| 98 | entry_name = (char *) malloc(strlen(filename) + 1); |
|---|
| 99 | if (!entry_name) |
|---|
| 100 | { |
|---|
| 101 | printf("Error in malloc\n"); |
|---|
| 102 | return (-1); |
|---|
| 103 | } |
|---|
| 104 | memcpy(entry_name, filename, strlen(filename) + 1); |
|---|
| 105 | PVFS_util_gen_credentials(&credentials); |
|---|
| 106 | |
|---|
| 107 | attr.mask = PVFS_ATTR_SYS_ALL_SETABLE; |
|---|
| 108 | attr.owner = credentials.uid; |
|---|
| 109 | attr.group = credentials.gid; |
|---|
| 110 | attr.perms = 1877; |
|---|
| 111 | attr.atime = attr.mtime = attr.ctime = time(NULL); |
|---|
| 112 | |
|---|
| 113 | parent_refn.handle = resp_look.ref.handle; |
|---|
| 114 | parent_refn.fs_id = fs_id; |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | #if 0 |
|---|
| 118 | // Fill in the dist |
|---|
| 119 | //req_create->dist = malloc(sizeof(PVFS_dist)); |
|---|
| 120 | req_create->dist.type = PVFS_DIST_STRIPED; |
|---|
| 121 | req_create->dist.u.striped.base = 0; |
|---|
| 122 | req_create->dist.u.striped.pcount = 3; |
|---|
| 123 | req_create->dist.u.striped.ssize = 512; |
|---|
| 124 | #endif |
|---|
| 125 | |
|---|
| 126 | // call create |
|---|
| 127 | ret = PVFS_sys_create(entry_name, parent_refn, attr, |
|---|
| 128 | &credentials, NULL, resp_create, NULL, NULL); |
|---|
| 129 | if (ret < 0) |
|---|
| 130 | { |
|---|
| 131 | printf("create failed with errcode = %d\n", ret); |
|---|
| 132 | return (-1); |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | // print the handle |
|---|
| 136 | printf("--create--\n"); |
|---|
| 137 | printf("Handle:%ld\n", (long int) resp_create->ref.handle); |
|---|
| 138 | |
|---|
| 139 | #if 0 |
|---|
| 140 | printf("GETATTR HERE===>\n"); |
|---|
| 141 | req_gattr = (PVFS_sysreq_getattr *) malloc(sizeof(PVFS_sysreq_getattr)); |
|---|
| 142 | if (!req_gattr) |
|---|
| 143 | { |
|---|
| 144 | printf("Error in malloc\n"); |
|---|
| 145 | return (-1); |
|---|
| 146 | } |
|---|
| 147 | resp_gattr = (PVFS_sysresp_getattr *) malloc(sizeof(PVFS_sysresp_getattr)); |
|---|
| 148 | if (!resp_gattr) |
|---|
| 149 | { |
|---|
| 150 | printf("Error in malloc\n"); |
|---|
| 151 | return (-1); |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | // Fill in the handle |
|---|
| 155 | req_gattr->pinode_refn.handle = resp_create->pinode_refn.handle; |
|---|
| 156 | req_gattr->pinode_refn.fs_id = resp_init.fsid_list[0]; |
|---|
| 157 | req_gattr->attrmask = ATTR_META; |
|---|
| 158 | |
|---|
| 159 | // Use it |
|---|
| 160 | ret = PVFS_sys_getattr(req_gattr, resp_gattr); |
|---|
| 161 | if (ret < 0) |
|---|
| 162 | { |
|---|
| 163 | printf("getattr failed with errcode = %d\n", ret); |
|---|
| 164 | return (-1); |
|---|
| 165 | } |
|---|
| 166 | // print the handle |
|---|
| 167 | printf("--getattr--\n"); |
|---|
| 168 | printf("Handle:%ld\n", (long int) req_gattr->pinode_refn.handle); |
|---|
| 169 | printf("FSID:%ld\n", (long int) req_gattr->pinode_refn.fs_id); |
|---|
| 170 | printf("mask:%d\n", req_gattr->attrmask); |
|---|
| 171 | printf("uid:%d\n", resp_gattr->attr.owner); |
|---|
| 172 | printf("gid:%d\n", resp_gattr->attr.group); |
|---|
| 173 | printf("permissions:%d\n", resp_gattr->attr.perms); |
|---|
| 174 | printf("atime:%d\n", (int) resp_gattr->attr.atime); |
|---|
| 175 | printf("mtime:%d\n", (int) resp_gattr->attr.mtime); |
|---|
| 176 | printf("ctime:%d\n", (int) resp_gattr->attr.ctime); |
|---|
| 177 | printf("nr_datafiles:%d\n", resp_gattr->attr.u.meta.nr_datafiles); |
|---|
| 178 | |
|---|
| 179 | for (i = 0; i < resp_gattr->attr.u.meta.nr_datafiles; i++) |
|---|
| 180 | { |
|---|
| 181 | printf("\thandle: %d\n", resp_gattr->attr.u.meta.dfh[i]); |
|---|
| 182 | } |
|---|
| 183 | #endif |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | free(entry_name); |
|---|
| 187 | free(resp_create); |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | |
|---|
| 191 | /* test the lookup function */ |
|---|
| 192 | resp_lk = (PVFS_sysresp_lookup *) malloc(sizeof(PVFS_sysresp_lookup)); |
|---|
| 193 | if (!resp_lk) |
|---|
| 194 | { |
|---|
| 195 | printf("Error in malloc\n"); |
|---|
| 196 | return (-1); |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | name = (char *) malloc(strlen(filename) + 2); |
|---|
| 200 | if (!name) |
|---|
| 201 | { |
|---|
| 202 | printf("Error in malloc\n"); |
|---|
| 203 | return (-1); |
|---|
| 204 | } |
|---|
| 205 | name[0] = '/'; |
|---|
| 206 | memcpy(name + 1, filename, strlen(filename) + 1); |
|---|
| 207 | |
|---|
| 208 | ret = PVFS_sys_lookup(fs_id, name, &credentials, |
|---|
| 209 | resp_lk, PVFS2_LOOKUP_LINK_NO_FOLLOW, NULL); |
|---|
| 210 | if (ret < 0) |
|---|
| 211 | { |
|---|
| 212 | printf("Lookup failed with errcode = %d\n", ret); |
|---|
| 213 | return (-1); |
|---|
| 214 | } |
|---|
| 215 | // print the handle |
|---|
| 216 | printf("--lookup--\n"); |
|---|
| 217 | printf("Handle:%ld\n", (long int) resp_lk->ref.handle); |
|---|
| 218 | printf("FSID:%ld\n", (long int) resp_lk->ref.fs_id); |
|---|
| 219 | |
|---|
| 220 | lk_handle = resp_lk->ref.handle; |
|---|
| 221 | lk_fsid = resp_lk->ref.fs_id; |
|---|
| 222 | |
|---|
| 223 | free(name); |
|---|
| 224 | free(resp_lk); |
|---|
| 225 | |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | #if 0 |
|---|
| 231 | /* Test the getattr function */ |
|---|
| 232 | printf("GETATTR HERE===>\n"); |
|---|
| 233 | req_gattr = (PVFS_sysreq_getattr *) malloc(sizeof(PVFS_sysreq_getattr)); |
|---|
| 234 | if (!req_gattr) |
|---|
| 235 | { |
|---|
| 236 | printf("Error in malloc\n"); |
|---|
| 237 | return (-1); |
|---|
| 238 | } |
|---|
| 239 | resp_gattr = (PVFS_sysresp_getattr *) malloc(sizeof(PVFS_sysresp_getattr)); |
|---|
| 240 | if (!resp_gattr) |
|---|
| 241 | { |
|---|
| 242 | printf("Error in malloc\n"); |
|---|
| 243 | return (-1); |
|---|
| 244 | } |
|---|
| 245 | |
|---|
| 246 | // Fill in the handle |
|---|
| 247 | req_gattr->pinode_refn.handle = lk_handle; |
|---|
| 248 | req_gattr->pinode_refn.fs_id = lk_fsid; |
|---|
| 249 | req_gattr->attrmask = ATTR_META; |
|---|
| 250 | |
|---|
| 251 | // Use it |
|---|
| 252 | ret = PVFS_sys_getattr(req_gattr, resp_gattr); |
|---|
| 253 | if (ret < 0) |
|---|
| 254 | { |
|---|
| 255 | printf("getattr failed with errcode = %d\n", ret); |
|---|
| 256 | return (-1); |
|---|
| 257 | } |
|---|
| 258 | // print the handle |
|---|
| 259 | printf("--getattr--\n"); |
|---|
| 260 | printf("Handle:%ld\n", (long int) req_gattr->pinode_refn.handle); |
|---|
| 261 | printf("FSID:%ld\n", (long int) req_gattr->pinode_refn.fs_id); |
|---|
| 262 | printf("mask:%d\n", req_gattr->attrmask); |
|---|
| 263 | printf("uid:%d\n", resp_gattr->attr.owner); |
|---|
| 264 | printf("gid:%d\n", resp_gattr->attr.group); |
|---|
| 265 | printf("permissions:%d\n", resp_gattr->attr.perms); |
|---|
| 266 | printf("atime:%d\n", (int) resp_gattr->attr.atime); |
|---|
| 267 | printf("mtime:%d\n", (int) resp_gattr->attr.mtime); |
|---|
| 268 | printf("ctime:%d\n", (int) resp_gattr->attr.ctime); |
|---|
| 269 | printf("nr_datafiles:%d\n", resp_gattr->attr.u.meta.nr_datafiles); |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | // test the setattr function |
|---|
| 273 | printf("SETATTR HERE===>\n"); |
|---|
| 274 | req_sattr = (PVFS_sysreq_setattr *) malloc(sizeof(PVFS_sysreq_setattr)); |
|---|
| 275 | if (!req_sattr) |
|---|
| 276 | { |
|---|
| 277 | printf("Error in malloc\n"); |
|---|
| 278 | return (-1); |
|---|
| 279 | } |
|---|
| 280 | |
|---|
| 281 | // fill in the handle |
|---|
| 282 | req_sattr->pinode_refn.handle = lk_handle; //resp_lk->pinode_refn.handle; |
|---|
| 283 | req_sattr->pinode_refn.fs_id = lk_fsid; |
|---|
| 284 | req_sattr->attrmask = ATTR_META; |
|---|
| 285 | req_sattr->attr.owner = 12345; |
|---|
| 286 | req_sattr->attr.group = 56789; |
|---|
| 287 | req_sattr->attr.perms = 255; |
|---|
| 288 | req_sattr->attr.atime = 1111111; |
|---|
| 289 | req_sattr->attr.mtime = 2222222; |
|---|
| 290 | req_sattr->attr.ctime = 3333333; |
|---|
| 291 | req_sattr->attr.objtype = PVFS_TYPE_METAFILE; |
|---|
| 292 | |
|---|
| 293 | req_sattr->attr.u.meta.dfh = NULL; |
|---|
| 294 | req_sattr->attr.u.meta.nr_datafiles = 0; |
|---|
| 295 | //req_sattr->attr.u.meta.dfh = &some_datafile; |
|---|
| 296 | //req_sattr->attr.u.meta.nr_datafiles = 1; |
|---|
| 297 | |
|---|
| 298 | //use it |
|---|
| 299 | ret = PVFS_sys_setattr(req_sattr); |
|---|
| 300 | if (ret < 0) |
|---|
| 301 | { |
|---|
| 302 | printf("setattr failed with errcode = %d\n", ret); |
|---|
| 303 | return (-1); |
|---|
| 304 | } |
|---|
| 305 | // print the handle |
|---|
| 306 | printf("--setattr--\n"); |
|---|
| 307 | printf("Handle:%ld\n", (long int) req_sattr->pinode_refn.handle); |
|---|
| 308 | printf("FSID:%ld\n", (long int) req_sattr->pinode_refn.fs_id); |
|---|
| 309 | printf("mask:%d\n", req_sattr->attrmask); |
|---|
| 310 | printf("uid:%d\n", req_sattr->attr.owner); |
|---|
| 311 | printf("gid:%d\n", req_sattr->attr.group); |
|---|
| 312 | printf("permissions:%d\n", req_sattr->attr.perms); |
|---|
| 313 | printf("atime:%d\n", (int) req_sattr->attr.atime); |
|---|
| 314 | printf("mtime:%d\n", (int) req_sattr->attr.mtime); |
|---|
| 315 | printf("ctime:%d\n", (int) req_sattr->attr.ctime); |
|---|
| 316 | printf("nr_datafiles:%d\n", req_sattr->attr.u.meta.nr_datafiles); |
|---|
| 317 | |
|---|
| 318 | |
|---|
| 319 | /* Test the getattr function */ |
|---|
| 320 | printf("GETATTR HERE===>\n"); |
|---|
| 321 | req_gattr = (PVFS_sysreq_getattr *) malloc(sizeof(PVFS_sysreq_getattr)); |
|---|
| 322 | if (!req_gattr) |
|---|
| 323 | { |
|---|
| 324 | printf("Error in malloc\n"); |
|---|
| 325 | return (-1); |
|---|
| 326 | } |
|---|
| 327 | resp_gattr = (PVFS_sysresp_getattr *) malloc(sizeof(PVFS_sysresp_getattr)); |
|---|
| 328 | if (!resp_gattr) |
|---|
| 329 | { |
|---|
| 330 | printf("Error in malloc\n"); |
|---|
| 331 | return (-1); |
|---|
| 332 | } |
|---|
| 333 | |
|---|
| 334 | // Fill in the handle |
|---|
| 335 | req_gattr->pinode_refn.handle = req_sattr->pinode_refn.handle; |
|---|
| 336 | req_gattr->pinode_refn.fs_id = 9; |
|---|
| 337 | req_gattr->attrmask = ATTR_META; |
|---|
| 338 | |
|---|
| 339 | // Use it |
|---|
| 340 | ret = PVFS_sys_getattr(req_gattr, resp_gattr); |
|---|
| 341 | if (ret < 0) |
|---|
| 342 | { |
|---|
| 343 | printf("getattr failed with errcode = %d\n", ret); |
|---|
| 344 | return (-1); |
|---|
| 345 | } |
|---|
| 346 | // print the handle |
|---|
| 347 | printf("--getattr--\n"); |
|---|
| 348 | printf("Handle:%ld\n", (long int) req_gattr->pinode_refn.handle); |
|---|
| 349 | printf("FSID:%ld\n", (long int) req_gattr->pinode_refn.fs_id); |
|---|
| 350 | printf("mask:%d\n", req_gattr->attrmask); |
|---|
| 351 | printf("uid:%d\n", resp_gattr->attr.owner); |
|---|
| 352 | printf("gid:%d\n", resp_gattr->attr.group); |
|---|
| 353 | printf("permissions:%d\n", resp_gattr->attr.perms); |
|---|
| 354 | printf("atime:%d\n", (int) resp_gattr->attr.atime); |
|---|
| 355 | printf("mtime:%d\n", (int) resp_gattr->attr.mtime); |
|---|
| 356 | printf("ctime:%d\n", (int) resp_gattr->attr.ctime); |
|---|
| 357 | printf("nr_datafiles:%d\n", resp_gattr->attr.u.meta.nr_datafiles); |
|---|
| 358 | #endif |
|---|
| 359 | |
|---|
| 360 | #if 0 |
|---|
| 361 | // close it down |
|---|
| 362 | ret = PVFS_sys_finalize(); |
|---|
| 363 | |
|---|
| 364 | // Init the system interface |
|---|
| 365 | // Getattr test |
|---|
| 366 | ret = PVFS_sys_init(); |
|---|
| 367 | if (ret < 0) |
|---|
| 368 | { |
|---|
| 369 | printf("PVFS_sys_init() failure.\n"); |
|---|
| 370 | return (ret); |
|---|
| 371 | } |
|---|
| 372 | |
|---|
| 373 | // Test the getattr function |
|---|
| 374 | // Alloc memory and fill the structures |
|---|
| 375 | req_gattr = (PVFS_sysreq_getattr *) malloc(sizeof(PVFS_sysreq_getattr)); |
|---|
| 376 | if (!req_gattr) |
|---|
| 377 | { |
|---|
| 378 | printf("Error in malloc\n"); |
|---|
| 379 | return (-1); |
|---|
| 380 | } |
|---|
| 381 | resp_gattr = (PVFS_sysresp_getattr *) malloc(sizeof(PVFS_sysresp_getattr)); |
|---|
| 382 | if (!resp_gattr) |
|---|
| 383 | { |
|---|
| 384 | printf("Error in malloc\n"); |
|---|
| 385 | return (-1); |
|---|
| 386 | } |
|---|
| 387 | |
|---|
| 388 | // Fill in the handle |
|---|
| 389 | //req_gattr->pinode_no.handle = resp_lk->pinode_no.handle + 2; |
|---|
| 390 | req_gattr->pinode_no.handle = resp_lk->pinode_no.handle; |
|---|
| 391 | req_gattr->pinode_no.fs_id = 0; |
|---|
| 392 | req_gattr->attrmask = ATTR_UID + ATTR_GID + ATTR_SIZE + ATTR_PERM; |
|---|
| 393 | |
|---|
| 394 | // Use it |
|---|
| 395 | ret = PVFS_sys_getattr(req_gattr, resp_gattr); |
|---|
| 396 | if (ret < 0) |
|---|
| 397 | { |
|---|
| 398 | printf("getattr failed with errcode = %d\n", ret); |
|---|
| 399 | return (-1); |
|---|
| 400 | } |
|---|
| 401 | // print the handle |
|---|
| 402 | printf("--getattr--\n"); |
|---|
| 403 | printf("Handle:%ld\n", (long int) resp_gattr->pinode_no.handle); |
|---|
| 404 | printf("mask:%d\n", resp_gattr->attrmask); |
|---|
| 405 | printf("uid:%d\n", resp_gattr->attr.owner); |
|---|
| 406 | printf("gid:%d\n", resp_gattr->attr.group); |
|---|
| 407 | printf("size:%lu\n", (unsigned long) resp_gattr->attr.size); |
|---|
| 408 | printf("permissions:%d\n", resp_gattr->attr.perms); |
|---|
| 409 | |
|---|
| 410 | //close it down |
|---|
| 411 | ret = PVFS_sys_finalize(); |
|---|
| 412 | |
|---|
| 413 | // Init the system interface |
|---|
| 414 | // mkdir test |
|---|
| 415 | |
|---|
| 416 | ret = PVFS_sys_init(); |
|---|
| 417 | if (ret < 0) |
|---|
| 418 | { |
|---|
| 419 | printf("PVFS_sys_init() failure.\n"); |
|---|
| 420 | return (ret); |
|---|
| 421 | } |
|---|
| 422 | |
|---|
| 423 | // test the mkdir function |
|---|
| 424 | // Alloc memory and fill the structures |
|---|
| 425 | req_mkdir = (PVFS_sysreq_mkdir *) malloc(sizeof(PVFS_sysreq_mkdir)); |
|---|
| 426 | if (!req_mkdir) |
|---|
| 427 | { |
|---|
| 428 | printf("Error in malloc\n"); |
|---|
| 429 | return (-1); |
|---|
| 430 | } |
|---|
| 431 | resp_mkdir = (PVFS_sysresp_mkdir *) malloc(sizeof(PVFS_sysresp_mkdir)); |
|---|
| 432 | if (!resp_mkdir) |
|---|
| 433 | { |
|---|
| 434 | printf("Error in malloc\n"); |
|---|
| 435 | return (-1); |
|---|
| 436 | } |
|---|
| 437 | |
|---|
| 438 | // Fill in the dir info |
|---|
| 439 | req_mkdir->entry_name = (char *) malloc(strlen(dirname) + 1); |
|---|
| 440 | if (!req_mkdir->entry_name) |
|---|
| 441 | { |
|---|
| 442 | printf("Error in malloc\n"); |
|---|
| 443 | return (-1); |
|---|
| 444 | } |
|---|
| 445 | strncpy(req_mkdir->entry_name, dirname, strlen(dirname)); |
|---|
| 446 | req_mkdir->entry_name[strlen(dirname)] = '\0'; |
|---|
| 447 | req_mkdir->parent_refn.handle = req_sattr->pinode_refn.handle - 1; |
|---|
| 448 | req_mkdir->parent_refn.fs_id = 1; |
|---|
| 449 | req_mkdir->attrmask = ATTR_BASIC; |
|---|
| 450 | req_mkdir->attr.owner = 12345; |
|---|
| 451 | req_mkdir->attr.group = 56789; |
|---|
| 452 | req_mkdir->attr.perms = 63; |
|---|
| 453 | req_mkdir->attr.objtype = PVFS_TYPE_DIRECTORY; |
|---|
| 454 | |
|---|
| 455 | // call mkdir |
|---|
| 456 | ret = PVFS_sys_mkdir(req_mkdir, resp_mkdir); |
|---|
| 457 | if (ret < 0) |
|---|
| 458 | { |
|---|
| 459 | printf("mkdir failed\n"); |
|---|
| 460 | return (-1); |
|---|
| 461 | } |
|---|
| 462 | // print the handle |
|---|
| 463 | printf("--mkdir--\n"); |
|---|
| 464 | printf("Handle:%ld\n", (long int) (resp_mkdir->pinode_refn.handle & 127)); |
|---|
| 465 | printf("FSID:%ld\n", (long int) req_mkdir->parent_refn.fs_id); |
|---|
| 466 | #endif |
|---|
| 467 | |
|---|
| 468 | resp_readdir = |
|---|
| 469 | (PVFS_sysresp_readdir *) malloc(sizeof(PVFS_sysresp_readdir)); |
|---|
| 470 | if (!resp_readdir) |
|---|
| 471 | { |
|---|
| 472 | printf("Error in malloc\n"); |
|---|
| 473 | return (-1); |
|---|
| 474 | } |
|---|
| 475 | |
|---|
| 476 | // Fill in the dir info |
|---|
| 477 | |
|---|
| 478 | pinode_refn.handle = resp_look.ref.handle; |
|---|
| 479 | pinode_refn.fs_id = fs_id; |
|---|
| 480 | token = PVFS_READDIR_START; |
|---|
| 481 | pvfs_dirent_incount = 6; |
|---|
| 482 | |
|---|
| 483 | /* |
|---|
| 484 | do |
|---|
| 485 | { |
|---|
| 486 | */ |
|---|
| 487 | // call readdir |
|---|
| 488 | ret = PVFS_sys_readdir(pinode_refn, token, pvfs_dirent_incount, |
|---|
| 489 | &credentials, resp_readdir, NULL); |
|---|
| 490 | if (ret < 0) |
|---|
| 491 | { |
|---|
| 492 | printf("readdir failed with errcode = %d\n", ret); |
|---|
| 493 | return (-1); |
|---|
| 494 | } |
|---|
| 495 | |
|---|
| 496 | // print the handle |
|---|
| 497 | printf("--readdir--\n"); |
|---|
| 498 | printf("Token:%ld\n", (long int) resp_readdir->token); |
|---|
| 499 | for (i = 0; i < resp_readdir->pvfs_dirent_outcount; i++) |
|---|
| 500 | { |
|---|
| 501 | printf("name:%s\n", resp_readdir->dirent_array[i].d_name); |
|---|
| 502 | } |
|---|
| 503 | token = resp_readdir->token; |
|---|
| 504 | pvfs_dirent_outcount = resp_readdir->pvfs_dirent_outcount; |
|---|
| 505 | /* |
|---|
| 506 | } |
|---|
| 507 | while (pvfs_dirent_outcount == 6); |
|---|
| 508 | */ |
|---|
| 509 | #if 0 |
|---|
| 510 | |
|---|
| 511 | // test the rmdir function |
|---|
| 512 | // Alloc memory and fill the structures |
|---|
| 513 | printf("--rmdir--\n"); |
|---|
| 514 | req_rmdir = (PVFS_sysreq_rmdir *) malloc(sizeof(PVFS_sysreq_rmdir)); |
|---|
| 515 | if (!req_rmdir) |
|---|
| 516 | { |
|---|
| 517 | printf("Error in malloc\n"); |
|---|
| 518 | return (-1); |
|---|
| 519 | } |
|---|
| 520 | |
|---|
| 521 | // Fill in the dir info |
|---|
| 522 | req_rmdir->entry_name = (char *) malloc(strlen(dirname) + 1); |
|---|
| 523 | if (!req_rmdir->entry_name) |
|---|
| 524 | { |
|---|
| 525 | printf("Error in malloc\n"); |
|---|
| 526 | return (-1); |
|---|
| 527 | } |
|---|
| 528 | strncpy(req_rmdir->entry_name, dirname, strlen(dirname)); |
|---|
| 529 | req_rmdir->entry_name[strlen(dirname)] = '\0'; |
|---|
| 530 | req_rmdir->parent_refn.handle = resp_mkdir->pinode_refn.handle - 1; |
|---|
| 531 | req_rmdir->parent_refn.fs_id = 1; |
|---|
| 532 | |
|---|
| 533 | // call rmdir |
|---|
| 534 | ret = PVFS_sys_rmdir(req_rmdir); |
|---|
| 535 | if (ret < 0) |
|---|
| 536 | { |
|---|
| 537 | printf("rmdir failed\n"); |
|---|
| 538 | return (-1); |
|---|
| 539 | } |
|---|
| 540 | // test the statfs function |
|---|
| 541 | // Alloc memory and fill the structures |
|---|
| 542 | req_statfs = (PVFS_sysreq_statfs *) malloc(sizeof(PVFS_sysreq_statfs)); |
|---|
| 543 | if (!req_statfs) |
|---|
| 544 | { |
|---|
| 545 | printf("Error in malloc\n"); |
|---|
| 546 | return (-1); |
|---|
| 547 | } |
|---|
| 548 | resp_statfs = (PVFS_sysresp_statfs *) malloc(sizeof(PVFS_sysresp_statfs)); |
|---|
| 549 | if (!resp_statfs) |
|---|
| 550 | { |
|---|
| 551 | printf("Error in malloc\n"); |
|---|
| 552 | return (-1); |
|---|
| 553 | } |
|---|
| 554 | |
|---|
| 555 | // Fill in the dir info |
|---|
| 556 | req_statfs->fs_id = 0; |
|---|
| 557 | |
|---|
| 558 | // call statfs |
|---|
| 559 | ret = PVFS_sys_statfs(req_statfs, resp_statfs); |
|---|
| 560 | if (ret < 0) |
|---|
| 561 | { |
|---|
| 562 | printf("statfs failed\n"); |
|---|
| 563 | return (-1); |
|---|
| 564 | } |
|---|
| 565 | |
|---|
| 566 | // print the handle |
|---|
| 567 | printf("--statfs--\n"); |
|---|
| 568 | printf("Meta stats\n"); |
|---|
| 569 | printf("filetotal:%d\n", resp_statfs->statfs.mstat.filetotal); |
|---|
| 570 | printf("filesystem id:%d\n", req_statfs->fs_id); |
|---|
| 571 | |
|---|
| 572 | printf("IO stats\n"); |
|---|
| 573 | printf("blocksize:%lu\n", |
|---|
| 574 | (unsigned long int) resp_statfs->statfs.iostat.blksize); |
|---|
| 575 | printf("blockfree:%u\n", resp_statfs->statfs.iostat.blkfree); |
|---|
| 576 | printf("blockstotal:%u\n", resp_statfs->statfs.iostat.blktotal); |
|---|
| 577 | printf("filestotal:%u\n", resp_statfs->statfs.iostat.filetotal); |
|---|
| 578 | printf("filefree id:%u\n", resp_statfs->statfs.iostat.filefree); |
|---|
| 579 | |
|---|
| 580 | #endif |
|---|
| 581 | //close it down |
|---|
| 582 | ret = PVFS_sys_finalize(); |
|---|
| 583 | if (ret < 0) |
|---|
| 584 | { |
|---|
| 585 | printf("finalizing sysint failed with errcode = %d\n", ret); |
|---|
| 586 | return (-1); |
|---|
| 587 | } |
|---|
| 588 | |
|---|
| 589 | free(filename); |
|---|
| 590 | return (0); |
|---|
| 591 | } |
|---|
| 592 | |
|---|
| 593 | /* generate random filenames cause ddd sucks and doesn't like taking cmd line |
|---|
| 594 | * arguments (and remove doesn't work yet so I can't cleanup the crap I already |
|---|
| 595 | * created) |
|---|
| 596 | */ |
|---|
| 597 | void gen_rand_str( |
|---|
| 598 | int len, |
|---|
| 599 | char **gen_str) |
|---|
| 600 | { |
|---|
| 601 | static char alphabet[] = "abcdefghijklmnopqrstuvwxyz"; |
|---|
| 602 | int i; |
|---|
| 603 | struct timeval poop; |
|---|
| 604 | int newchar = 0; |
|---|
| 605 | gettimeofday(&poop, NULL); |
|---|
| 606 | |
|---|
| 607 | srand(poop.tv_sec); |
|---|
| 608 | *gen_str = malloc(len + 1); |
|---|
| 609 | for (i = 0; i < len; i++) |
|---|
| 610 | { |
|---|
| 611 | newchar = ((1 + (rand() % 26)) + poop.tv_usec) % 26; |
|---|
| 612 | (*gen_str)[i] = alphabet[newchar]; |
|---|
| 613 | } |
|---|
| 614 | (*gen_str)[len] = '\0'; |
|---|
| 615 | } |
|---|
| 616 | |
|---|
| 617 | /* |
|---|
| 618 | * Local variables: |
|---|
| 619 | * c-indent-level: 4 |
|---|
| 620 | * c-basic-offset: 4 |
|---|
| 621 | * End: |
|---|
| 622 | * |
|---|
| 623 | * vim: ts=8 sts=4 sw=4 expandtab |
|---|
| 624 | */ |
|---|