4 * Copryright (C) 1996 Arthur Ma <arthur.ma@mountainviewdata.com>
6 * Copyright (C) 2001 Mountainview Data, Inc.
8 #include <linux/module.h>
9 #include <linux/errno.h>
10 #include <linux/kernel.h>
11 #include <linux/major.h>
12 #include <linux/slab.h>
13 #include <linux/vmalloc.h>
15 #include "intermezzo_fs.h"
16 #include "intermezzo_kml.h"
18 static int size_round (int val);
19 static int unpack_create (struct kml_create *rec, char *buf,
20 int pos, int *rec_offs);
21 static int unpack_open (struct kml_open *rec, char *buf,
22 int pos, int *rec_offs);
23 static int unpack_symlink (struct kml_symlink *rec, char *buf,
24 int pos, int *rec_offs);
25 static int unpack_mknod (struct kml_mknod *rec, char *buf,
26 int pos, int *rec_offs);
27 static int unpack_link (struct kml_link *rec, char *buf,
28 int pos, int *rec_offs);
29 static int unpack_rename (struct kml_rename *rec, char *buf,
30 int pos, int *rec_offs);
31 static int unpack_unlink (struct kml_unlink *rec, char *buf,
32 int pos, int *rec_offs);
33 static int unpack_rmdir (struct kml_rmdir *rec, char *buf,
34 int pos, int *rec_offs);
35 static int unpack_setattr (struct kml_setattr *rec, char *buf,
36 int pos, int *rec_offs);
37 static int unpack_close (struct kml_close *rec, char *buf,
38 int pos, int *rec_offs);
39 static int unpack_mkdir (struct kml_mkdir *rec, char *buf,
40 int pos, int *rec_offs);
43 static int unpack_endmark (struct kml_endmark *rec, char *buf,
44 int pos, int *rec_offs);
45 static void print_kml_endmark (struct kml_endmark *rec);
48 static int kml_unpack (char *kml_buf, int rec_size, int kml_offset,
49 struct kml_rec **newrec);
50 static char *kml_version (struct presto_version *ver);
51 static void print_kml_prefix (struct big_journal_prefix *head);
52 static void print_kml_create (struct kml_create *rec);
53 static void print_kml_mkdir (struct kml_mkdir *rec);
54 static void print_kml_unlink (struct kml_unlink *rec);
55 static void print_kml_rmdir (struct kml_rmdir *rec);
56 static void print_kml_close (struct kml_close *rec);
57 static void print_kml_symlink (struct kml_symlink *rec);
58 static void print_kml_rename (struct kml_rename *rec);
59 static void print_kml_setattr (struct kml_setattr *rec);
60 static void print_kml_link (struct kml_link *rec);
61 static void print_kml_mknod (struct kml_mknod *rec);
62 static void print_kml_open (struct kml_open *rec);
63 static void print_kml_suffix (struct journal_suffix *tail);
64 static char *readrec (char *recbuf, int reclen, int pos, int *size);
66 #define KML_PREFIX_WORDS 8
67 static int kml_unpack (char *kml_buf, int rec_size, int kml_offset,
68 struct kml_rec **newrec)
76 if (rec_size < sizeof (struct journal_prefix) +
77 sizeof (struct journal_suffix))
80 PRESTO_ALLOC(rec, struct kml_rec *, sizeof (struct kml_rec));
85 rec->rec_kml_offset = kml_offset;
86 rec->rec_size = rec_size;
88 p = dlogit (&rec->rec_head, p, KML_PREFIX_WORDS * sizeof (int));
89 p = dlogit (&rec->rec_head.groups, p,
90 sizeof (int) * rec->rec_head.ngroups);
92 pos = sizeof (struct journal_prefix) +
93 sizeof (int) * rec->rec_head.ngroups;
94 switch (rec->rec_head.opcode)
97 error = unpack_create (&rec->rec_kml.create,
98 kml_buf, pos, &rec_offs);
101 error = unpack_mkdir (&rec->rec_kml.mkdir,
102 kml_buf, pos, &rec_offs);
105 error = unpack_unlink (&rec->rec_kml.unlink,
106 kml_buf, pos, &rec_offs);
109 error = unpack_rmdir (&rec->rec_kml.rmdir,
110 kml_buf, pos, &rec_offs);
113 error = unpack_close (&rec->rec_kml.close,
114 kml_buf, pos, &rec_offs);
117 error = unpack_symlink (&rec->rec_kml.symlink,
118 kml_buf, pos, &rec_offs);
121 error = unpack_rename (&rec->rec_kml.rename,
122 kml_buf, pos, &rec_offs);
125 error = unpack_setattr (&rec->rec_kml.setattr,
126 kml_buf, pos, &rec_offs);
129 error = unpack_link (&rec->rec_kml.link,
130 kml_buf, pos, &rec_offs);
133 error = unpack_open (&rec->rec_kml.open,
134 kml_buf, pos, &rec_offs);
137 error = unpack_mknod (&rec->rec_kml.mknod,
138 kml_buf, pos, &rec_offs);
142 error = unpack_endmark (&rec->rec_kml.endmark,
143 kml_buf, pos, &rec_offs);
147 CDEBUG (D_KML, "wrong opcode::%u\n",
148 rec->rec_head.opcode);
153 PRESTO_FREE (rec, sizeof (struct kml_rec));
156 p = kml_buf + rec_offs;
157 p = dlogit (&rec->rec_tail, p, sizeof (struct journal_suffix));
158 memset (&rec->kml_optimize, 0, sizeof (struct kml_optimize));
164 static int size_round (int val)
166 return (val + 3) & (~0x3);
169 static int unpack_create (struct kml_create *rec, char *buf,
170 int pos, int *rec_offs)
173 int unpack_size = 88;
178 p = dlogit (&rec->old_parentv, p, sizeof (struct presto_version));
179 p = dlogit (&rec->new_parentv, p, sizeof (struct presto_version));
180 p = dlogit (&rec->new_objectv, p, sizeof (struct presto_version));
181 p = dlogit (&rec->mode, p, sizeof (int));
182 p = dlogit (&rec->uid, p, sizeof (int));
183 p = dlogit (&rec->gid, p, sizeof (int));
184 p = dlogit (&pathlen, p, sizeof (int));
186 PRESTO_ALLOC(q, char *, pathlen + 1);
192 memcpy (q, p, pathlen);
196 *rec_offs = pos + unpack_size + size_round(pathlen);
201 static int unpack_open (struct kml_open *rec, char *buf,
202 int pos, int *rec_offs)
208 static int unpack_symlink (struct kml_symlink *rec, char *buf,
209 int pos, int *rec_offs)
212 int unpack_size = 88;
213 int pathlen, targetlen;
217 p = dlogit (&rec->old_parentv, p, sizeof (struct presto_version));
218 p = dlogit (&rec->new_parentv, p, sizeof (struct presto_version));
219 p = dlogit (&rec->new_objectv, p, sizeof (struct presto_version));
220 p = dlogit (&rec->uid, p, sizeof (int));
221 p = dlogit (&rec->gid, p, sizeof (int));
222 p = dlogit (&pathlen, p, sizeof (int));
223 p = dlogit (&targetlen, p, sizeof (int));
225 PRESTO_ALLOC(q, char *, pathlen + 1);
231 memcpy (q, p, pathlen);
235 PRESTO_ALLOC(q, char *, targetlen + 1);
237 PRESTO_FREE (rec->sourcepath, pathlen + 1);
242 memcpy (q, p, targetlen);
246 *rec_offs = pos + unpack_size + size_round(pathlen) +
247 size_round(targetlen);
252 static int unpack_mknod (struct kml_mknod *rec, char *buf,
253 int pos, int *rec_offs)
256 int unpack_size = 96;
261 p = dlogit (&rec->old_parentv, p, sizeof (struct presto_version));
262 p = dlogit (&rec->new_parentv, p, sizeof (struct presto_version));
263 p = dlogit (&rec->new_objectv, p, sizeof (struct presto_version));
264 p = dlogit (&rec->mode, p, sizeof (int));
265 p = dlogit (&rec->uid, p, sizeof (int));
266 p = dlogit (&rec->gid, p, sizeof (int));
267 p = dlogit (&rec->major, p, sizeof (int));
268 p = dlogit (&rec->minor, p, sizeof (int));
269 p = dlogit (&pathlen, p, sizeof (int));
271 PRESTO_ALLOC(q, char *, pathlen + 1);
277 memcpy (q, p, pathlen);
281 *rec_offs = pos + unpack_size + size_round(pathlen);
286 static int unpack_link (struct kml_link *rec, char *buf,
287 int pos, int *rec_offs)
290 int unpack_size = 80;
291 int pathlen, targetlen;
295 p = dlogit (&rec->old_parentv, p, sizeof (struct presto_version));
296 p = dlogit (&rec->new_parentv, p, sizeof (struct presto_version));
297 p = dlogit (&rec->new_objectv, p, sizeof (struct presto_version));
298 p = dlogit (&pathlen, p, sizeof (int));
299 p = dlogit (&targetlen, p, sizeof (int));
301 PRESTO_ALLOC(q, char *, pathlen + 1);
307 memcpy (q, p, pathlen);
310 p += size_round (pathlen);
312 PRESTO_ALLOC(q, char *, targetlen + 1);
314 PRESTO_FREE (rec->sourcepath, pathlen + 1);
318 memcpy (q, p, targetlen);
322 *rec_offs = pos + unpack_size + size_round(pathlen) +
323 size_round(targetlen);
328 static int unpack_rename (struct kml_rename *rec, char *buf,
329 int pos, int *rec_offs)
332 int unpack_size = 104;
333 int pathlen, targetlen;
337 p = dlogit (&rec->old_objectv, p, sizeof (struct presto_version));
338 p = dlogit (&rec->new_objectv, p, sizeof (struct presto_version));
339 p = dlogit (&rec->new_tgtv, p, sizeof (struct presto_version));
340 p = dlogit (&rec->old_tgtv, p, sizeof (struct presto_version));
341 p = dlogit (&pathlen, p, sizeof (int));
342 p = dlogit (&targetlen, p, sizeof (int));
344 PRESTO_ALLOC(q, char *, pathlen + 1);
350 memcpy (q, p, pathlen);
353 p += size_round (pathlen);
355 PRESTO_ALLOC(q, char *, targetlen + 1);
357 PRESTO_FREE (rec->sourcepath, pathlen + 1);
362 memcpy (q, p, targetlen);
366 *rec_offs = pos + unpack_size + size_round(pathlen) +
367 size_round(targetlen);
372 static int unpack_unlink (struct kml_unlink *rec, char *buf,
373 int pos, int *rec_offs)
376 int unpack_size = 80;
377 int pathlen, targetlen;
381 p = dlogit (&rec->old_parentv, p, sizeof (struct presto_version));
382 p = dlogit (&rec->new_parentv, p, sizeof (struct presto_version));
383 p = dlogit (&rec->old_tgtv, p, sizeof (struct presto_version));
384 p = dlogit (&pathlen, p, sizeof (int));
385 p = dlogit (&targetlen, p, sizeof (int));
387 PRESTO_ALLOC(q, char *, pathlen + 1);
393 memcpy (q, p, pathlen);
396 p += size_round (pathlen);
398 PRESTO_ALLOC(q, char *, targetlen + 1);
400 PRESTO_FREE (rec->path, pathlen + 1);
405 memcpy (q, p, targetlen);
409 /* fix the presto_journal_unlink problem */
410 *rec_offs = pos + unpack_size + size_round(pathlen) +
411 size_round(targetlen);
416 static int unpack_rmdir (struct kml_rmdir *rec, char *buf,
417 int pos, int *rec_offs)
420 int unpack_size = 80;
421 int pathlen, targetlen;
425 p = dlogit (&rec->old_parentv, p, sizeof (struct presto_version));
426 p = dlogit (&rec->new_parentv, p, sizeof (struct presto_version));
427 p = dlogit (&rec->old_tgtv, p, sizeof (struct presto_version));
428 p = dlogit (&pathlen, p, sizeof (int));
429 p = dlogit (&targetlen, p, sizeof (int));
431 PRESTO_ALLOC(q, char *, pathlen + 1);
437 memcpy (q, p, pathlen);
440 p += size_round (pathlen);
442 PRESTO_ALLOC(q, char *, targetlen + 1);
444 PRESTO_FREE (rec->path, pathlen + 1);
448 memcpy (q, p, targetlen);
452 *rec_offs = pos + unpack_size + size_round(pathlen) +
453 size_round(targetlen);
458 static int unpack_setattr (struct kml_setattr *rec, char *buf,
459 int pos, int *rec_offs)
462 int unpack_size = 72;
464 __u64 size, mtime, ctime;
466 int valid, mode, uid, gid, flags;
471 p = dlogit (&rec->old_objectv, p, sizeof (struct presto_version));
472 p = dlogit (&valid, p, sizeof (int));
473 p = dlogit (&mode, p, sizeof (int));
474 p = dlogit (&uid, p, sizeof (int));
475 p = dlogit (&gid, p, sizeof (int));
476 p = dlogit (&objattr, p, sizeof (struct kml_attr));
477 p = dlogit (&flags, p, sizeof (int));
478 p = dlogit (&pathlen, p, sizeof (int));
480 rec->iattr.ia_valid = valid;
481 rec->iattr.ia_mode = mode;
482 rec->iattr.ia_uid = uid;
483 rec->iattr.ia_gid = gid;
484 rec->iattr.ia_size = objattr.size;
485 rec->iattr.ia_mtime = objattr.mtime;
486 rec->iattr.ia_ctime = objattr.ctime;
487 rec->iattr.ia_atime = 0;
488 rec->iattr.ia_attr_flags = flags;
490 PRESTO_ALLOC(q, char *, pathlen + 1);
495 memcpy (q, p, pathlen);
500 *rec_offs = pos + unpack_size + size_round(pathlen);
505 static int unpack_close (struct kml_close *rec, char *buf,
506 int pos, int *rec_offs)
509 int unpack_size = 52;
514 p = dlogit (&rec->open_mode, p, sizeof (int));
515 p = dlogit (&rec->open_uid, p, sizeof (int));
516 p = dlogit (&rec->open_gid, p, sizeof (int));
517 p = dlogit (&rec->new_objectv, p, sizeof (struct presto_version));
518 p = dlogit (&rec->ino, p, sizeof (__u64));
519 p = dlogit (&rec->generation, p, sizeof (int));
520 p = dlogit (&pathlen, p, sizeof (int));
522 PRESTO_ALLOC(q, char *, pathlen + 1);
528 memcpy (q, p, pathlen);
533 *rec_offs = pos + unpack_size + size_round(pathlen);
538 static int unpack_mkdir (struct kml_mkdir *rec, char *buf,
539 int pos, int *rec_offs)
542 int unpack_size = 88;
547 p = dlogit (&rec->old_parentv, p, sizeof (struct presto_version));
548 p = dlogit (&rec->new_parentv, p, sizeof (struct presto_version));
549 p = dlogit (&rec->new_objectv, p, sizeof (struct presto_version));
550 p = dlogit (&rec->mode, p, sizeof (int));
551 p = dlogit (&rec->uid, p, sizeof (int));
552 p = dlogit (&rec->gid, p, sizeof (int));
553 p = dlogit (&pathlen, p, sizeof (int));
555 PRESTO_ALLOC(q, char *, pathlen + 1);
561 memcpy (q, p, pathlen);
566 *rec_offs = pos + unpack_size + size_round(pathlen);
572 static int unpack_endmark (struct kml_endmark *rec, char *buf,
573 int pos, int *rec_offs)
577 p = dlogit (&rec->total, p, sizeof (int));
579 PRESTO_ALLOC (rec->kop, struct kml_kop_node *,
580 sizeof (struct kml_kop_node) * rec->total);
581 if (rec->kop == NULL) {
586 p = dlogit (rec->kop, p, sizeof (struct kml_kop_node) * rec->total);
588 *rec_offs = pos + sizeof (int) + sizeof (struct kml_kop_node) * rec->total;
593 static char *kml_version (struct presto_version *ver)
595 static char buf[256];
596 sprintf (buf, "mt::%lld, ct::%lld, size::%lld",
597 ver->pv_mtime, ver->pv_ctime, ver->pv_size);
601 static void print_kml_prefix (struct big_journal_prefix *head)
605 CDEBUG (D_KML, " === KML PREFIX\n");
606 CDEBUG (D_KML, " len = %u\n", head->len);
607 CDEBUG (D_KML, " version = %u\n", head->version);
608 CDEBUG (D_KML, " pid = %u\n", head->pid);
609 CDEBUG (D_KML, " uid = %u\n", head->uid);
610 CDEBUG (D_KML, " fsuid = %u\n", head->fsuid);
611 CDEBUG (D_KML, " fsgid = %u\n", head->fsgid);
612 CDEBUG (D_KML, " opcode = %u\n", head->opcode);
613 CDEBUG (D_KML, " ngroup = %u", head->ngroups);
614 for (i = 0; i < head->ngroups; i++)
615 CDEBUG (D_KML, "%u ", head->groups[i]);
616 CDEBUG (D_KML, "\n");
619 static void print_kml_create (struct kml_create *rec)
621 CDEBUG (D_KML, " === CREATE\n");
622 CDEBUG (D_KML, " path::%s\n", rec->path);
623 CDEBUG (D_KML, " new_objv::%s\n", kml_version (&rec->new_objectv));
624 CDEBUG (D_KML, " old_parv::%s\n", kml_version (&rec->old_parentv));
625 CDEBUG (D_KML, " new_parv::%s\n", kml_version (&rec->new_parentv));
626 CDEBUG (D_KML, " mode::%o\n", rec->mode);
627 CDEBUG (D_KML, " uid::%d\n", rec->uid);
628 CDEBUG (D_KML, " gid::%d\n", rec->gid);
631 static void print_kml_mkdir (struct kml_mkdir *rec)
633 CDEBUG (D_KML, " === MKDIR\n");
634 CDEBUG (D_KML, " path::%s\n", rec->path);
635 CDEBUG (D_KML, " new_objv::%s\n", kml_version (&rec->new_objectv));
636 CDEBUG (D_KML, " old_parv::%s\n", kml_version (&rec->old_parentv));
637 CDEBUG (D_KML, " new_parv::%s\n", kml_version (&rec->new_parentv));
638 CDEBUG (D_KML, " mode::%o\n", rec->mode);
639 CDEBUG (D_KML, " uid::%d\n", rec->uid);
640 CDEBUG (D_KML, " gid::%d\n", rec->gid);
643 static void print_kml_unlink (struct kml_unlink *rec)
645 CDEBUG (D_KML, " === UNLINK\n");
646 CDEBUG (D_KML, " path::%s/%s\n", rec->path, rec->name);
647 CDEBUG (D_KML, " old_tgtv::%s\n", kml_version (&rec->old_tgtv));
648 CDEBUG (D_KML, " old_parv::%s\n", kml_version (&rec->old_parentv));
649 CDEBUG (D_KML, " new_parv::%s\n", kml_version (&rec->new_parentv));
652 static void print_kml_rmdir (struct kml_rmdir *rec)
654 CDEBUG (D_KML, " === RMDIR\n");
655 CDEBUG (D_KML, " path::%s/%s\n", rec->path, rec->name);
656 CDEBUG (D_KML, " old_tgtv::%s\n", kml_version (&rec->old_tgtv));
657 CDEBUG (D_KML, " old_parv::%s\n", kml_version (&rec->old_parentv));
658 CDEBUG (D_KML, " new_parv::%s\n", kml_version (&rec->new_parentv));
661 static void print_kml_close (struct kml_close *rec)
663 CDEBUG (D_KML, " === CLOSE\n");
664 CDEBUG (D_KML, " mode::%o\n", rec->open_mode);
665 CDEBUG (D_KML, " uid::%d\n", rec->open_uid);
666 CDEBUG (D_KML, " gid::%d\n", rec->open_gid);
667 CDEBUG (D_KML, " path::%s\n", rec->path);
668 CDEBUG (D_KML, " new_objv::%s\n", kml_version (&rec->new_objectv));
669 CDEBUG (D_KML, " ino::%lld\n", rec->ino);
670 CDEBUG (D_KML, " gen::%u\n", rec->generation);
673 static void print_kml_symlink (struct kml_symlink *rec)
675 CDEBUG (D_KML, " === SYMLINK\n");
676 CDEBUG (D_KML, " s-path::%s\n", rec->sourcepath);
677 CDEBUG (D_KML, " t-path::%s\n", rec->targetpath);
678 CDEBUG (D_KML, " old_parv::%s\n", kml_version (&rec->old_parentv));
679 CDEBUG (D_KML, " new_parv::%s\n", kml_version (&rec->new_parentv));
680 CDEBUG (D_KML, " new_objv::%s\n", kml_version (&rec->new_objectv));
681 CDEBUG (D_KML, " uid::%d\n", rec->uid);
682 CDEBUG (D_KML, " gid::%d\n", rec->gid);
685 static void print_kml_rename (struct kml_rename *rec)
687 CDEBUG (D_KML, " === RENAME\n");
688 CDEBUG (D_KML, " s-path::%s\n", rec->sourcepath);
689 CDEBUG (D_KML, " t-path::%s\n", rec->targetpath);
690 CDEBUG (D_KML, " old_tgtv::%s\n", kml_version (&rec->old_tgtv));
691 CDEBUG (D_KML, " new_tgtv::%s\n", kml_version (&rec->new_tgtv));
692 CDEBUG (D_KML, " new_objv::%s\n", kml_version (&rec->new_objectv));
693 CDEBUG (D_KML, " old_objv::%s\n", kml_version (&rec->old_objectv));
696 static void print_kml_setattr (struct kml_setattr *rec)
698 CDEBUG (D_KML, " === SETATTR\n");
699 CDEBUG (D_KML, " path::%s\n", rec->path);
700 CDEBUG (D_KML, " old_objv::%s\n", kml_version (&rec->old_objectv));
701 CDEBUG (D_KML, " valid::0x%x\n", rec->iattr.ia_valid);
702 CDEBUG (D_KML, " mode::%o\n", rec->iattr.ia_mode);
703 CDEBUG (D_KML, " uid::%d\n", rec->iattr.ia_uid);
704 CDEBUG (D_KML, " gid::%d\n", rec->iattr.ia_gid);
705 CDEBUG (D_KML, " size::%u\n", (u32) rec->iattr.ia_size);
706 CDEBUG (D_KML, " mtime::%u\n", (u32) rec->iattr.ia_mtime);
707 CDEBUG (D_KML, " ctime::%u\n", (u32) rec->iattr.ia_ctime);
708 CDEBUG (D_KML, " flags::%u\n", (u32) rec->iattr.ia_attr_flags);
711 static void print_kml_link (struct kml_link *rec)
713 CDEBUG (D_KML, " === LINK\n");
714 CDEBUG (D_KML, " path::%s ==> %s\n", rec->sourcepath, rec->targetpath);
715 CDEBUG (D_KML, " old_parv::%s\n", kml_version (&rec->old_parentv));
716 CDEBUG (D_KML, " new_obj::%s\n", kml_version (&rec->new_objectv));
717 CDEBUG (D_KML, " new_parv::%s\n", kml_version (&rec->new_parentv));
720 static void print_kml_mknod (struct kml_mknod *rec)
722 CDEBUG (D_KML, " === MKNOD\n");
723 CDEBUG (D_KML, " path::%s\n", rec->path);
724 CDEBUG (D_KML, " new_obj::%s\n", kml_version (&rec->new_objectv));
725 CDEBUG (D_KML, " old_parv::%s\n", kml_version (&rec->old_parentv));
726 CDEBUG (D_KML, " new_parv::%s\n", kml_version (&rec->new_parentv));
727 CDEBUG (D_KML, " mode::%o\n", rec->mode);
728 CDEBUG (D_KML, " uid::%d\n", rec->uid);
729 CDEBUG (D_KML, " gid::%d\n", rec->gid);
730 CDEBUG (D_KML, " major::%d\n", rec->major);
731 CDEBUG (D_KML, " minor::%d\n", rec->minor);
734 static void print_kml_open (struct kml_open *rec)
736 CDEBUG (D_KML, " === OPEN\n");
740 static void print_kml_endmark (struct kml_endmark *rec)
743 CDEBUG (D_KML, " === ENDMARK\n");
744 CDEBUG (D_KML, " total::%u\n", rec->total);
745 for (i = 0; i < rec->total; i++)
747 CDEBUG (D_KML, " recno=%ld::flag=%ld,op=%ld, i_ino=%ld, \
748 i_nlink=%ld\n", (long) rec->kop[i].kml_recno,
749 (long) rec->kop[i].kml_flag, (long) rec->kop[i].kml_op,
750 (long) rec->kop[i].i_ino, (long) rec->kop[i].i_nlink);
755 static void print_kml_optimize (struct kml_optimize *rec)
757 CDEBUG (D_KML, " === OPTIMIZE\n");
758 if (rec->kml_flag == KML_REC_DELETE)
759 CDEBUG (D_KML, " kml_flag::deleted\n");
761 CDEBUG (D_KML, " kml_flag::exist\n");
762 CDEBUG (D_KML, " kml_op::%u\n", rec->kml_op);
763 CDEBUG (D_KML, " i_nlink::%d\n", rec->i_nlink);
764 CDEBUG (D_KML, " i_ino::%u\n", rec->i_ino);
767 static void print_kml_suffix (struct journal_suffix *tail)
769 CDEBUG (D_KML, " === KML SUFFIX\n");
770 CDEBUG (D_KML, " prevrec::%ld\n", tail->prevrec);
771 CDEBUG (D_KML, " recno::%ld\n", (long) tail->recno);
772 CDEBUG (D_KML, " time::%d\n", tail->time);
773 CDEBUG (D_KML, " len::%d\n", tail->len);
776 void kml_printrec (struct kml_rec *rec, int kml_printop)
778 if (kml_printop & PRINT_KML_PREFIX)
779 print_kml_prefix (&rec->rec_head);
780 if (kml_printop & PRINT_KML_REC)
782 switch (rec->rec_head.opcode)
785 print_kml_create (&rec->rec_kml.create);
788 print_kml_mkdir (&rec->rec_kml.mkdir);
791 print_kml_unlink (&rec->rec_kml.unlink);
794 print_kml_rmdir (&rec->rec_kml.rmdir);
797 print_kml_close (&rec->rec_kml.close);
800 print_kml_symlink (&rec->rec_kml.symlink);
803 print_kml_rename (&rec->rec_kml.rename);
806 print_kml_setattr (&rec->rec_kml.setattr);
809 print_kml_link (&rec->rec_kml.link);
812 print_kml_open (&rec->rec_kml.open);
815 print_kml_mknod (&rec->rec_kml.mknod);
819 print_kml_endmark (&rec->rec_kml.endmark);
823 CDEBUG (D_KML, " === BAD RECORD, opcode=%u\n",
824 rec->rec_head.opcode);
828 if (kml_printop & PRINT_KML_SUFFIX)
829 print_kml_suffix (&rec->rec_tail);
830 if (kml_printop & PRINT_KML_OPTIMIZE)
831 print_kml_optimize (&rec->kml_optimize);
834 void kml_freerec (struct kml_rec *rec)
836 char *sourcepath = NULL,
838 switch (rec->rec_head.opcode)
841 sourcepath = rec->rec_kml.create.path;
844 sourcepath = rec->rec_kml.create.path;
847 sourcepath = rec->rec_kml.unlink.path;
848 targetpath = rec->rec_kml.unlink.name;
851 sourcepath = rec->rec_kml.rmdir.path;
852 targetpath = rec->rec_kml.rmdir.name;
855 sourcepath = rec->rec_kml.close.path;
858 sourcepath = rec->rec_kml.symlink.sourcepath;
859 targetpath = rec->rec_kml.symlink.targetpath;
862 sourcepath = rec->rec_kml.rename.sourcepath;
863 targetpath = rec->rec_kml.rename.targetpath;
866 sourcepath = rec->rec_kml.setattr.path;
869 sourcepath = rec->rec_kml.link.sourcepath;
870 targetpath = rec->rec_kml.link.targetpath;
875 sourcepath = rec->rec_kml.mknod.path;
879 PRESTO_FREE (rec->rec_kml.endmark.kop, sizeof (int) +
880 sizeof (struct kml_kop_node) *
881 rec->rec_kml.endmark.total);
887 if (sourcepath != NULL)
888 PRESTO_FREE (sourcepath, strlen (sourcepath) + 1);
889 if (targetpath != NULL)
890 PRESTO_FREE (targetpath, strlen (targetpath) + 1);
893 char *readrec (char *recbuf, int reclen, int pos, int *size)
895 char *p = recbuf + pos;
896 *size = *((int *) p);
897 if (*size > (reclen - pos))
902 int kml_decoderec (char *buf, int pos, int buflen, int *size,
903 struct kml_rec **newrec)
907 tmp = readrec (buf, buflen, pos, size);
910 error = kml_unpack (tmp, *size, pos, newrec);
915 static void fill_kmlrec_optimize (struct list_head *head,
916 struct kml_rec *optrec)
918 struct kml_rec *kmlrec;
919 struct list_head *tmp;
920 struct kml_endmark *km;
921 struct kml_optimize *ko;
924 if (optrec->rec_kml.endmark.total == 0)
926 n = optrec->rec_kml.endmark.total - 1;
928 km = &optrec->rec_kml.endmark;
929 while ( n >= 0 && tmp != head )
931 kmlrec = list_entry(tmp, struct kml_rec,
932 kml_optimize.kml_chains);
934 if (kmlrec->rec_tail.recno == km->kop[n].kml_recno)
936 ko = &kmlrec->kml_optimize;
937 ko->kml_flag = km->kop[n].kml_flag;
938 ko->kml_op = km->kop[n].kml_op;
939 ko->i_nlink = km->kop[n].i_nlink;
940 ko->i_ino = km->kop[n].i_ino;
945 CDEBUG (D_KML, "Yeah!!!, KML optimize error, recno=%d, n=%d\n",
946 optrec->rec_tail.recno, n);
950 int decode_kmlrec (struct list_head *head, char *kml_buf, int buflen)
955 while (pos < buflen) {
956 err = kml_decoderec (kml_buf, pos, buflen, &size, &rec);
960 if (rec->rec_head.opcode == KML_ENDMARK) {
961 fill_kmlrec_optimize (head, rec);
962 mark_rec_deleted (rec);
965 list_add_tail (&rec->kml_optimize.kml_chains, head);
971 int delete_kmlrec (struct list_head *head)
974 struct list_head *tmp;
976 if (list_empty(head))
979 while ( tmp != head ) {
980 rec = list_entry(tmp, struct kml_rec,
981 kml_optimize.kml_chains);
985 INIT_LIST_HEAD(head);
989 int print_allkmlrec (struct list_head *head, int printop)
992 struct list_head *tmp;
994 if (list_empty(head))
997 while ( tmp != head ) {
998 rec = list_entry(tmp, struct kml_rec,
999 kml_optimize.kml_chains);
1002 if (printop & PRINT_KML_EXIST) {
1003 if (is_deleted_node (rec))
1006 else if (printop & PRINT_KML_DELETE) {
1007 if (! is_deleted_node (rec))
1011 kml_printrec (rec, printop);
1013 INIT_LIST_HEAD(head);