Exemplo n.º 1
0
static int mount_device(const char *dev_name, const char *vol_name)
{
	int result = 0;
	
	result = fs_mkdir(vol_name, 0);
	if(result < 0)
	{
		FS_PRINTF("mkdir: %s failed! ret = %d\n", vol_name, result);
		return result;
	}
	FS_PRINTF("mount: %s -> %s...", dev_name, vol_name);
	result = fs_mount(vol_name, dev_name, "FAT", 0, NULL);
	if(result == -EINVAL)
	{
		result = fs_mount(vol_name, dev_name, "NTFS", 0, NULL);
        if (result == -EBUSY)
		{
			fs_unmount(vol_name, 1);
			result = fs_mount(vol_name, dev_name, "NTFS", 0, NULL);    
		}
	}
	else if(result == -EBUSY)
	{
		fs_unmount(vol_name, 1);
		result = fs_mount(vol_name, dev_name, "FAT", 0, NULL);
		if(result == -EINVAL)
		{
			result = fs_mount(vol_name, dev_name, "NTFS", 0, NULL);
			if(result == -EBUSY)
			{
				fs_unmount(vol_name, 1);
				result = fs_mount(vol_name, dev_name, "NTFS", 0, NULL);    
			}
		}
	}
	if(result >= 0)
	{
		FS_PRINTF("successed!\n");
	}
	else
	{
		FS_PRINTF("failed! err = %d\n", result);
		fs_rmdir(vol_name);
	}

	return result;	
}
Exemplo n.º 2
0
void ide_fs_unmount(UINT32 param)
{
	int i;
	char mount_name[16];	
	int result;
	struct statvfs sfs;
	int fd;
	
	char dirbuf[sizeof(struct dirent) + 32];	
	struct dirent *dire = (struct dirent *)dirbuf;

	unlink_device("/c", MNT_TYPE_IDE);
	unlink_device("/r", MNT_TYPE_IDE);

	fd = fs_opendir("/mnt");

	while (fs_readdir(fd, dire) > 0)
	{
		fs_get_mount_name(MNT_TYPE_IDE, 0, 0, mount_name);
		if(!MEMCMP(&dire->d_name, &mount_name[5], 3))
		{
			STRCPY(mount_name, "/mnt/");
			strcat(mount_name, dire->d_name);

			FS_PRINTF("unmount: %s ...\n", mount_name);
			result = fs_statvfs(mount_name, &sfs);
			if (result < 0)
			{
				FS_PRINTF("%s is not mounted! err = %d\n", mount_name, result);
				FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, MNT_MSG_PARAM(UNMNT_FAILED, MNT_TYPE_IDE, 0));
//				IDE_MESSAGE(MP_FS_UNMOUNT, UNMNT_FAILED);	
				continue;
			}

			result = fs_unmount(mount_name, 1);
			if (result < 0)
			{
				FS_PRINTF("%s unmounted failed! err = %d\n", mount_name, result);
				FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, MNT_MSG_PARAM(UNMNT_FAILED, MNT_TYPE_IDE, 0));
//				IDE_MESSAGE(MP_FS_UNMOUNT, UNMNT_FAILED);
			}
			else
			{
				FS_PRINTF("%s unmounted successed!\n", mount_name);
			}

	        result = fs_rmdir(mount_name);
			if (result < 0)
			{
	            FS_PRINTF("remove dir %s failed! err = %d\n", mount_name, result);
			}
		}	
	}	

	fs_closedir(fd);
    ide_hdd_cleanup(0);
	FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, MNT_MSG_PARAM(UNMNT_UNMOUNT_OK, MNT_TYPE_IDE, 0));
//	IDE_MESSAGE(MP_FS_UNMOUNT, UNMNT_UNMOUNT_OK);
}
Exemplo n.º 3
0
void nodemcu_init(void)
{
    NODE_ERR("\n");
    // Initialize platform first for lua modules.
    if( platform_init() != PLATFORM_OK )
    {
        // This should never happen
        NODE_DBG("Can not init platform for modules.\n");
        return;
    }

#if defined(FLASH_SAFE_API)
    if( flash_safe_get_size_byte() != flash_rom_get_size_byte()) {
        NODE_ERR("Self adjust flash size.\n");
        // Fit hardware real flash size.
        flash_rom_set_size_byte(flash_safe_get_size_byte());

        if( !fs_format() )
        {
            NODE_ERR( "\ni*** ERROR ***: unable to format. FS might be compromised.\n" );
            NODE_ERR( "It is advised to re-flash the NodeMCU image.\n" );
        }
        else {
            NODE_ERR( "format done.\n" );
        }
        fs_unmount();   // mounted by format.

        // Reboot to get SDK to use (or write) init data at new location
        system_restart ();

        // Don't post the start_lua task, we're about to reboot...
        return;
    }
#endif // defined(FLASH_SAFE_API)

#if defined ( BUILD_SPIFFS )
    fs_mount();
    // test_spiffs();
#endif
    // endpoint_setup();

    task_post_low(task_get_id(start_lua),'s');
}
Exemplo n.º 4
0
void nodemcu_init(void)
{
    NODE_ERR("\n");
    // Initialize platform first for lua modules.   
    if( platform_init() != PLATFORM_OK )
    {
        // This should never happen
        NODE_DBG("Can not init platform for modules.\n");
        return;
    }

#if defined(FLASH_SAFE_API)
    if( flash_safe_get_size_byte() != flash_rom_get_size_byte()) {
        NODE_ERR("Self adjust flash size.\n");
        // Fit hardware real flash size.
        flash_rom_set_size_byte(flash_safe_get_size_byte());
        // Flash init data at FLASHSIZE - 0x04000 Byte.
        flash_init_data_default();
        // Flash blank data at FLASHSIZE - 0x02000 Byte.
        flash_init_data_blank();
        if( !fs_format() )
        {
            NODE_ERR( "\ni*** ERROR ***: unable to format. FS might be compromised.\n" );
            NODE_ERR( "It is advised to re-flash the NodeMCU image.\n" );
        }
        else{
            NODE_ERR( "format done.\n" );
        }
        fs_unmount();   // mounted by format.
    }
#endif // defined(FLASH_SAFE_API)

    if( !flash_init_data_written() ){
        NODE_ERR("Restore init data.\n");
        // Flash init data at FLASHSIZE - 0x04000 Byte.
        flash_init_data_default();
        // Flash blank data at FLASHSIZE - 0x02000 Byte.
        flash_init_data_blank(); 
    }

#if defined( BUILD_WOFS )
    romfs_init();

    // if( !wofs_format() )
    // {
    //     NODE_ERR( "\ni*** ERROR ***: unable to erase the flash. WOFS might be compromised.\n" );
    //     NODE_ERR( "It is advised to re-flash the NodeWifi image.\n" );
    // }
    // else
    //     NODE_ERR( "format done.\n" );

    // test_romfs();
#elif defined ( BUILD_SPIFFS )
    fs_mount();
    // test_spiffs();
#endif
    // endpoint_setup();

    // char* lua_argv[] = { (char *)"lua", (char *)"-e", (char *)"print(collectgarbage'count');ttt={};for i=1,100 do table.insert(ttt,i*2 -1);print(i);end for k, v in pairs(ttt) do print('<'..k..' '..v..'>') end print(collectgarbage'count');", NULL };
    // lua_main( 3, lua_argv );
    // char* lua_argv[] = { (char *)"lua", (char *)"-i", NULL };
    // lua_main( 2, lua_argv );
    // char* lua_argv[] = { (char *)"lua", (char *)"-e", (char *)"pwm.setup(0,100,50) pwm.start(0) pwm.stop(0)", NULL };
    // lua_main( 3, lua_argv );
    // NODE_DBG("Flash sec num: 0x%x\n", flash_get_sec_num());
    task_init();
    system_os_post(USER_TASK_PRIO_0,SIG_LUA,'s');
}
Exemplo n.º 5
0
void sd_fs_unmount(UINT32 param)
{
	int i;
	char mount_name[16];	
	int result;
	struct statvfs sfs;
	int fd;
	struct stat st;
	char dirbuf[sizeof(struct dirent) + 32];	
	struct dirent *dire = (struct dirent *)dirbuf;
#ifdef USB_SUPPORT_HUB
	UINT32 msg_code = 0;
	struct fs_sto_param fs_param;
	fs_param.type = MNT_TYPE_SD;
	fs_param.id = 0;
	fs_param.partition_id = 0;
#endif	
	

#if (SYS_CHIP_MODULE != ALI_S3602)
	unlink_device("/c", MNT_TYPE_SD);
	unlink_device("/r", MNT_TYPE_SD);
#endif

	fd = fs_opendir("/mnt");

	while(fs_readdir(fd, dire) > 0)
	{
		fs_get_mount_name(MNT_TYPE_SD, 0, 0, mount_name);
		if(!MEMCMP(&dire->d_name, &mount_name[5], 3))
		{
			STRCPY(mount_name, "/mnt/");
			strcat(mount_name, dire->d_name);

			FS_PRINTF("unmount: %s ...", mount_name);
			result = fs_statvfs(mount_name, &sfs);
			if(result < 0)
			{
				FS_PRINTF("the %s is not mounted!\n", mount_name);
#if (SYS_CHIP_MODULE == ALI_S3602)
				FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, MNT_MSG_PARAM(UNMNT_FAILED, MNT_TYPE_SD, 0));
//				SD_MESSAGE(MP_FS_UNMOUNT, UNMNT_FAILED);
#else
#ifdef USB_SUPPORT_HUB
				fs_param.msg_code = UNMNT_FAILED;
				msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code;
#else
				msg_code = 1;
#endif		
				FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, msg_code);
#endif				
				continue;
			}

			result = fs_unmount(mount_name, 1);
			if(result < 0)
			{
				FS_PRINTF("the %s is unmounted failed!\n", mount_name);
#if (SYS_CHIP_MODULE == ALI_S3602)
				FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, MNT_MSG_PARAM(UNMNT_FAILED, MNT_TYPE_SD, 0));
//				SD_MESSAGE(MP_FS_UNMOUNT, UNMNT_FAILED);
#else
#ifdef USB_SUPPORT_HUB
				fs_param.msg_code = UNMNT_FAILED;
				msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code;
#else
				msg_code = 1;
#endif		
				FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, msg_code);
#endif				
				FS_PRINTF("failed! err = %d\n", result);
			}
			else
			{
				FS_PRINTF("successed!\n");
			}

	        result = fs_rmdir(mount_name);
			if (result < 0)
			{
	            FS_PRINTF("remove dir %s failed! err = %d\n", mount_name, result);
			}
		}
	}


#if (SYS_CHIP_MODULE != ALI_S3602)
#ifdef USB_SUPPORT_HUB
	fs_param.msg_code = UNMNT_PLUGOUT;
	msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code;
#else
	msg_code = 0;
#endif		
	FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, msg_code);
#ifdef USB_SUPPORT_HUB
	fs_param.msg_code = 102;
	msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code;
#else
	msg_code = 102;
#endif		
	FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, msg_code);	
#endif
	
	fs_closedir(fd);
	sdio_hdd_cleanup(0);
#if (SYS_CHIP_MODULE == ALI_S3602)
	FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, MNT_MSG_PARAM(UNMNT_UNMOUNT_OK, MNT_TYPE_SD, 0));
//	SD_MESSAGE(MP_FS_UNMOUNT, UNMNT_UNMOUNT_OK);
#endif
}
Exemplo n.º 6
0
void sata_fs_unmount(UINT32 param)
{
	int i;
	char mount_name[16];	
	int result;
	struct statvfs sfs;
	int fd;
	
	char dirbuf[sizeof(struct dirent) + 32];	
	struct dirent *dire = (struct dirent *)dirbuf;

	struct fs_sto_param fs_param;
	
	fs_param.type = MNT_TYPE_SATA;
	fs_param.id = 0;
	fs_param.partition_id = 0;

	fd = fs_opendir("/mnt");

	while (fs_readdir(fd, dire) > 0)
	{
		fs_get_mount_name(MNT_TYPE_SATA, 0, 0, mount_name);
		if(!MEMCMP(&dire->d_name, &mount_name[5], 3))
		{
			STRCPY(mount_name, "/mnt/");
			strcat(mount_name, dire->d_name);

			FS_PRINTF("unmount: %s ...\n", mount_name);
			result = fs_statvfs(mount_name, &sfs);
			if (result < 0)
			{
				FS_PRINTF("%s is not mounted! err = %d\n", mount_name, result);
				fs_param.msg_code = UNMNT_FAILED;
				PUT_MESSAGE(MP_FS_UNMOUNT, fs_param);
				continue;
			}

			result = fs_unmount(mount_name, 1);
			if (result < 0)
			{
				FS_PRINTF("%s unmounted failed! err = %d\n", mount_name, result);
				fs_param.msg_code = UNMNT_FAILED;
				PUT_MESSAGE(MP_FS_UNMOUNT, fs_param);
			}
			else
			{
				FS_PRINTF("%s unmounted successed!\n", mount_name);
			}

	        result = fs_rmdir(mount_name);
			if (result < 0)
			{
	            FS_PRINTF("remove dir %s failed! err = %d\n", mount_name, result);
			}
		}	
	}	

	fs_closedir(fd);
    sata_hdd_cleanup(0);
	fs_param.msg_code = UNMNT_UNMOUNT_OK;
	PUT_MESSAGE(MP_FS_UNMOUNT, fs_param);

	return;
}
Exemplo n.º 7
0
void usb_fs_unmount(UINT32 nodeid)
{
	int i;
	char mount_name[16];	
	int result;
	int devid;
	struct statvfs sfs;
	char dirbuf[sizeof(struct dirent) + 32];	
	struct dirent *dire = (struct dirent *)dirbuf;
	int fd;
	struct stat st;
	UINT32 msg_code = 0;

	int lunlist[16];
	
	INT32 lun_num = usb_hdd_get_lunlist(nodeid, lunlist, 16);

#ifdef USB_SUPPORT_HUB
	struct fs_sto_param fs_param;
	fs_param.type = MNT_TYPE_USB;
	fs_param.id = 0;
	fs_param.partition_id = 0;
#endif

	unlink_device("/c", MNT_TYPE_USB);
#if (SYS_CHIP_MODULE != ALI_S3602)
	unlink_device("/r", MNT_TYPE_USB);
#endif

	for( i = 0; i<lun_num; ++i)
	{
		devid = usb_hdd_get_dev(nodeid, lunlist[i]);
		if(devid < 0) continue;
			
#ifdef USB_SUPPORT_HUB
		fs_param.id = devid;
#endif		

		fd = fs_opendir("/mnt");
		while(fs_readdir(fd, dire) > 0)
		{
			fs_get_mount_name(MNT_TYPE_USB, devid, 0, mount_name);
			if(!MEMCMP(&dire->d_name, &mount_name[5], 3)) 
			{
				STRCPY(mount_name, "/mnt/");
				strcat(mount_name, dire->d_name);

				FS_PRINTF("unmount: %s ...", mount_name);
				result = fs_statvfs(mount_name, &sfs);
				if(result < 0)
				{
					FS_PRINTF("the %s is not mounted!\n", mount_name);
#if (SYS_CHIP_MODULE == ALI_S3602)
	#ifdef USB_SUPPORT_HUB
					FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, MNT_MSG_PARAM(UNMNT_FAILED, fs_param.type, fs_param.id));
	#else
					FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, MNT_MSG_PARAM(UNMNT_FAILED, MNT_TYPE_USB, 0));
//					USB_MESSAGE(MP_FS_UNMOUNT, UNMNT_FAILED);
	#endif
#else
	#ifdef USB_SUPPORT_HUB
					fs_param.msg_code = UNMNT_FAILED;
					msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code;
	#else
					msg_code = 1;
	#endif		
					FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, msg_code);
#endif			
					continue;
				}

				result = fs_unmount(mount_name, 1);
				if(result < 0)
				{
					FS_PRINTF("the %s is unmounted failed!\n", mount_name);
#if (SYS_CHIP_MODULE == ALI_S3602)
	#ifdef USB_SUPPORT_HUB
					FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, MNT_MSG_PARAM(UNMNT_FAILED, fs_param.type, fs_param.id));
	#else
					FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, MNT_MSG_PARAM(UNMNT_FAILED, MNT_TYPE_USB, 0));
//					USB_MESSAGE(MP_FS_UNMOUNT, UNMNT_FAILED);
	#endif
#else
	#ifdef USB_SUPPORT_HUB
					fs_param.msg_code = UNMNT_FAILED;
					msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code;
	#else
					msg_code = 1;
	#endif		
					FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, msg_code);
#endif							
					FS_PRINTF("failed! err = %d\n", result);
				}
				else
				{
					FS_PRINTF("successed!\n");
				}
				
				fs_rmdir(mount_name);
			}
		}

		//FS_PRINTF("fs_unmount ok!\n");

#ifdef USB_SUPPORT_HUB	//fix for usb with multi-device, every device should notify APP				
#if (SYS_CHIP_MODULE != ALI_S3602)
		fs_param.msg_code = UNMNT_PLUGOUT;
		msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code;
		FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, msg_code);
		fs_param.msg_code = UNMNT_UNMOUNT;
		msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code;
		FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, msg_code);
#endif
#endif
		fs_closedir(fd);
		usb_hdd_cleanup(nodeid, lunlist[i]);
		
#if (SYS_CHIP_MODULE == ALI_S3602)
	#ifdef USB_SUPPORT_HUB
		FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, MNT_MSG_PARAM(UNMNT_UNMOUNT_OK, fs_param.type, fs_param.id));
	#else
		FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, MNT_MSG_PARAM(UNMNT_UNMOUNT_OK, MNT_TYPE_USB, 0));
	#endif
#endif
	}

#ifndef USB_SUPPORT_HUB
#if (SYS_CHIP_MODULE != ALI_S3602)
#ifdef USB_SUPPORT_HUB
	fs_param.msg_code = UNMNT_PLUGOUT;
	msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code;
#else
	msg_code = 0;
#endif		
	FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, msg_code);
#ifdef USB_SUPPORT_HUB
	fs_param.msg_code = UNMNT_UNMOUNT;
	msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code;
#else
	msg_code = 2;
#endif		
	FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, msg_code);
#endif
#endif
}
Exemplo n.º 8
0
int main(int argc, char **argv)
{
    char		rawdevpath[MAXPATHLEN];
    char		blockdevpath[MAXPATHLEN];
    char		opt;
    struct stat	sb;
    int			ret = FSUR_INVAL;

    /* save & strip off program name */
    progname = argv[0];
    argc--;
    argv++;

    /* secret debug flag - must be 1st flag */
    debug = (argc > 0 && !strcmp(argv[0], "-D"));
    if (debug) { /* strip off debug flag argument */
        argc--;
        argv++;
    }

    if (argc < 2 || argv[0][0] != '-')
        usage();
    opt = argv[0][1];
    if (opt != FSUC_PROBE && opt != FSUC_MOUNT && opt != FSUC_UNMOUNT && opt != FSUC_LABEL
         && FSUC_GETUUID != opt) {
        usage(); /* Not supported action */
    }
    if ((opt == FSUC_MOUNT || opt == FSUC_UNMOUNT || opt == FSUC_LABEL) && argc < 3)
        usage(); /* mountpoint arg missing! */

    snprintf(rawdevpath, MAXPATHLEN, "%s%s", RAWDEV_PREFIX, argv[1]);
    if (stat(rawdevpath, &sb) != 0) {
        fprintf(stderr, "%s: stat %s failed, %s\n", progname, rawdevpath,
                strerror(errno));
        exit(FSUR_INVAL);
    }

    snprintf(blockdevpath, MAXPATHLEN, "%s%s", BLOCKDEV_PREFIX, argv[1]);
    if (stat(blockdevpath, &sb) != 0) {
        fprintf(stderr, "%s: stat %s failed, %s\n", progname, blockdevpath,
                strerror(errno));
        exit(FSUR_INVAL);
    }

    switch (opt) {
        case FSUC_PROBE: {
            if (argc != 4)
                usage();
            ret = fs_probe(rawdevpath,
                        strcmp(argv[2], DEVICE_FIXED),
                        strcmp(argv[3], DEVICE_READONLY));
            break;
        }

        case FSUC_MOUNT:
        case FSUC_MOUNT_FORCE:
            if (argc != 7)
                usage();
            if (strcmp(argv[3], DEVICE_FIXED) && strcmp(argv[3], DEVICE_REMOVABLE)) {
                printf("ext2fs.util: ERROR: unrecognized flag (removable/fixed) argv[%d]='%s'\n",3,argv[3]);
                usage();
            }
                if (strcmp(argv[4], DEVICE_READONLY) && strcmp(argv[4], DEVICE_WRITABLE)) {
                    printf("ext2fs.util: ERROR: unrecognized flag (readonly/writable) argv[%d]='%s'\n",4,argv[4]);
                    usage();
                }
                if (strcmp(argv[5], DEVICE_SUID) && strcmp(argv[5], DEVICE_NOSUID)) {
                    printf("ext2fs.util: ERROR: unrecognized flag (suid/nosuid) argv[%d]='%s'\n",5,argv[5]);
                    usage();
                }
                if (strcmp(argv[6], DEVICE_DEV) && strcmp(argv[6], DEVICE_NODEV)) {
                    printf("ext2fs.util: ERROR: unrecognized flag (dev/nodev) argv[%d]='%s'\n",6,argv[6]);
                    usage();
                }
                ret = fs_mount(blockdevpath,
                            argv[2],
                            strcmp(argv[3], DEVICE_FIXED),
                            strcmp(argv[4], DEVICE_READONLY),
                            strcmp(argv[5], DEVICE_NOSUID),
                            strcmp(argv[6], DEVICE_NODEV));
            break;
        case FSUC_UNMOUNT:
            ret = fs_unmount(rawdevpath);
            break;
        case FSUC_LABEL:
            if (argc != 3)
               usage();
               
            ret = fs_label(blockdevpath, argv[2]);
            break;
         case FSUC_GETUUID:
            {
               CFStringRef uuid;
               
               if (argc != 2)
                  usage();
               
               ret = FSUR_INVAL;
               uuid = extsuper_uuid(blockdevpath);
               if (uuid) {
                  char pruuid[40];
                  ret = FSUR_IO_SUCCESS;
                  /* Convert to UTF8 */
                  (void) CFStringGetCString(uuid, pruuid, sizeof(pruuid),
                     kCFStringEncodingUTF8);
                  CFRelease(uuid);
                  /* Write to stdout */
                  write(1, pruuid, strlen(pruuid));
               }
            }
            break;
         case FSUC_SETUUID:
            /* This is done at volume creation time */
         case FSUC_ADOPT:
         case FSUC_DISOWN:
         case FSUC_MKJNL:
         case FSUC_UNJNL:
            ret = FSUR_INVAL;
            break;
        default:
            usage();
    }

    #ifdef DEBUG
    report_exit_code(ret);
    #endif
    exit(ret);

    return(ret);
}
Exemplo n.º 9
0
int main (int argc, char **argv) {
	
	srand(time(NULL));
	unsigned char test_data[TEST_DATA_SIZE] = {0};
	unsigned char cmp_test_data[TEST_DATA_SIZE] = {0};
	createRandomData(test_data,TEST_DATA_SIZE);
	memcpy(&cmp_test_data, &test_data,TEST_DATA_SIZE);
	
	int PASSES = 0;

	assert (fs_mount() >= 0);
	assert (fs_create_file("/testDir", DIR_FILE) >= 0);
	assert (fs_unmount() >= 0);

PASS_OK

	assert (fs_mount() >= 0);
	assert (fs_create_file("/testDir", DIR_FILE) >= 0);
	assert (fs_create_file("/testDir/checkMe.txt", REG_FILE) >= 0);
	assert (fs_unmount() >= 0);
	
PASS_OK


	assert (fs_mount() >= 0);
	assert (fs_create_file("/testDir", DIR_FILE) >= 0);
	assert (fs_create_file("/testDir/checkMe.txt", REG_FILE) >= 0);
	assert (fs_write_file("/testDir/checkMe.txt", test_data, TEST_DATA_SIZE) >= 0);
	assert (fs_unmount() >= 0);
	
PASS_OK

	unsigned char readResults[TEST_DATA_SIZE] = {0};
	
	assert (fs_mount() >= 0);
	assert (fs_create_file("/testDir", DIR_FILE) >= 0);
	assert (fs_create_file("/testDir/checkMe.txt", REG_FILE) >= 0);
	assert (fs_write_file("/testDir/checkMe.txt", test_data, TEST_DATA_SIZE) >= 0);
	assert (fs_read_file("/testDir/checkMe.txt", readResults, TEST_DATA_SIZE) >= 0);
	int i = 0;
	for (;i < TEST_DATA_SIZE; ++i) {
		assert(readResults[i] == cmp_test_data[i]);
	}
	assert (fs_unmount() >= 0);
	
PASS_OK
	
	assert (fs_mount() >= 0);
	assert (fs_create_file("/testDir", DIR_FILE) >= 0);
	assert (fs_create_file("/testDir/checkMe.txt", REG_FILE) >= 0);
	assert (fs_create_file("/testDir/secondMe.txt", REG_FILE) >= 0);
	assert (fs_create_file("/testDir/thirdMe.txt", REG_FILE) >= 0);
	
	Directory_t dir;
	assert (fs_get_directory("/testDir/", &dir) >= 0);
	assert (dir.size == 3);
	assert(strncmp(dir.entries[0].filename,"checkMe.txt",strlen("checkMe.txt")) == 0);
	assert(strncmp(dir.entries[1].filename,"secondMe.txt",strlen("secondMe.txt")) == 0);
	assert(strncmp(dir.entries[2].filename,"thirdMe.txt",strlen("thirdMe.txt")) == 0);
	assert (fs_unmount() >= 0);
	
PASS_OK
	/*NEW TEST ADDED */
	assert (fs_mount() >= 0);
	assert (fs_create_file("/testDir", DIR_FILE) >= 0);
	assert (fs_create_file("/testDir/checkMe.txt", REG_FILE) >= 0);
	assert (fs_create_file("/testDir/secondMe.txt", REG_FILE) >= 0);
	assert (fs_create_file("/testDir/thirdMe.txt", REG_FILE) >= 0);
	assert (fs_remove_file("/testDir/thirdMe.txt") >= 0);
	
	assert (fs_get_directory("/testDir/", &dir) >= 0);
	assert (dir.size == 2);
	assert(strncmp(dir.entries[0].filename,"checkMe.txt",strlen("checkMe.txt")) == 0);
	assert(strncmp(dir.entries[1].filename,"secondMe.txt",strlen("secondMe.txt")) == 0);
	assert (fs_unmount() >= 0);
	

	return 0;
}