int fs_format() { if(mb.magic == FS_MAGIC) { printf("Refusing to format a mounted disk\n"); return -1; } disk_read(0, (char *)&mb); if(mb.magic == FS_MAGIC){ printf("Refusing to format a formatted disk!\n"); mb.magic = 0; return -1; } //Format disk init_super_block(); init_empty_dir(); //Flush disk_write(0, (char*)&mb); disk_write(1, (char*)dir); mb.magic = 0; // mark disk as unmounted return 0; }
/* Change the protections of FILE to MODE. */ int __chmod (const char* file, mode_t mode) { struct dir dir; size_t mlen; char mbuf[STATFIXLEN]; int ret; if (file == NULL) { __set_errno (EINVAL); return -1; } init_empty_dir(&dir); dir.mode = mode; mlen = convD2M(&dir, mbuf, STATFIXLEN); ret = ros_syscall(SYS_wstat, file, strlen(file), mbuf, mlen, WSTAT_MODE, 0); return (ret == mlen ? 0 : -1); }