Mercurial > hg > toybox
view toys/mkswap.c @ 551:2548e6e590b2
Add string to mode_t parser
added new function string_to_mode(char *m_string, mode_t base) which
parses a given string and converts it to a mode_t.
If either + or - are part of m_string the permissions are either
added or removed from base.
Currently support for permision copy is missing (e.g. g=u),
but all other flags should work.
Format for m_string: either symbolic modes or octal representation.
symbolic modes:
[auog][[+-=][rwxst]*]
examples:
string_to_mode("u=rwx,g=rw,o=r", 0);
string_to_mode("a-x", 0777);
string_to_mode("0744", 0);
author | Daniel Walter <d.walter@0x90.at> |
---|---|
date | Mon, 19 Mar 2012 19:57:56 -0500 |
parents | d51be130fda2 |
children |
line wrap: on
line source
/* vi: set sw=4 ts=4: * * mkswap.c - Format swap device. * * Copyright 2009 Rob Landley <rob@landley.net> * * Not in SUSv4. USE_MKSWAP(NEWTOY(mkswap, "<1>1", TOYFLAG_SBIN)) config MKSWAP bool "mkswap" default y help usage: mkswap DEVICE Sets up a Linux swap area on a device or file. */ #include "toys.h" void mkswap_main(void) { int fd = xopen(*toys.optargs, O_RDWR), pagesize = sysconf(_SC_PAGE_SIZE); off_t len = fdlength(fd); unsigned int pages = (len/pagesize)-1, *swap = (unsigned int *)toybuf; // Write header. Note that older kernel versions checked signature // on disk (not in cache) during swapon, so sync after writing. swap[0] = 1; swap[1] = pages; xlseek(fd, 1024, SEEK_SET); xwrite(fd, swap, 129*sizeof(unsigned int)); xlseek(fd, pagesize-10, SEEK_SET); xwrite(fd, "SWAPSPACE2", 10); fsync(fd); if (CFG_TOYBOX_FREE) close(fd); printf("Swapspace size: %luk\n", pages*(unsigned long)(pagesize/1024)); }