Example #1
0
int main(int argc, char **argv)
{
    int ret = EXIT_SUCCESS, result;

    /* Verify command-line arguments. */
    if (argc < 2)
    {
	printf("usage: %s FILE1 FILE2 ...\r\n",
		argv[0]);
	return EXIT_FAILURE;
    }
    refreshMounts(0);

    /* Touch all given files. */
    for (int i = 0; i < argc - 1; i++)
    {
	/* Perform touch. */
	result = touch(argv[0], argv[i + 1]);

	/* Update exit code if needed. */
	if (result > ret)
	{
	    ret = result;
	}
    }
    /* Done. */
    return ret;
}
Example #2
0
void refreshMounts(const char *path)
{
    char tmp[PATH_MAX], number[16];
    int fd;
    struct dirent *dent;
    DIR *d;
    pid_t pid = getpid();

    // Skip for rootfs and mountfs
    if (pid == ROOTFS_PID || pid == MOUNTFS_PID)
        return;

    // Clear mounts table
    if (!path)
    {
        path = "/mount";
        MemoryBlock::set(&mounts[2], 0, sizeof(FileSystemMount) * (FILESYSTEM_MAXMOUNTS-2));
    }

    // Attempt to open the directory
    if (!(d = opendir(path)))
        return;

    // walk the /mounts recursively and refill the mounts table (starting from index 2)
    while ((dent = readdir(d)))
    {
        snprintf(tmp, sizeof(tmp), "/mount/%s", dent->d_name);

        switch (dent->d_type)
        {
            case DT_DIR:
                if (dent->d_name[0] != '.')
                    refreshMounts(tmp);
                break;

            case DT_REG:
                fd = open(tmp, O_RDONLY);
                if (fd >= 0)
                {
                    MemoryBlock::set(number, 0, sizeof(number));

                    if (read(fd, number, sizeof(number)) > 0)
                    {
                        pid_t pid = atoi(number);

                        // Append to the mounts table
                        for (Size i = 0; i < FILESYSTEM_MAXMOUNTS; i++)
                        {
                            if (!mounts[i].path[0])
                            {
                                mounts[i].procID = pid;
                                strlcpy(mounts[i].path, tmp+6, PATH_MAX);
                                break;
                            }
                        }
                    }
                    close(fd);
                }
                break;

            default:
                break;
        }
    }
    closedir(d);
}