char *select_image(char *image) /* Look image up on the filesystem, if it is a file then we're done, but * if its a directory then we want the newest file in that directory. If * it doesn't exist at all, then see if it is 'number:number' and get the * image from that absolute offset off the disk. */ { ino_t image_ino; struct stat st; image= strcpy(malloc((strlen(image) + 1 + NAME_MAX + 1) * sizeof(char)), image); fsok= r_super(&block_size) != 0; if (!fsok || (image_ino= r_lookup(ROOT_INO, image)) == 0) { char *size; if (numprefix(image, &size) && *size++ == ':' && numeric(size)) { vir2sec= flat_vir2sec; image_off= a2l(image); image_sectors= a2l(size); strcpy(image, "Minix"); return image; } if (!fsok) printf("No image selected\n"); else printf("Can't load %s: %s\n", image, unix_err(errno)); goto bail_out; } r_stat(image_ino, &st); image_bytes = st.st_size; if (!S_ISREG(st.st_mode)) { char *version= image + strlen(image); char dots[NAME_MAX + 1]; if (!S_ISDIR(st.st_mode)) { printf("%s: %s\n", image, unix_err(ENOTDIR)); goto bail_out; } (void) r_readdir(dots); (void) r_readdir(dots); /* "." & ".." */ *version++= '/'; *version= 0; if ((image_ino= latest_version(version, &st)) == 0) { printf("There are no images in %s\n", image); goto bail_out; } r_stat(image_ino, &st); } vir2sec= file_vir2sec; image_sectors= (st.st_size + SECTOR_SIZE - 1) >> SECTOR_SHIFT; return image; bail_out: free(image); return nil; }
ino_t latest_version(char *version, struct stat *stp) /* Recursively read the current directory, selecting the newest image on * the way up. (One can't use r_stat while reading a directory.) */ { char name[NAME_MAX + 1]; ino_t ino, newest; time_t mtime; if ((ino= r_readdir(name)) == 0) { stp->st_mtime= 0; return 0; } newest= latest_version(version, stp); mtime= stp->st_mtime; r_stat(ino, stp); if (S_ISREG(stp->st_mode) && stp->st_mtime > mtime) { newest= ino; strcpy(version, name); } else { stp->st_mtime= mtime; } return newest; }
void _fl_stat(int *w) { r_stat ((char *)(w[0]), (int)(w[1]), (struct occam_stat *)(w[2]), (int *)(w[3])); }