Lines Matching +full:group +full:- +full:index +full:- +full:shift
1 /*-
27 /*-
32 * The Mach Operating System project at Carnegie-Mellon University.
83 * Pittsburgh PA 15213-3890
127 #define EXT2_MINBSHIFT 10 /* minimum block shift */
128 #define EXT2_MINFSHIFT 10 /* minimum frag shift */
136 #define fsb_to_db(fs, blk) ((blk) << (fs)->fs_fsbtodb)
139 * inode to block group offset
140 * inode to block group
144 #define ino_to_bgo(fs, ino) (((ino) - 1) % (fs)->fs_ipg)
145 #define ino_to_bg(fs, ino) (((ino) - 1) / (fs)->fs_ipg)
148 ino_to_bgo(fs, ino) / (fs)->fs_ipb))
149 #define ino_to_bo(fs, ino) (ino_to_bgo(fs, ino) % (fs)->fs_ipb)
152 ((fs)->fs_bsize / sizeof(uint32_t))
154 ((loc) >> (fs)->fs_bshift)
156 ((blk) << (fs)->fs_bshift)
158 ((loc) & (fs)->fs_bmask)
160 (((size) + (fs)->fs_fmask) & ~(fs)->fs_fmask)
162 (((lbn) >= EXT2_NDADDR || (dip)->di_size >= smalllblktosize(fs, (lbn) + 1)) \
163 ? (fs)->fs_bsize \
164 : (fragroundup(fs, blkoff(fs, (dip)->di_size))))
178 uint32_t fd_bpg; /* blocks per group */
179 uint32_t fd_fpg; /* frags per group */
180 uint32_t fd_ipg; /* inodes per group */
196 uint32_t fd_firstino; /* first non-reserved inode */
198 uint16_t fd_nblkgrp; /* block group # of superblock */
201 uint32_t fd_frocompat; /* read-only compatibilties */
213 int fc_bshift; /* block shift amount */
216 int fc_fshift; /* frag shift amount */
220 int fc_firstino; /* first non-reserved inode */
222 int fc_fsbtodb; /* fsb to ds shift */
227 char fs_pad[EXT2_SBSIZE - sizeof(struct ext2fs_disk)];
302 struct ext2fs *f_fs; /* pointer to super-block */
304 struct ext2dinode f_di; /* copy of on-disk inode */
348 f->f_fsdata = (void *)fp; in ext2fs_open()
352 fp->f_fs = fs; in ext2fs_open()
354 error = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, in ext2fs_open()
359 if (buf_size != EXT2_SBSIZE || fs->fs_magic != EXT2_MAGIC) { in ext2fs_open()
365 * compute in-core values for the superblock in ext2fs_open()
367 fs->fs_bshift = EXT2_MINBSHIFT + fs->fs_fd.fd_bsize; in ext2fs_open()
368 fs->fs_bsize = 1 << fs->fs_bshift; in ext2fs_open()
369 fs->fs_bmask = fs->fs_bsize - 1; in ext2fs_open()
371 fs->fs_fshift = EXT2_MINFSHIFT + fs->fs_fd.fd_fsize; in ext2fs_open()
372 fs->fs_fsize = 1 << fs->fs_fshift; in ext2fs_open()
373 fs->fs_fmask = fs->fs_fsize - 1; in ext2fs_open()
375 if (fs->fs_revision == EXT2_REV0) { in ext2fs_open()
376 fs->fs_isize = EXT2_R0_ISIZE; in ext2fs_open()
377 fs->fs_firstino = EXT2_R0_FIRSTINO; in ext2fs_open()
379 fs->fs_isize = fs->fs_fd.fd_isize; in ext2fs_open()
380 fs->fs_firstino = fs->fs_fd.fd_firstino; in ext2fs_open()
382 fs->fs_imask = fs->fs_isize - 1; in ext2fs_open()
383 fs->fs_ipb = fs->fs_bsize / fs->fs_isize; in ext2fs_open()
384 fs->fs_fsbtodb = (fs->fs_bsize / DEV_BSIZE) - 1; in ext2fs_open()
387 * we have to load in the "group descriptors" here in ext2fs_open()
389 groups = howmany(fs->fs_blocks - fs->fs_firstblk, fs->fs_bpg); in ext2fs_open()
390 bg_per_blk = fs->fs_bsize / sizeof(struct ext2blkgrp); in ext2fs_open()
392 len = blkgrps * fs->fs_bsize; in ext2fs_open()
394 fp->f_bg = malloc(len); in ext2fs_open()
396 error = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, in ext2fs_open()
398 (char *)fp->f_bg, &buf_size); in ext2fs_open()
413 fp->f_nindir[i] = mult; in ext2fs_open()
438 if (! S_ISDIR(fp->f_di.di_mode)) { in ext2fs_open()
478 if (S_ISLNK(fp->f_di.di_mode)) { in ext2fs_open()
479 int link_len = fp->f_di.di_size; in ext2fs_open()
490 if (fp->f_di.di_nblk == 0) { in ext2fs_open()
491 bcopy(fp->f_di.di_shortlink, in ext2fs_open()
497 struct ext2fs *fs = fp->f_fs; in ext2fs_open()
502 buf = malloc(fs->fs_bsize); in ext2fs_open()
508 error = (f->f_dev->dv_strategy)(f->f_devdata, in ext2fs_open()
510 fs->fs_bsize, buf, &buf_size); in ext2fs_open()
536 fp->f_seekp = 0; in ext2fs_open()
543 if (fp->f_buf) in ext2fs_open()
544 free(fp->f_buf); in ext2fs_open()
545 free(fp->f_fs); in ext2fs_open()
557 struct file *fp = (struct file *)f->f_fsdata; in read_inode()
558 struct ext2fs *fs = fp->f_fs; in read_inode()
567 buf = malloc(fs->fs_bsize); in read_inode()
569 error = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, in read_inode()
570 ino_to_db(fs, fp->f_bg, inumber), fs->fs_bsize, buf, &rsize); in read_inode()
573 if (rsize != fs->fs_bsize) { in read_inode()
579 fp->f_di = dp[ino_to_bo(fs, inumber)]; in read_inode()
583 fp->f_blkno[level] = -1; in read_inode()
584 fp->f_buf_blkno = -1; in read_inode()
585 fp->f_seekp = 0; in read_inode()
599 struct file *fp = (struct file *)f->f_fsdata; in block_map()
600 struct ext2fs *fs = fp->f_fs; in block_map()
607 * Index structure of an inode: in block_map()
609 * di_db[0..EXT2_NDADDR-1] hold block numbers for blocks in block_map()
610 * 0..EXT2_NDADDR-1 in block_map()
612 * di_ib[0] index block 0 is the single indirect block in block_map()
614 * EXT2_NDADDR .. EXT2_NDADDR + NINDIR(fs)-1 in block_map()
616 * di_ib[1] index block 1 is the double indirect block in block_map()
617 * holds block numbers for INDEX blocks for blocks in block_map()
619 * EXT2_NDADDR + NINDIR(fs) + NINDIR(fs)**2 - 1 in block_map()
621 * di_ib[2] index block 2 is the triple indirect block in block_map()
622 * holds block numbers for double-indirect in block_map()
626 * + NINDIR(fs)**3 - 1 in block_map()
631 *disk_block_p = fp->f_di.di_db[file_block]; in block_map()
635 file_block -= EXT2_NDADDR; in block_map()
644 if (file_block < fp->f_nindir[level]) in block_map()
646 file_block -= fp->f_nindir[level]; in block_map()
653 ind_block_num = fp->f_di.di_ib[level]; in block_map()
655 for (; level >= 0; level--) { in block_map()
661 if (fp->f_blkno[level] != ind_block_num) { in block_map()
662 if (fp->f_blk[level] == (char *)0) in block_map()
663 fp->f_blk[level] = in block_map()
664 malloc(fs->fs_bsize); in block_map()
666 error = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, in block_map()
667 fsb_to_db(fp->f_fs, ind_block_num), fs->fs_bsize, in block_map()
668 fp->f_blk[level], &fp->f_blksize[level]); in block_map()
671 if (fp->f_blksize[level] != fs->fs_bsize) in block_map()
673 fp->f_blkno[level] = ind_block_num; in block_map()
676 ind_p = (int32_t *)fp->f_blk[level]; in block_map()
679 idx = file_block / fp->f_nindir[level - 1]; in block_map()
680 file_block %= fp->f_nindir[level - 1]; in block_map()
699 struct file *fp = (struct file *)f->f_fsdata; in buf_read_file()
700 struct ext2fs *fs = fp->f_fs; in buf_read_file()
707 off = blkoff(fs, fp->f_seekp); in buf_read_file()
708 file_block = lblkno(fs, fp->f_seekp); in buf_read_file()
709 block_size = dblksize(fs, &fp->f_di, file_block); in buf_read_file()
711 if (file_block != fp->f_buf_blkno) { in buf_read_file()
716 if (fp->f_buf == (char *)0) in buf_read_file()
717 fp->f_buf = malloc(fs->fs_bsize); in buf_read_file()
720 bzero(fp->f_buf, block_size); in buf_read_file()
721 fp->f_buf_size = block_size; in buf_read_file()
724 error = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, in buf_read_file()
726 fp->f_buf, &fp->f_buf_size); in buf_read_file()
730 fp->f_buf_blkno = file_block; in buf_read_file()
738 *buf_p = fp->f_buf + off; in buf_read_file()
739 *size_p = block_size - off; in buf_read_file()
744 if (*size_p > fp->f_di.di_size - fp->f_seekp) in buf_read_file()
745 *size_p = fp->f_di.di_size - fp->f_seekp; in buf_read_file()
757 struct file *fp = (struct file *)f->f_fsdata; in search_directory()
765 fp->f_seekp = 0; in search_directory()
766 while (fp->f_seekp < fp->f_di.di_size) { in search_directory()
773 if (dp->d_ino == (ino_t)0) in search_directory()
775 namlen = dp->d_namlen; in search_directory()
777 strncmp(name, dp->d_name, length) == 0) { in search_directory()
779 *inumber_p = dp->d_ino; in search_directory()
783 dp = (struct ext2dirent *)((char *)dp + dp->d_reclen); in search_directory()
785 fp->f_seekp += buf_size; in search_directory()
793 struct file *fp = (struct file *)f->f_fsdata; in ext2fs_close()
799 f->f_fsdata = NULL; in ext2fs_close()
802 if (fp->f_blk[level]) in ext2fs_close()
803 free(fp->f_blk[level]); in ext2fs_close()
805 if (fp->f_buf) in ext2fs_close()
806 free(fp->f_buf); in ext2fs_close()
807 if (fp->f_bg) in ext2fs_close()
808 free(fp->f_bg); in ext2fs_close()
809 free(fp->f_fs); in ext2fs_close()
817 struct file *fp = (struct file *)f->f_fsdata; in ext2fs_read()
823 if (fp->f_seekp >= fp->f_di.di_size) in ext2fs_read()
836 fp->f_seekp += csize; in ext2fs_read()
838 size -= csize; in ext2fs_read()
848 struct file *fp = (struct file *)f->f_fsdata; in ext2fs_seek()
852 fp->f_seekp = offset; in ext2fs_seek()
855 fp->f_seekp += offset; in ext2fs_seek()
858 fp->f_seekp = fp->f_di.di_size - offset; in ext2fs_seek()
862 return (-1); in ext2fs_seek()
864 return (fp->f_seekp); in ext2fs_seek()
870 struct file *fp = (struct file *)f->f_fsdata; in ext2fs_stat()
873 sb->st_mode = fp->f_di.di_mode; in ext2fs_stat()
874 sb->st_uid = fp->f_di.di_uid; in ext2fs_stat()
875 sb->st_gid = fp->f_di.di_gid; in ext2fs_stat()
876 sb->st_size = fp->f_di.di_size; in ext2fs_stat()
883 struct file *fp = (struct file *)f->f_fsdata; in ext2fs_readdir()
894 if (fp->f_seekp >= fp->f_di.di_size) in ext2fs_readdir()
900 fp->f_seekp += ed->d_reclen; in ext2fs_readdir()
901 } while (ed->d_ino == (ino_t)0); in ext2fs_readdir()
903 d->d_type = EXTFTODT(ed->d_type); in ext2fs_readdir()
904 strncpy(d->d_name, ed->d_name, ed->d_namlen); in ext2fs_readdir()
905 d->d_name[ed->d_namlen] = '\0'; in ext2fs_readdir()