4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
39 #include <sys/param.h>
40 #include <sys/signal.h>
42 #include <sys/sysmacros.h>
43 #include <sys/types.h>
44 #include <sys/vnode.h>
45 #include <sys/mntent.h>
50 #include <sys/fs/udf_volume.h>
54 typedef unsigned short unicode_t
;
55 #define MAXNAMLEN 0x200
57 extern uint32_t i_number
;
59 extern int32_t run_fsdb();
64 int32_t parse_udfs(uint32_t);
65 int32_t parse_vds(uint32_t, uint32_t);
66 int32_t parse_part(struct part_desc
*);
67 int32_t parse_lvd(struct log_vol_desc
*);
69 int32_t get_vat_loc();
70 int32_t get_fid(uint32_t, uint8_t *, uint64_t);
74 char prompt
[256] = "fsdb>";
76 #define ARG_OVERRIDE 0
77 #define ARG_NEW_PROMPT 1
78 #define ARG_WR_ENABLED 2
89 int32_t openflg
= O_RDONLY
;
96 #define UDP_BITMAPS 0x00
97 #define UDP_SPACETBLS 0x01
100 int32_t fd
, nparts
, nmaps
;
101 int32_t bmask
, l2d
, l2b
;
105 uint32_t ricb_loc
, ricb_len
;
110 main(int argc
, char *argv
[])
114 char *subopts
, *optval
;
116 #if !defined(TEXT_DOMAIN)
117 #define TEXT_DOMAIN "SYS_TEST"
119 (void) textdomain(TEXT_DOMAIN
);
123 while ((opt
= getopt(argc
, argv
, "o:")) != EOF
) {
127 while (*subopts
!= '\0') {
128 switch (getsubopt(&subopts
,
129 subopt_v
, &optval
)) {
132 (void) fprintf(stdout
,
133 gettext("error checking off\n"));
135 case ARG_NEW_PROMPT
:
136 if (optval
== NULL
) {
139 if (strlen(optval
) > 255) {
140 (void) fprintf(stdout
,
141 gettext("prompt should be less"
142 "than 255 bytes\n"));
145 (void) strcpy(prompt
, optval
);
147 case ARG_WR_ENABLED
:
161 if ((argc
- optind
) != 1) { /* Should just have "special" left */
165 if (ud_init(-1, &udh
) != 0) {
166 (void) fprintf(stderr
,
167 gettext("udfs labelit: cannot initialize ud_lib\n"));
171 if ((fd
= ud_open_dev(udh
, argv
[optind
], openflg
)) < 0) {
176 if ((ret
= ud_fill_udfs_info(udh
)) != 0) {
180 if ((udh
->udfs
.flags
& VALID_UDFS
) == 0) {
184 bsize
= udh
->udfs
.lbsize
;
187 while ((bsize
>> l2d
) > DEV_BSIZE
) {
192 ricb_prn
= udh
->udfs
.ricb_prn
;
193 ricb_loc
= udh
->udfs
.ricb_loc
;
194 ricb_len
= udh
->udfs
.ricb_len
;
196 value
= i_number
= ud_xlate_to_daddr(udh
, ricb_prn
, ricb_loc
);
209 * usage - print usage and exit
214 (void) fprintf(stdout
,
215 gettext("usage: %s [options] special\n"), progname
);
216 (void) fprintf(stdout
,
217 gettext("options:\n"));
218 (void) fprintf(stdout
,
219 gettext("\t-o\tSpecify udfs filesystem sepcific options\n"));
220 (void) fprintf(stdout
,
221 gettext("\t\tAvailable suboptions are:\n"));
222 (void) fprintf(stdout
,
223 gettext("\t\t?\tdisplay usage\n"));
224 (void) fprintf(stdout
,
225 gettext("\t\to\toverride some error conditions\n"));
226 (void) fprintf(stdout
,
227 gettext("\t\tp\t\"string\" set prompt to string\n"));
228 (void) fprintf(stdout
,
229 gettext("\t\tw\topen for write\n"));
245 bp->fwd = bhdr.fwd; \
246 bhdr.fwd->back = bp; \
257 addr
= malloc(NBUF
* udh
->udfs
.lbsize
);
258 bhdr
.fwd
= bhdr
.back
= &bhdr
;
259 for (i
= 0; i
< NBUF
; i
++) {
261 bp
->blkaddr
= addr
+ i
* udh
->udfs
.lbsize
;
268 getblk(uoff_t address
)
273 off
= address
& ~bmask
;
274 block
= address
>> l2b
;
275 for (bp
= bhdr
.fwd
; bp
!= &bhdr
; bp
= bp
->fwd
) {
276 if (bp
->valid
&& bp
->blkno
== block
) {
284 if (llseek(fd
, off
, SEEK_SET
) != off
) {
285 (void) fprintf(stdout
,
286 gettext("Seek failed fd %x off %llx errno %x\n"),
291 if (read(fd
, bp
->blkaddr
, udh
->udfs
.lbsize
) != udh
->udfs
.lbsize
) {
292 (void) fprintf(stdout
,
293 gettext("Read failed fd %x off %llx errno %x\n"),
299 bp
->back
->fwd
= bp
->fwd
;
300 bp
->fwd
->back
= bp
->back
;
302 return (bp
->blkaddr
);
307 putblk(caddr_t address
)
312 if (openflg
== O_RDONLY
) {
313 (void) fprintf(stdout
,
314 gettext("Not run with -w flag\n"));
318 for (bp
= bhdr
.fwd
; bp
!= &bhdr
; bp
= bp
->fwd
) {
319 if (bp
->valid
&& bp
->blkaddr
== address
) {
323 (void) fprintf(stdout
,
324 gettext("Could not find the buffer\n"));
328 off
= bp
->blkno
<< l2b
;
329 if (llseek(fd
, off
, SEEK_SET
) == off
) {
330 if (write(fd
, bp
->blkaddr
, udh
->udfs
.lbsize
) ==
334 (void) fprintf(stdout
,
335 gettext("Write failed fd %x off %llx errno %x\n"),
338 (void) fprintf(stdout
,
339 gettext("Seek failed fd %x off %llx errno %x\n"),
350 for (bp
= bhdr
.fwd
; bp
!= &bhdr
; bp
= bp
->fwd
) {
356 * If addr == NULL then use id to print the desc
357 * other wise use addr to self identify the type of desc
360 print_desc(uint32_t addr
, int32_t id
)
366 * Read the block at addr
367 * find out the type of tag
368 * and print the descriptor
371 if ((baddr
= getblk(addr
& (~bmask
))) == NULL
) {
372 (void) fprintf(stdout
,
373 gettext("Could not read block %x\n"),
377 tag
= (struct tag
*)(baddr
+ (addr
& bmask
));
382 if ((tag
= (struct tag
*)getblk(
383 udh
->udfs
.avdp_loc
<< l2b
)) == NULL
) {
384 (void) fprintf(stdout
,
385 gettext("Could not read AVDP\n"));
395 i
= udh
->udfs
.mvds_loc
;
397 (udh
->udfs
.mvds_len
>> l2b
);
398 } else if (id
== RVDS
) {
399 i
= udh
->udfs
.rvds_loc
;
401 (udh
->udfs
.rvds_len
>> l2b
);
403 i
= udh
->udfs
.lvid_loc
;
405 (udh
->udfs
.lvid_len
>> l2b
);
408 for (; i
< end
; i
++) {
409 print_desc(i
<< l2b
, 0);
417 uint32_t i
, end
, block
;
420 prn
= udh
->udfs
.fsds_prn
;
421 i
= udh
->udfs
.fsds_loc
;
423 (udh
->udfs
.fsds_len
>> l2b
);
427 end
= i
+ (ricb_len
>> l2b
);
430 for (; i
< end
; i
++) {
431 if ((block
= ud_xlate_to_daddr(
432 udh
, prn
, i
)) == 0) {
433 (void) fprintf(stdout
,
434 gettext("Cannot xlate "
439 print_desc(block
<< l2b
, 0);
448 switch (SWAP_16(tag
->tag_id
)) {
449 case UD_PRI_VOL_DESC
:
450 print_pvd(stdout
, (struct pri_vol_desc
*)tag
);
452 case UD_ANCH_VOL_DESC
:
453 print_avd(stdout
, (struct anch_vol_desc_ptr
*)tag
);
455 case UD_VOL_DESC_PTR
:
456 print_vdp(stdout
, (struct vol_desc_ptr
*)tag
);
458 case UD_IMPL_USE_DESC
:
459 print_iuvd(stdout
, (struct iuvd_desc
*)tag
);
462 print_part(stdout
, (struct part_desc
*)tag
);
464 case UD_LOG_VOL_DESC
:
465 print_lvd(stdout
, (struct log_vol_desc
*)tag
);
467 case UD_UNALL_SPA_DESC
:
468 print_usd(stdout
, (struct unall_spc_desc
*)tag
);
471 (void) fprintf(stdout
, "TERM DESC\n");
472 print_tag(stdout
, tag
);
474 case UD_LOG_VOL_INT
:
475 print_lvid(stdout
, (struct log_vol_int_desc
*)tag
);
477 case UD_FILE_SET_DESC
:
478 print_fsd(stdout
, udh
, (struct file_set_desc
*)tag
);
480 case UD_FILE_ID_DESC
:
481 print_fid(stdout
, (struct file_id
*)tag
);
483 case UD_ALLOC_EXT_DESC
:
484 print_aed(stdout
, (struct alloc_ext_desc
*)tag
);
486 case UD_INDIRECT_ENT
:
487 print_ie(stdout
, (struct indirect_entry
*)tag
);
489 case UD_TERMINAL_ENT
:
490 print_td(stdout
, (struct term_desc
*)tag
);
493 print_fe(stdout
, (struct file_entry
*)tag
);
495 case UD_EXT_ATTR_HDR
:
496 case UD_UNALL_SPA_ENT
:
497 case UD_SPA_BMAP_DESC
:
498 case UD_PART_INT_DESC
:
499 case UD_EXT_FILE_ENT
:
502 (void) fprintf(stdout
,
503 gettext("unknown descriptor\n"));
504 print_tag(stdout
, tag
);
510 set_file(int32_t id
, uint32_t iloc
, uint64_t value
)
514 uint32_t i32
, block
, ea_len
, ea_off
;
516 struct file_entry
*fe
;
517 struct dev_spec_ear
*ds
;
519 struct ext_attr_hdr
*eah
;
522 if ((fe
= (struct file_entry
*)getblk(iloc
)) == NULL
) {
525 if (ud_verify_tag(udh
, &fe
->fe_tag
, UD_FILE_ENTRY
,
526 SWAP_32(fe
->fe_tag
.tag_loc
), 1, 1) != 0) {
530 i16
= SWAP_16(((uint16_t)value
));
531 i32
= SWAP_32(((uint32_t)value
));
532 i64
= SWAP_64(value
);
535 fe
->fe_acc_time
.ts_tzone
= i16
;
538 fe
->fe_acc_time
.ts_year
= i16
;
541 fe
->fe_acc_time
.ts_month
= i8
;
544 fe
->fe_acc_time
.ts_day
= i8
;
547 fe
->fe_acc_time
.ts_hour
= i8
;
550 fe
->fe_acc_time
.ts_min
= i8
;
553 fe
->fe_acc_time
.ts_sec
= i8
;
556 fe
->fe_acc_time
.ts_csec
= i8
;
559 fe
->fe_acc_time
.ts_husec
= i8
;
562 fe
->fe_acc_time
.ts_usec
= i8
;
565 fe
->fe_attr_time
.ts_tzone
= i16
;
568 fe
->fe_attr_time
.ts_year
= i16
;
571 fe
->fe_attr_time
.ts_month
= i8
;
574 fe
->fe_attr_time
.ts_day
= i8
;
577 fe
->fe_attr_time
.ts_hour
= i8
;
580 fe
->fe_attr_time
.ts_min
= i8
;
583 fe
->fe_attr_time
.ts_sec
= i8
;
586 fe
->fe_attr_time
.ts_csec
= i8
;
589 fe
->fe_attr_time
.ts_husec
= i8
;
592 fe
->fe_attr_time
.ts_usec
= i8
;
595 fe
->fe_mod_time
.ts_tzone
= i16
;
598 fe
->fe_mod_time
.ts_year
= i16
;
601 fe
->fe_mod_time
.ts_month
= i8
;
604 fe
->fe_mod_time
.ts_day
= i8
;
607 fe
->fe_mod_time
.ts_hour
= i8
;
610 fe
->fe_mod_time
.ts_min
= i8
;
613 fe
->fe_mod_time
.ts_sec
= i8
;
616 fe
->fe_mod_time
.ts_csec
= i8
;
619 fe
->fe_mod_time
.ts_husec
= i8
;
622 fe
->fe_mod_time
.ts_usec
= i8
;
635 if ((fe
->fe_icb_tag
.itag_ftype
!= VBLK
) &&
636 (fe
->fe_icb_tag
.itag_ftype
!= VCHR
)) {
637 (void) fprintf(stdout
,
638 gettext("Not a device\n"));
642 eah
= (struct ext_attr_hdr
*)fe
->fe_spec
;
643 ea_off
= SWAP_32(eah
->eah_ial
);
644 ea_len
= SWAP_32(fe
->fe_len_ear
);
645 block
= SWAP_32(eah
->eah_tag
.tag_loc
);
646 if (ea_len
&& (ud_verify_tag(udh
, &eah
->eah_tag
,
647 UD_EXT_ATTR_HDR
, block
, 1, 1) == 0)) {
648 while (ea_off
< ea_len
) {
650 ah
= (struct attr_hdr
*)
651 &fe
->fe_spec
[ea_off
];
652 if ((ah
->ahdr_atype
== SWAP_32(12)) &&
653 (ah
->ahdr_astype
== 1)) {
655 ds
= (struct dev_spec_ear
*)ah
;
657 ds
->ds_major_id
= i32
;
659 ds
->ds_minor_id
= i32
;
661 ud_make_tag(udh
, &eah
->eah_tag
,
662 UD_EXT_ATTR_HDR
, block
,
663 eah
->eah_tag
.tag_crc_len
);
668 (void) fprintf(stdout
,
669 gettext("does not have a Device Specification EA\n"));
674 fe
->fe_info_len
= i64
;
680 fe
->fe_uniq_id
= i32
;
683 (void) fprintf(stdout
,
684 gettext("Unknown set\n"));
686 ud_make_tag(udh
, &fe
->fe_tag
, UD_FILE_ENTRY
,
687 SWAP_32(fe
->fe_tag
.tag_loc
), fe
->fe_tag
.tag_crc_len
);
688 (void) putblk((caddr_t
)fe
);
692 verify_inode(uint32_t addr
, uint32_t type
)
694 struct file_entry
*fe
;
698 if ((tag
= (struct tag
*)getblk(addr
& (~bmask
))) == NULL
) {
699 (void) fprintf(stdout
,
700 gettext("Could not read block %x\n"),
703 if (ud_verify_tag(udh
, tag
, UD_FILE_ENTRY
,
704 addr
>> l2b
, 0, 1) != 0) {
705 (void) fprintf(stdout
,
706 gettext("Not a file entry(inode) at %x\n"),
709 if (ud_verify_tag(udh
, tag
, UD_FILE_ENTRY
,
710 SWAP_32(tag
->tag_loc
), 1, 1) != 0) {
711 (void) fprintf(stdout
,
712 gettext("CRC failed\n"));
714 fe
= (struct file_entry
*)tag
;
716 (type
== fe
->fe_icb_tag
.itag_ftype
)) {
717 return ((caddr_t
)tag
);
726 print_inode(uint32_t addr
)
728 if (verify_inode(addr
, 0) != NULL
) {
734 verify_dent(uint32_t i_addr
, uint32_t nent
)
742 fid
= (struct file_id
*)buf
;
744 if (verify_inode(i_addr
, 4) == 0) {
745 (void) fprintf(stdout
,
746 gettext("Inode is not a directory\n"));
750 while (get_fid(i_addr
>> l2b
, buf
, off
) == 0) {
757 (void) fprintf(stdout
,
758 gettext("Reached EOF\n"));
763 print_dent(uint32_t i_addr
, uint32_t nent
)
771 fid
= (struct file_id
*)buf
;
773 if (verify_dent(i_addr
, nent
) == 0) {
774 while (get_fid(i_addr
>> l2b
, buf
, off
) == 0) {
777 print_fid(stdout
, fid
);
786 uint32_t de_count
, ie_count
;
795 get_blkno(uint32_t inode
, uint32_t *blkno
, uint64_t off
)
797 struct file_entry
*fe
;
799 uint16_t prn
, flags
, elen
;
800 uint32_t desc_type
, bno
, len
;
801 struct short_ad
*sad
;
803 uint64_t b_off
, e_off
;
807 if ((fe
= (struct file_entry
*)
808 getblk(inode
<< l2b
)) == NULL
) {
809 (void) fprintf(stdout
,
810 gettext("Could not read block %x\n"),
814 desc_type
= SWAP_16(fe
->fe_icb_tag
.itag_flags
) & 0x7;
815 if (desc_type
== ICB_FLAG_SHORT_AD
) {
816 elen
= sizeof (struct short_ad
);
818 sad
= (struct short_ad
*)
819 (fe
->fe_spec
+ SWAP_32(fe
->fe_len_ear
));
820 } else if (desc_type
== ICB_FLAG_LONG_AD
) {
821 elen
= sizeof (struct long_ad
);
823 lad
= (struct long_ad
*)
824 (fe
->fe_spec
+ SWAP_32(fe
->fe_len_ear
));
825 } else if (desc_type
== ICB_FLAG_ONE_AD
) {
829 /* This cannot happen return */
833 nent
= SWAP_32(fe
->fe_len_adesc
) / elen
;
834 de
= malloc(nent
* sizeof (struct ext
));
836 (void) fprintf(stdout
,
837 gettext("could not allocate memeory\n"));
842 for (d
= 0, i
= 0; i
< nent
; i
++) {
843 if (desc_type
== ICB_FLAG_SHORT_AD
) {
845 bno
= SWAP_32(sad
->sad_ext_loc
);
846 len
= SWAP_32(sad
->sad_ext_len
);
847 } else if (desc_type
== ICB_FLAG_LONG_AD
) {
848 prn
= SWAP_16(lad
->lad_ext_prn
);
849 bno
= SWAP_32(lad
->lad_ext_loc
);
850 len
= SWAP_32(lad
->lad_ext_len
);
854 (void) fprintf(stdout
,
855 gettext("Handle IE\n"));
860 de
[d
].len
= len
& 0x3FFFFFFF;
867 for (i
= 0; i
< de_count
; i
++) {
868 e_off
= b_off
+ de
[i
].len
;
870 bno
= de
[i
].blkno
+ ((off
- b_off
) >> l2b
);
871 if ((*blkno
= ud_xlate_to_daddr(
872 udh
, de
[i
].prn
, bno
)) == 0) {
883 * assume the buffer is big enough
884 * for the entire request
887 read_file(uint32_t inode
, uint8_t *buf
, uint32_t count
, uint64_t off
)
890 uint32_t bno
, tcount
;
894 if (get_blkno(inode
, &bno
, off
) != 0) {
897 if ((addr
= getblk(bno
<< l2b
)) == NULL
) {
901 struct file_entry
*fe
;
906 fe
= (struct file_entry
*)addr
;
907 addr
+= 0xB0 + SWAP_32(fe
->fe_len_ear
);
908 if (off
>= SWAP_64(fe
->fe_info_len
)) {
912 tcount
= udh
->udfs
.lbsize
- (off
& bmask
);
913 if (tcount
> count
) {
917 (void) memcpy(buf
, addr
, tcount
);
926 get_fid(uint32_t inode
, uint8_t *buf
, uint64_t off
)
931 fid
= (struct file_id
*)buf
;
932 if ((read_file(inode
, buf
, sizeof (struct file_id
), off
)) != 0) {
936 if (ud_verify_tag(udh
, &fid
->fid_tag
, UD_FILE_ID_DESC
, 0, 0, 1) != 0) {
937 (void) fprintf(stdout
,
938 gettext("file_id tag does not verify off %llx\n"),
943 if ((read_file(inode
, buf
, FID_LEN(fid
), off
)) != 0) {
951 * Path is absolute path
954 inode_from_path(char *path
, uint32_t *in
, uint8_t *fl
)
968 if (strcmp(path
, "/") == 0) {
970 if ((*in
= ud_xlate_to_daddr(udh
, ricb_prn
, ricb_loc
)) == 0) {
976 (void) strcpy(dname
, path
);
977 (void) strcpy(fname
, basename(dname
));
978 (void) dirname(dname
);
980 if ((err
= inode_from_path(dname
, &dinode
, &flags
)) != 0) {
986 * Check if dname is a directory
988 if ((flags
& FID_DIR
) == 0) {
989 (void) fprintf(stdout
,
990 gettext("Path %s is not a directory\n"), path
);
994 * Search for the fname in the directory now
1000 fid
= (struct file_id
*)buf
;
1001 while (get_fid(dinode
, buf
, off
) == 0) {
1002 off
+= FID_LEN(fid
);
1003 if (fid
->fid_flags
& FID_DELETED
) {
1006 addr
= &fid
->fid_spec
[SWAP_16((fid
)->fid_iulen
) + 1];
1007 if (fid
->fid_flags
& FID_PARENT
) {
1012 addr
[fid
->fid_idlen
] = '\0';
1014 if (strcmp((caddr_t
)addr
, fname
) == 0) {
1015 *fl
= fid
->fid_flags
;
1016 if ((*in
= ud_xlate_to_daddr(udh
,
1017 SWAP_16(fid
->fid_icb
.lad_ext_prn
),
1018 SWAP_32(fid
->fid_icb
.lad_ext_loc
))) == 0) {
1022 if ((tag
= (struct tag
*)getblk(*in
<< l2b
)) == NULL
) {
1023 (void) fprintf(stdout
,
1024 gettext("Could not read block %x\n"),
1028 if (ud_verify_tag(udh
, tag
, UD_FILE_ENTRY
,
1030 (void) fprintf(stdout
,
1031 gettext("Not a file entry(inode)"
1035 if (ud_verify_tag(udh
, tag
, UD_FILE_ENTRY
,
1036 SWAP_32(tag
->tag_loc
), 1, 1) != 0) {
1037 (void) fprintf(stdout
,
1038 gettext("CRC failed\n"));
1049 struct recu_dir
*next
;
1055 list(char *nm
, uint32_t in
, uint32_t fl
)
1059 struct file_id
*fid
;
1060 struct recu_dir
*rd
, *erd
, *temp
;
1063 rd
= erd
= temp
= NULL
;
1064 if (verify_inode(in
<< l2b
, 4) == 0) {
1065 (void) fprintf(stdout
,
1066 gettext("Inode is not a directory\n"));
1071 (void) printf("\n");
1073 (void) fprintf(stdout
,
1074 gettext("i#: %x\t"), in
);
1076 (void) printf("%s\n", nm
);
1081 fid
= (struct file_id
*)buf
;
1082 while (get_fid(in
, buf
, off
) == 0) {
1083 off
+= FID_LEN(fid
);
1084 if (fid
->fid_flags
& FID_DELETED
) {
1087 iloc
= ud_xlate_to_daddr(udh
, SWAP_16(fid
->fid_icb
.lad_ext_prn
),
1088 SWAP_32(fid
->fid_icb
.lad_ext_loc
));
1090 (void) fprintf(stdout
,
1091 gettext("i#: %x\t"), iloc
);
1093 if (fid
->fid_flags
& FID_PARENT
) {
1094 (void) fprintf(stdout
,
1100 addr
= &fid
->fid_spec
[SWAP_16((fid
)->fid_iulen
) + 1];
1101 for (i
= 0; i
< fid
->fid_idlen
- 1; i
++)
1102 (void) fprintf(stdout
, "%c", addr
[i
]);
1103 (void) fprintf(stdout
, "\n");
1104 if ((fid
->fid_flags
& FID_DIR
) &&
1106 temp
= (struct recu_dir
*)
1107 malloc(sizeof (struct recu_dir
));
1109 (void) fprintf(stdout
,
1110 gettext("Could not allocate memory\n"));
1114 temp
->nm
= malloc(strlen(nm
) + 1 +
1115 fid
->fid_idlen
+ 1);
1116 if (temp
->nm
!= NULL
) {
1117 (void) strcpy(temp
->nm
, nm
);
1118 (void) strcat(temp
->nm
, "/");
1119 (void) strncat(temp
->nm
,
1134 while (rd
!= NULL
) {
1135 if (rd
->nm
!= NULL
) {
1136 list(rd
->nm
, rd
->inode
, fl
);
1138 list(".", rd
->inode
, fl
);
1150 fill_pattern(uint32_t addr
, uint32_t count
, char *pattern
)
1152 uint32_t beg
, end
, soff
, lcount
;
1153 int32_t len
= strlen(pattern
);
1156 if (openflg
== O_RDONLY
) {
1157 (void) fprintf(stdout
,
1158 gettext("Not run with -w flag\n"));
1166 end
= addr
+ count
* len
;
1167 soff
= beg
& (~bmask
);
1168 lcount
= ((end
+ bmask
) & (~bmask
)) - soff
;
1172 buf
= malloc(lcount
);
1174 if (llseek(fd
, soff
, SEEK_SET
) != soff
) {
1175 (void) fprintf(stdout
,
1176 gettext("Seek failed fd %x off %llx errno %x\n"),
1181 if (read(fd
, buf
, lcount
) != lcount
) {
1182 (void) fprintf(stdout
,
1183 gettext("Read failed fd %x off %llx errno %x\n"),
1188 p
= buf
+ (addr
& bmask
);
1190 (void) strncpy(p
, pattern
, len
);
1194 if (write(fd
, buf
, lcount
) != lcount
) {
1195 (void) fprintf(stdout
,
1196 gettext("Write failed fd %x off %llx errno %x\n"),
1205 dump_disk(uint32_t addr
, uint32_t count
, char *format
)
1207 uint32_t beg
, end
, soff
, lcount
;
1208 int32_t len
, prperline
, n
;
1213 if (strlen(format
) != 1) {
1214 (void) fprintf(stdout
,
1215 gettext("Invalid command\n"));
1245 (void) fprintf(stdout
,
1246 gettext("Invalid format\n"));
1251 end
= addr
+ count
* len
;
1252 soff
= beg
& (~bmask
);
1253 lcount
= ((end
+ bmask
) & (~bmask
)) - soff
;
1257 buf
= malloc(lcount
);
1258 if (llseek(fd
, soff
, SEEK_SET
) != soff
) {
1259 (void) fprintf(stdout
,
1260 gettext("Seek failed fd %x off %llx errno %x\n"),
1265 if (read(fd
, buf
, lcount
) != lcount
) {
1266 (void) fprintf(stdout
,
1267 gettext("Read failed fd %x off %llx errno %x\n"),
1271 p
= buf
+ (addr
& bmask
);
1273 p_16
= (uint16_t *)p
;
1275 p_32
= (uint32_t *)p
;
1280 (void) fprintf(stdout
,
1281 "%4x ", *((uint8_t *)p
));
1284 (void) fprintf(stdout
,
1285 "%4c ", *((uint8_t *)p
));
1288 (void) fprintf(stdout
,
1289 "%4d ", *((uint8_t *)p
));
1292 (void) fprintf(stdout
,
1293 "%4o ", *((uint8_t *)p
));
1296 (void) fprintf(stdout
,
1300 (void) fprintf(stdout
,
1304 (void) fprintf(stdout
,
1308 (void) fprintf(stdout
,
1314 if ((n
% prperline
) == 0) {
1315 (void) fprintf(stdout
, "\n");
1318 if (n
% prperline
) {
1319 (void) fprintf(stdout
, "\n");
1326 find_it(char *dir
, char *name
, uint32_t in
, uint32_t fl
)
1328 uint8_t buf
[1024], *addr
;
1330 struct file_id
*fid
;
1331 uint32_t iloc
, d_in
;
1333 struct recu_dir
*rd
, *erd
, *temp
;
1335 rd
= erd
= temp
= NULL
;
1337 if (inode_from_path(dir
, &d_in
, &d_fl
) != 0) {
1338 (void) fprintf(stdout
,
1339 gettext("Could not find directory %s"), dir
);
1343 if ((d_fl
& FID_DIR
) == 0) {
1344 (void) fprintf(stdout
,
1345 gettext("Path %s is not a directory\n"), dir
);
1349 if (verify_inode(d_in
<< l2b
, 4) == 0) {
1350 (void) fprintf(stdout
,
1351 gettext("Inode is not a directory\n"));
1357 fid
= (struct file_id
*)buf
;
1358 while (get_fid(d_in
, buf
, off
) == 0) {
1359 off
+= FID_LEN(fid
);
1360 if ((fid
->fid_flags
& FID_DELETED
) ||
1361 (fid
->fid_flags
& FID_PARENT
)) {
1365 iloc
= ud_xlate_to_daddr(udh
, SWAP_16(fid
->fid_icb
.lad_ext_prn
),
1366 SWAP_32(fid
->fid_icb
.lad_ext_loc
));
1367 addr
= &fid
->fid_spec
[SWAP_16((fid
)->fid_iulen
) + 1];
1368 if (((fl
& 4) && (in
== iloc
)) ||
1369 ((fl
& 2) && (strcmp(name
, (char *)addr
) == 0))) {
1370 (void) printf("%s %x %s\n", dir
, iloc
, addr
);
1373 if (fid
->fid_flags
& FID_DIR
) {
1374 temp
= (struct recu_dir
*)
1375 malloc(sizeof (struct recu_dir
));
1377 (void) fprintf(stdout
,
1378 gettext("Could not allocate memory\n"));
1382 temp
->nm
= malloc(strlen(dir
) + 1 +
1383 fid
->fid_idlen
+ 1);
1384 if (temp
->nm
!= NULL
) {
1385 (void) strcpy(temp
->nm
, dir
);
1386 (void) strcat(temp
->nm
, "/");
1387 (void) strncat(temp
->nm
, (char *)addr
,
1390 (void) fprintf(stdout
, gettext(
1391 "Could not allocate memory\n"));
1403 while (rd
!= NULL
) {
1404 if (rd
->nm
!= NULL
) {
1405 find_it(rd
->nm
, name
, in
, fl
);