diff --git a/src/sugar3/Makefile.am b/src/sugar3/Makefile.am index 24630fe9..668691e4 100644 --- a/src/sugar3/Makefile.am +++ b/src/sugar3/Makefile.am @@ -70,6 +70,8 @@ libsugarext_la_SOURCES = \ gsm-session.h \ gsm-xsmp.c \ gsm-xsmp.h \ + sugar-fatattr.c \ + sugar-fatattr.h \ sugar-grid.c \ sugar-grid.h \ sugar-cursor-tracker.c \ @@ -121,6 +123,8 @@ SugarExt_1_0_gir_FILES = \ gsm-session.h \ gsm-xsmp.c \ gsm-xsmp.h \ + sugar-fatattr.c \ + sugar-fatattr.h \ sugar-cursor-tracker.c \ sugar-cursor-tracker.h \ sugar-gesture-grabber.c \ diff --git a/src/sugar3/sugar-fatattr.c b/src/sugar3/sugar-fatattr.c new file mode 100644 index 00000000..40a6ee8d --- /dev/null +++ b/src/sugar3/sugar-fatattr.c @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2013, Walter Bender + * Copyright (C) 2009 Aaron Stone + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +// Gives us O_NOATIME +#define _GNU_SOURCE + +#include +#include +#include +#include + +#include + +#include +#include + +// This function is wrapped by getattrs/setattrs +static int _ioctl_attrs(char *file, __u32 *attrs, int ioctlnum, char *verb) +{ + int fd; + + // Interesting, we don't need a read-write handle to call the SET ioctl. + fd = open(file, O_RDONLY | O_NOATIME); + if (fd < 0) { + fprintf(stderr, "Error opening '%s': %s\n", file, strerror(errno)); + goto err; + } + + if (ioctl(fd, ioctlnum, attrs) != 0) { + fprintf(stderr, "Error %s attributes: %s\n", verb, strerror(errno)); + goto err; + } + + close (fd); + return 0; + + err: + close (fd); + return -1; +} + +static int getattrs(char *file, __u32 *attrs) +{ + return _ioctl_attrs(file, attrs, FAT_IOCTL_GET_ATTRIBUTES, "reading"); +} + +static int setattrs(char *file, __u32 *attrs) +{ + return _ioctl_attrs(file, attrs, FAT_IOCTL_SET_ATTRIBUTES, "writing"); +} + +static int set_hidden_attrib(char *pathname) +{ + __u32 attrs = 0; + char *file = NULL; + + file = pathname; + if (getattrs(file, &attrs) == 0) { + attrs |= ATTR_HIDDEN; + setattrs(file, &attrs); + return 0; + } + + return -1; +} + +/** + * Set the FAT HIDDEN attribute. + * + * sugar_fat_set_hidden_attrib: + * @const char: (file utf8) + */ +gboolean sugar_fat_set_hidden_attrib(const char *file) +{ + if (set_hidden_attrib(file) == 0) { + return TRUE; + } + return FALSE; +} diff --git a/src/sugar3/sugar-fatattr.h b/src/sugar3/sugar-fatattr.h new file mode 100644 index 00000000..3cbf6431 --- /dev/null +++ b/src/sugar3/sugar-fatattr.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2013, Walter Bender + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __SUGAR_FATATTR_H__ +#define __SUGAR_FATATTR_H__ + +G_BEGIN_DECLS + +gboolean sugar_fat_set_hidden_attrib(const char *file); + +G_END_DECLS + +#endif /* __SUGAR_FATATTR_H__ */