* Copyright (c) 1990 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* %sccs.include.noredist.c%
* @(#)sys.c 7.1 (Berkeley) %G%
#define DB printf("%s:%d\n",__FILE__,__LINE__)
register struct dinode
*dp
;
io
->i_bn
= fsbtodb(&io
->i_fs
, itod(&io
->i_fs
, n
)) + io
->i_boff
;
io
->i_cc
= io
->i_fs
.fs_bsize
;
dp
= (struct dinode
*)io
->i_buf
;
io
->i_ino
.i_ic
= dp
[itoo(&io
->i_fs
, n
)].di_ic
;
if (path
==NULL
|| *path
=='\0') {
if (openi((ino_t
) ROOTINO
, file
) < 0) {
printf("can't read root inode\n");
while(*q
!= '/' && *q
!= '\0')
if (path
== q
) path
= "." ; /* / means /. */
if ((n
= dlook(path
, file
)) != 0) {
printf("%s: not found\n", path
);
register struct inode
*ip
;
* blocks 0..NDADDR are direct blocks
* addresses NIADDR have single and double indirect blocks.
* the first step is to determine how many levels of indirection.
for (j
= NIADDR
; j
> 0; j
--) {
printf("bn ovf %D\n", bn
);
* fetch the first indirect block address from the inode
nb
= ip
->i_ib
[NIADDR
- j
];
printf("bn void %D\n",bn
);
* fetch through the indirect blocks
for (; j
<= NIADDR
; j
++) {
io
->i_bn
= fsbtodb(&io
->i_fs
, nb
) + io
->i_boff
;
io
->i_cc
= io
->i_fs
.fs_bsize
;
if (devread(io
) != io
->i_fs
.fs_bsize
) {
printf("bn %D: read error\n", io
->i_bn
);
i
= (bn
/ sh
) % NINDIR(&io
->i_fs
);
printf("bn void %D\n",bn
);
register struct direct
*dp
;
register struct inode
*ip
;
if (s
== NULL
|| *s
== '\0')
if ((ip
->i_mode
&IFMT
) != IFDIR
) {
printf("%s: not a directory\n", s
);
printf("%s: zero length directory\n", s
);
for (dp
= readdir(&dirp
); dp
!= NULL
; dp
= readdir(&dirp
)) {
if (dp
->d_namlen
== len
&& !strcmp(s
, dp
->d_name
))
* get next entry in a directory.
register struct dirstuff
*dirp
;
register struct direct
*dp
;
if (dirp
->loc
>= io
->i_ino
.i_size
)
off
= blkoff(&io
->i_fs
, dirp
->loc
);
lbn
= lblkno(&io
->i_fs
, dirp
->loc
);
io
->i_bn
= fsbtodb(&io
->i_fs
, d
) + io
->i_boff
;
io
->i_cc
= blksize(&io
->i_fs
, &io
->i_ino
, lbn
);
printf("bn %D: directory read error\n",
dp
= (struct direct
*)(io
->i_buf
+ off
);
dirp
->loc
+= dp
->d_reclen
;
printf("seek not from beginning of file\n");
if (fdesc
< 0 || fdesc
>= NFILES
||
((io
= &iob
[fdesc
])->i_flgs
& F_ALLOC
) == 0) {
int c
, lbn
, off
, size
, diff
;
if (fdesc
>= 0 && fdesc
<= 2)
if (fdesc
< 0 || fdesc
>= NFILES
||
((io
= &iob
[fdesc
])->i_flgs
&F_ALLOC
) == 0) {
if ((io
->i_flgs
& F_FILE
) != 0) {
diff
= io
->i_ino
.i_size
- io
->i_offset
;
lbn
= lblkno(fs
, io
->i_offset
);
io
->i_bn
= fsbtodb(fs
, sbmap(io
, lbn
)) + io
->i_boff
;
off
= blkoff(fs
, io
->i_offset
);
size
= blksize(fs
, &io
->i_ino
, lbn
);
io
->i_bn
= io
->i_offset
/ DEV_IOSIZE
*
off
= io
->i_offset
% DEV_IOSIZE
;
if ((io
->i_flgs
& F_FILE
) != 0) {
if (io
->i_offset
- off
+ size
>= io
->i_ino
.i_size
)
for (i = 0, val = 0, cp = &val; i < sizeof(val); i++) {
if (fdesc
>= 0 & fdesc
<= 2) {
} while (--i
&& *buf
++ != '\n');
if (fdesc
< 0 || fdesc
>= NFILES
||
((io
= &iob
[fdesc
])->i_flgs
&F_ALLOC
) == 0) {
if ((io
->i_flgs
&F_READ
) == 0) {
if ((io
->i_flgs
& F_FILE
) == 0) {
if (io
->i_offset
% 512 || count
% 512) {
io
->i_bn
= io
->i_boff
+ (io
->i_offset
/ DEV_BSIZE
);
if (io
->i_offset
+count
> io
->i_ino
.i_size
)
count
= io
->i_ino
.i_size
- io
->i_offset
;
* While reading full blocks, do I/O into user buffer.
* Anything else uses getc().
off
= blkoff(fs
, io
->i_offset
);
lbn
= lblkno(fs
, io
->i_offset
);
size
= blksize(fs
, &io
->i_ino
, lbn
);
if (off
== 0 && size
<= i
) {
io
->i_bn
= fsbtodb(fs
, sbmap(io
, lbn
)) + io
->i_boff
;
register struct iob
*file
;
if (fdesc
>= 0 && fdesc
<= 2) {
if (fdesc
< 0 || fdesc
>= NFILES
||
((file
= &iob
[fdesc
])->i_flgs
&F_ALLOC
) == 0) {
if ((file
->i_flgs
&F_WRITE
) == 0) {
file
->i_bn
= file
->i_boff
+ (file
->i_offset
/ DEV_BSIZE
);
int opendev
; /* last device opened; for boot to set bootdev */
register struct iob
*file
;
register struct devsw
*dp
;
for (i
= 0; i
< NFILES
; i
++)
for (fdesc
= 0; fdesc
< NFILES
; fdesc
++)
if (iob
[fdesc
].i_flgs
== 0)
_stop("no more file slots");
(file
= &iob
[fdesc
])->i_flgs
|= F_ALLOC
;
for (cp
= str
; *cp
&& *cp
!= '/' && *cp
!= ':'; cp
++)
/* default bootstrap unit and device */
file
->i_ino
.i_dev
= bootdev
;
# define isdigit(n) ((n>='0') && (n<='9'))
* syntax for possible device name:
* <alpha-string><digit-string><letter>:
for (cp
= str
; *cp
!= ':' && !isdigit(*cp
); cp
++)
for (dp
= devsw
; dp
->dv_name
; dp
++) {
if (!strncmp(str
, dp
->dv_name
,cp
-str
))
printf("unknown device\n");
while (*cp
>= '0' && *cp
<= '9')
i
= i
* 10 + *cp
++ - '0';
printf("minor device number out of range (0-255)\n");
if (*cp
>= 'a' && *cp
<= 'h') {
printf("unit number out of range (0-31)\n");
i
= make_minor(i
, *cp
++ - 'a');
printf("incorrect device specification\n");
file
->i_ino
.i_dev
= makedev(dp
-devsw
, i
);
opendev
= file
->i_ino
.i_dev
;
if (cp
!= str
&& *cp
== '\0') {
file
->i_ma
= file
->i_buf
;
file
->i_bn
= SBLOCK
+ file
->i_boff
;
printf("super block read error\n");
file
->i_fs
= *(struct fs
*)(file
->i_buf
);
if ((i
= find(cp
, file
)) == 0) {
printf("can't write files yet.. sorry\n");
if (openi(i
, file
) < 0) {
file
->i_flgs
|= F_FILE
| (how
+1);
if (fdesc
< 0 || fdesc
>= NFILES
||
((file
= &iob
[fdesc
])->i_flgs
&F_ALLOC
) == 0) {
if ((file
->i_flgs
&F_FILE
) == 0)
register struct iob
*file
;
if (fdesc
< 0 || fdesc
>= NFILES
||
((file
= &iob
[fdesc
])->i_flgs
&F_ALLOC
) == 0) {
file
->i_flgs
|= F_HCHECK
;
file
->i_flgs
&= ~F_ECCLM
;
file
->i_flgs
&= ~F_SEVRE
;
error
= devioctl(file
, cmd
, arg
);
for (i
= 0; i
< NFILES
; i
++)