* Copyright (c) 1982, 1988 The Regents of the University of California.
* %sccs.include.proprietary.c%
* @(#)open.c 7.3 (Berkeley) %G%
u_int opendev
; /* last device opened */
static ino_t dlook
__P((char *, struct iob
*, char *));
static int find
__P((char *, struct iob
*));
static int getdev
__P((char *, int));
static int getunit
__P((char *));
static struct direct
*readdir
__P((struct dirstuff
*));
static int openi
__P((int, struct iob
*));
static int firstopen
= 1;
register struct iob
*file
;
int fdesc
, args
[8], *argp
;
for (cnt
= 0; cnt
< SOPEN_MAX
; cnt
++)
for (fdesc
= 0;; fdesc
++) {
_stop("No more file slots");
if (iob
[fdesc
].i_flgs
== 0) {
file
->i_adapt
= file
->i_ctlr
= file
->i_unit
=
for (cnt
= 0; cnt
< sizeof(args
)/sizeof(args
[0]); args
[cnt
++] = 0);
for (t
= str
; *t
&& *t
!= '/' && *t
!= ':' && *t
!= '('; ++t
)
case '(': /* type(adapt, ctlr, drive, partition)file */
if ((file
->i_dev
= getdev(str
, t
- str
)) == -1)
for (argp
= args
+ 4, cnt
= 0; *t
!= ')'; ++cnt
) {
for (++t
; isspace(*t
); ++t
);
for (++t
; isdigit(*t
); ++t
);
if (*t
!= ',' && *t
!= ')' || cnt
== 4)
for (++t
; isspace(*t
); ++t
);
case ':': /* [A-Za-z]*[0-9]*[A-Za-z]:file */
for (t
= str
; *t
!= ':' && !isdigit(*t
); ++t
);
if ((file
->i_dev
= getdev(str
, t
- str
)) == -1)
if ((file
->i_unit
= getunit(t
)) == -1)
for (; isdigit(*t
); ++t
);
if (*t
>= 'a' && *t
<= 'h')
file
->i_part
= *t
++ - 'a';
for (++t
; isspace(*t
); ++t
);
default: /* default bootstrap unit and device */
file
->i_dev
= B_TYPE(bootdev
);
file
->i_adapt
= B_ADAPTOR(bootdev
);
file
->i_ctlr
= B_CONTROLLER(bootdev
);
file
->i_unit
= B_UNIT(bootdev
);
file
->i_part
= B_PARTITION(bootdev
);
opendev
= MAKEBOOTDEV(file
->i_dev
, file
->i_adapt
, file
->i_ctlr
,
file
->i_unit
, file
->i_part
);
if (errno
= devopen(file
))
printf("Can't write files yet.. Sorry\n");
file
->i_ma
= (char *)(&file
->i_fs
);
file
->i_bn
= SBOFF
/ DEV_BSIZE
+ file
->i_boff
;
printf("super block read error\n");
if ((cnt
= find(t
, file
)) == 0) {
if (openi(cnt
, file
) < 0) {
file
->i_flgs
|= F_FILE
| (how
+1);
printf("malformed device specification\nusage: device(adaptor, controller, drive, partition)file -or- <device><unit><partitionletter>:<file>\n");
register struct devsw
*dp
;
for (dp
= devsw
, i
= 0; i
< ndevs
; dp
++, i
++)
if (dp
->dv_name
&& strcmp(str
, dp
->dv_name
) == 0) {
printf("Unknown device\nKnown devices are:\n");
for (dp
= devsw
, i
= 0; i
< ndevs
; dp
++, i
++)
printf(" %s", dp
->dv_name
);
printf("minor device number out of range (0-255)\n");
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
, dir
)) != 0) {
printf("%s: not found\n", path
);
register struct direct
*dp
;
register struct dinode
*ip
;
if (s
== NULL
|| *s
== '\0')
if ((ip
->di_mode
&IFMT
) != IFDIR
) {
printf("%s: not a directory\n", dir
);
printf("%s: zero length directory\n", dir
);
for (dp
= readdir(&dirp
); dp
!= NULL
; dp
= readdir(&dirp
)) {
if (dp
->d_namlen
== len
&& !strcmp(s
, dp
->d_name
))
register struct dirstuff
*dirp
;
register struct direct
*dp
;
if (dirp
->loc
>= io
->i_ino
.di_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
= dblksize(&io
->i_fs
, &io
->i_ino
, lbn
);
printf("bn %ld: directory read error\n",
dp
= (struct direct
*)(io
->i_buf
+ off
);
dirp
->loc
+= dp
->d_reclen
;
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
= dp
[itoo(&io
->i_fs
, n
)];