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') {
openi((ino_t
) ROOTINO
, file
);
while(*q
!= '/' && *q
!= '\0')
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
;
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("zero length directory\n");
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
);
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
+= (count
/ DEV_BSIZE
);
if (file
->i_offset
+count
> file
->i_ino
.i_size
)
count
= file
->i_ino
.i_size
- file
->i_offset
;
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
+= (count
/ DEV_BSIZE
);
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
++)
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
> 31) {
printf("Bad unit specifier\n");
printf("Missing offset specification\n");
file
->i_ma
= (char *)(&file
->i_fs
);
if ((i
= find(cp
, file
)) == 0) {
printf("Can't write files yet.. Sorry\n");
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)
for (i
= 0; i
< NFILES
; i
++)