From: Klaus Strebel <stb@ep-ag.com>
To: Andi Kleen <ak@suse.de>
Cc: linux-lvm@msede.com
Subject: Re: [linux-lvm] Reduced dependecies for /root on lvm
Date: Tue, 01 Feb 2000 17:07:06 +0100 [thread overview]
Message-ID: <389704AA.5696F9C4@ep-ag.com> (raw)
In-Reply-To: 20000131153248.A9022@gruyere.muc.suse.de
[-- Attachment #1: Type: text/plain, Size: 664 bytes --]
Andi Kleen wrote:
>
> On Mon, Jan 31, 2000 at 01:37:05PM +0100, Klaus Strebel wrote:
> > Comments and bugreports are welcome.
>
> I don't think it will work with sub directories. dp->d_type
> is normally DT_UNKNOWN on all Linux systems, libc5 dirent
> does not even have that field. Please use a fstat.
Well, i think your're right. Made i tiny small test proggy. But the new
lvm_rm_rf.c does it (now tested with several dirs including subdirs and
files and s.o.).
Ciao
Klaus
--
Klaus Strebel
stb@ep-ag.com
EIGNER + PARTNER AG - The Engineering Warehouse Company -
<http://www.ep-ag.com>
-----------------------------------------------------------------------
[-- Attachment #2: lvm_rm_rf.c --]
[-- Type: application/octet-stream, Size: 2332 bytes --]
/*
* tools/lib/lvm_rm_rf.c
*
* Copyright (C) 2000 Klaus Strebel, Germany
*
* Janury 2000
*
*
* This LVM library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This LVM 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this LVM library; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA
*
*/
#include <liblvm.h>
#include <dirent.h>
int lvm_rm_rf (char *dirname)
{
DIR *dir_pointer;
struct dirent *dp;
int my_err=0;
char *indirname_buffer; /* Without buffering of parm, the recursion segfaults at the 3. level! */
char *dirname_buffer;
if (dirname != NULL && strlen(dirname) > 0)
{
indirname_buffer = malloc(strlen(dirname)+2);
sprintf(indirname_buffer, "%s%c", dirname, 0);
if (unlink(indirname_buffer) == 0) {
free(indirname_buffer);
return 0;
}
if (errno != EISDIR) {
my_err = errno;
fprintf(stderr, "lvm_rm_rf: ERROR unlinking <%s>:%ld\n", indirname_buffer,my_err);
free(indirname_buffer);
return my_err;
}
dir_pointer = opendir(indirname_buffer);
for (dp = readdir(dir_pointer); dp != NULL;
dp = readdir(dir_pointer)) {
dirname_buffer = malloc(strlen(indirname_buffer)+strlen(dp->d_name)+2);
sprintf(dirname_buffer, "%s/%s%c", indirname_buffer, dp->d_name, 0);
if ((strcmp(dp->d_name, ".") != 0) && (strcmp(dp->d_name, "..") != 0)) {
if (unlink(dirname_buffer) != 0) {
if (errno == EISDIR) {
my_err=lvm_rm_rf (dirname_buffer);
}
else {
my_err=errno;
fprintf(stderr, "lvm_rm_rf: ERROR unlinking <%s>:%ld\n", dirname_buffer,my_err);
}
}
}
free(dirname_buffer);
}
closedir(dir_pointer);
if (my_err == 0)
my_err = rmdir(indirname_buffer);
free(indirname_buffer);
return my_err;
}
return 0;
}
prev parent reply other threads:[~2000-02-01 16:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-01-31 12:37 [linux-lvm] Reduced dependecies for /root on lvm Klaus Strebel
2000-01-31 14:32 ` Andi Kleen
2000-02-01 16:07 ` Klaus Strebel [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=389704AA.5696F9C4@ep-ag.com \
--to=stb@ep-ag.com \
--cc=ak@suse.de \
--cc=linux-lvm@msede.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox