* Copyright (c) 1982 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
* @(#)sys.c 6.5 (Berkeley) %G%
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 (q
== path
) 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("not a directory\n");
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) {
io
->i_bn
= addr
/ DEV_BSIZE
;
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_BSIZE
;
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++) {
register struct iob
*file
;
if (fdesc
>= 0 & fdesc
<= 2) {
} while (--i
&& *buf
++ != '\n');
if (fdesc
< 0 || fdesc
>= NFILES
||
((file
= &iob
[fdesc
])->i_flgs
&F_ALLOC
) == 0) {
if ((file
->i_flgs
&F_READ
) == 0) {
if ((file
->i_flgs
& F_FILE
) == 0) {
file
->i_bn
= file
->i_boff
+ (file
->i_offset
/ DEV_BSIZE
);
if (file
->i_offset
+count
> file
->i_ino
.i_size
)
count
= file
->i_ino
.i_size
- file
->i_offset
;
* While reading full blocks, do I/O into user buffer.
* Anything else uses getc().
off
= blkoff(fs
, file
->i_offset
);
lbn
= lblkno(fs
, file
->i_offset
);
size
= blksize(fs
, &file
->i_ino
, lbn
);
if (off
== 0 && size
<= i
) {
file
->i_bn
= fsbtodb(fs
, sbmap(file
, lbn
)) +
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");
opendev
= file
->i_ino
.i_dev
= makedev(dp
-devsw
, i
);
if (cp
!= str
&& *cp
== '\0') {
for (cp
= str
; *cp
&& *cp
!= '('; cp
++)
for (dp
= devsw
; dp
->dv_name
; dp
++) {
if (!strcmp(str
, dp
->dv_name
))
printf("Unknown device\n");
file
->i_ino
.i_dev
= dp
-devsw
;
file
->i_unit
= *cp
++ - '0';
if (*cp
>= '0' && *cp
<= '9')
file
->i_unit
= file
->i_unit
* 10 + *cp
++ - '0';
if (file
->i_unit
< 0 || file
->i_unit
> 63) {
printf("Bad unit specifier\n");
printf("Missing offset specification\n");
file
->i_ma
= (char *)(&file
->i_fs
);
file
->i_bn
= SBLOCK
+ file
->i_boff
;
printf("super block read error\n");
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
++)