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.
26 #pragma ident "%Z%%M% %I% %E% SMI"
41 #include <sys/param.h>
42 #include <sys/signal.h>
44 #include <sys/sysmacros.h>
45 #include <sys/types.h>
46 #include <sys/vnode.h>
47 #include <sys/mntent.h>
52 #include <sys/fs/udf_volume.h>
56 typedef unsigned short unicode_t
;
57 #define MAXNAMLEN 0x200
59 extern uint32_t i_number
;
61 extern int32_t run_fsdb();
65 char *getblk(u_offset_t
);
66 int32_t parse_udfs(uint32_t);
67 int32_t parse_vds(uint32_t, uint32_t);
68 int32_t parse_part(struct part_desc
*);
69 int32_t parse_lvd(struct log_vol_desc
*);
71 int32_t get_vat_loc();
72 int32_t get_fid(uint32_t, uint8_t *, uint64_t);
76 char prompt
[256] = "fsdb>";
78 #define ARG_OVERRIDE 0
79 #define ARG_NEW_PROMPT 1
80 #define ARG_WR_ENABLED 2
91 int32_t openflg
= O_RDONLY
;
98 #define UDP_BITMAPS 0x00
99 #define UDP_SPACETBLS 0x01
102 int32_t fd
, nparts
, nmaps
;
103 int32_t bmask
, l2d
, l2b
;
107 uint32_t ricb_loc
, ricb_len
;
112 main(int argc
, char *argv
[])
116 char *subopts
, *optval
;
118 #if !defined(TEXT_DOMAIN)
119 #define TEXT_DOMAIN "SYS_TEST"
121 (void) textdomain(TEXT_DOMAIN
);
125 while ((opt
= getopt(argc
, argv
, "o:")) != EOF
) {
129 while (*subopts
!= '\0') {
130 switch (getsubopt(&subopts
,
131 subopt_v
, &optval
)) {
134 (void) fprintf(stdout
,
135 gettext("error checking off\n"));
137 case ARG_NEW_PROMPT
:
138 if (optval
== NULL
) {
141 if (strlen(optval
) > 255) {
142 (void) fprintf(stdout
,
143 gettext("prompt should be less"
144 "than 255 bytes\n"));
147 (void) strcpy(prompt
, optval
);
149 case ARG_WR_ENABLED
:
163 if ((argc
- optind
) != 1) { /* Should just have "special" left */
167 if (ud_init(-1, &udh
) != 0) {
168 (void) fprintf(stderr
,
169 gettext("udfs labelit: cannot initialize ud_lib\n"));
173 if ((fd
= ud_open_dev(udh
, argv
[optind
], openflg
)) < 0) {
178 if ((ret
= ud_fill_udfs_info(udh
)) != 0) {
182 if ((udh
->udfs
.flags
& VALID_UDFS
) == 0) {
186 bsize
= udh
->udfs
.lbsize
;
189 while ((bsize
>> l2d
) > DEV_BSIZE
) {
194 ricb_prn
= udh
->udfs
.ricb_prn
;
195 ricb_loc
= udh
->udfs
.ricb_loc
;
196 ricb_len
= udh
->udfs
.ricb_len
;
198 value
= i_number
= ud_xlate_to_daddr(udh
, ricb_prn
, ricb_loc
);
211 * usage - print usage and exit
216 (void) fprintf(stdout
,
217 gettext("usage: %s [options] special\n"), progname
);
218 (void) fprintf(stdout
,
219 gettext("options:\n"));
220 (void) fprintf(stdout
,
221 gettext("\t-o\tSpecify udfs filesystem sepcific options\n"));
222 (void) fprintf(stdout
,
223 gettext("\t\tAvailable suboptions are:\n"));
224 (void) fprintf(stdout
,
225 gettext("\t\t?\tdisplay usage\n"));
226 (void) fprintf(stdout
,
227 gettext("\t\to\toverride some error conditions\n"));
228 (void) fprintf(stdout
,
229 gettext("\t\tp\t\"string\" set prompt to string\n"));
230 (void) fprintf(stdout
,
231 gettext("\t\tw\topen for write\n"));
247 bp->fwd = bhdr.fwd; \
248 bhdr.fwd->back = bp; \
259 addr
= malloc(NBUF
* udh
->udfs
.lbsize
);
260 bhdr
.fwd
= bhdr
.back
= &bhdr
;
261 for (i
= 0; i
< NBUF
; i
++) {
263 bp
->blkaddr
= addr
+ i
* udh
->udfs
.lbsize
;
270 getblk(u_offset_t address
)
272 u_offset_t off
, block
;
275 off
= address
& ~bmask
;
276 block
= address
>> l2b
;
277 for (bp
= bhdr
.fwd
; bp
!= &bhdr
; bp
= bp
->fwd
) {
278 if (bp
->valid
&& bp
->blkno
== block
) {
286 if (llseek(fd
, off
, SEEK_SET
) != off
) {
287 (void) fprintf(stdout
,
288 gettext("Seek failed fd %x off %llx errno %x\n"),
293 if (read(fd
, bp
->blkaddr
, udh
->udfs
.lbsize
) != udh
->udfs
.lbsize
) {
294 (void) fprintf(stdout
,
295 gettext("Read failed fd %x off %llx errno %x\n"),
301 bp
->back
->fwd
= bp
->fwd
;
302 bp
->fwd
->back
= bp
->back
;
304 return (bp
->blkaddr
);
309 putblk(caddr_t address
)
314 if (openflg
== O_RDONLY
) {
315 (void) fprintf(stdout
,
316 gettext("Not run with -w flag\n"));
320 for (bp
= bhdr
.fwd
; bp
!= &bhdr
; bp
= bp
->fwd
) {
321 if (bp
->valid
&& bp
->blkaddr
== address
) {
325 (void) fprintf(stdout
,
326 gettext("Could not find the buffer\n"));
330 off
= bp
->blkno
<< l2b
;
331 if (llseek(fd
, off
, SEEK_SET
) == off
) {
332 if (write(fd
, bp
->blkaddr
, udh
->udfs
.lbsize
) ==
336 (void) fprintf(stdout
,
337 gettext("Write failed fd %x off %llx errno %x\n"),
340 (void) fprintf(stdout
,
341 gettext("Seek failed fd %x off %llx errno %x\n"),
352 for (bp
= bhdr
.fwd
; bp
!= &bhdr
; bp
= bp
->fwd
) {
358 * If addr == NULL then use id to print the desc
359 * other wise use addr to self identify the type of desc
362 print_desc(uint32_t addr
, int32_t id
)
368 * Read the block at addr
369 * find out the type of tag
370 * and print the descriptor
373 if ((baddr
= getblk(addr
& (~bmask
))) == NULL
) {
374 (void) fprintf(stdout
,
375 gettext("Could not read block %x\n"),
379 tag
= (struct tag
*)(baddr
+ (addr
& bmask
));
384 if ((tag
= (struct tag
*)getblk(
385 udh
->udfs
.avdp_loc
<< l2b
)) == NULL
) {
386 (void) fprintf(stdout
,
387 gettext("Could not read AVDP\n"));
397 i
= udh
->udfs
.mvds_loc
;
399 (udh
->udfs
.mvds_len
>> l2b
);
400 } else if (id
== RVDS
) {
401 i
= udh
->udfs
.rvds_loc
;
403 (udh
->udfs
.rvds_len
>> l2b
);
405 i
= udh
->udfs
.lvid_loc
;
407 (udh
->udfs
.lvid_len
>> l2b
);
410 for (; i
< end
; i
++) {
411 print_desc(i
<< l2b
, 0);
419 uint32_t i
, end
, block
;
422 prn
= udh
->udfs
.fsds_prn
;
423 i
= udh
->udfs
.fsds_loc
;
425 (udh
->udfs
.fsds_len
>> l2b
);
429 end
= i
+ (ricb_len
>> l2b
);
432 for (; i
< end
; i
++) {
433 if ((block
= ud_xlate_to_daddr(
434 udh
, prn
, i
)) == 0) {
435 (void) fprintf(stdout
,
436 gettext("Cannot xlate "
441 print_desc(block
<< l2b
, 0);
450 switch (SWAP_16(tag
->tag_id
)) {
451 case UD_PRI_VOL_DESC
:
452 print_pvd(stdout
, (struct pri_vol_desc
*)tag
);
454 case UD_ANCH_VOL_DESC
:
455 print_avd(stdout
, (struct anch_vol_desc_ptr
*)tag
);
457 case UD_VOL_DESC_PTR
:
458 print_vdp(stdout
, (struct vol_desc_ptr
*)tag
);
460 case UD_IMPL_USE_DESC
:
461 print_iuvd(stdout
, (struct iuvd_desc
*)tag
);
464 print_part(stdout
, (struct part_desc
*)tag
);
466 case UD_LOG_VOL_DESC
:
467 print_lvd(stdout
, (struct log_vol_desc
*)tag
);
469 case UD_UNALL_SPA_DESC
:
470 print_usd(stdout
, (struct unall_spc_desc
*)tag
);
473 (void) fprintf(stdout
, "TERM DESC\n");
474 print_tag(stdout
, tag
);
476 case UD_LOG_VOL_INT
:
477 print_lvid(stdout
, (struct log_vol_int_desc
*)tag
);
479 case UD_FILE_SET_DESC
:
480 print_fsd(stdout
, udh
, (struct file_set_desc
*)tag
);
482 case UD_FILE_ID_DESC
:
483 print_fid(stdout
, (struct file_id
*)tag
);
485 case UD_ALLOC_EXT_DESC
:
486 print_aed(stdout
, (struct alloc_ext_desc
*)tag
);
488 case UD_INDIRECT_ENT
:
489 print_ie(stdout
, (struct indirect_entry
*)tag
);
491 case UD_TERMINAL_ENT
:
492 print_td(stdout
, (struct term_desc
*)tag
);
495 print_fe(stdout
, (struct file_entry
*)tag
);
497 case UD_EXT_ATTR_HDR
:
498 case UD_UNALL_SPA_ENT
:
499 case UD_SPA_BMAP_DESC
:
500 case UD_PART_INT_DESC
:
501 case UD_EXT_FILE_ENT
:
504 (void) fprintf(stdout
,
505 gettext("unknown descriptor\n"));
506 print_tag(stdout
, tag
);
512 set_file(int32_t id
, uint32_t iloc
, uint64_t value
)
516 uint32_t i32
, block
, ea_len
, ea_off
;
518 struct file_entry
*fe
;
519 struct dev_spec_ear
*ds
;
521 struct ext_attr_hdr
*eah
;
524 if ((fe
= (struct file_entry
*)getblk(iloc
)) == NULL
) {
527 if (ud_verify_tag(udh
, &fe
->fe_tag
, UD_FILE_ENTRY
,
528 SWAP_32(fe
->fe_tag
.tag_loc
), 1, 1) != 0) {
532 i16
= SWAP_16(((uint16_t)value
));
533 i32
= SWAP_32(((uint32_t)value
));
534 i64
= SWAP_64(value
);
537 fe
->fe_acc_time
.ts_tzone
= i16
;
540 fe
->fe_acc_time
.ts_year
= i16
;
543 fe
->fe_acc_time
.ts_month
= i8
;
546 fe
->fe_acc_time
.ts_day
= i8
;
549 fe
->fe_acc_time
.ts_hour
= i8
;
552 fe
->fe_acc_time
.ts_min
= i8
;
555 fe
->fe_acc_time
.ts_sec
= i8
;
558 fe
->fe_acc_time
.ts_csec
= i8
;
561 fe
->fe_acc_time
.ts_husec
= i8
;
564 fe
->fe_acc_time
.ts_usec
= i8
;
567 fe
->fe_attr_time
.ts_tzone
= i16
;
570 fe
->fe_attr_time
.ts_year
= i16
;
573 fe
->fe_attr_time
.ts_month
= i8
;
576 fe
->fe_attr_time
.ts_day
= i8
;
579 fe
->fe_attr_time
.ts_hour
= i8
;
582 fe
->fe_attr_time
.ts_min
= i8
;
585 fe
->fe_attr_time
.ts_sec
= i8
;
588 fe
->fe_attr_time
.ts_csec
= i8
;
591 fe
->fe_attr_time
.ts_husec
= i8
;
594 fe
->fe_attr_time
.ts_usec
= i8
;
597 fe
->fe_mod_time
.ts_tzone
= i16
;
600 fe
->fe_mod_time
.ts_year
= i16
;
603 fe
->fe_mod_time
.ts_month
= i8
;
606 fe
->fe_mod_time
.ts_day
= i8
;
609 fe
->fe_mod_time
.ts_hour
= i8
;
612 fe
->fe_mod_time
.ts_min
= i8
;
615 fe
->fe_mod_time
.ts_sec
= i8
;
618 fe
->fe_mod_time
.ts_csec
= i8
;
621 fe
->fe_mod_time
.ts_husec
= i8
;
624 fe
->fe_mod_time
.ts_usec
= i8
;
637 if ((fe
->fe_icb_tag
.itag_ftype
!= VBLK
) &&
638 (fe
->fe_icb_tag
.itag_ftype
!= VCHR
)) {
639 (void) fprintf(stdout
,
640 gettext("Not a device\n"));
644 eah
= (struct ext_attr_hdr
*)fe
->fe_spec
;
645 ea_off
= SWAP_32(eah
->eah_ial
);
646 ea_len
= SWAP_32(fe
->fe_len_ear
);
647 block
= SWAP_32(eah
->eah_tag
.tag_loc
);
648 if (ea_len
&& (ud_verify_tag(udh
, &eah
->eah_tag
,
649 UD_EXT_ATTR_HDR
, block
, 1, 1) == 0)) {
650 while (ea_off
< ea_len
) {
652 ah
= (struct attr_hdr
*)
653 &fe
->fe_spec
[ea_off
];
654 if ((ah
->ahdr_atype
== SWAP_32(12)) &&
655 (ah
->ahdr_astype
== 1)) {
657 ds
= (struct dev_spec_ear
*)ah
;
659 ds
->ds_major_id
= i32
;
661 ds
->ds_minor_id
= i32
;
663 ud_make_tag(udh
, &eah
->eah_tag
,
664 UD_EXT_ATTR_HDR
, block
,
665 eah
->eah_tag
.tag_crc_len
);
670 (void) fprintf(stdout
,
671 gettext("does not have a Device Specification EA\n"));
676 fe
->fe_info_len
= i64
;
682 fe
->fe_uniq_id
= i32
;
685 (void) fprintf(stdout
,
686 gettext("Unknown set\n"));
688 ud_make_tag(udh
, &fe
->fe_tag
, UD_FILE_ENTRY
,
689 SWAP_32(fe
->fe_tag
.tag_loc
), fe
->fe_tag
.tag_crc_len
);
690 (void) putblk((caddr_t
)fe
);
694 verify_inode(uint32_t addr
, uint32_t type
)
696 struct file_entry
*fe
;
700 if ((tag
= (struct tag
*)getblk(addr
& (~bmask
))) == NULL
) {
701 (void) fprintf(stdout
,
702 gettext("Could not read block %x\n"),
705 if (ud_verify_tag(udh
, tag
, UD_FILE_ENTRY
,
706 addr
>> l2b
, 0, 1) != 0) {
707 (void) fprintf(stdout
,
708 gettext("Not a file entry(inode) at %x\n"),
711 if (ud_verify_tag(udh
, tag
, UD_FILE_ENTRY
,
712 SWAP_32(tag
->tag_loc
), 1, 1) != 0) {
713 (void) fprintf(stdout
,
714 gettext("CRC failed\n"));
716 fe
= (struct file_entry
*)tag
;
718 (type
== fe
->fe_icb_tag
.itag_ftype
)) {
719 return ((caddr_t
)tag
);
728 print_inode(uint32_t addr
)
730 if (verify_inode(addr
, 0) != NULL
) {
736 verify_dent(uint32_t i_addr
, uint32_t nent
)
744 fid
= (struct file_id
*)buf
;
746 if (verify_inode(i_addr
, 4) == 0) {
747 (void) fprintf(stdout
,
748 gettext("Inode is not a directory\n"));
752 while (get_fid(i_addr
>> l2b
, buf
, off
) == 0) {
759 (void) fprintf(stdout
,
760 gettext("Reached EOF\n"));
765 print_dent(uint32_t i_addr
, uint32_t nent
)
773 fid
= (struct file_id
*)buf
;
775 if (verify_dent(i_addr
, nent
) == 0) {
776 while (get_fid(i_addr
>> l2b
, buf
, off
) == 0) {
779 print_fid(stdout
, fid
);
788 uint32_t de_count
, ie_count
;
797 get_blkno(uint32_t inode
, uint32_t *blkno
, uint64_t off
)
799 struct file_entry
*fe
;
801 uint16_t prn
, flags
, elen
;
802 uint32_t desc_type
, bno
, len
;
803 struct short_ad
*sad
;
805 uint64_t b_off
, e_off
;
809 if ((fe
= (struct file_entry
*)
810 getblk(inode
<< l2b
)) == NULL
) {
811 (void) fprintf(stdout
,
812 gettext("Could not read block %x\n"),
816 desc_type
= SWAP_16(fe
->fe_icb_tag
.itag_flags
) & 0x7;
817 if (desc_type
== ICB_FLAG_SHORT_AD
) {
818 elen
= sizeof (struct short_ad
);
820 sad
= (struct short_ad
*)
821 (fe
->fe_spec
+ SWAP_32(fe
->fe_len_ear
));
822 } else if (desc_type
== ICB_FLAG_LONG_AD
) {
823 elen
= sizeof (struct long_ad
);
825 lad
= (struct long_ad
*)
826 (fe
->fe_spec
+ SWAP_32(fe
->fe_len_ear
));
827 } else if (desc_type
== ICB_FLAG_ONE_AD
) {
831 /* This cannot happen return */
835 nent
= SWAP_32(fe
->fe_len_adesc
) / elen
;
836 de
= malloc(nent
* sizeof (struct ext
));
838 (void) fprintf(stdout
,
839 gettext("could not allocate memeory\n"));
844 for (d
= 0, i
= 0; i
< nent
; i
++) {
845 if (desc_type
== ICB_FLAG_SHORT_AD
) {
847 bno
= SWAP_32(sad
->sad_ext_loc
);
848 len
= SWAP_32(sad
->sad_ext_len
);
849 } else if (desc_type
== ICB_FLAG_LONG_AD
) {
850 prn
= SWAP_16(lad
->lad_ext_prn
);
851 bno
= SWAP_32(lad
->lad_ext_loc
);
852 len
= SWAP_32(lad
->lad_ext_len
);
856 (void) fprintf(stdout
,
857 gettext("Handle IE\n"));
862 de
[d
].len
= len
& 0x3FFFFFFF;
869 for (i
= 0; i
< de_count
; i
++) {
870 e_off
= b_off
+ de
[i
].len
;
872 bno
= de
[i
].blkno
+ ((off
- b_off
) >> l2b
);
873 if ((*blkno
= ud_xlate_to_daddr(
874 udh
, de
[i
].prn
, bno
)) == 0) {
885 * assume the buffer is big enough
886 * for the entire request
889 read_file(uint32_t inode
, uint8_t *buf
, uint32_t count
, uint64_t off
)
892 uint32_t bno
, tcount
;
896 if (get_blkno(inode
, &bno
, off
) != 0) {
899 if ((addr
= getblk(bno
<< l2b
)) == NULL
) {
903 struct file_entry
*fe
;
908 fe
= (struct file_entry
*)addr
;
909 addr
+= 0xB0 + SWAP_32(fe
->fe_len_ear
);
910 if (off
>= SWAP_64(fe
->fe_info_len
)) {
914 tcount
= udh
->udfs
.lbsize
- (off
& bmask
);
915 if (tcount
> count
) {
919 (void) memcpy(buf
, addr
, tcount
);
928 get_fid(uint32_t inode
, uint8_t *buf
, uint64_t off
)
933 fid
= (struct file_id
*)buf
;
934 if ((read_file(inode
, buf
, sizeof (struct file_id
), off
)) != 0) {
938 if (ud_verify_tag(udh
, &fid
->fid_tag
, UD_FILE_ID_DESC
, 0, 0, 1) != 0) {
939 (void) fprintf(stdout
,
940 gettext("file_id tag does not verify off %llx\n"),
945 if ((read_file(inode
, buf
, FID_LEN(fid
), off
)) != 0) {
953 * Path is absolute path
956 inode_from_path(char *path
, uint32_t *in
, uint8_t *fl
)
970 if (strcmp(path
, "/") == 0) {
972 if ((*in
= ud_xlate_to_daddr(udh
, ricb_prn
, ricb_loc
)) == 0) {
978 (void) strcpy(dname
, path
);
979 (void) strcpy(fname
, basename(dname
));
980 (void) dirname(dname
);
982 if ((err
= inode_from_path(dname
, &dinode
, &flags
)) != 0) {
988 * Check if dname is a directory
990 if ((flags
& FID_DIR
) == 0) {
991 (void) fprintf(stdout
,
992 gettext("Path %s is not a directory\n"), path
);
996 * Search for the fname in the directory now
1002 fid
= (struct file_id
*)buf
;
1003 while (get_fid(dinode
, buf
, off
) == 0) {
1004 off
+= FID_LEN(fid
);
1005 if (fid
->fid_flags
& FID_DELETED
) {
1008 addr
= &fid
->fid_spec
[SWAP_16((fid
)->fid_iulen
) + 1];
1009 if (fid
->fid_flags
& FID_PARENT
) {
1014 addr
[fid
->fid_idlen
] = '\0';
1016 if (strcmp((caddr_t
)addr
, fname
) == 0) {
1017 *fl
= fid
->fid_flags
;
1018 if ((*in
= ud_xlate_to_daddr(udh
,
1019 SWAP_16(fid
->fid_icb
.lad_ext_prn
),
1020 SWAP_32(fid
->fid_icb
.lad_ext_loc
))) == 0) {
1024 if ((tag
= (struct tag
*)getblk(*in
<< l2b
)) == NULL
) {
1025 (void) fprintf(stdout
,
1026 gettext("Could not read block %x\n"),
1030 if (ud_verify_tag(udh
, tag
, UD_FILE_ENTRY
,
1032 (void) fprintf(stdout
,
1033 gettext("Not a file entry(inode)"
1037 if (ud_verify_tag(udh
, tag
, UD_FILE_ENTRY
,
1038 SWAP_32(tag
->tag_loc
), 1, 1) != 0) {
1039 (void) fprintf(stdout
,
1040 gettext("CRC failed\n"));
1051 struct recu_dir
*next
;
1057 list(char *nm
, uint32_t in
, uint32_t fl
)
1061 struct file_id
*fid
;
1062 struct recu_dir
*rd
, *erd
, *temp
;
1065 rd
= erd
= temp
= NULL
;
1066 if (verify_inode(in
<< l2b
, 4) == 0) {
1067 (void) fprintf(stdout
,
1068 gettext("Inode is not a directory\n"));
1073 (void) printf("\n");
1075 (void) fprintf(stdout
,
1076 gettext("i#: %x\t"), in
);
1078 (void) printf("%s\n", nm
);
1083 fid
= (struct file_id
*)buf
;
1084 while (get_fid(in
, buf
, off
) == 0) {
1085 off
+= FID_LEN(fid
);
1086 if (fid
->fid_flags
& FID_DELETED
) {
1089 iloc
= ud_xlate_to_daddr(udh
, SWAP_16(fid
->fid_icb
.lad_ext_prn
),
1090 SWAP_32(fid
->fid_icb
.lad_ext_loc
));
1092 (void) fprintf(stdout
,
1093 gettext("i#: %x\t"), iloc
);
1095 if (fid
->fid_flags
& FID_PARENT
) {
1096 (void) fprintf(stdout
,
1102 addr
= &fid
->fid_spec
[SWAP_16((fid
)->fid_iulen
) + 1];
1103 for (i
= 0; i
< fid
->fid_idlen
- 1; i
++)
1104 (void) fprintf(stdout
, "%c", addr
[i
]);
1105 (void) fprintf(stdout
, "\n");
1106 if ((fid
->fid_flags
& FID_DIR
) &&
1108 temp
= (struct recu_dir
*)
1109 malloc(sizeof (struct recu_dir
));
1111 (void) fprintf(stdout
,
1112 gettext("Could not allocate memory\n"));
1116 temp
->nm
= malloc(strlen(nm
) + 1 +
1117 fid
->fid_idlen
+ 1);
1118 if (temp
->nm
!= NULL
) {
1119 (void) strcpy(temp
->nm
, nm
);
1120 (void) strcat(temp
->nm
, "/");
1121 (void) strncat(temp
->nm
,
1136 while (rd
!= NULL
) {
1137 if (rd
->nm
!= NULL
) {
1138 list(rd
->nm
, rd
->inode
, fl
);
1140 list(".", rd
->inode
, fl
);
1152 fill_pattern(uint32_t addr
, uint32_t count
, char *pattern
)
1154 uint32_t beg
, end
, soff
, lcount
;
1155 int32_t len
= strlen(pattern
);
1158 if (openflg
== O_RDONLY
) {
1159 (void) fprintf(stdout
,
1160 gettext("Not run with -w flag\n"));
1168 end
= addr
+ count
* len
;
1169 soff
= beg
& (~bmask
);
1170 lcount
= ((end
+ bmask
) & (~bmask
)) - soff
;
1174 buf
= malloc(lcount
);
1176 if (llseek(fd
, soff
, SEEK_SET
) != soff
) {
1177 (void) fprintf(stdout
,
1178 gettext("Seek failed fd %x off %llx errno %x\n"),
1183 if (read(fd
, buf
, lcount
) != lcount
) {
1184 (void) fprintf(stdout
,
1185 gettext("Read failed fd %x off %llx errno %x\n"),
1190 p
= buf
+ (addr
& bmask
);
1192 (void) strncpy(p
, pattern
, len
);
1196 if (write(fd
, buf
, lcount
) != lcount
) {
1197 (void) fprintf(stdout
,
1198 gettext("Write failed fd %x off %llx errno %x\n"),
1207 dump_disk(uint32_t addr
, uint32_t count
, char *format
)
1209 uint32_t beg
, end
, soff
, lcount
;
1210 int32_t len
, prperline
, n
;
1215 if (strlen(format
) != 1) {
1216 (void) fprintf(stdout
,
1217 gettext("Invalid command\n"));
1247 (void) fprintf(stdout
,
1248 gettext("Invalid format\n"));
1253 end
= addr
+ count
* len
;
1254 soff
= beg
& (~bmask
);
1255 lcount
= ((end
+ bmask
) & (~bmask
)) - soff
;
1259 buf
= malloc(lcount
);
1260 if (llseek(fd
, soff
, SEEK_SET
) != soff
) {
1261 (void) fprintf(stdout
,
1262 gettext("Seek failed fd %x off %llx errno %x\n"),
1267 if (read(fd
, buf
, lcount
) != lcount
) {
1268 (void) fprintf(stdout
,
1269 gettext("Read failed fd %x off %llx errno %x\n"),
1273 p
= buf
+ (addr
& bmask
);
1275 p_16
= (uint16_t *)p
;
1277 p_32
= (uint32_t *)p
;
1282 (void) fprintf(stdout
,
1283 "%4x ", *((uint8_t *)p
));
1286 (void) fprintf(stdout
,
1287 "%4c ", *((uint8_t *)p
));
1290 (void) fprintf(stdout
,
1291 "%4d ", *((uint8_t *)p
));
1294 (void) fprintf(stdout
,
1295 "%4o ", *((uint8_t *)p
));
1298 (void) fprintf(stdout
,
1302 (void) fprintf(stdout
,
1306 (void) fprintf(stdout
,
1310 (void) fprintf(stdout
,
1316 if ((n
% prperline
) == 0) {
1317 (void) fprintf(stdout
, "\n");
1320 if (n
% prperline
) {
1321 (void) fprintf(stdout
, "\n");
1328 find_it(char *dir
, char *name
, uint32_t in
, uint32_t fl
)
1330 uint8_t buf
[1024], *addr
;
1332 struct file_id
*fid
;
1333 uint32_t iloc
, d_in
;
1335 struct recu_dir
*rd
, *erd
, *temp
;
1337 rd
= erd
= temp
= NULL
;
1339 if (inode_from_path(dir
, &d_in
, &d_fl
) != 0) {
1340 (void) fprintf(stdout
,
1341 gettext("Could not find directory %s"), dir
);
1345 if ((d_fl
& FID_DIR
) == 0) {
1346 (void) fprintf(stdout
,
1347 gettext("Path %s is not a directory\n"), dir
);
1351 if (verify_inode(d_in
<< l2b
, 4) == 0) {
1352 (void) fprintf(stdout
,
1353 gettext("Inode is not a directory\n"));
1359 fid
= (struct file_id
*)buf
;
1360 while (get_fid(d_in
, buf
, off
) == 0) {
1361 off
+= FID_LEN(fid
);
1362 if ((fid
->fid_flags
& FID_DELETED
) ||
1363 (fid
->fid_flags
& FID_PARENT
)) {
1367 iloc
= ud_xlate_to_daddr(udh
, SWAP_16(fid
->fid_icb
.lad_ext_prn
),
1368 SWAP_32(fid
->fid_icb
.lad_ext_loc
));
1369 addr
= &fid
->fid_spec
[SWAP_16((fid
)->fid_iulen
) + 1];
1370 if (((fl
& 4) && (in
== iloc
)) ||
1371 ((fl
& 2) && (strcmp(name
, (char *)addr
) == 0))) {
1372 (void) printf("%s %x %s\n", dir
, iloc
, addr
);
1375 if (fid
->fid_flags
& FID_DIR
) {
1376 temp
= (struct recu_dir
*)
1377 malloc(sizeof (struct recu_dir
));
1379 (void) fprintf(stdout
,
1380 gettext("Could not allocate memory\n"));
1384 temp
->nm
= malloc(strlen(dir
) + 1 +
1385 fid
->fid_idlen
+ 1);
1386 if (temp
->nm
!= NULL
) {
1387 (void) strcpy(temp
->nm
, dir
);
1388 (void) strcat(temp
->nm
, "/");
1389 (void) strncat(temp
->nm
, (char *)addr
,
1392 (void) fprintf(stdout
, gettext(
1393 "Could not allocate memory\n"));
1405 while (rd
!= NULL
) {
1406 if (rd
->nm
!= NULL
) {
1407 find_it(rd
->nm
, name
, in
, fl
);