* Make a file system prototype.
* usage: mkfs filsys proto/size [ m n ]
#define NIPB (BSIZE/sizeof(struct dinode))
#define NINDIR (BSIZE/sizeof(daddr_t))
#define NDIRECT (BSIZE/sizeof(struct direct))
#define itoo(x) (int)((x+15)&07)
printf("usage: mkfs filsys proto/size [ m n ]\n");
printf("file sys size: ");
} while (fso
< 0 || fsi
< 0);
printf("%s: cannot create\n", fsys
);
printf("%s: cannot open\n", fsys
);
for(f
=0; c
=proto
[f
]; f
++) {
printf("%s: cannot open\n", proto
);
printf("isize = %D\n", n
*NIPB
);
* get name of boot load program
printf("%s: cannot open init\n", string
);
read(f
, (char *)&head
, sizeof head
);
if(head
.a_magic
!= A_MAGIC1
) {
printf("%s: bad format\n", string
);
c
= head
.a_text
+ head
.a_data
;
printf("%s: too big\n", string
);
filsys
.s_fsize
= getnum();
if(f_n
<= 0 || f_n
>= MAXFN
)
if(f_m
<= 0 || f_m
> f_n
)
printf("m/n = %d %d\n", f_m
, f_n
);
if(filsys
.s_isize
>= filsys
.s_fsize
) {
printf("%ld/%ld: bad ratio\n", filsys
.s_fsize
, filsys
.s_isize
-2);
for(n
=2; n
!=filsys
.s_isize
; n
++) {
cfile((struct inode
*)0);
wtfs((long)1, (char *)&filsys
);
in
.i_mode
= gmode(string
[0], "-bcd", IFREG
, IFBLK
, IFCHR
, IFDIR
);
in
.i_mode
|= gmode(string
[1], "-u", 0, ISUID
, 0, 0);
in
.i_mode
|= gmode(string
[2], "-g", 0, ISGID
, 0, 0);
printf("%c/%s: bad octal mode digit\n", c
, string
);
in
.i_mode
|= (c
-'0')<<(15-3*i
);
* general initialization prior to
in
.i_un
.i_addr
[i
] = (daddr_t
)0;
if(par
== (struct inode
*)0) {
* contents is a file name
printf("%s: cannot open\n", string
);
while((i
=read(f
, db
, BSIZE
)) > 0) {
newblk(&dbc
, db
, &ibc
, ib
);
* content is maj/min types
in
.i_un
.i_addr
[0] = (i
<<8) | f
;
entry(in
.i_number
, ".", &dbc
, db
, &ibc
, ib
);
entry(par
->i_number
, "..", &dbc
, db
, &ibc
, ib
);
in
.i_size
= 2*sizeof(struct direct
);
if(string
[0]=='$' && string
[1]=='\0')
entry(ino
+1, string
, &dbc
, db
, &ibc
, ib
);
in
.i_size
+= sizeof(struct direct
);
newblk(&dbc
, db
, &ibc
, ib
);
gmode(c
, s
, m0
, m1
, m2
, m3
)
printf("%c/%s: bad mode\n", c
, string
);
for(i
=0; c
=string
[i
]; i
++) {
printf("%s: bad number\n", string
);
} while(c
!=' '&&c
!='\t'&&c
!='\n'&&c
!='\0');
lseek(fsi
, bno
*BSIZE
, 0);
n
= read(fsi
, bf
, BSIZE
);
printf("read error: %ld\n", bno
);
lseek(fso
, bno
*BSIZE
, 0);
n
= write(fso
, bf
, BSIZE
);
printf("write error: %D\n", bno
);
bno
= filsys
.s_free
[--filsys
.s_nfree
];
printf("out of free space\n");
if(filsys
.s_nfree
<= 0) {
rdfs(bno
, (char *)&fbuf
);
filsys
.s_nfree
= fbuf
.df_nfree
;
filsys
.s_free
[i
] = fbuf
.df_free
[i
];
if(filsys
.s_nfree
>= NICFREE
) {
fbuf
.df_nfree
= filsys
.s_nfree
;
fbuf
.df_free
[i
] = filsys
.s_free
[i
];
wtfs(bno
, (char *)&fbuf
);
filsys
.s_free
[filsys
.s_nfree
++] = bno
;
entry(inum
, str
, adbc
, db
, aibc
, ib
)
dp
= (struct direct
*)db
;
if((dp
->d_name
[i
] = str
[i
]) == 0)
newblk(adbc
, db
, aibc
, ib
);
newblk(adbc
, db
, aibc
, ib
)
printf("indirect block full\n");
in
.i_un
.i_addr
[i
] = (daddr_t
)0;
if(f
< filsys
.s_fsize
&& f
>= filsys
.s_isize
)
printf("too many bad blocks\n");
if(d
>= filsys
.s_isize
) {
printf("ilist too small\n");
dp
= (struct dinode
*)buf
;
dp
+= itoo(ip
->i_number
);
dp
->di_mode
= ip
->i_mode
;
dp
->di_nlink
= ip
->i_nlink
;
dp
->di_size
= ip
->i_size
;
switch(ip
->i_mode
&IFMT
) {
ip
->i_un
.i_addr
[i
] = ib
[i
];
ip
->i_un
.i_addr
[LADDR
] = alloc();
for(i
=0; i
<NINDIR
-LADDR
; i
++) {
ib
[i
+LADDR
] = (daddr_t
)0;
wtfs(ip
->i_un
.i_addr
[LADDR
], (char *)ib
);
ltol3(dp
->di_addr
, ip
->i_un
.i_addr
, NADDR
);
printf("bad mode %o\n", ip
->i_mode
);